/** * Define container paths for an object. * * @param pairs a model version number followed by a container path, repeated * for all relevant versions */ private ObjectType(Object... pairs) { if ((pairs.length % 2) != 0) { throw new IllegalArgumentException("Invalid ObjectType declaration"); } for (int i = 0; i < pairs.length; i += 2) { try { this.paths.put((Integer) pairs[i], new PathInfo((String) pairs[i + 1])); } catch (ClassCastException e) { throw new IllegalArgumentException("Invalid ObjectType declaration", e); } } }
/** * Extracts the object name from the given $ref URL fragment, assuming that * fragment matches this model object type * * @param refFragment the fragment portion of a $ref node URL * @param version model version * @return the object name (i.e. property name in the container object) */ public String getObjectName(String refFragment, int version) { return paths.get(version).getObjectName(refFragment); }
public String getPathString(int version) { return paths.get(version).getPathString(); }
JsonPointer p = paths.get(version).getPath(); try { while (!p.matches()) {
/** * Locate the object type, if any, that matches the given $ref URL fragment. * * @param refFragment fragment of a $ref node URL * @param version model version * @return matching object type, if any */ public static Optional<ObjectType> find(String refFragment, int version) { if (typesByVersion.containsKey(version)) { return typesByVersion.get(version).stream() // .filter(type -> type.paths.get(version).matches(refFragment)) // .findFirst(); } else { return Optional.empty(); } }
public JsonPointer getPath(int version) { return paths.get(version).getPath(); }
/** * Obtains the value of this object container from the given tree * * @param tree the model tree * @param version the model version * @return container value, including all objects of this model object type */ public JsonNode getFromNode(JsonNode tree, int version) { return tree.at(paths.get(version).getPath()); }
/** * Tests whether the given $ref URL fragment could apply to an object of this * type, meaning that it consists of this object type's container path followed * by an object name * * @param refFragment the fragment portion of a $ref node URL * @param version model version * @return */ public boolean matches(String refFragment, int version) { return paths.get(version).matches(refFragment); }