# Class TraitChangeBatch

java.lang.Object
com.codename1.home.TraitChangeBatch

public final class TraitChangeBatch extends Object

A coalesced set of trait changes, delivered to a `HomeChangeListener` on the EDT.

##### One entry per trait, not one per change

Within the subscription's window -- see `SubscriptionRequest.setMinIntervalMillis(int)` -- changes are collapsed per accessory, service and trait, keeping only the newest value. Dragging a dimmer produces one reading showing where it ended up, not forty showing the journey.

That means a batch is a state update, not an event log: you cannot count changes from it and you cannot see intermediate values. If you need every step, set the window to zero and accept the cost.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TraitChangeBatch(String subscriptionId, List<TraitReading> readings, boolean initialDelivery, boolean resyncRequired)`
  Creates a batch.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<TraitReading>`
  `getReadings()`
  The changed values, one per trait that moved.
  `String`
  `getSubscriptionId()`
  Which subscription produced this batch.
  `boolean`
  `isEmpty()`
  Whether this batch carries no readings.
  `boolean`
  `isInitialDelivery()`
  Whether this is the up-front delivery of current values rather than a report of something that just changed.
  `boolean`
  `isResyncRequired()`
  Whether changes were missed and the values you hold cannot be trusted.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### TraitChangeBatch

    public TraitChangeBatch(String subscriptionId, List<TraitReading> readings, boolean initialDelivery, boolean resyncRequired)

    Creates a batch. Called by the ports and by the local home.

    ###### Parameters

    - `subscriptionId`: which subscription produced this

    - `readings`: the coalesced changes; `null` becomes empty

    - `initialDelivery`: whether this is the up-front delivery of current values requested by `SubscriptionRequest.setDeliverInitialValues(boolean)`

    - `resyncRequired`: whether changes were missed

- ## Method Details

  - ### getSubscriptionId

    public String getSubscriptionId()

    Which subscription produced this batch.

    Matches `TraitSubscription.getId()`. Worth checking when one listener serves several subscriptions.

    ###### Returns

    the subscription identifier, or `null`

  - ### getReadings

    public List<TraitReading> getReadings()

    The changed values, one per trait that moved.

    A reading here can have no value or carry an error, exactly as one from a read can -- an accessory going unreachable is a change worth delivering. See `TraitReading`.

    ###### Returns

    an immutable list, possibly empty

  - ### isInitialDelivery

    public boolean isInitialDelivery()

    Whether this is the up-front delivery of current values rather than a report of something that just changed.

    ###### Returns

    `true` for the initial delivery

  - ### isResyncRequired

    public boolean isResyncRequired()

    Whether changes were missed and the values you hold cannot be trusted.

    The platform dropped its notification stream -- the app was backgrounded long enough, the connection to a hub was rebuilt, the accessory rejoined. The readings in this batch are still good; everything else you were tracking through this subscription is stale.

    Re-read the traits you care about with `SmartHome.read(TraitReadRequest)`. Ignoring this leaves a UI showing values from before the gap, indefinitely, with nothing to indicate it.

    ###### Returns

    `true` when a full re-read is needed

  - ### isEmpty

    public boolean isEmpty()

    Whether this batch carries no readings.

    An empty batch is delivered only when `isResyncRequired()` is `true` -- a resync is worth telling you about even with nothing to show.

    ###### Returns

    `true` when there are no readings

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
    Overrides:
      `toString` in class `Object`