Class GeneralDatum
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<DatumId>,Datum,DatumSamplesContainer,DatumSamplesOperations,MutableDatum,MutableDatumSamplesOperations,Differentiable<DatumSamplesOperations>,Identity<DatumId>
MutableDatum.- Since:
- 1.71
- Version:
- 2.0
- Author:
- matt
- See Also:
-
Field Summary
Fields inherited from interface net.solarnetwork.domain.datum.Datum
DATUM_TYPE_PROPERTY, DATUM_TYPES_PROPERTY, OP_STATE, OP_STATES, REVERSE_ACCUMULATING_SUFFIX_KEY, SOURCE_ID, TIMESTAMP -
Constructor Summary
ConstructorsConstructorDescriptionGeneralDatum(Long objectId, String sourceId, Instant timestamp, DatumSamples samples) Constructor.GeneralDatum(String sourceId) Constructor.GeneralDatum(String sourceId, Instant timestamp) Constructor.GeneralDatum(String sourceId, Instant timestamp, DatumSamples samples) Constructor.GeneralDatum(DatumId id, DatumSamples samples) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a sample tag.Get a mutable general accessor for the sample data.Get a general accessor for the sample data.Get a simpleMapview of this datum.voidclear()Remove all property values and tags.clone()copyWithId(DatumId id) Get a copy of this datum with a new ID.copyWithSamples(DatumSamplesOperations samples) Create a copy of this instance with the sample properties replaced by a given samples instance.Create a map of simple property data out of this object.protected String[]<V> VfindSampleValue(String key) Find a sample value.getKind()Get the object kind.Get the object ID.getSampleBigDecimal(DatumSamplesType type, String key) Get a BigDecimal value from a sample map, or null if not available.Get a map of all available data sampled or collected on this datum.Get specific sample data.getSampleDouble(DatumSamplesType type, String key) Get a Double value from a sample map, or null if not available.getSampleFloat(DatumSamplesType type, String key) Get a Float value from a sample map, or null if not available.getSampleInteger(DatumSamplesType type, String key) Get an Integer value from a sample map, or null if not available.getSampleLong(DatumSamplesType type, String key) Get a Long value from a sample map, or null if not available.Get the samples instance.getSampleString(DatumSamplesType type, String key) Get a String value from a sample map, or null if not available.<V> VgetSampleValue(DatumSamplesType type, String key) Get a sample value.Get a unique source ID for this datum.getTags()Get the sample tags.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.booleanhasSampleValue(String key) Test is a sample value is present for a given key.booleanhasSampleValue(DatumSamplesType type, String key) Test is a sample value is present for a given key.booleanTest if a sample tag exists.booleanisEmpty()Test if this datum has any sample property values.static GeneralDatumlocationDatum(Long locationId, String sourceId, Instant timestamp, DatumSamples samples) Create a location datum.static GeneralDatumnodeDatum(Long nodeId, String sourceId, Instant timestamp, DatumSamples samples) Create a node datum.voidputSampleValue(DatumSamplesType type, String key, Object value) Add a value into or remove a value from a sample type collection, creating the collection if it doesn't already exist.voidRemove a sample tag.voidsetSampleData(DatumSamplesType type, Map<String, ?> data) Set specific sample data.voidSet the sample tags.toString()Methods inherited from class net.solarnetwork.domain.BasicIdentity
compareTo, equals, getId, hashCodeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface net.solarnetwork.domain.datum.DatumSamplesOperations
differsFromMethods inherited from interface net.solarnetwork.domain.datum.MutableDatumSamplesOperations
copyFrom, mergeFrom, mergeFrom, removeTag
-
Constructor Details
-
GeneralDatum
Constructor.- Parameters:
id- the IDsamples- the samples; if null a new instance will be created
-
GeneralDatum
Constructor.This creates a null
kindandobjectIdand sets the timestamp to the system time.- Parameters:
sourceId- the source ID
-
GeneralDatum
Constructor.This creates a null
kindandobjectId.- Parameters:
sourceId- the source IDtimestamp- the timestamp
-
GeneralDatum
Constructor.This creates a null
kindandobjectId.- Parameters:
sourceId- the source IDtimestamp- the timestampsamples- the samples
-
GeneralDatum
Constructor.This creates a null
kind.- Parameters:
objectId- the object IDsourceId- the source IDtimestamp- the timestampsamples- 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 IDsourceId- the source IDtimestamp- the timestampsamples- 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 IDsourceId- the source IDtimestamp- the timestampsamples- the samples- Returns:
- the new instance
-
toString
-
clone
- Overrides:
clonein classBasicIdentity<DatumId>
-
copyWithSamples
Description copied from interface:DatumCreate a copy of this instance with the sample properties replaced by a given samples instance.- Specified by:
copyWithSamplesin interfaceDatum- Parameters:
samples- the samples to use for the copy- Returns:
- a new copy of this instance
-
copyWithId
Description copied from interface:DatumGet a copy of this datum with a new ID.A new samples instance will also be created.
- Specified by:
copyWithIdin interfaceDatum- Parameters:
id- the new ID to use- Returns:
- the copy with the given ID
-
getKind
Get the object kind. -
getObjectId
Get the object ID.- Specified by:
getObjectIdin interfaceDatum- Returns:
- the object ID
-
getSourceId
Description copied from interface:DatumGet a unique source ID for this datum.A single datum type may collect data from many different sources.
- Specified by:
getSourceIdin interfaceDatum- Returns:
- the source ID
-
getTimestamp
Description copied from interface:DatumGet 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:
getTimestampin interfaceDatum- Returns:
- the timestamp
-
getSampleData
Description copied from interface:DatumGet a map of all available data sampled or collected on this datum.- Specified by:
getSampleDatain interfaceDatum- Returns:
- a map with all available sample data
-
asSimpleMap
Description copied from interface:DatumGet a simpleMapview 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_PROPERTYandDatum.DATUM_TYPES_PROPERTYvalues.- Specified by:
asSimpleMapin interfaceDatum- Returns:
- a Map view of this datum
-
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_PROPERTYandDatum.DATUM_TYPES_PROPERTYproperties with the result from callingdatumTypes(). It will then callgetSampleData()and add all those values to the returned result.- Returns:
- a map of simple property data
-
datumTypes
-
asSampleOperations
Description copied from interface:DatumGet a general accessor for the sample data.- Specified by:
asSampleOperationsin interfaceDatum- Returns:
- the operations instance, never null
-
asMutableSampleOperations
Description copied from interface:MutableDatumGet a mutable general accessor for the sample data.- Specified by:
asMutableSampleOperationsin interfaceMutableDatum- Returns:
- the operations instance, never null
-
isEmpty
public boolean isEmpty()Test if this datum has any sample property values.- Specified by:
isEmptyin interfaceDatumSamplesOperations- Returns:
- true if the samples is not empty
- See Also:
-
getSampleData
Description copied from interface:DatumSamplesOperationsGet specific sample data.- Specified by:
getSampleDatain interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to get- Returns:
- a map with the specific sample data, or null
-
setSampleData
Description copied from interface:MutableDatumSamplesOperationsSet specific sample data.In the case of
DatumSamplesType.Tagthe keys ofdatawill be used as the tag values to save.- Specified by:
setSampleDatain interfaceMutableDatumSamplesOperations- Parameters:
type- the type of sample data to setdata- the data to set; this is cast to the appropriate type without checking
-
getSampleInteger
Description copied from interface:DatumSamplesOperationsGet an Integer value from a sample map, or null if not available.- Specified by:
getSampleIntegerin interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key of the value to get- Returns:
- the value as an Integer, or null if not available
-
getSampleLong
Description copied from interface:DatumSamplesOperationsGet a Long value from a sample map, or null if not available.- Specified by:
getSampleLongin interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key of the value to get- Returns:
- the value as an Long, or null if not available
-
getSampleFloat
Description copied from interface:DatumSamplesOperationsGet a Float value from a sample map, or null if not available.- Specified by:
getSampleFloatin interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key of the value to get- Returns:
- the value as an Float, or null if not available
-
getSampleDouble
Description copied from interface:DatumSamplesOperationsGet a Double value from a sample map, or null if not available.- Specified by:
getSampleDoublein interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key of the value to get- Returns:
- the value as an Double, or null if not available
-
getSampleBigDecimal
Description copied from interface:DatumSamplesOperationsGet a BigDecimal value from a sample map, or null if not available.- Specified by:
getSampleBigDecimalin interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key of the value to get- Returns:
- the value as an BigDecimal, or null if not available
-
getSampleString
Description copied from interface:DatumSamplesOperationsGet a String value from a sample map, or null if not available.If
typeisDatumSamplesType.Tag, then this method will returnkeyif a tag by that name exists and otherwise it will return null.- Specified by:
getSampleStringin interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key of the value, or tag name, to get- Returns:
- the value as an String, or null if not available
-
getSampleValue
Description copied from interface:DatumSamplesOperationsGet a sample value.If
typeisDatumSamplesType.Tag, then this method will returnkeyif a tag by that name exists and otherwise it will return null.- Specified by:
getSampleValuein interfaceDatumSamplesOperations- Type Parameters:
V- the expected value type- Parameters:
type- the type of sample data to getkey- the key of the value, or tag name, to get- Returns:
- the value cast as a
V, or null if not available
-
getTags
Description copied from interface:DatumSamplesOperationsGet the sample tags.- Specified by:
getTagsin interfaceDatumSamplesOperations- Returns:
- the tags, or null
-
clear
public void clear()Description copied from interface:MutableDatumSamplesOperationsRemove all property values and tags.- Specified by:
clearin interfaceMutableDatumSamplesOperations
-
setTags
Set the sample tags.- Specified by:
setTagsin interfaceMutableDatumSamplesOperations- Parameters:
tags- the tags to set- See Also:
-
findSampleValue
Description copied from interface:DatumSamplesOperationsFind a sample value.This will search
Instantaneous,Accumulating, andStatusdata types, in that order, and return the first non-null value found.- Specified by:
findSampleValuein interfaceDatumSamplesOperations- 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
Test if a sample tag exists.- Specified by:
hasTagin interfaceDatumSamplesOperations- Parameters:
tag- the tag to test- Returns:
- true if the sample tag exists
- See Also:
-
addTag
Add a sample tag.- Specified by:
addTagin interfaceMutableDatumSamplesOperations- Parameters:
tag- the tag to add- Returns:
- true if the tag was not already present
- See Also:
-
hasSampleValue
Description copied from interface:DatumSamplesOperationsTest is a sample value is present for a given key.This will search
Instantaneous,Accumulating, andStatusdata types, in that order, and return the first non-null value found.- Specified by:
hasSampleValuein interfaceDatumSamplesOperations- 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
Description copied from interface:MutableDatumSamplesOperationsAdd 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
keyandvalue. To remove a tag, pass the tag name forkeyand null forvalue. To replace a tag, pass the tag to remove forkeyand the tag to add asvalue.For
DatumSamplesType.InstantaneousandDatumSamplesType.Accumulatingifvalueis non-null but not aNumber, it will be silently ignored.- Specified by:
putSampleValuein interfaceMutableDatumSamplesOperations- Parameters:
type- the type of sample data to getkey- the key to put, or tag to add/remove forDatumSamplesType.Tagvalue- the value to put, or tag to add, or null to remove the value; this will be cast without checking
-
removeTag
Remove a sample tag.- Parameters:
tag- the tag to remove.- See Also:
-
hasSampleValue
Description copied from interface:DatumSamplesOperationsTest is a sample value is present for a given key.Tags can be tested for as well by passing
DatumSamplesType.Tagand the tag name askey.- Specified by:
hasSampleValuein interfaceDatumSamplesOperations- Parameters:
type- the type of sample data to testkey- 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
Get the samples instance.- Specified by:
getSamplesin interfaceDatumSamplesContainer- Returns:
- the samples, never null
-