Ignore:
Timestamp:
06/28/13 11:56:03 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • FramsClass? and contained Param are now immutable classes (like String),

which allows to refer to them concurrently without synchronization
(which for example in turn simplifies GUI management)

  • also make Path immutable (which was earlier only assumed)
  • add global cache for FramsClasses? created solely and automatically

on base of Java classes.

representations basing on given FramsClass?

  • above changes greatly improved GUI responsivness during browsing
  • furtherly improve Param class hierarchy
  • allow to inject actions on state changes into MultiParamLoader?
  • add more tests

CHANGELOG:

Add StatusListener? to MultiParamLoader?.

Minor refactorization in MultiParamLoader?.

First step with auto append.

Add SchemaTest?.

Improve Registry.

Clean up in Registry.

Work out Registry.

Use annotations for Param.

Fix ListChange?.

Improve fluent interface of the FramsClassBuilder?.

Done caching of ReflectionAccess?.Backend

Fix hashCode of Pair.

A step on a way to cache ReflectionAccess?.Backend

Make SimpleAbstractAccess?.framsClass a final field.

Add static cache for FramsClasses? based on java.

Only classes created strictly and automatically
based on java classes are using this cache.

Make all Params immutable.

Many improvement to make Param immutable.

Make PrimitiveParam? generic type.

Several changes to make Param immutable.

Make FramsClass? immutable.

Another improvement to Path immutability.

Several improvements to Path.

Improve PathTest?.

