Class MapBackedCollection<U extends java.util.Collection<T>,​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.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MapBackedCollection​(java.util.Map sourceMap, java.lang.String property)
      Construct a MapBackedCollection with a certain property name.
      protected MapBackedCollection​(java.util.Map sourceMap, java.lang.String property, EntityInstantiator entityInstantiator)
      Construct a MapBackedCollection with a certain property name.
      protected MapBackedCollection​(java.util.Map sourceMap, java.lang.String property, java.util.Collection valueIfMissing)
      Construct a MapBackedEntityCollection with a certain property name.
      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
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(T value)
      Add a value to the collection
      protected java.util.Collection deTransform​(java.util.Collection<T> source)
      Reverses the transformation of the transform(Collection) method.
      U get()
      Return the internal collection.
      protected java.lang.Object map​(java.lang.Object o)
      Converts a map into an entity via the entityInstantiator.
      protected java.util.Optional<java.util.Collection> queryOption()
      Hook to allow the Collection to be queryable
      void remove​(T value)
      Remove a value from the collection
      void sync()
      Sync's the collection to the Map
      protected abstract java.lang.Object toMap​(T o)
      Return the internal map where the MapBackedCollection is stored
      protected U transform​(java.util.Collection source)
      Replace the internal collectionReference with the source collection transformed via the map(Object) method
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 in
        property - Key name of the property
        valueIfMissing - value to set if missing
        entityInstantiator - 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 in
        property - Key name of the property
        valueIfMissing - 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 in
        property - Key name of the property
        entityInstantiator - 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 in
        property - 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.CoreException
        Sync'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 the transform(Collection) method using super.get() as the parameter
        Overrides:
        get in class MapBackedProperty<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.CoreException
        Hook to allow the Collection to be queryable
        Specified by:
        queryOption in class MapBackedProperty<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 the map(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 the transform(Collection) method. The internal collection reference is not updated.
        Parameters:
        source - the collection to deTransform via the toMap(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 the entityInstantiator. 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