org.apache.storm.starter.tools

## Class RankableObjectWithFields

- java.lang.Object
- - org.apache.storm.starter.tools.RankableObjectWithFields

- All Implemented Interfaces:
    Serializable, Comparable<Rankable>, Rankable

      public class RankableObjectWithFields
      extends Object
      implements Rankable, Serializable

  This class wraps an objects and its associated count, including any additional data fields.

  This class can be used, for instance, to track the number of occurrences of an object in a Storm topology.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RankableObjectWithFields(Object obj, long count, Object... otherFields)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(Rankable other)`
    `Rankable` | `copy()` Note: We do not defensively copy the wrapped object and any accompanying fields.
    `boolean` | `equals(Object o)`
    `static RankableObjectWithFields` | `from(Tuple tuple)` Construct a new instance based on the provided `Tuple`.
    `long` | `getCount()`
    `List<Object>` | `getFields()` Get fields.
    `Object` | `getObject()`
    `int` | `hashCode()`
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### RankableObjectWithFields

          public RankableObjectWithFields(Object obj,
                                          long count,
                                          Object... otherFields)

  - ### Method Detail

    - #### from

          public static RankableObjectWithFields from(Tuple tuple)

      Construct a new instance based on the provided `Tuple`.

      This method expects the object to be ranked in the first field (index 0) of the provided tuple, and the number of occurrences of the object (its count) in the second field (index 1). Any further fields in the tuple will be extracted and tracked, too. These fields can be accessed via `getFields()`.
      Parameters:
        `tuple` -
      Returns:
        new instance based on the provided tuple

    - #### getObject

          public Object getObject()

      Specified by:
        `getObject` in interface `Rankable`

    - #### getCount

          public long getCount()

      Specified by:
        `getCount` in interface `Rankable`

    - #### getFields

          public List<Object> getFields()

      Get fields.

      Returns:
        an immutable list of any additional data fields of the object (may be empty but will never be null)

    - #### compareTo

          public int compareTo(Rankable other)

      Specified by:
        `compareTo` in interface `Comparable<Rankable>`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### copy

          public Rankable copy()

      Note: We do not defensively copy the wrapped object and any accompanying fields. We do guarantee, however, do return a defensive (shallow) copy of the List object that is wrapping any accompanying fields.

      Specified by:
        `copy` in interface `Rankable`
      Returns:
        a defensive copy

Copyright © 2021 The Apache Software Foundation. All rights reserved.