@Override public List<MetricType.Blueprint> getMetricTypes() { try (Stream<MetricType.Blueprint> s = structure.getChildren(RelativePath.empty().get(), MetricType.class)) { return s.collect(toList()); } }
if (!structureRoot.equals(structurePath) && !structureRoot.isParentOf(structurePath)) { continue; RelativePath strippedStructurePath = structurePath.slide(structureRoot.getDepth(), 0); RelativePath newStructurePath = myPath.modified().extend(strippedStructurePath.getPath()).get(); RelativePath parentPath = newStructurePath.up(); Map<EntityType, Set<FullNode>> parentChildren = children.get(parentPath); if (parentChildren == null) { EntityType structureType = EntityType.of(newStructurePath.getSegment().getElementType());
@Override public int hashCode() { return dataPath.hashCode(); } }
private static InventoryStructure.AbstractBuilder<?> findStructParent(List<? extends InventoryStructure.AbstractBuilder<?>> possibleParents, RelativePath childPath) { return possibleParents.stream() .filter(p -> p.getPath().isParentOf(childPath) && p.getPath().getDepth() == childPath.getDepth() - 1) .findAny() .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); }
/** * 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; }
ProcessingTree<BE> getChild(RelativePath childPath) { Iterator<Path.Segment> segments = childPath.getPath().iterator(); Set<ProcessingTree<BE>> children = this.children; ProcessingTree<BE> current = null; while (segments.hasNext()) { Path.Segment seg = segments.next(); current = null; for (ProcessingTree<BE> c : children) { //children are bound to each have a different ending segment, otherwise their CP would be the same //which is illegal in inventory. We can therefore just compare the current segment with the last //segment of the child path and if they match, move on to that child. if (seg.equals(c.cp.getSegment())) { current = c; children = c.children; break; } } //no child found matching this segment... if (current == null) { break; } } return segments.hasNext() ? null : current; }
public void addChild(T childTree) { getChildren().put(childTree.getPath().getSegment(), childTree); }
@Override public List<OperationType.Blueprint> getOperationTypes(ResourceType.Blueprint rt) { RelativePath p = rt.equals(structure.getRoot()) ? RelativePath.empty().get() : RelativePath.to().resourceType(rt.getId()).get(); try (Stream<OperationType.Blueprint> s = structure.getChildren(p, OperationType.class)) { return s.collect(toList()); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof DataAt)) return false; DataAt dataAt = (DataAt) o; return dataPath.equals(dataAt.dataPath); }
/** * If the provided path is canonical, it is prefixed with the {@code canonicalPrefix} and returned. If the provided * path is relative, it is resolved against the {@code relativeOrigin} and then converted to a canonical path. * <p> * <p>The path can be partially untyped. * * @param path the string representation of a path (either canonical or relative) * @param canonicalPrefix the prefix to apply to a canonical path * @param relativeOrigin origin to resolve a relative path against * @param intendedFinalType the intended type of the final segment of the path * @return the canonical path represented by the provided path string * @see Path#fromPartiallyUntypedString(String, CanonicalPath, CanonicalPath, SegmentType) */ public static CanonicalPath canonicalize(String path, CanonicalPath canonicalPrefix, CanonicalPath relativeOrigin, SegmentType intendedFinalType) { Path p = Path.fromPartiallyUntypedString(path, canonicalPrefix, relativeOrigin, intendedFinalType); if (p instanceof RelativePath) { return ((RelativePath) p).applyTo(relativeOrigin); } else { return p.toCanonicalPath(); } }
@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); }
@Override public DataEntity.Blueprint<?> getConnectionConfiguration(RelativePath root, Resource.Blueprint parentResource) { RelativePath.Extender resourcePath = root.modified().extend(SegmentType.r, parentResource.getId()) .get().slide(1, 0).modified(); return getData(resourcePath, connectionConfiguration); }
/** * 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; }
default Single descendContained(RelativePath resourcePath) { ReadContained parent = this; Single access = null; for(Path.Segment s : resourcePath.getPath()) { access = parent.get(s.getElementId()); parent = access.resources(); } if (access == null) { throw new IllegalArgumentException("Empty resource path"); } return access; } }
@Override public void serialize(T value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeStartObject(); serializers.defaultSerializeField("hash", value.getHash(), gen); gen.writeObjectFieldStart("children"); for (T child : value.getChildren()) { gen.writeFieldName(segmentToString(child.getPath().getSegment())); serialize(child, gen, serializers); } //children gen.writeEndObject(); //whole object gen.writeEndObject(); }