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 class
Represents a set of all items.static class
Used to collect specific types and items stored in the TrailItemSet.static final class
Represents an empty set.static final class
Represents a set with just one item.static final class
Represents a set of all items of one specific type.static interface
Alternate visitor interface for reading out the specific items and types.static final class
Represents a set of several specific items.static final class
Represents a set of all items of several specific types.static interface
Visitor interface for analyzing the set. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
accept
(TrailItemSet.Visitor visitor) Allows the caller to perform per-subclass actions.abstract boolean
contains
(ItemIdentity id) Checks if the set contains the given item.boolean
containsAny
(Collection<ItemIdentity> itemIds) final boolean
abstract TrailItemSet
expand
(ItemIdentity trailItem) Expands the set to include the given item.final int
hashCode()
final boolean
isEmpty()
Returns true if this set will not match any item.static TrailItemSet
of
(ItemIdentity... ids) Constructs a set for specific item IDs.static TrailItemSet
of
(Collection<ItemIdentity> ids) Constructs a set for specific item IDs.static TrailItemSet
ofTypes
(Collection<String> types) Constructs a set for specific item types.toString()
abstract TrailItemSet
union
(TrailItemSet anotherSet) Creates a new set with all items fromthis
andanotherSet
sets.
-
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
this
andanotherSet
sets.If
anotherSet == null
orthis.equals(anotherSet)
-this
set should be returnedNote that:
AllItems
set union with any set is alwaysAllItems
set.- Type-based set union with any set is type-based set.
None
union with non nullanotherSet
set is alwaysanotherSet
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 withthis
- Returns:
- a new set with all items of
this
set 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
-