Class TrailItemSet
- Direct Known Subclasses:
TrailItemSet.AllItems,TrailItemSet.None,TrailItemSet.OneItem,TrailItemSet.OneType,TrailItemSet.SpecificItems,TrailItemSet.SpecificTypes
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a set of all items.static classUsed to collect specific types and items stored in the TrailItemSet.static final classRepresents an empty set.static final classRepresents a set with just one item.static final classRepresents a set of all items of one specific type.static interfaceAlternate visitor interface for reading out the specific items and types.static final classRepresents a set of several specific items.static final classRepresents a set of all items of several specific types.static interfaceVisitor interface for analyzing the set. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaccept(TrailItemSet.Visitor visitor) Allows the caller to perform per-subclass actions.abstract booleancontains(ItemIdentity id) Checks if the set contains the given item.booleancontainsAny(Collection<ItemIdentity> itemIds) final booleanabstract TrailItemSetexpand(ItemIdentity trailItem) Expands the set to include the given item.final inthashCode()final booleanisEmpty()Returns true if this set will not match any item.static TrailItemSetof(ItemIdentity... ids) Constructs a set for specific item IDs.static TrailItemSetof(Collection<ItemIdentity> ids) Constructs a set for specific item IDs.static TrailItemSetofTypes(Collection<String> types) Constructs a set for specific item types.toString()abstract TrailItemSetunion(TrailItemSet anotherSet) Creates a new set with all items fromthisandanotherSetsets.
-
Method Details
-
contains
Checks if the set contains the given item.- Parameters:
id- item ID- Returns:
- true if the item is a part of this set
-
containsAny
-
expand
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
Creates a new set with all items from
thisandanotherSetsets.If
anotherSet == nullorthis.equals(anotherSet)-thisset should be returnedNote that:
AllItemsset union with any set is alwaysAllItemsset.- Type-based set union with any set is type-based set.
Noneunion with non nullanotherSetset is alwaysanotherSetset.- 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
AllItemsset if number of types after union is sufficient.
- Parameters:
anotherSet- - another set to union withthis- Returns:
- a new set with all items of
thisset andanotherSet
-
accept
Allows the caller to perform per-subclass actions. -
isEmpty
public final boolean isEmpty()Returns true if this set will not match any item. -
equals
-
hashCode
public final int hashCode() -
toString
-
of
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
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
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
-