@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.
TrailItemSet.SpecificItems
,
TrailItemSet.OneType
Modifier and Type | Class and Description |
---|---|
static class |
TrailItemSet.AllItems
Represents a set of all items.
|
static class |
TrailItemSet.Collector
Used to collect specific types and items stored in the TrailItemSet.
|
static class |
TrailItemSet.None
Represents an empty set.
|
static class |
TrailItemSet.OneItem
Represents a set with just one item.
|
static class |
TrailItemSet.OneType
Represents a set of all items of one specific type.
|
static interface |
TrailItemSet.ReadVisitor
Alternate visitor interface for reading out the specific items and types.
|
static class |
TrailItemSet.SpecificItems
Represents a set of several specific items.
|
static class |
TrailItemSet.SpecificTypes
Represents a set of all items of several specific types.
|
static interface |
TrailItemSet.Visitor
Visitor interface for analyzing the set.
|
Modifier and Type | Method and Description |
---|---|
abstract 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) |
boolean |
equals(Object obj) |
abstract TrailItemSet |
expand(ItemIdentity trailItem)
Expands the set to include the given item.
|
int |
hashCode() |
boolean |
isEmpty()
Returns true if this set will not match any item.
|
static TrailItemSet |
of(Collection<ItemIdentity> ids)
Constructs a set for specific item IDs.
|
static TrailItemSet |
of(ItemIdentity... ids)
Constructs a set for specific item IDs.
|
static TrailItemSet |
ofTypes(Collection<String> types)
Constructs a set for specific item types.
|
String |
toString() |
abstract TrailItemSet |
union(TrailItemSet anotherSet)
Creates a new set with all items from
this and anotherSet sets. |
public abstract boolean contains(@Nullable ItemIdentity id)
id
- item IDpublic boolean containsAny(@Nullable Collection<ItemIdentity> itemIds)
@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.
trailItem
- item to add to the settrailItem
@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.None
union with non null anotherSet
set is always anotherSet
set.AllItems
set if number of types after union is sufficient.anotherSet
- - another set to union with this
this
set and anotherSet
public abstract void accept(@NotNull TrailItemSet.Visitor visitor)
public final boolean isEmpty()
public static TrailItemSet of(ItemIdentity... ids)
ids
- item identities - null elements are ignored!public static TrailItemSet of(Collection<ItemIdentity> ids)
ids
- item identities collection - null elements are ignored!public static TrailItemSet ofTypes(Collection<String> types)
types
- item types - null elements are ignored!Copyright © 2024 Tempo Software. All Rights Reserved.