Module com.legyver.utils.mapqua
Class MapBackedProperty<T>
- java.lang.Object
-
- com.legyver.utils.mapqua.mapbacked.MapBackedProperty<T>
-
- Type Parameters:
T- Type of Object that this will be backing (in an internal map)
- Direct Known Subclasses:
MapBackedCollection,MapBackedDouble,MapBackedEntity,MapBackedInteger,MapBackedLocalDate,MapBackedLocalDateTime,MapBackedMap,MapBackedString
public abstract class MapBackedProperty<T> extends java.lang.ObjectAbstract superclass for MapBacked anything.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringpropertyThe key that the value will be associated with.protected java.util.MapsourceMapThe internal map in which all member values will be storedprotected TvalueIfMissingThe value to use if the value has not been set.
-
Constructor Summary
Constructors Constructor Description MapBackedProperty(java.util.Map sourceMap, java.lang.String property, T valueIfMissing)Construct a MapBackedProperty with a certain property name and default value
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tget()Return the value of the the property.protected abstract java.util.Optional<T>queryOption()Hook to allow the property to be queryablevoidset(T value)Set the value of the property.
-
-
-
Field Detail
-
sourceMap
protected final java.util.Map sourceMap
The internal map in which all member values will be stored
-
property
protected final java.lang.String property
The key that the value will be associated with. This is analogous to the variable name in a standard POJO
-
valueIfMissing
protected final T valueIfMissing
The value to use if the value has not been set. This is largely derived from the extending class so it can be a List for a collection, 0.0 for a double, etc Although it is analogous to a boolean being false by default, or an integer being -1 if it wasn't otherwise set, an Object will not be null by default unless that was specifically specified.
-
-
Constructor Detail
-
MapBackedProperty
public MapBackedProperty(java.util.Map sourceMap, java.lang.String property, T valueIfMissing)Construct a MapBackedProperty with a certain property name and default value- Parameters:
sourceMap- Map to store the value inproperty- Key name of the propertyvalueIfMissing- value to set if missing
-
-
Method Detail
-
get
public T get() throws com.legyver.core.exception.CoreException
Return the value of the the property. This is analogous to the standard getter on a POJO. If the value has not been set, it will be defaulted to thevalueIfMissing.- Returns:
- the property
- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
set
public void set(T value) throws com.legyver.core.exception.CoreException
Set the value of the property. This is analogous to a standard setter on a POJO.- Parameters:
value- the value to set- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
queryOption
protected abstract java.util.Optional<T> queryOption() throws com.legyver.core.exception.CoreException
Hook to allow the property to be queryable- Returns:
- the query option to use for the Property
- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
-