Class MapSampleOperations
- All Implemented Interfaces:
DatumSamplesOperations,MutableDatumSamplesOperations,Differentiable<DatumSamplesOperations>
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 Summary
ConstructorsConstructorDescriptionMapSampleOperations(Map<String, Object> parameters) Constructor.MapSampleOperations(Map<String, Object> parameters, DatumSamplesOperations datum) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all property values and tags.<V> VfindSampleValue(String key) Find a sample value.getSampleBigDecimal(DatumSamplesType type, String key) Get a BigDecimal value from a sample map, or null if not available.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.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.getTags()Set the tags.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.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.voidsetSampleData(DatumSamplesType type, Map<String, ?> data) Set the sample data map.voidSet the tags.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.domain.datum.DatumSamplesOperations
differsFrom, hasTag, isEmpty
-
Constructor Details
-
MapSampleOperations
Constructor.- Parameters:
parameters- the parameters- Throws:
IllegalArgumentException- if any argument is null
-
MapSampleOperations
Constructor.- Parameters:
parameters- the parametersdatum- the optional sample operations to delegate get operations to- Throws:
IllegalArgumentException- ifparametersis null
-
-
Method Details
-
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
-
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
-
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
-
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
-
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
-
clear
public void clear()Description copied from interface:MutableDatumSamplesOperationsRemove all property values and tags.- Specified by:
clearin interfaceMutableDatumSamplesOperations
-
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
-
setSampleData
Set the sample data map.Note this method does not set
Set specific sample data.dataas the map used internally by this class. Instead the internal map is cleared and all values indataare copied into it. This differs from the contract ofMutableDatumSamplesOperationsbut is by design and simply a compromise required by this class.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
-
getTags
Set the tags.Note this method will always return null as tags are not supported.
Get the sample tags.- Specified by:
getTagsin interfaceDatumSamplesOperations- Returns:
- the tags, or null
-
setTags
Set the tags.Note this method does nothing as tags are not supported.
Set the tags.- Specified by:
setTagsin interfaceMutableDatumSamplesOperations- Parameters:
tags- the tags to set
-