Class Path
java.lang.Object
ch.tocco.nice2.persist.core.api.entity.Path
- All Implemented Interfaces:
Serializable
Path class for working with entity field and relation paths.
Example usage:
Path path = Path.parse("someRel.anotherRel.aField");
FieldModel fieldModel = (FieldModel) path.resolve(myEntityModelThatHasSomeRel);
Note: Features are turned off by default!
Example with features:
Path path = Path.parse("someRel[myselector].anotherRel?.aField", Path.Feature.SELECTORS, Path.Feature.OPTIONALS)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic classstatic classstatic final classstatic interface -
Constructor Summary
ConstructorsConstructorDescriptionPath(Path.PathElement... elements) Path(Path parent, Path.PathElement child) Path(Collection<Path.PathElement> elements) -
Method Summary
Modifier and TypeMethodDescriptionbooleanget(int index) getHead()getHead(int count) getTail()getTail(int count) booleanhasFeature(Path.Feature feature) inthashCode()intlength()static PathParses the given string path into a path object and returns it.static Pathparse(String path, Path.Feature... features) resolve(EntityModel source, Path.Feature... features) Resolves the last element of this path and returns its model.<T extends Path.Resolver>
Tresolve(EntityModel source, T resolver, Path.Feature... features) Resolves this path using a resolver.resolveToLastEntity(EntityModel source, Path.Feature... features) Resolves the path to the last entity, returning that entity's model plus the path element after it.stepDown()Example: "aa.bb.cc" → "bb.cc"stepUp()Example: "aa.bb.cc" → "aa.bb"stripFeatures(Path.Feature... features) toString()toString(boolean quoteIdentifiers)
-
Constructor Details
-
Path
-
Path
- Parameters:
elements- At least one element, no null values.
-
Path
-
Path
-
Path
-
Path
-
-
Method Details
-
parse
Parses the given string path into a path object and returns it.NOTE that this method is not too picky and does not try to resolve; invalid stuff will be detected in the
resolve(EntityModel, Path.Feature...)method.Chunks that are given single-quoted like 'foo' lose the quotes here, calls to
get(int)etc. will be without.- Parameters:
path- For example "someRel.someField" or "'someRel'.'someField'". Will be trimmed, may not be empty.- Returns:
- The parsed path object
- Throws:
IllegalArgumentException- On illegal syntax or empty input.
-
parse
- Throws:
IllegalArgumentException
-
getFullPaths
-
equals
-
hashCode
-
toString
-
toString
-
length
public int length() -
get
-
getHead
-
getHead
-
getTail
-
getTail
-
stepUp
Example: "aa.bb.cc" → "aa.bb"- Returns:
- A new path without the last element.
- Throws:
IndexOutOfBoundsException- If the path contains just one element.
-
stepDown
Example: "aa.bb.cc" → "bb.cc"- Returns:
- A new path without the first element.
- Throws:
IndexOutOfBoundsException- If the path contains just one element.
-
hasFeature
-
stripFeatures
-
resolve
Resolves the last element of this path and returns its model.- Parameters:
source- The model of the first element to start resolving.features- Enabled path features.- Returns:
- Either an instance of FieldModel or RelationModel.
- Throws:
PersistException- On a syntax or model error. Never contacts the persistence layer so it's more of a model exception.
-
resolveToLastEntity
Resolves the path to the last entity, returning that entity's model plus the path element after it.Example:
Path "someRel.otherRel.someField" - The returned EntityModel is the target entity of the "otherRel" relation. - The returned PathElement is for the "someField", which is either for a standard field, for a localized field, or for a relation. If it is for a localized field then it may be just its base name.- Parameters:
source- The model of the first element to start resolving.features- Enabled path features.- Throws:
PersistException- On a syntax or model error. Never contacts the persistence layer so it's more of a model exception.
-
resolve
public <T extends Path.Resolver> T resolve(EntityModel source, T resolver, Path.Feature... features) Resolves this path using a resolver.- Parameters:
source- The model of the first element to start resolving.resolver- A handler that handlers each step in the path.features- Enabled path features.- Returns:
- The passed in resolver.
- Throws:
PersistException- On a syntax or model error. Never contacts the persistence layer so it's more of a model exception.
-