Class MapSampleOperations

java.lang.Object
net.solarnetwork.domain.datum.MapSampleOperations
All Implemented Interfaces:
DatumSamplesOperations, MutableDatumSamplesOperations, Differentiable<DatumSamplesOperations>

public class MapSampleOperations extends Object implements MutableDatumSamplesOperations
MutableDatumSamplesOperations that delegates all operations to a simple Map.

All the methods of this API ignore any DatumSamplesType argument, and simply get/set values in a single Map passed to the constructor. A DatumSamplesOperations delegate can also be provided, in which case all get methods will delegate to that instance, falling back to the internal Map if the value is not found.

Since:
2.3
Version:
1.0
Author:
matt
  • Constructor Details

  • Method Details

    • getSampleData

      public Map<String,?> getSampleData(DatumSamplesType type)
      Description copied from interface: DatumSamplesOperations
      Get specific sample data.
      Specified by:
      getSampleData in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      Returns:
      a map with the specific sample data, or null
    • getSampleInteger

      public Integer getSampleInteger(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get an Integer value from a sample map, or null if not available.
      Specified by:
      getSampleInteger in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key of the value to get
      Returns:
      the value as an Integer, or null if not available
    • getSampleLong

      public Long getSampleLong(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get a Long value from a sample map, or null if not available.
      Specified by:
      getSampleLong in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key of the value to get
      Returns:
      the value as an Long, or null if not available
    • getSampleFloat

      public Float getSampleFloat(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get a Float value from a sample map, or null if not available.
      Specified by:
      getSampleFloat in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key of the value to get
      Returns:
      the value as an Float, or null if not available
    • getSampleDouble

      public Double getSampleDouble(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get a Double value from a sample map, or null if not available.
      Specified by:
      getSampleDouble in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key of the value to get
      Returns:
      the value as an Double, or null if not available
    • getSampleBigDecimal

      public BigDecimal getSampleBigDecimal(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get a BigDecimal value from a sample map, or null if not available.
      Specified by:
      getSampleBigDecimal in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key of the value to get
      Returns:
      the value as an BigDecimal, or null if not available
    • getSampleString

      public String getSampleString(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get a String value from a sample map, or null if not available.

      If type is DatumSamplesType.Tag, then this method will return key if a tag by that name exists and otherwise it will return null.

      Specified by:
      getSampleString in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key of the value, or tag name, to get
      Returns:
      the value as an String, or null if not available
    • getSampleValue

      public <V> V getSampleValue(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Get a sample value.

      If type is DatumSamplesType.Tag, then this method will return key if a tag by that name exists and otherwise it will return null.

      Specified by:
      getSampleValue in interface DatumSamplesOperations
      Type Parameters:
      V - the expected value type
      Parameters:
      type - the type of sample data to get
      key - the key of the value, or tag name, to get
      Returns:
      the value cast as a V, or null if not available
    • hasSampleValue

      public boolean hasSampleValue(DatumSamplesType type, String key)
      Description copied from interface: DatumSamplesOperations
      Test is a sample value is present for a given key.

      Tags can be tested for as well by passing DatumSamplesType.Tag and the tag name as key.

      Specified by:
      hasSampleValue in interface DatumSamplesOperations
      Parameters:
      type - the type of sample data to test
      key - the key of the value, or name of the tag, to look for
      Returns:
      true if a value is present for the given key
    • findSampleValue

      public <V> V findSampleValue(String key)
      Description copied from interface: DatumSamplesOperations
      Find a sample value.

      This will search Instantaneous, Accumulating, and Status data types, in that order, and return the first non-null value found.

      Specified by:
      findSampleValue in interface DatumSamplesOperations
      Type Parameters:
      V - the expected value type
      Parameters:
      key - the key of the value, or tag name, to get
      Returns:
      the value cast as a V, or null if not available
    • hasSampleValue

      public boolean hasSampleValue(String key)
      Description copied from interface: DatumSamplesOperations
      Test is a sample value is present for a given key.

      This will search Instantaneous, Accumulating, and Status data types, in that order, and return the first non-null value found.

      Specified by:
      hasSampleValue in interface DatumSamplesOperations
      Parameters:
      key - the key of the value, or name of the tag, to look for
      Returns:
      true if a value is present for the given key
    • clear

      public void clear()
      Description copied from interface: MutableDatumSamplesOperations
      Remove all property values and tags.
      Specified by:
      clear in interface MutableDatumSamplesOperations
    • putSampleValue

      public void putSampleValue(DatumSamplesType type, String key, Object value)
      Description copied from interface: MutableDatumSamplesOperations
      Add a value into or remove a value from a sample type collection, creating the collection if it doesn't already exist.

      To add a tag, pass the tag name for both key and value. To remove a tag, pass the tag name for key and null for value. To replace a tag, pass the tag to remove for key and the tag to add as value.

      For DatumSamplesType.Instantaneous and DatumSamplesType.Accumulating if value is non-null but not a Number, it will be silently ignored.

      Specified by:
      putSampleValue in interface MutableDatumSamplesOperations
      Parameters:
      type - the type of sample data to get
      key - the key to put, or tag to add/remove for DatumSamplesType.Tag
      value - the value to put, or tag to add, or null to remove the value; this will be cast without checking
    • setSampleData

      public void setSampleData(DatumSamplesType type, Map<String,?> data)
      Set the sample data map.

      Note this method does not set data as the map used internally by this class. Instead the internal map is cleared and all values in data are copied into it. This differs from the contract of MutableDatumSamplesOperations but is by design and simply a compromise required by this class.

      Set specific sample data.

      In the case of DatumSamplesType.Tag the keys of data will be used as the tag values to save.

      Specified by:
      setSampleData in interface MutableDatumSamplesOperations
      Parameters:
      type - the type of sample data to set
      data - the data to set; this is cast to the appropriate type without checking
    • getTags

      public Set<String> getTags()
      Set the tags.

      Note this method will always return null as tags are not supported.

      Get the sample tags.
      Specified by:
      getTags in interface DatumSamplesOperations
      Returns:
      the tags, or null
    • setTags

      public void setTags(Set<String> tags)
      Set the tags.

      Note this method does nothing as tags are not supported.

      Set the tags.
      Specified by:
      setTags in interface MutableDatumSamplesOperations
      Parameters:
      tags - the tags to set