Module com.legyver.utils.mapqua
Class MapBackedCollection<U extends java.util.Collection<T>,T>
- java.lang.Object
-
- com.legyver.utils.mapqua.mapbacked.MapBackedProperty<java.util.Collection>
-
- com.legyver.utils.mapqua.mapbacked.MapBackedCollection<U,T>
-
- Type Parameters:
U- Type of Collection (ie: List/Set)T- Type of Entity in the Collection
- Direct Known Subclasses:
MapBackedEntityCollection,MapBackedNativeCollection
public abstract class MapBackedCollection<U extends java.util.Collection<T>,T> extends MapBackedProperty<java.util.Collection>
Abstract superclass for MapBacked Collections.
-
-
Field Summary
-
Fields inherited from class com.legyver.utils.mapqua.mapbacked.MapBackedProperty
property, sourceMap, valueIfMissing
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMapBackedCollection(java.util.Map sourceMap, java.lang.String property)Construct a MapBackedCollection with a certain property name.protectedMapBackedCollection(java.util.Map sourceMap, java.lang.String property, EntityInstantiator entityInstantiator)Construct a MapBackedCollection with a certain property name.protectedMapBackedCollection(java.util.Map sourceMap, java.lang.String property, java.util.Collection valueIfMissing)Construct a MapBackedEntityCollection with a certain property name.protectedMapBackedCollection(java.util.Map sourceMap, java.lang.String property, java.util.Collection valueIfMissing, EntityInstantiator entityInstantiator)Construct a MapBackedCollection with a certain property name and default value
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(T value)Add a value to the collectionprotected java.util.CollectiondeTransform(java.util.Collection<T> source)Reverses the transformation of thetransform(Collection)method.Uget()Return the internal collection.protected java.lang.Objectmap(java.lang.Object o)Converts a map into an entity via theentityInstantiator.protected java.util.Optional<java.util.Collection>queryOption()Hook to allow the Collection to be queryablevoidremove(T value)Remove a value from the collectionvoidsync()Sync's the collection to the Mapprotected abstract java.lang.ObjecttoMap(T o)Return the internal map where the MapBackedCollection is storedprotected Utransform(java.util.Collection source)Replace the internal collectionReference with the source collection transformed via themap(Object)method-
Methods inherited from class com.legyver.utils.mapqua.mapbacked.MapBackedProperty
set
-
-
-
-
Constructor Detail
-
MapBackedCollection
protected MapBackedCollection(java.util.Map sourceMap, java.lang.String property, java.util.Collection valueIfMissing, EntityInstantiator entityInstantiator)Construct a MapBackedCollection with a certain property name and default value- Parameters:
sourceMap- Map to store the Collection value inproperty- Key name of the propertyvalueIfMissing- value to set if missingentityInstantiator- function to use to instantiate a new entry in the collection
-
MapBackedCollection
protected MapBackedCollection(java.util.Map sourceMap, java.lang.String property, java.util.Collection valueIfMissing)Construct a MapBackedEntityCollection with a certain property name.- Parameters:
sourceMap- Map to store the Collection value inproperty- Key name of the propertyvalueIfMissing- The default value.
-
MapBackedCollection
protected MapBackedCollection(java.util.Map sourceMap, java.lang.String property, EntityInstantiator entityInstantiator)Construct a MapBackedCollection with a certain property name. The default value will be a new ArrayList- Parameters:
sourceMap- Map to store the Collection value inproperty- Key name of the propertyentityInstantiator- function to use to instantiate a new entry in the collection
-
MapBackedCollection
protected MapBackedCollection(java.util.Map sourceMap, java.lang.String property)Construct a MapBackedCollection with a certain property name. The default value will be a new ArrayList The entityInstantiator will be null.- Parameters:
sourceMap- Map to store the Collection value inproperty- Key name of the property
-
-
Method Detail
-
add
public void add(T value) throws com.legyver.core.exception.CoreException
Add a value to the collection- Parameters:
value- the value to be added- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
remove
public void remove(T value) throws com.legyver.core.exception.CoreException
Remove a value from the collection- Parameters:
value- the value to be removed- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
sync
public void sync() throws com.legyver.core.exception.CoreExceptionSync's the collection to the Map- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
get
public U get() throws com.legyver.core.exception.CoreException
Return the internal collection. If the internal collection is null, it will create it via thetransform(Collection)method using super.get() as the parameter- Overrides:
getin classMapBackedProperty<java.util.Collection>- Returns:
- the internal collection
- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
queryOption
protected java.util.Optional<java.util.Collection> queryOption() throws com.legyver.core.exception.CoreExceptionHook to allow the Collection to be queryable- Specified by:
queryOptionin classMapBackedProperty<java.util.Collection>- Returns:
- the query option to use for the Collection
- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
transform
protected U transform(java.util.Collection source)
Replace the internal collectionReference with the source collection transformed via themap(Object)method- Parameters:
source- the source collection- Returns:
- the internal collectionReference
-
deTransform
protected java.util.Collection deTransform(java.util.Collection<T> source) throws com.legyver.core.exception.CoreException
Reverses the transformation of thetransform(Collection)method. The internal collection reference is not updated.- Parameters:
source- the collection to deTransform via thetoMap(Object)method- Returns:
- the source collection de-transformed
- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
toMap
protected abstract java.lang.Object toMap(T o) throws com.legyver.core.exception.CoreException
Return the internal map where the MapBackedCollection is stored- Parameters:
o- the object whose map will be returned- Returns:
- the raw map for the passed in Object
- Throws:
com.legyver.core.exception.CoreException- if there is a problem marshalling to/from JSON
-
map
protected final java.lang.Object map(java.lang.Object o)
Converts a map into an entity via theentityInstantiator. If the entityInstantiator is null, any Map will not be converted- Parameters:
o- object to be converted- Returns:
- the object or a map converted to an entity
-
-