public class SimpleHashableStateFactory extends java.lang.Object implements HashableStateFactory
HashableState
objects from
State
instances. By default, this factory will be object identifier independent
(the names of objects don't affect the state definition). However, you can make it object identifier dependent
with the either of the constructors SimpleHashableStateFactory(boolean)
or
SimpleHashableStateFactory(boolean, boolean)
.
HashableState
instances
that cache the hash code so that it does not need to be recomputed on multiple calls of the hashCode method.
To enable hash code caching, use the SimpleHashableStateFactory(boolean, boolean)
constructor.
Using caching will use slightly more memory by having to associate an int with each HashableState
.
Modifier and Type | Class and Description |
---|---|
protected static class |
SimpleHashableStateFactory.AttClass
Classes of
Attribute.AttributeType that affect how hashing will be performed |
protected class |
SimpleHashableStateFactory.SimpleCachedHashableState |
protected class |
SimpleHashableStateFactory.SimpleHashableState |
static interface |
SimpleHashableStateFactory.SimpleHashableStateInterface
An interface for
HashableState instances that are created
by the SimpleHashableStateFactory . |
Modifier and Type | Field and Description |
---|---|
protected boolean |
identifierIndependent
Whether state evaluations are object identifier independent (the names of objects don't matter).
|
protected boolean |
useCached
Whether to cache the hash code for each produced
HashableState . |
Constructor and Description |
---|
SimpleHashableStateFactory()
Default constructor: object identifier independent and no hash code caching.
|
SimpleHashableStateFactory(boolean identifierIndependent)
Initializes with no hash code caching.
|
SimpleHashableStateFactory(boolean identifierIndependent,
boolean useCached)
Initializes.
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendHashcodeForValue(org.apache.commons.lang3.builder.HashCodeBuilder hashCodeBuilder,
Value v)
Appends the hash code for the given
Value to the HashCodeBuilder |
protected int |
computeHashCode(ObjectInstance o)
Computes the hash code for an individual
ObjectInstance . |
protected int |
computeHashCode(State s)
Computes the hash code for the input state.
|
protected SimpleHashableStateFactory.AttClass |
getAttClass(Attribute att) |
HashableState |
hashState(State s)
Turns
State s into a HashableState |
protected boolean |
identifierDependentEquals(State s1,
State s2)
Evaluates whether two states are equal when equality depends on object identifiers/names being equal.
|
protected boolean |
identifierIndependentEquals(State s1,
State s2)
Evaluates whether two states are equal when equality is independent of object identifiers/names being equal
|
boolean |
objectIdentifierIndependent()
Returns true if the
HashableState objects returned are object identifier independent; false if they are dependent. |
protected boolean |
objectValuesEqual(ObjectInstance o1,
ObjectInstance o2)
Evaluates whether the values of two
ObjectInstance s are equal. |
protected boolean |
statesEqual(State s1,
State s2)
Returns true if the two input states are equal.
|
protected boolean |
valuesEqual(Value v1,
Value v2)
Returns whether two values are equal.
|
protected boolean identifierIndependent
protected boolean useCached
HashableState
.
Default is non-cached.public SimpleHashableStateFactory()
public SimpleHashableStateFactory(boolean identifierIndependent)
identifierIndependent
- if true then state evaluations are object identifier independent; if false then dependent.public SimpleHashableStateFactory(boolean identifierIndependent, boolean useCached)
identifierIndependent
- if true then state evaluations are object identifier independent; if false then dependent.useCached
- if true then the hash code for each produced HashableState
will be cached; if false then they will not be cached.public HashableState hashState(State s)
HashableStateFactory
State
s into a HashableState
hashState
in interface HashableStateFactory
s
- the input State
to transform.HashableState
.public boolean objectIdentifierIndependent()
HashableStateFactory
HashableState
objects returned are object identifier independent; false if they are dependent.objectIdentifierIndependent
in interface HashableStateFactory
HashableState
objects returned are object identifier independent; false if they are dependent.protected int computeHashCode(State s)
s
- the input state for which a hash code is to be computedprotected int computeHashCode(ObjectInstance o)
ObjectInstance
.o
- the ObjectInstance
whose hash code will be computed.ObjectInstance
.protected void appendHashcodeForValue(org.apache.commons.lang3.builder.HashCodeBuilder hashCodeBuilder, Value v)
Value
to the HashCodeBuilder
hashCodeBuilder
- the HashCodeBuilder
to which the value's hash code will be appendedv
- the Value
whose hash code should be appended.protected SimpleHashableStateFactory.AttClass getAttClass(Attribute att)
protected boolean statesEqual(State s1, State s2)
protected boolean identifierIndependentEquals(State s1, State s2)
protected boolean identifierDependentEquals(State s1, State s2)
protected boolean objectValuesEqual(ObjectInstance o1, ObjectInstance o2)
ObjectInstance
s are equal.o1
- the first ObjectInstance
to compareo2
- the second ObjectInstance
to compare