/** * Returns a child builder of a pre-existing child. * @param childPath the path to the child * @return the child builder or null */ public ChildBuilder<This> getChild(Path.Segment childPath) { Map<EntityType, Set<FullNode>> myChildren = children.get(myPath); if (myChildren == null) { return null; } EntityType childType = EntityType.of(childPath.getElementType()); Set<FullNode> childrenOfType = myChildren.get(childType); return childrenOfType.stream().filter(child -> child.getEntity().getId().equals(childPath.getElementId())) .findAny().map(child -> { RelativePath rp = myPath.modified().extend(childPath).get(); return new ChildBuilder<>(castThis(), rp, blueprints, children); }).orElse(null); }
@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); }
/** * 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); }
/** * 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); }
/** * Returns a child builder of a pre-existing child. * @param childPath the path to the child * @return the child builder or null */ public ChildBuilder<This> getChild(Path.Segment childPath) { Map<EntityType, Set<FullNode>> myChildren = children.get(myPath); if (myChildren == null) { return null; } EntityType childType = EntityType.of(childPath.getElementType()); Set<FullNode> childrenOfType = myChildren.get(childType); return childrenOfType.stream().filter(child -> child.getEntity().getId().equals(childPath.getElementId())) .findAny().map(child -> { RelativePath rp = myPath.modified().extend(childPath).get(); return new ChildBuilder<>(castThis(), rp, blueprints, children); }).orElse(null); }
public This addChild(Entity.Blueprint child, Object attachment) { startChild(child, attachment).end(); return castThis(); } public This addChild(InventoryStructure<?> structure, boolean overwrite) {
public This removeChild(Path.Segment childPath) { ChildBuilder<This> childBuilder = getChild(childPath); if (childBuilder != null) { childBuilder.remove(); } return castThis(); }
public This addChild(Entity.Blueprint child, Object attachment) { startChild(child, attachment).end(); return castThis(); }
/** * Removes this child from the structure. * @return the parent builder */ public ParentBuilder remove() { removeAllChildren(); Set<FullNode> siblings = getSiblings(); FullNode myBlueprint = blueprints.remove(myPath); siblings.remove(myBlueprint); return parentBuilder; }
/** * Removes this child from the structure. * @return the parent builder */ public ParentBuilder remove() { removeAllChildren(); Set<FullNode> siblings = getSiblings(); FullNode myBlueprint = blueprints.remove(myPath); siblings.remove(myBlueprint); return parentBuilder; }
public This removeChild(Path.Segment childPath) { ChildBuilder<This> childBuilder = getChild(childPath); if (childBuilder != null) { childBuilder.remove(); } return castThis(); }
@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); }