@NotNull static ItemPathImpl createFromIterator(@NotNull Iterator<?> iterator) { ItemPathImpl path = new ItemPathImpl(); iterator.forEachRemaining(path::add); return path; }
@NotNull @Override public ItemPath removeIds() { List<Object> filtered = new ArrayList<>(segments); filtered.removeIf(ItemPath::isId); return new ItemPathImpl(filtered); }
@Override public ItemPath subPath(int from, int to) { int fromClipped = Math.max(0, from); int toClipped = Math.min(to, segments.size()); if (fromClipped >= toClipped) { return EMPTY_PATH; } else { // TODO ... the problem is that subList is not serializable; but this creates one object more return new ItemPathImpl(new ArrayList<>(segments.subList(fromClipped, toClipped))); } }
@NotNull static ItemPathImpl createFromArray(@NotNull Object[] components) { ItemPathImpl path = new ItemPathImpl(); path.addAll(components); return path; }
@NotNull static ItemPathImpl createFromListReverse(@NotNull List<?> components) { ItemPathImpl path = new ItemPathImpl(); for (int i = components.size() - 1; i >= 0; i--) { path.add(components.get(i)); } return path; }
@NotNull @Override public ItemPath namedSegmentsOnly() { List<Object> newComponents = new ArrayList<>(); for (Object segment : segments) { if (ItemPath.isName(segment)) { newComponents.add(segment); } } return new ItemPathImpl(newComponents); }
@NotNull static ItemPathImpl createFromList(@NotNull List<?> components) { ItemPathImpl path = new ItemPathImpl(); path.addAll(components); return path; }
@Override public ItemPath firstAsPath() { return segments.isEmpty() ? this : new ItemPathImpl(Collections.singletonList(first())); }