Class GeneralDatum

java.lang.Object
net.solarnetwork.domain.BasicIdentity<DatumId>
net.solarnetwork.domain.datum.GeneralDatum
All Implemented Interfaces:
Serializable, Cloneable, Comparable<DatumId>, Datum, DatumSamplesContainer, DatumSamplesOperations, MutableDatum, MutableDatumSamplesOperations, Differentiable<DatumSamplesOperations>, Identity<DatumId>

A basic implementation of MutableDatum.
Since:
1.71
Version:
2.0
Author:
matt
See Also:
  • Constructor Details

    • GeneralDatum

      public GeneralDatum(DatumId id, DatumSamples samples)
      Constructor.
      Parameters:
      id - the ID
      samples - the samples; if null a new instance will be created
    • GeneralDatum

      public GeneralDatum(String sourceId)
      Constructor.

      This creates a null kind and objectId and sets the timestamp to the system time.

      Parameters:
      sourceId - the source ID
    • GeneralDatum

      public GeneralDatum(String sourceId, Instant timestamp)
      Constructor.

      This creates a null kind and objectId.

      Parameters:
      sourceId - the source ID
      timestamp - the timestamp
    • GeneralDatum

      public GeneralDatum(String sourceId, Instant timestamp, DatumSamples samples)
      Constructor.

      This creates a null kind and objectId.

      Parameters:
      sourceId - the source ID
      timestamp - the timestamp
      samples - the samples
    • GeneralDatum

      public GeneralDatum(Long objectId, String sourceId, Instant timestamp, DatumSamples samples)
      Constructor.

      This creates a null kind.

      Parameters:
      objectId - the object ID
      sourceId - the source ID
      timestamp - the timestamp
      samples - the samples
  • Method Details

    • nodeDatum

      public static GeneralDatum nodeDatum(Long nodeId, String sourceId, Instant timestamp, DatumSamples samples)
      Create a node datum.
      Parameters:
      nodeId - the node ID
      sourceId - the source ID
      timestamp - the timestamp
      samples - the samples
      Returns:
      the new instance
    • locationDatum

      public static GeneralDatum locationDatum(Long locationId, String sourceId, Instant timestamp, DatumSamples samples)
      Create a location datum.
      Parameters:
      locationId - the location ID
      sourceId - the source ID
      timestamp - the timestamp
      samples - the samples
      Returns:
      the new instance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public GeneralDatum clone()
      Overrides:
      clone in class BasicIdentity<DatumId>
    • copyWithSamples

      public GeneralDatum copyWithSamples(DatumSamplesOperations samples)
      Description copied from interface: Datum
      Create a copy of this instance with the sample properties replaced by a given samples instance.
      Specified by:
      copyWithSamples in interface Datum
      Parameters:
      samples - the samples to use for the copy
      Returns:
      a new copy of this instance
    • copyWithId

      public GeneralDatum copyWithId(DatumId id)
      Description copied from interface: Datum
      Get a copy of this datum with a new ID.

      A new samples instance will also be created.

      Specified by:
      copyWithId in interface Datum
      Parameters:
      id - the new ID to use
      Returns:
      the copy with the given ID
    • getKind

      public ObjectDatumKind getKind()
      Get the object kind.
      Specified by:
      getKind in interface Datum
      Returns:
      the kind
    • getObjectId

      public Long getObjectId()
      Get the object ID.
      Specified by:
      getObjectId in interface Datum
      Returns:
      the object ID
    • getSourceId

      public String getSourceId()
      Description copied from interface: Datum
      Get a unique source ID for this datum.

      A single datum type may collect data from many different sources.

      Specified by:
      getSourceId in interface Datum
      Returns:
      the source ID
    • getTimestamp

      public Instant getTimestamp()
      Description copied from interface: Datum
      Get the date this datum is associated with, which is often equal to either the date it was persisted or the date the associated data in this object was captured.
      Specified by:
      getTimestamp in interface Datum
      Returns:
      the timestamp
    • getSampleData

      public Map<String,?> getSampleData()
      Description copied from interface: Datum
      Get a map of all available data sampled or collected on this datum.
      Specified by:
      getSampleData in interface Datum
      Returns:
      a map with all available sample data
    • asSimpleMap

      public Map<String,?> asSimpleMap()
      Description copied from interface: Datum
      Get a simple Map view of this datum.

      The returned map should include all the available properties of this datum, in as flat of a structure as possible, i.e. without nested maps. The property values should be composed only if simple Java types like numbers, strings, and arrays or lists of those types. It should also include the Datum.DATUM_TYPE_PROPERTY and Datum.DATUM_TYPES_PROPERTY values.

      Specified by:
      asSimpleMap in interface Datum
      Returns:
      a Map view of this datum
    • createSimpleMap

      protected Map<String,Object> createSimpleMap()
      Create a map of simple property data out of this object.

      This method will populate the properties of this class and the Datum.DATUM_TYPE_PROPERTY and Datum.DATUM_TYPES_PROPERTY properties with the result from calling datumTypes(). It will then call getSampleData() and add all those values to the returned result.

      Returns:
      a map of simple property data
    • datumTypes

      protected String[] datumTypes()
    • asSampleOperations

      public DatumSamplesOperations asSampleOperations()
      Description copied from interface: Datum
      Get a general accessor for the sample data.
      Specified by:
      asSampleOperations in interface Datum
      Returns:
      the operations instance, never null
    • asMutableSampleOperations

      public MutableDatumSamplesOperations asMutableSampleOperations()
      Description copied from interface: MutableDatum
      Get a mutable general accessor for the sample data.
      Specified by:
      asMutableSampleOperations in interface MutableDatum
      Returns:
      the operations instance, never null
    • isEmpty

      public boolean isEmpty()
      Test if this datum has any sample property values.
      Specified by:
      isEmpty in interface DatumSamplesOperations
      Returns:
      true if the samples is not empty
      See Also:
    • 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
    • setSampleData

      public void setSampleData(DatumSamplesType type, Map<String,?> data)
      Description copied from interface: MutableDatumSamplesOperations
      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
    • 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
    • getTags

      public Set<String> getTags()
      Description copied from interface: DatumSamplesOperations
      Get the sample tags.
      Specified by:
      getTags in interface DatumSamplesOperations
      Returns:
      the tags, or null
    • clear

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

      public void setTags(Set<String> tags)
      Set the sample tags.
      Specified by:
      setTags in interface MutableDatumSamplesOperations
      Parameters:
      tags - the tags to set
      See Also:
    • 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
    • hasTag

      public boolean hasTag(String tag)
      Test if a sample tag exists.
      Specified by:
      hasTag in interface DatumSamplesOperations
      Parameters:
      tag - the tag to test
      Returns:
      true if the sample tag exists
      See Also:
    • addTag

      public boolean addTag(String tag)
      Add a sample tag.
      Specified by:
      addTag in interface MutableDatumSamplesOperations
      Parameters:
      tag - the tag to add
      Returns:
      true if the tag was not already present
      See Also:
    • 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
    • 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
    • removeTag

      public void removeTag(String tag)
      Remove a sample tag.
      Parameters:
      tag - the tag to remove.
      See Also:
    • 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
    • getSamples

      public DatumSamples getSamples()
      Get the samples instance.
      Specified by:
      getSamples in interface DatumSamplesContainer
      Returns:
      the samples, never null