Class NodeImpl
- java.lang.Object
-
- org.hibernate.validator.internal.engine.path.NodeImpl
-
- All Implemented Interfaces:
Path.BeanNode,Path.ConstructorNode,Path.ContainerElementNode,Path.CrossParameterNode,Path.MethodNode,Path.Node,Path.ParameterNode,Path.PropertyNode,Path.ReturnValueNode,Serializable,ContainerElementNode,PropertyNode
public class NodeImpl extends Object implements Path.PropertyNode, Path.MethodNode, Path.ConstructorNode, Path.BeanNode, Path.ParameterNode, Path.ReturnValueNode, Path.CrossParameterNode, Path.ContainerElementNode, PropertyNode, ContainerElementNode, Serializable
Immutable implementation of aPath.Node.- Author:
- Hardy Ferentschik, Gunnar Morling, Guillaume Smet
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringCROSS_PARAMETER_NODE_NAMEstatic StringITERABLE_ELEMENT_NODE_NAMEstatic StringLIST_ELEMENT_NODE_NAMEstatic StringMAP_KEY_NODE_NAMEstatic StringMAP_VALUE_NODE_NAMEstatic StringRETURN_VALUE_NODE_NAME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Path.Node>
Tas(Class<T> nodeType)Narrows the type of this node down to the given type.StringasString()intbuildHashCode()static NodeImplcreateBeanNode(NodeImpl parent)static NodeImplcreateConstructorNode(String name, NodeImpl parent, Class<?>[] parameterTypes)static NodeImplcreateContainerElementNode(String name, NodeImpl parent)static NodeImplcreateCrossParameterNode(NodeImpl parent)static NodeImplcreateMethodNode(String name, NodeImpl parent, Class<?>[] parameterTypes)static NodeImplcreateParameterNode(String name, NodeImpl parent, int parameterIndex)static NodeImplcreatePropertyNode(String name, NodeImpl parent)static NodeImplcreateReturnValue(NodeImpl parent)booleanequals(Object obj)Class<?>getContainerClass()IntegergetIndex()ObjectgetKey()ElementKindgetKind()The kind of element represented by the node.StringgetName()Returns the name of the element which the node represents:nullif it is a leaf node which represents an entity / bean.intgetParameterIndex()List<Class<?>>getParameterTypes()NodeImplgetParent()IntegergetTypeArgumentIndex()ObjectgetValue()inthashCode()booleanisInIterable()booleanisIterable()static NodeImplmakeIterable(NodeImpl node)static NodeImplmakeIterableAndSetIndex(NodeImpl node, Integer index)static NodeImplmakeIterableAndSetMapKey(NodeImpl node, Object key)static NodeImplsetPropertyValue(NodeImpl node, Object value)static NodeImplsetTypeParameter(NodeImpl node, Class<?> containerClass, Integer typeArgumentIndex)StringtoString()Returns a human-readable representation of this node.
-
-
-
Field Detail
-
RETURN_VALUE_NODE_NAME
public static final String RETURN_VALUE_NODE_NAME
- See Also:
- Constant Field Values
-
CROSS_PARAMETER_NODE_NAME
public static final String CROSS_PARAMETER_NODE_NAME
- See Also:
- Constant Field Values
-
ITERABLE_ELEMENT_NODE_NAME
public static final String ITERABLE_ELEMENT_NODE_NAME
- See Also:
- Constant Field Values
-
LIST_ELEMENT_NODE_NAME
public static final String LIST_ELEMENT_NODE_NAME
- See Also:
- Constant Field Values
-
MAP_KEY_NODE_NAME
public static final String MAP_KEY_NODE_NAME
- See Also:
- Constant Field Values
-
MAP_VALUE_NODE_NAME
public static final String MAP_VALUE_NODE_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
createContainerElementNode
public static NodeImpl createContainerElementNode(String name, NodeImpl parent)
-
createParameterNode
public static NodeImpl createParameterNode(String name, NodeImpl parent, int parameterIndex)
-
createMethodNode
public static NodeImpl createMethodNode(String name, NodeImpl parent, Class<?>[] parameterTypes)
-
createConstructorNode
public static NodeImpl createConstructorNode(String name, NodeImpl parent, Class<?>[] parameterTypes)
-
makeIterableAndSetIndex
public static NodeImpl makeIterableAndSetIndex(NodeImpl node, Integer index)
-
makeIterableAndSetMapKey
public static NodeImpl makeIterableAndSetMapKey(NodeImpl node, Object key)
-
setTypeParameter
public static NodeImpl setTypeParameter(NodeImpl node, Class<?> containerClass, Integer typeArgumentIndex)
-
getName
public final String getName()
Description copied from interface:Path.NodeReturns 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.
-
isInIterable
public final boolean isInIterable()
- Specified by:
isInIterablein interfacePath.Node- Returns:
trueif the node represents an object contained in a multi-valued container such asIterableorMapor an array,falseotherwise
-
isIterable
public final boolean isIterable()
-
getIndex
public final Integer getIndex()
-
getKey
public final Object getKey()
-
getContainerClass
public Class<?> getContainerClass()
- Specified by:
getContainerClassin interfacePath.BeanNode- Specified by:
getContainerClassin interfacePath.ContainerElementNode- Specified by:
getContainerClassin interfacePath.PropertyNode- Returns:
- the type of the container the node is placed in, if contained in a
container type such as
Optional,ListorMap,nullotherwise
-
getTypeArgumentIndex
public Integer getTypeArgumentIndex()
- Specified by:
getTypeArgumentIndexin interfacePath.BeanNode- Specified by:
getTypeArgumentIndexin interfacePath.ContainerElementNode- Specified by:
getTypeArgumentIndexin interfacePath.PropertyNode- Returns:
- the index of the type argument affected by the violated constraint, if
contained in a generic container type such as
Optional,ListorMap,nullotherwise
-
getParent
public final NodeImpl getParent()
-
getKind
public ElementKind getKind()
Description copied from interface:Path.NodeThe 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(); [...] }
-
as
public <T extends Path.Node> T as(Class<T> nodeType)
Description copied from interface:Path.NodeNarrows the type of this node down to the given type. The appropriate type should be checked before by callingPath.Node.getKind().
-
getParameterTypes
public List<Class<?>> getParameterTypes()
- Specified by:
getParameterTypesin interfacePath.ConstructorNode- Specified by:
getParameterTypesin interfacePath.MethodNode- Returns:
- the list of parameter types
-
getParameterIndex
public int getParameterIndex()
- Specified by:
getParameterIndexin interfacePath.ParameterNode- Returns:
- the parameter index in the method or constructor definition
-
getValue
public Object getValue()
- Specified by:
getValuein interfaceContainerElementNode- Specified by:
getValuein interfacePropertyNode- Returns:
- Returns the value of the bean property represented by this node.
-
toString
public String toString()
Description copied from interface:Path.NodeReturns 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.
-
asString
public final String asString()
-
buildHashCode
public final int buildHashCode()
-
-