Class MapBackedProperty<T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String property
      The key that the value will be associated with.
      protected java.util.Map sourceMap
      The internal map in which all member values will be stored
      protected T valueIfMissing
      The 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
      T get()
      Return the value of the the property.
      protected abstract java.util.Optional<T> queryOption()
      Hook to allow the property to be queryable
      void set​(T value)
      Set the value of the property.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 in
        property - Key name of the property
        valueIfMissing - 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 the valueIfMissing.
        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