共用方式為


TwinMetadata Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.deps.twin.TwinMetadata

public class TwinMetadata

Representation of a single Twin metadata for the TwinCollection.

The metadata is a set of pairs lastUpdated/lastUpdatedVersion for each property and sub-property in the Twin. It is optionally provided by the service and the clients can only ready it.

This class store the Date and Version for each entity in the TwinCollection.

For instance, the following is a valid TwinCollection with its metadata.

"$metadata":{
      "$lastUpdated":"2017-09-21T02:07:44.238Z",
      "$lastUpdatedVersion":4,
      "MaxSpeed":{
          "$lastUpdated":"2017-09-21T02:07:44.238Z",
          "$lastUpdatedVersion":3,
          "Value":{
              "$lastUpdated":"2017-09-21T02:07:44.238Z",
              "$lastUpdatedVersion":5
          },
          "NewValue":{
              "$lastUpdated":"2017-09-21T02:07:44.238Z",
              "$lastUpdatedVersion":5
          }
      }
  }

Field Summary

Modifier and Type Field and Description
static final java.lang.String LAST_UPDATE_TAG
static final java.lang.String LAST_UPDATE_VERSION_TAG

Method Summary

Modifier and Type Method and Description
java.util.Date getLastUpdated()

Getter for the lastUpdated.

java.lang.Integer getLastUpdatedVersion()

Getter for the lastUpdatedVersion.

protected com.google.gson.JsonElement toJsonElement()

Serializer

java.lang.String toString()

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

protected static TwinMetadata tryExtractFromMap(Object metadata)

Metadata extractor

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

Field Details

LAST_UPDATE_TAG

public static final String LAST_UPDATE_TAG

LAST_UPDATE_VERSION_TAG

public static final String LAST_UPDATE_VERSION_TAG

Method Details

getLastUpdated

public Date getLastUpdated()

Getter for the lastUpdated.

Returns:

the Date with the stored lastUpdated. It can be null.

getLastUpdatedVersion

public Integer getLastUpdatedVersion()

Getter for the lastUpdatedVersion.

Returns:

the Integer with the stored lastUpdatedVersion. It can be null.

toJsonElement

protected JsonElement toJsonElement()

Serializer

Creates a JsonElement, which the content represents the information in this class 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:

TwinMetadata.toString()

Returns:

The String with the pretty print JSON.

tryExtractFromMap

protected static TwinMetadata tryExtractFromMap(Object metadata)

Metadata extractor

This internal method will try to find $lastUpdated and $lastUpdatedVersion at the first level of the provided Map (Object), and create a new instance of the TwinMetadata with this information.

Once the provide Object can or cannot be a Map, and, if it is a Map, it can or cannot contains a valid metadata, this method contains the label try, which means that it can return a valid TwinMetadata or null.

For instance, for the follow Map, this method will create a TwinMetadata with lastUpdated = 2015-09-21T02:07:44.238Z and lastUpdatedVersion = 3

"$lastUpdated":"2015-09-21T02:07:44.238Z",
 "$lastUpdatedVersion":3,
 "Value":{
     "$lastUpdated":"2016-09-21T02:07:44.238Z",
     "$lastUpdatedVersion":5
 },
 "NewValue":{
     "$lastUpdated":"2017-09-21T02:07:44.238Z",
     "$lastUpdatedVersion":5
 }

Parameters:

metadata - the Object that may contains the metadata.

Returns:

A valid TwinMetadata instance it the provided metadata Object is a Map with data and version metadata, or null for the other cases.

Applies to