Package jakarta.validation
Interface Path.Node
- All Known Subinterfaces:
Path.BeanNode,Path.ConstructorNode,Path.ContainerElementNode,Path.CrossParameterNode,Path.MethodNode,Path.ParameterNode,Path.PropertyNode,Path.ReturnValueNode
- Enclosing interface:
- Path
public static interface Path.Node
Represents an element of a navigation path.
-
Method Summary
Modifier and TypeMethodDescription<T extends Path.Node>
TNarrows the type of this node down to the given type.getIndex()getKey()getKind()The kind of element represented by the node.getName()Returns the name of the element which the node represents:nullif it is a leaf node which represents an entity / bean.booleantoString()Returns a human-readable representation of this node.
-
Method Details
-
getName
String getName()Returns the name of the element which the node represents:nullif it is a leaf node which represents an entity / bean. In particular, the node representing the root object.- The property name for a property.
- The method name for a method.
- The unqualified name of the type declaring the constructor for a constructor.
- The parameter named as defined by the
ParameterNameProviderfor a method or constructor parameter. - The literal
<cross-parameter>for a method or constructor cross-parameter. - The literal
<return value>for a method or constructor return value. - The node name as defined by the
ValueExtractorfor a container element; specifically, the literal<list element>for elements stored in a list, the literal<iterable element>for elements stored in anIterable, the literal<map key>for the keys stored in aMapand the literal<map value>for the values stored in aMap.
- Returns:
- name of the element which the node represents
-
isInIterable
boolean isInIterable()- Returns:
trueif the node represents an object contained in a multi-valued container such asIterableorMapor an array,falseotherwise
-
getIndex
Integer getIndex()- Returns:
- the index the node is placed in if contained in an array, a
Listor any other container supporting indexed access,nullotherwise
-
getKey
Object getKey()- Returns:
- the key the node is placed in if contained in a
Mapor any other container supporting keyed access,nullotherwise
-
getKind
ElementKind getKind()The kind of element represented by the node. The following relationship between anElementKindand itsNodesubtype exists:ElementKind.BEAN:Path.BeanNodeElementKind.PROPERTY:Path.PropertyNodeElementKind.METHOD:Path.MethodNodeElementKind.CONSTRUCTOR:Path.ConstructorNodeElementKind.PARAMETER:Path.ParameterNodeElementKind.CROSS_PARAMETER:Path.CrossParameterNodeElementKind.RETURN_VALUE:Path.ReturnValueNodeElementKind.CONTAINER_ELEMENT:Path.ContainerElementNode
This is useful to narrow down the
Nodetype and access node specific information:switch(node.getKind() { case METHOD: name = node.getName(); params = node.as(MethodNode.class).getParameterTypes(); case PARAMETER: index = node.as(ParameterNode.class).getParameterIndex(); [...] }- Returns:
- the
ElementKind - Since:
- 1.1
-
as
Narrows the type of this node down to the given type. The appropriate type should be checked before by callinggetKind().- Type Parameters:
T- the type to narrow down to- Parameters:
nodeType- class object representing the descriptor type to narrow down to to- Returns:
- this node narrowed down to the given type.
- Throws:
ClassCastException- if this node is not assignable to the typeT- Since:
- 1.1
-
toString
String toString()Returns a human-readable representation of this node.Clients should not rely on any specific structure of the returned value. Instead they should obtain any required information by calling the methods on this interface and its sub-types.
-