Class FunctionData

  • All Implemented Interfaces:
    java.lang.Comparable<java.lang.Object>
    Direct Known Subclasses:
    AlarmData, BooleanData, KeypadData, LevelData

    public abstract class FunctionData
    extends java.lang.Object
    implements java.lang.Comparable<java.lang.Object>
    Abstract Function data wrapper. A subclass must be used for an access to the property values by all functions. It takes care about the timestamp and additional metadata. The subclasses are responsible to provide concrete value and unit if required.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DESCRIPTION
      Metadata key, which value represents the data description.
      static java.lang.String FIELD_METADATA
      Represents the metadata field name.
      static java.lang.String FIELD_TIMESTAMP
      Represents the timestamp field name.
    • Constructor Summary

      Constructors 
      Constructor Description
      FunctionData​(long timestamp, java.util.Map<java.lang.String,​?> metadata)
      Constructs new FunctionData instance with the specified arguments.
      FunctionData​(java.util.Map<java.lang.String,​?> fields)
      Constructs new FunctionData instance with the specified field values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(java.lang.Object o)
      Compares this FunctionData instance with the given argument.
      boolean equals​(java.lang.Object other)
      Two FunctionData instances are equal if their metadata and timestamp are equivalent.
      java.util.Map<java.lang.String,​?> getMetadata()
      Returns FunctionData metadata.
      long getTimestamp()
      Returns FunctionData timestamp.
      int hashCode()
      Returns the hash code of this FunctionData.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FIELD_TIMESTAMP

        public static final java.lang.String FIELD_TIMESTAMP
        Represents the timestamp field name. The field value is available with getTimestamp(). The field type is long. The constant can be used as a key to FunctionData(Map).
        See Also:
        Constant Field Values
      • FIELD_METADATA

        public static final java.lang.String FIELD_METADATA
        Represents the metadata field name. The field value is available with getMetadata(). The field type is Map. The constant can be used as a key to FunctionData(Map).
        See Also:
        Constant Field Values
      • DESCRIPTION

        public static final java.lang.String DESCRIPTION
        Metadata key, which value represents the data description. The property value type is java.lang.String.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FunctionData

        public FunctionData​(java.util.Map<java.lang.String,​?> fields)
        Constructs new FunctionData instance with the specified field values. The map keys must match to the field names. The map values will be assigned to the appropriate class fields. For example, the maps can be: {"timestamp"=Long(1384440775495)}. That map will initialize the FIELD_TIMESTAMP field with 1384440775495. If timestamp is missing, Long.MIN_VALUE is used.
        Parameters:
        fields - Contains the new FunctionData instance field values.
        Throws:
        java.lang.ClassCastException - If the field value types are not expected.
        java.lang.NullPointerException - If the fields map is null.
      • FunctionData

        public FunctionData​(long timestamp,
                            java.util.Map<java.lang.String,​?> metadata)
        Constructs new FunctionData instance with the specified arguments.
        Parameters:
        timestamp - The data timestamp optional field.
        metadata - The data metadata optional field.
    • Method Detail

      • getTimestamp

        public long getTimestamp()
        Returns FunctionData timestamp. The timestamp is the difference between the value collecting time and midnight, January 1, 1970 UTC. It's measured in milliseconds. The device driver is responsible to generate that value when the value is received from the device. Long.MIN_VALUE value means no timestamp.
        Returns:
        FunctionData timestamp.
      • getMetadata

        public java.util.Map<java.lang.String,​?> getMetadata()
        Returns FunctionData metadata. It's dynamic metadata related only to this specific value. Possible keys:
        Returns:
        FunctionData metadata or null is there is no metadata.
      • equals

        public boolean equals​(java.lang.Object other)
        Two FunctionData instances are equal if their metadata and timestamp are equivalent.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        other - The other instance to compare. It must be of FunctionData type.
        Returns:
        true if this instance and argument have equivalent metadata and timestamp, false otherwise.
        See Also:
        Object.equals(java.lang.Object)
      • hashCode

        public int hashCode()
        Returns the hash code of this FunctionData.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        FunctionData hash code.
        See Also:
        Object.hashCode()
      • compareTo

        public int compareTo​(java.lang.Object o)
        Compares this FunctionData instance with the given argument. If the argument is not FunctionData, it throws ClassCastException. Otherwise, this method returns:
        • -1 if this instance timestamp is less than the argument timestamp. If they are equivalent, it can be the result of the metadata map deep comparison.
        • 0 if all fields are equivalent.
        • 1 if this instance timestamp is greater than the argument timestamp. If they are equivalent, it can be the result of the metadata map deep comparison.
        Metadata map deep comparison compares the elements of all nested java.util.Map and array instances. null is less than any other non-null instance.
        Specified by:
        compareTo in interface java.lang.Comparable<java.lang.Object>
        Parameters:
        o - FunctionData to be compared.
        Returns:
        -1, 0 or 1 depending on the comparison rules.
        Throws:
        java.lang.ClassCastException - If the method argument is not of type FunctionData or metadata maps contain values of different types for the same key.
        java.lang.NullPointerException - If the method argument is null.
        See Also:
        Comparable.compareTo(java.lang.Object)