/** * Trim the path to the depth required * * @param depth the depth * @return the path up to the depth given, if the path is shorter the whole path is returned */ public SelectorPath toDepth(int depth) { return new SelectorPath(path.subList(0, Math.min(depth, path.size()))); }
/** * Trim the path to the depth required * * @param depth the depth * @return the path up to the depth given, if the path is shorter the whole path is returned */ public SelectorPath toDepth(int depth) { return new SelectorPath(path.subList(0, Math.min(depth, path.size()))); }
@Override public void head(Node<Structure> node, int depth) { sb.append(new SelectorPath(node.toPath())); sb.append("\n"); } })
/** * Step one part of the path * * @return new path of remaining parts */ public SelectorPath step() { return new SelectorPath(path.subList(Math.min(getDepth(), 1), getDepth())); }
/** * Step one part of the path * * @return new path of remaining parts */ public SelectorPath step() { return new SelectorPath(path.subList(Math.min(getDepth(), 1), getDepth())); }
/** * Get the selector path of the given item * * @param a the item * @return the selector path in this hierarchy for the given item */ public SelectorPath getSelectorPath(T a, Class<? extends T> type) { Node<T> node = getIndex().get(a); if (node == null) { return null; } return new SelectorPath(node.toPath(type)); }
/** * Get the remaining path after the given path to get this path * * @param from * @return the remaining path having remove the matching elements from the given path */ public SelectorPath from(SelectorPath from) { int i = 0; List<SelectorPart> remaining = new ArrayList<>(path); while (!remaining.isEmpty() && from.getDepth() > i && from.path.get(i).equals(remaining.get(0))) { i++; remaining.remove(0); } return new SelectorPath(remaining); }
/** * Get the remaining path after the given path to get this path * * @param from * @return the remaining path having remove the matching elements from the given path */ public SelectorPath from(SelectorPath from) { int i = 0; List<SelectorPart> remaining = new ArrayList<>(path); while (!remaining.isEmpty() && from.getDepth() > i && from.path.get(i).equals(remaining.get(0))) { i++; remaining.remove(0); } return new SelectorPath(remaining); }
/** * Get the selector path of the given item * * @param a the item * @return the selector path in this hierarchy for the given item */ public SelectorPath getSelectorPath(T a) { Node<T> node = getIndex().get(a); if (node == null) { return null; } return new SelectorPath(node.toPath()); }
/** * Get the selector path of the given item * * @param a the item * @return the selector path in this hierarchy for the given item */ public SelectorPath getSelectorPath(T a) { Node<T> node = getIndex().get(a); if (node == null) { return null; } return new SelectorPath(node.toPath()); }
/** * Get the selector path of the given item * * @param a the item * @return the selector path in this hierarchy for the given item */ public SelectorPath getSelectorPath(T a, Class<? extends T> type) { Node<T> node = getIndex().get(a); if (node == null) { return null; } return new SelectorPath(node.toPath(type)); }
/** * Parses the selector string and returns an ordered List of {@link SelectorPart} objects that * represent each clause between <code>><code> symbols. * * @param value the value * @return the list * @throws InvalidParameterException the invalid parameter exception */ public static SelectorPath parse(String value) throws InvalidParameterException { List<SelectorPart> selectorParts = new ArrayList<>(); if (value == null) { return new SelectorPath(selectorParts); } String[] parts = value.split("\\s*>\\s*"); for (String part : parts) { if (StringUtils.isNotEmpty(part)) { int colon = part.indexOf(':'); if (colon != -1) { String[] typeAndQualifier = part.split(":"); selectorParts.add(new SelectorPart(getType(typeAndQualifier[0]), typeAndQualifier[1])); } else { selectorParts.add(new SelectorPart(getType(part))); } } } return new SelectorPath(selectorParts); }
/** * Parses the selector string and returns an ordered List of {@link SelectorPart} objects that * represent each clause between <code>><code> symbols. * * @param value the value * @return the list * @throws InvalidParameterException the invalid parameter exception */ public static SelectorPath parse(String value) throws InvalidParameterException { List<SelectorPart> selectorParts = new ArrayList<>(); if (value == null) { return new SelectorPath(selectorParts); } String[] parts = value.split("\\s*>\\s*"); for (String part : parts) { if (StringUtils.isNotEmpty(part)) { int colon = part.indexOf(':'); if (colon != -1) { String[] typeAndQualifier = part.split(":"); selectorParts.add(new SelectorPart(getType(typeAndQualifier[0]), typeAndQualifier[1])); } else { selectorParts.add(new SelectorPart(getType(part))); } } } return new SelectorPath(selectorParts); }
/** * Get the selector path of the structure annotation covering the given annotation * * @param annotation the annotation * @return the selector path in this hierarchy covering the given annotation */ public SelectorPath generatePath(Annotation annotation) { Optional<Structure> covering = getCoveringStructure(annotation); Node<Structure> node = getRoot(); if (covering.isPresent()) { node = getIndex().get(covering.get()); } return new SelectorPath(node.toPath()); }
/** * Get the selector path of the structure annotation covering the given annotation * * @param annotation the annotation * @return the selector path in this hierarchy covering the given annotation */ public SelectorPath generatePath(Annotation annotation) { Optional<Structure> covering = getCoveringStructure(annotation); Node<Structure> node = getRoot(); if (covering.isPresent()) { node = getIndex().get(covering.get()); } return new SelectorPath(node.toPath()); }