Class AbstractNodeState
java.lang.Object
org.apache.jackrabbit.oak.spi.state.AbstractNodeState
- All Implemented Interfaces:
NodeState
- Direct Known Subclasses:
AbstractDecoratedNodeState,ModifiedNodeState
Abstract base class for
NodeState implementations.
This base class contains default implementations of the
equals(Object) and hashCode() methods based on
the implemented interface.
This class also implements trivial (and potentially very slow) versions of
the getProperty(String) and getPropertyCount() methods
based on NodeState.getProperties(). The getChildNodeCount(long) method
is similarly implemented based on NodeState.getChildNodeEntries().
Subclasses should normally override these method with a more efficient
alternatives.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckValidName(String name) booleancompareAgainstBaseState(NodeState base, NodeStateDiff diff) Generic default comparison algorithm that simply walks through the property and child node lists of the given base state and compares the entries one by one with corresponding ones (if any) in this state.static booleancompareAgainstBaseState(NodeState state, NodeState base, NodeStateDiff diff) Generic default comparison algorithm that simply walks through the property and child node lists of the given base state and compares the entries one by one with corresponding ones (if any) in this state.static booleancomparePropertiesAgainstBaseState(NodeState state, NodeState base, NodeStateDiff diff) Compares the properties ofbasestate withthisstate.booleanChecks whether the given object is equal to this one.static booleanbooleangetBoolean(@NotNull String name) Returns the boolean value of the named property.static booleangetBoolean(NodeState state, String name) longgetChildNodeCount(long max) Returns the number of iterable child nodes of this node.Returns the names of all iterable child nodes.longReturns the long value of the named property.static long@Nullable StringReturns the name value of the named property.static StringReturns the name values of the named property.getProperty(@NotNull String name) Returns the named property, ornullif no such property exists.longReturns the number of properties of this node.Returns the string value of the named property.static StringgetStrings(@NotNull String name) Returns the string values of the named property.getStrings(NodeState state, String name) inthashCode()Returns a hash code that's compatible with how theequals(Object)method is implemented.booleanhasProperty(@NotNull String name) Checks whether the named property exists.static booleanisValidName(String name) toString()Returns a string representation of this node state.static StringMethods inherited from interface org.apache.jackrabbit.oak.spi.state.NodeState
builder, exists, getChildNode, getChildNodeEntries, getProperties, hasChildNode
-
Constructor Details
-
AbstractNodeState
public AbstractNodeState()
-
-
Method Details
-
isValidName
-
checkValidName
- Throws:
IllegalArgumentException
-
getBoolean
-
getLong
-
getString
-
getStrings
-
getName
-
getNames
-
compareAgainstBaseState
Generic default comparison algorithm that simply walks through the property and child node lists of the given base state and compares the entries one by one with corresponding ones (if any) in this state. -
comparePropertiesAgainstBaseState
public static boolean comparePropertiesAgainstBaseState(NodeState state, NodeState base, NodeStateDiff diff) Compares the properties ofbasestate withthisstate.- Parameters:
state- the head node state.base- the base node state.diff- the node state diff.- Returns:
trueto continue the comparison,falseto stop
-
toString
-
hasProperty
Description copied from interface:NodeStateChecks whether the named property exists. The implementation is equivalent togetProperty(name) != null, but may be optimized to avoid having to load the property value.- Specified by:
hasPropertyin interfaceNodeState- Parameters:
name- property name- Returns:
trueif the named property exists,falseotherwise
-
getBoolean
Description copied from interface:NodeStateReturns the boolean value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); return property != null && property.getType() == Type.BOOLEAN && property.getValue(Type.BOOLEAN);- Specified by:
getBooleanin interfaceNodeState- Parameters:
name- property name- Returns:
- boolean value of the named property, or
false
-
getLong
Description copied from interface:NodeStateReturns the long value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.LONG) { return property.getValue(Type.LONG); } else { return 0; } -
getString
Description copied from interface:NodeStateReturns the string value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRING) { return property.getValue(Type.STRING); } else { return null; } -
getStrings
Description copied from interface:NodeStateReturns the string values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.STRINGS) { return property.getValue(Type.STRINGS); } else { return Collections.emptyList(); }- Specified by:
getStringsin interfaceNodeState- Parameters:
name- property name- Returns:
- string values of the named property, or an empty collection
-
getName
Description copied from interface:NodeStateReturns the name value of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAME) { return property.getValue(Type.NAME); } else { return null; } -
getNames
Description copied from interface:NodeStateReturns the name values of the named property. The implementation is equivalent to the following code, but may be optimized.PropertyState property = state.getProperty(name); if (property != null && property.getType() == Type.NAMES) { return property.getValue(Type.NAMES); } else { return Collections.emptyList(); } -
getProperty
Description copied from interface:NodeStateReturns the named property, ornullif no such property exists.- Specified by:
getPropertyin interfaceNodeState- Parameters:
name- name of the property to return- Returns:
- named property, or
nullif not found
-
getPropertyCount
public long getPropertyCount()Description copied from interface:NodeStateReturns the number of properties of this node.- Specified by:
getPropertyCountin interfaceNodeState- Returns:
- number of properties
-
getChildNodeCount
public long getChildNodeCount(long max) Description copied from interface:NodeStateReturns the number of iterable child nodes of this node.If an implementation knows the exact value, it returns it (even if the value is higher than max). If the implementation does not know the exact value, and the child node count is higher than max, it may return Long.MAX_VALUE. The cost of the operation is at most O(max).
- Specified by:
getChildNodeCountin interfaceNodeState- Parameters:
max- the maximum number of entries to traverse- Returns:
- number of iterable child nodes
-
getChildNodeNames
Description copied from interface:NodeStateReturns the names of all iterable child nodes.- Specified by:
getChildNodeNamesin interfaceNodeState- Returns:
- child node names in some stable order
-
compareAgainstBaseState
Generic default comparison algorithm that simply walks through the property and child node lists of the given base state and compares the entries one by one with corresponding ones (if any) in this state.- Specified by:
compareAgainstBaseStatein interfaceNodeState- Parameters:
base- base statediff- handler of node state differences- Returns:
trueif the full diff was performed, orfalseif it was aborted as requested by the handler (see theNodeStateDiffcontract for more details)
-
toString
Returns a string representation of this node state. -
equals
Checks whether the given object is equal to this one. Two node states are considered equal if all their properties and child nodes match, regardless of ordering. Subclasses may override this method with a more efficient equality check if one is available. -
equals
-
hashCode
public int hashCode()Returns a hash code that's compatible with how theequals(Object)method is implemented. The current implementation simply returns zero for everything sinceNodeStateinstances are not intended for use as hash keys.
-