public abstract class AbstractProperty<K,V> extends Object implements Property<K,V>
Property.Operator
Modifier and Type | Field and Description |
---|---|
protected Property.Operator |
operator
Operator for comparing to other properties.
|
protected V |
value
The value.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractProperty()
Initialise internal values to defaults, use this ctor if you plan to
override
getKey() and getValue() yourself. |
protected |
AbstractProperty(K key,
V value)
Use the specified key and value and set operator to the default.
|
protected |
AbstractProperty(K key,
V value,
Property.Operator op) |
protected |
AbstractProperty(V value)
Initialise key to default, and value to the supplied value.
|
protected |
AbstractProperty(V value,
Property.Operator op)
Initialise the value to the specified value and use the specified
operator, use the default key.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
protected K |
getDefaultKey(V value)
Gets the default value for
key , used in case null is passed in
(since we can't have a null key). |
protected Property.Operator |
getDefaultOperator(K key,
V value)
Return the default operator to use, based on the supplied key and value.
|
K |
getKey()
Gets the key for this property.
|
Property.Operator |
getOperator()
Gets the operator to use when comparing another property with this
property.
|
V |
getValue()
Gets the "value" of this property.
|
int |
hashCode() |
protected int |
hashCodeOf(Object value)
Convenience method to avoid null-checking.
|
boolean |
matches(Property<?,?> other)
Compares this property to
other using this property's
operator. |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compareTo
protected final Property.Operator operator
protected AbstractProperty()
getKey()
and getValue()
yourself.protected AbstractProperty(@Nullable V value)
value
- The value of the propertyprotected AbstractProperty(@Nullable V value, @Nullable Property.Operator op)
value
- The property valueop
- The operator for the propertyprotected AbstractProperty(@Nullable K key, @Nullable V value)
key
- The key identifying the propertyvalue
- The property valueprotected K getDefaultKey(@Nullable V value)
key
, used in case null is passed in
(since we can't have a null key). In general this should return the class
name of the property itself but subclasses are free to alter this
behaviour if they wish.value
- Value passed in to the ctor, supplied in case a subclass
wants to return a specific default key based on the valueprotected Property.Operator getDefaultOperator(K key, @Nullable V value)
key
- Property keyvalue
- Property initial value, may be nullpublic K getKey()
Property
public V getValue()
Property
public Property.Operator getOperator()
Property
getOperator
in interface Property<K,V>
public boolean matches(@Nullable Property<?,?> other)
Property
Compares this property to other
using this property's
operator. This is equivalent to the code:
thisObject.getOperator().compare(thisObject, other);
The order of the operands is important, since Property.Operator
treats
its type as infix between the two operands, and thus (for example) if
this property's operator is set to GREATER, then when calling this method
we want to know whether this is GREATER than other
and must pass in the operands in the corresponding order.
matches
in interface Property<K,V>
other
- Property to compare toProperty.getOperator()