E
- The type of element wrapped by this valuepublic interface BaseValue<E>
BaseValue
is a "wrapper" around an actual value from a
ValueContainer
. The actual value may come from various sources of
the ValueContainer
, but usually it's a generic dynamic system for
being able to fetch values from object fields without having to know the
type of Class
of the ValueContainer
, the getters and
setters for that particular value. The driving force behind this is that
instead of having a traditional hierarchical structure of data that is
possible to be retrieved from an Entity
, Living
, etc.,
all that is required is container.supports(Keys.HEALTH) ?
container.get(Keys.HEALTH).get() : 0
where the container is simply
a ValueContainer
, nothing more, nothing less.
The advantage of this is that now, these various known and unknown
Value
s can be retrieved by simple java generics:
ValueContainer.getValue(Key)
. While having a Value
for
something so primitive as the current health of a Living
entity,
the power is wielded when a Value
can be offered up to multiple
ValueContainer
s without worrying about whether it's supported or not,
or getting the right cast information.
Modifier and Type | Method and Description |
---|---|
boolean |
exists()
Checks that the underlying value exists (or "set").
|
E |
get()
Gets the held value.
|
E |
getDefault()
Gets the default value.
|
Optional<E> |
getDirect()
Gets the direct value.
|
Key<? extends BaseValue<E>> |
getKey()
Gets the key for this
BaseValue . |
E get()
exists()
returns false, the getDefault()
value is
returned.boolean exists()
E getDefault()
Optional<E> getDirect()
get()
would return the getDefault()
when
necessary.