Package com.gears42.iot.webthing
Class Property<T>
- java.lang.Object
-
- com.gears42.iot.webthing.Property<T>
-
- Type Parameters:
T- The type of the property value.
public class Property<T> extends java.lang.ObjectA 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 classProperty.POLLING_TYPEPolling type of a property.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.gson.JsonObjectasPropertyDescription()Get the property description.java.lang.StringgetHref()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.StringgetName()Get the name of this property.ThinggetThing()Get the thing associated with this property.java.lang.StringgetType()Get the Value type of the property.TgetValue()Get the current property value.voidsetHrefPrefix(java.lang.String prefix)Set the prefix of any hrefs associated with this property.voidsetValue(T value)Set the current value of the property.
-
-
-
Constructor Detail
-
Property
public Property(Thing thing, java.lang.String name, Value<T> value)
Initialize the object.- Parameters:
thing- Thing this property belongs toname- Name of the propertyvalue- 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 toname- Name of the propertyvalue- Value object to hold the property valuemetadata- 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.
-
-