Class Predicates
This class provides static methods to create predicates for filtering game entities based on their names, IDs, or text content. These predicates are commonly used with query methods throughout the API.
The predicates support:
- Name matching (exact, contains, case-sensitive/insensitive)
- ID matching (supports both regular and transformed IDs)
- Text matching (for string values)
Example usage:
// Find items by name
var items = Inventory.query()
.filter(Predicates.names("Lobster", "Shark"))
.results();
// Find NPCs by ID
var npcs = NPCs.query()
.filter(Predicates.ids(1234, 5678))
.results();
// Find objects containing "tree" in name (case-insensitive)
var trees = TileObjects.query()
.filter(Predicates.nameContains("tree", false))
.results();
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Identifiable>
Predicate<T> allIds(int... ids) Creates a predicate that matches entities whose ID equals all specified IDs.static <T extends Identifiable>
Predicate<T> allIds(Collection<Integer> ids) Creates a predicate that matches entities whose ID equals all IDs in the collection.Creates a predicate that matches entities whose name equals all specified names.allNames(Collection<String> names) Creates a predicate that matches entities whose name equals all names in the collection.Creates a predicate that matches strings equal to all specified texts.static <T extends Identifiable>
Predicate<T> ids(int... ids) Creates a predicate that matches entities with any of the specified IDs.static <T extends Identifiable>
Predicate<T> ids(Collection<Integer> ids) Creates a predicate that matches entities with any of the IDs in the collection.nameContains(String subString) Creates a predicate that matches entities whose name contains the specified substring.nameContains(String subString, boolean caseSensitive) Creates a predicate that matches entities whose name contains the specified substring.nameContains(Collection<String> subStrings) Creates a predicate that matches entities whose name contains any of the specified substrings.nameContains(Collection<String> subStrings, boolean caseSensitive) Creates a predicate that matches entities whose name contains any of the specified substrings.Creates a predicate that matches entities with any of the specified names.names(Collection<String> names) Creates a predicate that matches entities with any of the names in the collection.textContains(String subString) Creates a predicate that matches strings containing the specified substring.textContains(String subString, boolean caseSensitive) Creates a predicate that matches strings containing the specified substring.Creates a predicate that matches strings equal to any of the specified texts.
-
Constructor Details
-
Predicates
public Predicates()
-
-
Method Details
-
names
Creates a predicate that matches entities with any of the specified names.The comparison is case-sensitive and uses exact matching.
- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
names- the names to match against- Returns:
- a predicate that returns
trueif the entity's name matches any of the specified names
-
allNames
Creates a predicate that matches entities whose name equals all specified names.This is typically used to verify an entity's name matches a single expected value, since a name cannot equal multiple different values simultaneously.
- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
names- the names that must all match- Returns:
- a predicate that returns
trueif the entity's name equals all specified names
-
texts
Creates a predicate that matches strings equal to any of the specified texts.The comparison is case-sensitive and uses exact matching.
- Parameters:
texts- the texts to match against- Returns:
- a predicate that returns
trueif the string equals any of the specified texts
-
allTexts
Creates a predicate that matches strings equal to all specified texts.This is typically used to verify a string matches a single expected value, since a string cannot equal multiple different values simultaneously.
- Parameters:
texts- the texts that must all match- Returns:
- a predicate that returns
trueif the string equals all specified texts
-
textContains
Creates a predicate that matches strings containing the specified substring.- Parameters:
subString- the substring to search forcaseSensitive- whether the comparison should be case-sensitive- Returns:
- a predicate that returns
trueif the string contains the specified substring
-
textContains
Creates a predicate that matches strings containing the specified substring.The comparison is case-sensitive.
- Parameters:
subString- the substring to search for- Returns:
- a predicate that returns
trueif the string contains the specified substring
-
names
Creates a predicate that matches entities with any of the names in the collection.The comparison is case-sensitive and uses exact matching.
- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
names- the collection of names to match against- Returns:
- a predicate that returns
trueif the entity's name is contained in the collection
-
allNames
Creates a predicate that matches entities whose name equals all names in the collection.This is typically used to verify an entity's name matches a single expected value, since a name cannot equal multiple different values simultaneously.
- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
names- the collection of names that must all match- Returns:
- a predicate that returns
trueif the entity's name equals all names in the collection
-
nameContains
public static <T extends Nameable> Predicate<T> nameContains(String subString, boolean caseSensitive) Creates a predicate that matches entities whose name contains the specified substring.- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
subString- the substring to search for in the entity's namecaseSensitive- whether the comparison should be case-sensitive- Returns:
- a predicate that returns
trueif the entity's name contains the specified substring
-
nameContains
Creates a predicate that matches entities whose name contains the specified substring.The comparison is case-sensitive.
- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
subString- the substring to search for in the entity's name- Returns:
- a predicate that returns
trueif the entity's name contains the specified substring
-
nameContains
public static <T extends Nameable> Predicate<T> nameContains(Collection<String> subStrings, boolean caseSensitive) Creates a predicate that matches entities whose name contains any of the specified substrings.- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
subStrings- the collection of substrings to search forcaseSensitive- whether the comparison should be case-sensitive- Returns:
- a predicate that returns
trueif the entity's name contains any of the specified substrings
-
nameContains
Creates a predicate that matches entities whose name contains any of the specified substrings.The comparison is case-sensitive.
- Type Parameters:
T- the type of entity, must implementNameable- Parameters:
subStrings- the collection of substrings to search for- Returns:
- a predicate that returns
trueif the entity's name contains any of the specified substrings
-
ids
Creates a predicate that matches entities with any of the specified IDs.For entities that implement
Transformable, both the regular ID and the actual (transformed) ID are checked.- Type Parameters:
T- the type of entity, must implementIdentifiable- Parameters:
ids- the IDs to match against- Returns:
- a predicate that returns
trueif the entity's ID (or actual ID for transformable entities) matches any of the specified IDs
-
allIds
Creates a predicate that matches entities whose ID equals all specified IDs.For entities that implement
Transformable, both the regular ID and the actual (transformed) ID are checked.- Type Parameters:
T- the type of entity, must implementIdentifiable- Parameters:
ids- the IDs that must all match- Returns:
- a predicate that returns
trueif the entity's ID matches all specified IDs
-
ids
Creates a predicate that matches entities with any of the IDs in the collection.For entities that implement
Transformable, both the regular ID and the actual (transformed) ID are checked.- Type Parameters:
T- the type of entity, must implementIdentifiable- Parameters:
ids- the collection of IDs to match against- Returns:
- a predicate that returns
trueif the entity's ID (or actual ID for transformable entities) is contained in the collection
-
allIds
Creates a predicate that matches entities whose ID equals all IDs in the collection.For entities that implement
Transformable, both the regular ID and the actual (transformed) ID are checked.- Type Parameters:
T- the type of entity, must implementIdentifiable- Parameters:
ids- the collection of IDs that must all match- Returns:
- a predicate that returns
trueif the entity's ID matches all IDs in the collection
-