T
- The Field-Type for this Field.
This Type represents the value that will be modified by the managerM
- The Manager-Type for this Field.
This Type represents the Manager that is returned by setValue(Object)
for chaining convenience.public abstract class Field<T,M>
extends java.lang.Object
Field
s of an entity.
Most managers have specific implementations that provide needed functionality and specify behaviour.
This class is abstract and requires an implementation
for checkValue(Object)
Constructor and Description |
---|
Field(M manager,
java.util.function.Supplier<T> originalValue)
Creates a new Field instance
|
Modifier and Type | Method and Description |
---|---|
abstract void |
checkValue(T value)
Hook method for custom value verification.
|
boolean |
equals(java.lang.Object o) |
M |
getManager()
The Manager of this specific Field instance
|
T |
getOriginalValue()
Resolves the original value for the underlying entity.
|
T |
getValue()
The currently set value, null if no value has been set.
|
boolean |
isSet()
Whether the value for this Field has been set
|
M |
reset()
|
M |
setValue(T value)
Sets the value which should be used in the update
operation for the Manager instance.
|
boolean |
shouldUpdate()
Whether the field should be update or not
|
java.lang.String |
toString() |
public Field(M manager, java.util.function.Supplier<T> originalValue)
manager
- The updatable manager instance this field
is used in. This will be returned by setValue(Object)
for chaining convenienceoriginalValue
- The original value, represented with a Supplier
access function.public T getValue()
getOriginalValue()
public T getOriginalValue()
UnsupportedOperationException
.java.lang.UnsupportedOperationException
- If the original value is not accessiblegetValue()
public M setValue(T value)
isSet()
to return true
!
Values might be checked differently depending on the Field implementation.
The check criteria are specified in the field getter of the updatable manager.
value
- The value that should be used by the update operationjava.lang.IllegalArgumentException
- If the provided value does not pass the specified checksisSet()
public boolean isSet()
public boolean shouldUpdate()
true
when the value has been set and is
different from the value returned by the original value Supplier
public M getManager()
public M reset()
setValue(Object)
public abstract void checkValue(T value)
This method is abstract and requires specific implementation
value
- The value that should be checkedjava.lang.IllegalArgumentException
- If the specified value does not pass the specified checksInsufficientPermissionException
- If this value requires specific Permissions
that are not fulfilledpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object