Configurarable MutabilityDetector?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/core/Path.java

    r85 r87  
    1111
    1212import javax.annotation.concurrent.Immutable;
    13 import javax.annotation.Nonnull;
    1413
    1514import org.apache.commons.collections.ListUtils;
     
    1918 */
    2019@Immutable
    21 public class Path {
     20public final class Path {
    2221        // private final static Logger log = Logger.getLogger(Path.class.getName());
    2322
    24         final LinkedList<Node> nodes = new LinkedList<Node>();
    25         String textual;
    26         Instance instance;
    27 
    28         protected Object getKnownChild(AccessInterface access, CompositeParam param) {
     23        final Instance instance;
     24        final String textual;
     25        final LinkedList<Node> nodes;
     26
     27        protected static Object getKnownChild(Instance instance, AccessInterface access, CompositeParam param) {
    2928                Object child = access.get(param, Object.class);
    3029                if (child == null) {
     
    3433        }
    3534
    36         // public Path constructPath(Instance instance, String textual) {
    37         //      assert instance.isActive();
    38 
    39         // }
    40 
    41         Path(Instance instance, String textual) {
    42                 assert instance.isActive();
     35        /**
     36         * @param instance
     37         * @param textual
     38         * @param nodes
     39         */
     40        Path(Instance instance, String textual, LinkedList<Node> nodes) {
    4341                this.instance = instance;
    44 
    45                 nodes.add(instance.root);
    46                 Node current = instance.root;
    47 
    48                 StringBuilder b = new StringBuilder();
    49                 Iterator<String> i = Instance.splitPath(textual);
    50                 while (i.hasNext() && current.getObject() != null) {
    51                         AccessInterface access = instance.registry.prepareAccess(current.getParam());
    52                         if (access == null) {
    53                                 break;
    54                         }
    55                         String e = i.next();
    56                         Param p = access.getParam(e);
    57                         if (!(p instanceof CompositeParam)) {
    58                                 //entries.add(new Entry());
    59                                 break;
    60                         }
    61                         CompositeParam c = (CompositeParam)p;
    62                         b.append("/").append(e);
    63                         access.select(current.getObject());
    64                         current = new Node(c, getKnownChild(access, c));
    65                         nodes.add(current);
    66                 }
    67                 this.textual = (size() == 1) ? "/" : b.toString();
    68         }
    69 
    70         public Path(@Nonnull Instance instance, List<Node> nodes, Node node) {
    71                 this.instance = instance;
    72                 StringBuilder b = new StringBuilder();
    73                 boolean add = false;
    74                 for (Node n : nodes) {
    75                         this.nodes.add(n);
    76                         if (add) {
    77                                 b.append("/").append(n.getParam().getId());
    78                         }
    79                         add = true;
    80                         if (n == node) {
    81                                 break;
    82                         }
    83                 }
    84                 this.textual = (size() == 1) ? "/" : b.toString();
    85         }
    86 
    87         protected Path() {
    88 
     42                this.textual = textual;
     43                this.nodes = nodes;
    8944        }
    9045
    9146        public Path appendNode(Node node) {
    9247                assert isResolved();
    93                 Path result = new Path();
    94                 result.textual = textual + ((size() == 1) ? "" : "/") + node.getParam().getId();
    95                 result.instance = instance;
    96                 result.nodes.addAll(nodes);
    97                 result.nodes.add(node);
    98                 return result;
     48                return new PathBuilder().instance(instance).textual(textual + ((size() == 1) ? "" : "/") + node.getParam().getId()).add(nodes).add(node).finish();
    9949        }
    10050
     
    10454        }
    10555
     56        public static class PathBuilder {
     57
     58                Instance instance;
     59                String textual;
     60                final LinkedList<Node> nodes = new LinkedList<Node>();
     61
     62                public Path finish() {
     63                        assert instance != null;
     64                        assert textual != null;
     65                        return new Path(instance, textual, nodes);
     66                }
     67
     68                public PathBuilder()
     69                {
     70                }
     71
     72                public PathBuilder instance(Instance instance) {
     73                        this.instance = instance;
     74                        return this;
     75                }
     76
     77                public PathBuilder textual(String textual) {
     78                        this.textual = textual;
     79                        return this;
     80                }
     81
     82                public PathBuilder add(List<Node> nodes) {
     83                        this.nodes.addAll(nodes);
     84                        return this;
     85                }
     86
     87                public PathBuilder add(Node node) {
     88                        this.nodes.add(node);
     89                        return this;
     90                }
     91
     92                public PathBuilder setLast(Object object) {
     93                        Node n = nodes.pollLast();
     94                        nodes.add(new Node(n.getParam(), object));
     95                        return this;
     96                }
     97
     98                public PathBuilder buildUpTo(List<Node> nodes, Node node) {
     99                        StringBuilder b = new StringBuilder();
     100                        boolean add = false;
     101                        for (Node n : nodes) {
     102                                this.nodes.add(n);
     103                                if (add) {
     104                                        b.append("/").append(n.getParam().getId());
     105                                }
     106                                add = true;
     107                                if (n == node) {
     108                                        break;
     109                                }
     110                        }
     111                        this.textual = (nodes.size() == 1) ? "/" : b.toString();
     112                        return this;
     113                }
     114
     115                public PathBuilder resolve(Instance instance, String textual) {
     116
     117                        assert nodes.isEmpty();
     118                        assert instance.isActive();
     119                        this.instance = instance;
     120
     121                        nodes.add(instance.root);
     122                        Node current = instance.root;
     123
     124                        StringBuilder b = new StringBuilder();
     125                        Iterator<String> i = Instance.splitPath(textual);
     126                        while (i.hasNext() && current.getObject() != null) {
     127                                AccessInterface access = instance.registry.prepareAccess(current.getParam());
     128                                if (access == null) {
     129                                        break;
     130                                }
     131                                String e = i.next();
     132                                Param p = access.getParam(e);
     133                                if (!(p instanceof CompositeParam)) {
     134                                        //entries.add(new Entry());
     135                                        break;
     136                                }
     137                                CompositeParam c = (CompositeParam)p;
     138                                b.append("/").append(e);
     139                                access.select(current.getObject());
     140                                current = new Node(c, getKnownChild(instance, access, c));
     141                                nodes.add(current);
     142                        }
     143                        this.textual = (nodes.size() == 1) ? "/" : b.toString();
     144
     145                        return this;
     146                }
     147        }
     148
     149        public static PathBuilder build() {
     150                return new PathBuilder();
     151        }
     152
    106153        public Path appendResolution(Object object) {
    107154                assert !isResolved();
    108                 Path result = new Path();
    109                 result.textual = textual;
    110                 result.instance = instance;
    111                 result.nodes.addAll(nodes);
    112                 result.nodes.add(new Node(result.nodes.pollLast().getParam(), object));
     155                Path result = new PathBuilder().textual(textual).instance(instance).add(nodes).setLast(object).finish();
     156                assert size() == result.size();
    113157                return result;
    114158        }
     
    169213                assert !isResolved();
    170214                if (size() == 1) {
    171                         return new Path(instance, "/");//appendResolution(instance.root.object);
    172                 }
    173                 Object child = getKnownChild(instance.bindAccess(getUnder()), getTop().getParam());
     215                        return Path.build().resolve(instance, "/").finish();//appendResolution(instance.root.object);
     216                }
     217                Object child = getKnownChild(instance, instance.bindAccess(getUnder()), getTop().getParam());
    174218                if (child == null) {
    175219                        return this;
     
    201245        }
    202246
    203         public void setInstance(Instance instance) {
    204                 this.instance = instance;
    205         }
     247        // public void setInstance(Instance instance) {
     248        //      this.instance = instance;
     249        // }
    206250
    207251        @SuppressWarnings("unchecked")
Note: See TracChangeset for help on using the changeset viewer.