- Timestamp:
- 07/14/13 23:20:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/core/TreeOperations.java
r100 r101 1 1 package com.framsticks.core; 2 3 2 4 3 import java.util.HashSet; … … 22 21 import com.framsticks.params.PropertiesAccess; 23 22 import com.framsticks.params.UniqueListAccess; 24 import com.framsticks.params. Util;23 import com.framsticks.params.ParamsUtil; 25 24 import com.framsticks.params.types.EventParam; 26 25 import com.framsticks.params.types.ObjectParam; … … 43 42 } 44 43 45 public static final Object FETCHED_MARK = new Object(); 46 47 public static @Nonnull FramsClass processFetchedInfo(Tree tree, File file) { 44 public static final SideNoteKey<Boolean> FETCHED_MARK = SideNoteKey.make(Boolean.class); 45 46 public static @Nonnull 47 FramsClass processFetchedInfo(Tree tree, File file) { 48 48 assert tree.isActive(); 49 49 FramsClass framsClass = Loaders.loadFramsClass(file.getContent()); … … 80 80 assert path.isTheSame(files.get(0).getPath()); 81 81 82 83 82 try { 84 83 log.debug("process fetched values: {}", path); … … 98 97 if (path.getTop().getParam() instanceof ObjectParam) { 99 98 assert results.size() == 1; 100 Util.takeAllNonNullValues(bindAccess(result), parsingAccess.select(results.get(0)));99 ParamsUtil.takeAllNonNullValues(bindAccess(result), parsingAccess.select(results.get(0))); 101 100 mark(result.getTree(), result.getTopObject(), FETCHED_MARK, true); 102 101 future.pass(result); 103 102 return; 104 103 } 105 106 104 107 105 final ListAccess listAccess = (ListAccess) access; … … 139 137 140 138 targetAccess.select(childTo); 141 Util.takeAllNonNullValues(targetAccess, parsingAccess);139 ParamsUtil.takeAllNonNullValues(targetAccess, parsingAccess); 142 140 if (newOne) { 143 141 listAccess.set(id, childTo); … … 188 186 } 189 187 190 191 public static @NonnullAccess bindAccessFromSideNote(Tree tree, Object object) {192 CompositeParam param = tree.getSideNote(object, CompositeParam.class, CompositeParam.class);188 public static @Nonnull 189 Access bindAccessFromSideNote(Tree tree, Object object) { 190 CompositeParam param = tree.getSideNote(object, Path.OBJECT_PARAM_KEY); 193 191 if (param == null) { 194 192 throw new FramsticksException().msg("failed to bind access from side node").arg("tree", tree).arg("object", object).arg("type", object.getClass()); … … 197 195 } 198 196 199 public static @Nonnull Access bindAccess(Tree tree, String path) { 197 public static @Nonnull 198 Access bindAccess(Tree tree, String path) { 200 199 log.debug("bind access for textual: {} in {}", path, tree); 201 200 return bindAccess(Path.to(tree, path)); 202 201 } 203 202 204 public static @Nonnull Access bindAccess(Node node) { 203 public static @Nonnull 204 Access bindAccess(Node node) { 205 205 Tree tree = node.getTree(); 206 206 assert tree.isActive(); … … 209 209 try { 210 210 Access access = tree.prepareAccess(node.getParam()); 211 tree.putSideNote(node.getObject(), CompositeParam.class, node.getParam());211 tree.putSideNote(node.getObject(), Path.OBJECT_PARAM_KEY, node.getParam()); 212 212 213 213 return access.select(node.getObject()); … … 218 218 } 219 219 220 public static @Nonnull Access bindAccess(Path path) { 220 public static @Nonnull 221 Access bindAccess(Path path) { 221 222 assert path.getTree().isActive(); 222 223 path.assureResolved(); … … 280 281 }); 281 282 } 282 283 283 284 284 /** … … 323 323 public static Object createAccessee(Tree tree, CompositeParam param) { 324 324 Object object = tree.prepareAccess(param).createAccessee(); 325 tree.putSideNote(object, CompositeParam.class, param);325 tree.putSideNote(object, Path.OBJECT_PARAM_KEY, param); 326 326 return object; 327 327 } … … 329 329 public static Object createAccessee(Tree tree, Access access) { 330 330 Object object = access.createAccessee(); 331 tree.putSideNote(object, CompositeParam.class, access.buildParam(new ParamBuilder()).finish(CompositeParam.class));331 tree.putSideNote(object, Path.OBJECT_PARAM_KEY, access.buildParam(new ParamBuilder()).finish(CompositeParam.class)); 332 332 return object; 333 333 } 334 334 335 public static boolean isMarked(Tree tree, Object object, Objectmark, boolean defValue) {336 assert tree.isActive(); 337 Boolean v = tree.getSideNote(object, mark , Boolean.class);335 public static boolean isMarked(Tree tree, Object object, SideNoteKey<Boolean> mark, boolean defValue) { 336 assert tree.isActive(); 337 Boolean v = tree.getSideNote(object, mark); 338 338 return (v != null ? v : defValue); 339 339 } 340 340 341 public static void mark(Tree tree, Object object, Objectmark, boolean value) {341 public static void mark(Tree tree, Object object, SideNoteKey<Boolean> mark, boolean value) { 342 342 assert tree.isActive(); 343 343 tree.putSideNote(object, mark, value); … … 348 348 } 349 349 350 public static <T extends Param> T getParam(Path path, String id, Class<T> type) { 351 return getFramsClass(path).getParamEntry(id, type); 352 } 353 354 public static <T> T getOrCreateSideNote(Tree tree, Object object, SideNoteKey<T> key) { 355 T result = tree.getSideNote(object, key); 356 if (result == null) { 357 result = key.newValue(); 358 tree.putSideNote(object, key, result); 359 } 360 return result; 361 } 362 363 public static <T> boolean hasSideNotes(Tree tree, Object object, SideNoteKey<T> key) { 364 return tree.getSideNote(object, key) != null; 365 } 366 367 public static <T> boolean hasSideNote(Path path, SideNoteKey<T> key) { 368 return path.getTree().getSideNote(path.getTopObject(), key) != null; 369 } 370 371 public static <T> T getSideNote(Path path, SideNoteKey<T> key) { 372 assert path.isResolved(); 373 return path.getTree().getSideNote(path.getTopObject(), key); 374 } 375 376 public static <T> void putSideNote(Path path, SideNoteKey<T> key, T value) { 377 path.getTree().putSideNote(path.getTopObject(), key, value); 378 } 379 380 public static boolean removeSideNote(Path path, SideNoteKey<?> key) { 381 assert path.isResolved(); 382 return path.getTree().removeSideNote(path.getTopObject(), key); 383 } 384 350 385 }
Note: See TracChangeset
for help on using the changeset viewer.