TwinState Class
- java.
lang. Object - com.
microsoft. azure. sdk. iot. service. twin. TwinState
- com.
public class TwinState
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
</code> in the rest API. <pre><code>{
"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
}
}
}
}
</code></pre></p>
Field Summary
Modifier and Type
Field and Description
TwinConnectionState
connectionState
Constructor Summary
Constructor
Description
TwinState(String json)
Create a new instance of the TwinState parsing the provided string as a JSON with the full Twin information.
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
}
}
}
}
Method Summary
Modifier and Type
Method and Description
TwinState
createFromDesiredPropertyJson(String json)
Factory
Create a new instance of the TwinState parsing the provided string as a JSON with only desired properties information.
TwinState
createFromPropertiesJson(String json)
Factory
Create a new instance of the TwinState parsing the provided string as a JSON with only desired properties information.
TwinState
createFromReportedPropertyJson(String json)
Factory
Create a new instance of the TwinState parsing the provided string as a JSON with only reported properties information.
String
getConnectionState()
Get the connection state
TwinCollection
getDesiredProperties()
Getter for the desired property.
TwinCollection
getReportedProperties()
Getter for the reported property.
TwinCollection
getTags()
Getter for the tags.
JsonElement
toJsonElement()
Serializer
Creates aJsonElement
</code> , which the content represents the information in this class and its subclasses in a JSON format.</p>
This is useful if the caller will integrate this JSON with JSON from other classes to generate a consolidated JSON.
String
toString()
Creates a pretty print JSON with the content of this class and subclasses.
Field Details
connectionState
protected TwinConnectionState connectionState= null
Constructor Details
TwinState
public TwinState(String json)
Create a new instance of the TwinState parsing the provided string as a JSON with the full Twin information.
Parameters:
json
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
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:
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
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwinState
</code> . </p>
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
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwinState
</code> . </p>
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
- theString
</code> with the JSON received from the service. It cannot be<code>null
</code> or empty. </p>
Returns:
The new instance of theTwinState
</code> . </p>
getConnectionState
public String getConnectionState()
Get the connection state
Returns:
the connection state
getDesiredProperties
public TwinCollection getDesiredProperties()
Getter for the desired property.
Returns:
TheTwinCollection
</code> with the desired property content. It can be<code>null
</code> . </p>
getReportedProperties
public TwinCollection getReportedProperties()
Getter for the reported property.
Returns:
TheTwinCollection
</code> with the reported property content. It can be<code>null
</code> . </p>
getTags
public TwinCollection getTags()
Getter for the tags.
Returns:
TheTwinCollection
</code> with the tags content. It can be<code>null
</code> . </p>
toJsonElement
public JsonElement toJsonElement()
Serializer
Creates aJsonElement
</code> , which the content represents the information in this class and its subclasses in a JSON format.</p>
This is useful if the caller will integrate this JSON with JSON from other classes to generate a consolidated JSON.
Returns:
TheJsonElement
</code> with the content of this class. </p>
toString
public String toString()
Creates a pretty print JSON with the content of this class and subclasses.
Returns:
TheString
</code> with the pretty print JSON. </p>
Applies to
Azure SDK for Java