Changeset 97 for java/main/src/main/java/com/framsticks/core/Path.java
- Timestamp:
- 07/06/13 03:51:11 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/core/Path.java
r96 r97 23 23 // private final static Logger log = Logger.getLogger(Path.class.getName()); 24 24 25 final Instance instance;25 final Tree tree; 26 26 final String textual; 27 27 final LinkedList<Node> nodes; 28 28 29 protected static Object getKnownChild( Instance instance, AccessInterface access, CompositeParam param) {29 protected static Object getKnownChild(Tree tree, AccessInterface access, CompositeParam param) { 30 30 Object child = access.get(param, Object.class); 31 31 if (child == null) { … … 33 33 } 34 34 try { 35 instance.prepareAccess(param);35 tree.prepareAccess(param); 36 36 return child; 37 37 } catch (FramsticksException e) { … … 41 41 42 42 /** 43 * @param instance43 * @param tree 44 44 * @param textual 45 45 * @param nodes 46 46 */ 47 Path( Instance instance, String textual, LinkedList<Node> nodes) {48 this. instance = instance;47 Path(Tree tree, String textual, LinkedList<Node> nodes) { 48 this.tree = tree; 49 49 this.textual = textual; 50 50 this.nodes = nodes; … … 53 53 public Path appendNode(Node node) { 54 54 assert isResolved(); 55 return new PathBuilder(). instance(instance).textual(textual + ((size() == 1) ? "" : "/") + node.getParam().getId()).add(nodes).add(node).finish();55 return new PathBuilder().tree(tree).textual(textual + ((size() == 1) ? "" : "/") + node.getParam().getId()).add(nodes).add(node).finish(); 56 56 } 57 57 … … 63 63 public static class PathBuilder { 64 64 65 Instance instance;65 Tree tree; 66 66 String textual; 67 67 final LinkedList<Node> nodes = new LinkedList<Node>(); 68 68 69 69 public Path finish() { 70 assert instance != null;70 assert tree != null; 71 71 assert textual != null; 72 return new Path( instance, textual, nodes);72 return new Path(tree, textual, nodes); 73 73 } 74 74 … … 77 77 } 78 78 79 public PathBuilder instance(Instance instance) {80 this. instance = instance;79 public PathBuilder tree(Tree tree) { 80 this.tree = tree; 81 81 return this; 82 82 } … … 130 130 } 131 131 132 public PathBuilder resolve(@Nonnull Instance instance, String textual) {132 public PathBuilder resolve(@Nonnull Tree tree, String textual) { 133 133 134 134 assert nodes.isEmpty(); 135 assert instance.isActive();136 this. instance = instance;137 138 nodes.add( instance.getRoot());139 Node current = instance.getRoot();135 assert tree.isActive(); 136 this.tree = tree; 137 138 nodes.add(tree.getRoot()); 139 Node current = tree.getRoot(); 140 140 141 141 StringBuilder b = new StringBuilder(); 142 142 Iterator<String> i = splitPath(textual); 143 143 while (i.hasNext() && current.getObject() != null) { 144 AccessInterface access = instance.prepareAccess(current.getParam());144 AccessInterface access = tree.prepareAccess(current.getParam()); 145 145 if (access == null) { 146 146 break; … … 155 155 b.append("/").append(e); 156 156 access.select(current.getObject()); 157 current = new Node(c, getKnownChild( instance, access, c));157 current = new Node(c, getKnownChild(tree, access, c)); 158 158 nodes.add(current); 159 159 } … … 170 170 public Path appendResolution(Object object) { 171 171 assert !isResolved(); 172 Path result = new PathBuilder().textual(textual). instance(instance).add(nodes).setLast(object).finish();172 Path result = new PathBuilder().textual(textual).tree(tree).add(nodes).setLast(object).finish(); 173 173 assert size() == result.size(); 174 174 return result; … … 193 193 194 194 public String toString() { 195 return instance + textual + (!isResolved() ? "!" : ""); 195 return tree + textual + (!isResolved() ? "!" : ""); 196 } 197 198 public String getFullTextual() { 199 return tree.getName() + textual; 196 200 } 197 201 … … 216 220 } 217 221 218 public final @Nonnull Instance getInstance() {219 assert Dispatching.isThreadSafe(); 220 return instance;222 public final @Nonnull Tree getTree() { 223 assert Dispatching.isThreadSafe(); 224 return tree; 221 225 } 222 226 … … 233 237 */ 234 238 public Path tryFindResolution() { 235 assert instance.isActive();239 assert tree.isActive(); 236 240 assert !isResolved(); 237 241 if (size() == 1) { 238 return Path.build().resolve( instance, "/").finish();//appendResolution(instance.root.object);239 } 240 Object child = getKnownChild( instance, InstanceUtils.bindAccess(instance, getUnder()), getTop().getParam());242 return Path.build().resolve(tree, "/").finish(); 243 } 244 Object child = getKnownChild(tree, TreeOperations.bindAccess(tree, getUnder()), getTop().getParam()); 241 245 if (child == null) { 242 246 return this; … … 247 251 public boolean matches(Path p) { 248 252 assert Dispatching.isThreadSafe(); 249 assert instance == p.instance;253 assert tree == p.tree; 250 254 Iterator<Node> a = nodes.iterator(); 251 255 Iterator<Node> b = p.nodes.iterator(); … … 264 268 } 265 269 266 public final boolean isOwner(Instance instance) { 267 return this.instance == instance; 268 } 269 270 // public void setInstance(Instance instance) { 271 // this.instance = instance; 272 // } 270 public final boolean isOwner(Tree tree) { 271 return this.tree == tree; 272 } 273 273 274 274 @SuppressWarnings("unchecked") … … 284 284 } 285 285 286 public static Path to(@Nonnull Instance instance, String textual) {287 return Path.build().resolve( instance, textual).finish();286 public static Path to(@Nonnull Tree tree, String textual) { 287 return Path.build().resolve(tree, textual).finish(); 288 288 } 289 289 }
Note: See TracChangeset
for help on using the changeset viewer.