private Entity.Update updateFromBlueprint(Blueprint blueprint) { return blueprint.accept(new ElementBlueprintVisitor.Simple<Entity.Update, Void>() { @Override public DataEntity.Update visitData(DataEntity.Blueprint<?> data, Void parameter) { return fillCommon(DataEntity.Update.builder(), data).withValue(data.getValue()).build();
private Set<FullNode> getSiblings() { FullNode myBlueprint = blueprints.get(myPath); Map<EntityType, Set<FullNode>> siblingsByType = children.get(parentBuilder.myPath); EntityType myType = EntityType.of(Blueprint.getEntityTypeOf(myBlueprint.getEntity())); return siblingsByType.get(myType); } }
public Set<Path.Segment> getChildrenPaths() { Map<EntityType, Set<FullNode>> myChildren = children.get(myPath); if (myChildren == null) { return Collections.emptySet(); } return myChildren.values().stream().flatMap(Collection::stream) .map(b -> new Path.Segment(Blueprint.getSegmentTypeOf(b.getEntity()), b.getEntity().getId())) .collect(Collectors.toSet()); }
/** * Starts building a new child of the currently built entity. * * @param child the child entity blueprint * @param childAttachment the attachment to store along with the child * @return a new child builder * @throws IllegalArgumentException if the provided child cannot be contained in the currently built entity * (i.e. a resource type cannot be contained in a resource for example). */ public ChildBuilder<This> startChild(Entity.Blueprint child, Object childAttachment) { RelativePath.Extender extender = myPath.modified(); Class<? extends AbstractElement> childType = Blueprint.getEntityTypeOf(child); SegmentType childSeg = Blueprint.getSegmentTypeOf(child); if (!extender.canExtendTo(childSeg)) { throw new IllegalArgumentException("Cannot extend path " + myPath + " with child of type " + childType); } RelativePath childPath = extender.extend(childSeg, child.getId()).get(); Set<FullNode> bls = getChildrenOfType(EntityType.of(childType)); FullNode node = new FullNode(child, childAttachment); bls.add(node); blueprints.put(childPath, node); return new ChildBuilder<>(castThis(), childPath, blueprints, children); }
acs = s.collect(Collectors.toList()); acs.forEach(b -> ElementTypeVisitor.accept(Blueprint.getSegmentTypeOf(b), visitor, empty.modified())); EntityType entityType = EntityType.of(Blueprint.getEntityTypeOf(entity.getEntity()));
/** * Starts building a new child of the currently built entity. * * @param child the child entity blueprint * @param childAttachment the attachment to store along with the child * @return a new child builder * @throws IllegalArgumentException if the provided child cannot be contained in the currently built entity * (i.e. a resource type cannot be contained in a resource for example). */ public ChildBuilder<This> startChild(Entity.Blueprint child, Object childAttachment) { RelativePath.Extender extender = myPath.modified(); Class<? extends AbstractElement<?, ?>> childType = Blueprint.getEntityTypeOf(child); SegmentType childSeg = Blueprint.getSegmentTypeOf(child); if (!extender.canExtendTo(childSeg)) { throw new IllegalArgumentException("Cannot extend path " + myPath + " with child of type " + childType); } RelativePath childPath = extender.extend(childSeg, child.getId()).get(); Set<FullNode> bls = getChildrenOfType(EntityType.of(childType)); FullNode node = new FullNode(child, childAttachment); bls.add(node); blueprints.put(childPath, node); return new ChildBuilder<>(castThis(), childPath, blueprints, children); }
public Set<Path.Segment> getChildrenPaths() { Map<EntityType, Set<FullNode>> myChildren = children.get(myPath); if (myChildren == null) { return Collections.emptySet(); } return myChildren.values().stream().flatMap(Collection::stream) .map(b -> new Path.Segment(Blueprint.getSegmentTypeOf(b.getEntity()), b.getEntity().getId())) .collect(Collectors.toSet()); }
@Override public Element persist(CanonicalPath path, Blueprint blueprint) { return blueprint.accept(new ElementBlueprintVisitor<Element, Void>() {
private Set<FullNode> getSiblings() { FullNode myBlueprint = blueprints.get(myPath); Map<EntityType, Set<FullNode>> siblingsByType = children.get(parentBuilder.myPath); EntityType myType = EntityType.of(Blueprint.getEntityTypeOf(myBlueprint.getEntity())); return siblingsByType.get(myType); } }
acs = s.collect(Collectors.toList()); acs.forEach(b -> ElementTypeVisitor.accept(Blueprint.getSegmentTypeOf(b), visitor, empty.modified())); EntityType entityType = EntityType.of(Blueprint.getEntityTypeOf(entity.getEntity()));
@Override void doReplace(Entity.Blueprint blueprint, Object attachment) { Set<FullNode> siblings = getSiblings(); FullNode myBlueprint = blueprints.remove(myPath); siblings.remove(myBlueprint); FullNode myNode = new FullNode(blueprint, attachment); siblings.add(myNode); children.remove(myPath); myPath = parentBuilder.myPath.modified().extend(Blueprint.getSegmentTypeOf(blueprint), blueprint.getId()) .get(); blueprints.put(myPath, myNode); }
boolean computeSync = compSync && syncable; return entity.accept(new ElementBlueprintVisitor.Simple<IntermediateHashResult, IntermediateHashContext>() { @Override public IntermediateHashResult visitData(DataEntity.Blueprint<?> data, IntermediateHashContext ctx) {
@Override void doReplace(Entity.Blueprint blueprint, Object attachment) { Set<FullNode> siblings = getSiblings(); FullNode myBlueprint = blueprints.remove(myPath); siblings.remove(myBlueprint); FullNode myNode = new FullNode(blueprint, attachment); siblings.add(myNode); children.remove(myPath); myPath = parentBuilder.myPath.modified().extend(Blueprint.getSegmentTypeOf(blueprint), blueprint.getId()) .get(); blueprints.put(myPath, myNode); }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
/** * Returns all direct children of the specified parent. * * <b>WARNING</b>: the returned stream MUST BE closed after processing. * * @param parent the parent of which to return the children * @return the stream of all children of the parent */ @SuppressWarnings({"unchecked", "rawtypes"}) default Stream<FullNode> getAllChildNodes(RelativePath parent) { Stream<FullNode> ret = Stream.empty(); RelativePath.Extender check = RelativePath.empty() .extend(Blueprint.getSegmentTypeOf(getRoot()),getRoot().getId()) .extend(parent.getPath()); for (EntityType et : EntityType.values()) { SegmentType st = et.segmentType; if (check.canExtendTo(st)) { List<FullNode> res; Class entityType = Entity.entityTypeFromSegmentType(st); try (Stream<FullNode> next = (Stream<FullNode>) getChildNodes(parent, entityType)) { res = next.collect(Collectors.toList()); } ret = Stream.concat(ret, res.stream()); } } return ret; }
IntermediateHashContext progress(Entity.Blueprint bl) { SegmentType st = Blueprint.getSegmentTypeOf(bl); String id = bl.getId(); return new IntermediateHashContext(origin == null ? null : origin.modified().extend(st, id).get(), root.modified().extend(st, id).get()); } }