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:
  • Constructor Details

    • RankableObjectWithFields

      public RankableObjectWithFields(Object obj, long count, Object... otherFields)
  • Method Details

    • 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