TwinState Class

public class TwinState
extends RegisterManager

Representation of a single Twin.

The TwinState can contain one TwinCollection of Tags, and one TwinCollection of properties.desired.

Each entity in the collections can contain a associated TwinMetadata.

These metadata are provided by the Service and contains information about the last updated date time, and version.

For instance, the following is a valid TwinState, represented as initialTwin in the rest API.

Java
{
          "initialTwin": {
              "tags":{
                  "SpeedUnity":"MPH",
                  "$metadata":{
                      "$lastUpdated":"2017-09-21T02:07:44.238Z",
                      "$lastUpdatedVersion":4,
                      "SpeedUnity":{
                          "$lastUpdated":"2017-09-21T02:07:44.238Z",
                          "$lastUpdatedVersion":4
                      }
                  },
                  "$version":4
              },
              "properties":{
                  "desired": {
                      "MaxSpeed":{
                          "Value":500,
                          "NewValue":300
                      },
                      "$metadata":{
                          "$lastUpdated":"2017-09-21T02:07:44.238Z",
                          "$lastUpdatedVersion":4,
                          "MaxSpeed":{
                              "$lastUpdated":"2017-09-21T02:07:44.238Z",
                              "$lastUpdatedVersion":4,
                              "Value":{
                                  "$lastUpdated":"2017-09-21T02:07:44.238Z",
                                  "$lastUpdatedVersion":4
                              },
                              "NewValue":{
                                  "$lastUpdated":"2017-09-21T02:07:44.238Z",
                                  "$lastUpdatedVersion":4
                              }
                          }
                      },
                      "$version":4
                  },
                  "reported": {
                      "MaxSpeed":{
                          "Value":500,
                          "NewValue":300
                      },
                      "$metadata":{
                          "$lastUpdated":"2017-09-21T02:07:44.238Z",
                          "$lastUpdatedVersion":5,
                          "MaxSpeed":{
                              "$lastUpdated":"2017-09-21T02:07:44.238Z",
                              "$lastUpdatedVersion":4,
                              "Value":{
                                  "$lastUpdated":"2017-09-21T02:07:44.238Z",
                                  "$lastUpdatedVersion":5
                              },
                              "NewValue":{
                                  "$lastUpdated":"2017-09-21T02:07:44.238Z",
                                  "$lastUpdatedVersion":4
                              }
                          }
                      },
                      "$version":6
                  }
              }
          }
      }

Constructor Summary

Method Summary

Modifier and Type Method and Description
static TwinState createFromDesiredPropertyJson(String json)

Factory

static TwinState createFromPropertiesJson(String json)

Factory

static TwinState createFromReportedPropertyJson(String json)

Factory

static TwinState createFromTwinJson(String json)

Factory

java.util.Map<java.lang.String,ConfigurationInfo> getConfigurations()

Getter for the configurations

java.lang.String getConnectionState()

Get the connection state

TwinCollection getDesiredProperty()

Getter for the desired property.

java.lang.String getDeviceScope()

Gets the device scope.

java.util.List<java.lang.String> getParentScopes()

Gets the parent scopes.

TwinCollection getReportedProperty()

Getter for the reported property.

TwinCollection getTags()

Getter for the tags.

com.google.gson.JsonElement toJsonElement()

Serializer

java.lang.String toString()

Creates a pretty print JSON with the content of this class and subclasses.

Methods inherited from RegisterManager

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

TwinState

public TwinState(TwinCollection tags, TwinCollection desiredProperty, TwinCollection reportedProperty)

CONSTRUCTOR

This constructor creates an instance of the TwinState with the provided TwinCollection tags and desired properties.

When serialized, this class will looks like the following example:

Java
"initialTwin": {
              "tags":{
                  "SpeedUnity":"MPH",
                  "$version":4
              }
              "properties":{
                  "desired":{
                      "MaxSpeed":{
                          "Value":500,
                          "NewValue":300
                      },
                      "$version":4
                  }
              }
          }
      
     }

Parameters:

tags - the TwinCollection with the initial tags state. It can be null.
desiredProperty - the TwinCollection with the desired properties. It can be null.
reportedProperty - the TwinCollection with the reported properties. It can be null.

Method Details

createFromDesiredPropertyJson

public static TwinState createFromDesiredPropertyJson(String json)

Factory

Create a new instance of the TwinState parsing the provided string as a JSON with only desired properties information.

Parameters:

json - the String with the JSON received from the service. It cannot be null or empty.

Returns:

The new instance of the TwinState.

createFromPropertiesJson

public static TwinState createFromPropertiesJson(String json)

Factory

Create a new instance of the TwinState parsing the provided string as a JSON with only desired properties information.

Parameters:

json - the String with the JSON received from the service. It cannot be null or empty.

Returns:

The new instance of the TwinState.

createFromReportedPropertyJson

public static TwinState createFromReportedPropertyJson(String json)

Factory

Create a new instance of the TwinState parsing the provided string as a JSON with only reported properties information.

Parameters:

json - the String with the JSON received from the service. It cannot be null or empty.

Returns:

The new instance of the TwinState.

createFromTwinJson

public static TwinState createFromTwinJson(String json)

Factory

Create a new instance of the TwinState parsing the provided string as a JSON with the full Twin information.

Parameters:

json - the String with the JSON received from the service. It cannot be null or empty.

Returns:

The new instance of the TwinState.

getConfigurations

public Map getConfigurations()

Getter for the configurations

Returns:

The configurations. It can be null.

getConnectionState

public String getConnectionState()

Get the connection state

Returns:

the connection state

getDesiredProperty

public TwinCollection getDesiredProperty()

Getter for the desired property.

Returns:

The TwinCollection with the desired property content. It can be null.

getDeviceScope

public String getDeviceScope()

Gets the device scope.

Returns:

The device scope.

getParentScopes

public List getParentScopes()

Gets the parent scopes.

Returns:

The parent scopes.

getReportedProperty

public TwinCollection getReportedProperty()

Getter for the reported property.

Returns:

The TwinCollection with the reported property content. It can be null.

getTags

public TwinCollection getTags()

Getter for the tags.

Returns:

The TwinCollection with the tags content. It can be null.

toJsonElement

public JsonElement toJsonElement()

Serializer

Creates a JsonElement, which the content represents the information in this class and its subclasses in a JSON format. This is useful if the caller will integrate this JSON with JSON from other classes to generate a consolidated JSON.

Returns:

The JsonElement with the content of this class.

toString

public String toString()

Creates a pretty print JSON with the content of this class and subclasses.

Overrides:

TwinState.toString()

Returns:

The String with the pretty print JSON.

Applies to

Azure SDK for Java

Latest