Object
TrailItemSet
Direct Known Subclasses:
TrailItemSet.AllItems, TrailItemSet.None, TrailItemSet.OneItem, TrailItemSet.OneType, TrailItemSet.SpecificItems, TrailItemSet.SpecificTypes

@PublicApi public abstract class TrailItemSet extends Object

Abstract class for defining a set of items (by their ItemIdentity). Specific subclasses provide the different ways to define a set.

The implementations of this class are immutable and thread-safe.

Implementation note: when adding another specific sub-class, make sure it is serializable and can be sent over to the client code.

See Also:
  • Method Details

    • contains

      public abstract boolean contains(@Nullable ItemIdentity id)
      Checks if the set contains the given item.
      Parameters:
      id - item ID
      Returns:
      true if the item is a part of this set
    • containsAny

      public boolean containsAny(@Nullable Collection<ItemIdentity> itemIds)
    • expand

      @NotNull public abstract TrailItemSet expand(@Nullable ItemIdentity trailItem)

      Expands the set to include the given item. The result of this operation is a new set, which a) includes everything this set includes, b) includes given item.

      Note that the resulting set may contain more items, due to escalation to a more wide set class. If you expand a set by a sufficient number of items, it will switch to be type-based set, which will contain all items of the given types.

      Parameters:
      trailItem - item to add to the set
      Returns:
      a new set with all items from this set and with trailItem
    • union

      @NotNull public abstract TrailItemSet union(@Nullable TrailItemSet anotherSet)

      Creates a new set with all items from this and anotherSet sets.

      If anotherSet == null or this.equals(anotherSet) - this set should be returned

      Note that:

      • AllItems set union with any set is always AllItems set.
      • Type-based set union with any set is type-based set.
      • None union with non null anotherSet set is always anotherSet set.
      • Union of NON type-set may switch to be type-based set if number of items after union is sufficient.
      • Union of type-set may switch to be AllItems set if number of types after union is sufficient.
      Parameters:
      anotherSet - - another set to union with this
      Returns:
      a new set with all items of this set and anotherSet
    • accept

      public abstract void accept(@NotNull TrailItemSet.Visitor visitor)
      Allows the caller to perform per-subclass actions.
    • isEmpty

      public final boolean isEmpty()
      Returns true if this set will not match any item.
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static TrailItemSet of(ItemIdentity... ids)
      Constructs a set for specific item IDs.
      Parameters:
      ids - item identities - null elements are ignored!
      Returns:
      a set that includes at least all the passed items
    • of

      public static TrailItemSet of(Collection<ItemIdentity> ids)
      Constructs a set for specific item IDs.
      Parameters:
      ids - item identities collection - null elements are ignored!
      Returns:
      a set that includes at least all the passed items
    • ofTypes

      public static TrailItemSet ofTypes(Collection<String> types)
      Constructs a set for specific item types.
      Parameters:
      types - item types - null elements are ignored!
      Returns:
      a set that includes all items of the given types