Class Property<T>

  • Type Parameters:
    T - The type of the property value.

    public class Property<T>
    extends java.lang.Object
     A Property object describes the available properties of a thing. property includes:
     
     1. A title (A name for the property)
     2. A description (A short description on the action)
     3. A links array (An array of links linking to one or more representations of an property resource, each with an implied default rel=property)
     4. A unit (SI unit of the property data)
     5. A minimum and maximum (Range of the property data)
     6. multipleOf (If input data is of numeric type it should be the multiple of this)
     7. enum (an enumeration of possible values for the property)
     8. A semantic @type (a string identifying a type from the linked context)
     9. A primitive type (Type of the input data)
     10. readOnly (A boolean value indicating whether the property is readonly or read-write, default is false)
    
     Example code snippet to create and add a property to a thing:
     
     Consider a light bulb, here the property indicates whether the light on or off
     
     	Map<String, Object> onDescription = new HashMap<String, Object>();
     	onDescription.put("@type", "OnOffProperty");
     	onDescription.put("title", "On/Off");
     	onDescription.put("type", "boolean");
     	onDescription.put("description", "Whether the light is turned on");
     	thing.addProperty(new Property(thing,"on",new Value(true),onDescription));
      
      
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Property.POLLING_TYPE
      Polling type of a property.
    • Constructor Summary

      Constructors 
      Constructor Description
      Property​(Thing thing, java.lang.String name, Value<T> value)
      Initialize the object.
      Property​(Thing thing, java.lang.String name, Value<T> value, java.util.Map<java.lang.String,​java.lang.Object> metadata)
      Initialize the object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.gson.JsonObject asPropertyDescription()
      Get the property description.
      java.lang.String getHref()
      Get the href of this property.
      java.util.Map<java.lang.String,​java.lang.Object> getMetadata()
      Get the metadata associated with this property.
      java.lang.String getName()
      Get the name of this property.
      Thing getThing()
      Get the thing associated with this property.
      java.lang.String getType()
      Get the Value type of the property.
      T getValue()
      Get the current property value.
      void setHrefPrefix​(java.lang.String prefix)
      Set the prefix of any hrefs associated with this property.
      void setValue​(T value)
      Set the current value of the property.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Property

        public Property​(Thing thing,
                        java.lang.String name,
                        Value<T> value)
        Initialize the object.
        Parameters:
        thing - Thing this property belongs to
        name - Name of the property
        value - Value object to hold the property value
      • Property

        public Property​(Thing thing,
                        java.lang.String name,
                        Value<T> value,
                        java.util.Map<java.lang.String,​java.lang.Object> metadata)
        Initialize the object.
        Parameters:
        thing - Thing this property belongs to
        name - Name of the property
        value - Value object to hold the property value
        metadata - Property metadata, i.e. type, description, unit, etc., as a Map
    • Method Detail

      • asPropertyDescription

        public com.google.gson.JsonObject asPropertyDescription()
        Get the property description.
        Returns:
        Description of the property as an object.
      • setHrefPrefix

        public void setHrefPrefix​(java.lang.String prefix)
        Set the prefix of any hrefs associated with this property.
        Parameters:
        prefix - The prefix
      • getHref

        public java.lang.String getHref()
        Get the href of this property.
        Returns:
        The href.
      • getValue

        public T getValue()
        Get the current property value.
        Returns:
        The current value.
      • setValue

        public void setValue​(T value)
                      throws PropertyError
        Set the current value of the property.
        Parameters:
        value - The value to set
        Throws:
        PropertyError - If value could not be set.
      • getName

        public java.lang.String getName()
        Get the name of this property.
        Returns:
        The proeprty name.
      • getType

        public java.lang.String getType()
        Get the Value type of the property.
        Returns:
        Value type of the property.
      • getThing

        public Thing getThing()
        Get the thing associated with this property.
        Returns:
        The thing.
      • getMetadata

        public java.util.Map<java.lang.String,​java.lang.Object> getMetadata()
        Get the metadata associated with this property.
        Returns:
        The metadata.