TwinState Class
- java.
lang. Object - com.
microsoft. azure. sdk. iot. deps. twin. RegisterManager - com.
microsoft. azure. sdk. iot. deps. twin. TwinState
- com.
- com.
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.
{
"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 | Description |
---|---|
Twin |
CONSTRUCTOR |
Modifier and Type | Method and Description |
---|---|
static
Twin |
create Factory |
static
Twin |
create Factory |
static
Twin |
create Factory |
static
Twin |
create Factory |
java.util.Map<java.lang.String,Configuration |
get Getter for the configurations |
java.lang.String |
get Get the connection state |
Twin |
get Getter for the desired property. |
java.lang.String |
get Gets the device scope. |
java.util.List<java.lang.String> |
get Gets the parent scopes. |
Twin |
get Getter for the reported property. |
Twin |
get Getter for the tags. |
com.google.gson.JsonElement |
to Serializer |
java.lang.String |
to Creates a pretty print JSON with the content of this class and subclasses. |
Methods inherited from RegisterManager
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:
"initialTwin": {
"tags":{
"SpeedUnity":"MPH",
"$version":4
}
"properties":{
"desired":{
"MaxSpeed":{
"Value":500,
"NewValue":300
},
"$version":4
}
}
}
}
Parameters:
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:
String
with the JSON received from the service. It cannot be null
or empty.
Returns:
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:
String
with the JSON received from the service. It cannot be null
or empty.
Returns:
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:
String
with the JSON received from the service. It cannot be null
or empty.
Returns:
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:
String
with the JSON received from the service. It cannot be null
or empty.
Returns:
TwinState
.getConfigurations
public Map
Getter for the configurations
Returns:
null
.getConnectionState
public String getConnectionState()
Get the connection state
Returns:
getDesiredProperty
public TwinCollection getDesiredProperty()
Getter for the desired property.
Returns:
TwinCollection
with the desired property content. It can be null
.getDeviceScope
public String getDeviceScope()
Gets the device scope.
Returns:
getParentScopes
public List
Gets the parent scopes.
Returns:
getReportedProperty
public TwinCollection getReportedProperty()
Getter for the reported property.
Returns:
TwinCollection
with the reported property content. It can be null
.getTags
public TwinCollection getTags()
Getter for the tags.
Returns:
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:
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:
String
with the pretty print JSON.Azure SDK for Java geri bildirimi
Azure SDK for Java, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: