@SuppressWarnings("unchecked") public static Filter[] pathTo(CanonicalPath path) { if (!path.isDefined()) { return new Filter[0]; } List<Filter> fs = new ArrayList<>(); for (Path.Segment s : path.getPath()) { fs.add(Related.by(Relationships.WellKnown.contains)); fs.add(With.type(Entity.entityTypeFromSegmentType(s.getElementType()))); fs.add(With.id(s.getElementId())); } if (fs.size() < 2) { return new Filter[0]; } else { // remove the first 'contains' defined in the loop above List<Filter> ret = fs.subList(1, fs.size()); return ret.toArray(new Filter[ret.size()]); } }
public static Filter[] pathTo(Entity<?, ?> entity) { return pathTo(entity.getPath()); }