Class Predicates

java.lang.Object
net.storm.api.commons.Predicates

public class Predicates extends Object
Factory class for creating common predicates used in entity filtering.

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 Details

    • Predicates

      public Predicates()
  • Method Details

    • names

      public static <T extends Nameable> Predicate<T> names(String... 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 implement Nameable
      Parameters:
      names - the names to match against
      Returns:
      a predicate that returns true if the entity's name matches any of the specified names
    • allNames

      public static <T extends Nameable> Predicate<T> allNames(String... names)
      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 implement Nameable
      Parameters:
      names - the names that must all match
      Returns:
      a predicate that returns true if the entity's name equals all specified names
    • texts

      public static Predicate<String> texts(String... 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 true if the string equals any of the specified texts
    • allTexts

      public static Predicate<String> allTexts(String... texts)
      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 true if the string equals all specified texts
    • textContains

      public static Predicate<String> textContains(String subString, boolean caseSensitive)
      Creates a predicate that matches strings containing the specified substring.
      Parameters:
      subString - the substring to search for
      caseSensitive - whether the comparison should be case-sensitive
      Returns:
      a predicate that returns true if the string contains the specified substring
    • textContains

      public static Predicate<String> textContains(String subString)
      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 true if the string contains the specified substring
    • names

      public static <T extends Nameable> Predicate<T> names(Collection<String> 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 implement Nameable
      Parameters:
      names - the collection of names to match against
      Returns:
      a predicate that returns true if the entity's name is contained in the collection
    • allNames

      public static <T extends Nameable> Predicate<T> allNames(Collection<String> names)
      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 implement Nameable
      Parameters:
      names - the collection of names that must all match
      Returns:
      a predicate that returns true if 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 implement Nameable
      Parameters:
      subString - the substring to search for in the entity's name
      caseSensitive - whether the comparison should be case-sensitive
      Returns:
      a predicate that returns true if the entity's name contains the specified substring
    • nameContains

      public static <T extends Nameable> Predicate<T> nameContains(String subString)
      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 implement Nameable
      Parameters:
      subString - the substring to search for in the entity's name
      Returns:
      a predicate that returns true if 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 implement Nameable
      Parameters:
      subStrings - the collection of substrings to search for
      caseSensitive - whether the comparison should be case-sensitive
      Returns:
      a predicate that returns true if the entity's name contains any of the specified substrings
    • nameContains

      public static <T extends Nameable> Predicate<T> nameContains(Collection<String> subStrings)
      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 implement Nameable
      Parameters:
      subStrings - the collection of substrings to search for
      Returns:
      a predicate that returns true if the entity's name contains any of the specified substrings
    • ids

      public static <T extends Identifiable> Predicate<T> ids(int... 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 implement Identifiable
      Parameters:
      ids - the IDs to match against
      Returns:
      a predicate that returns true if the entity's ID (or actual ID for transformable entities) matches any of the specified IDs
    • allIds

      public static <T extends Identifiable> Predicate<T> allIds(int... ids)
      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 implement Identifiable
      Parameters:
      ids - the IDs that must all match
      Returns:
      a predicate that returns true if the entity's ID matches all specified IDs
    • ids

      public static <T extends Identifiable> Predicate<T> ids(Collection<Integer> 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 implement Identifiable
      Parameters:
      ids - the collection of IDs to match against
      Returns:
      a predicate that returns true if the entity's ID (or actual ID for transformable entities) is contained in the collection
    • allIds

      public static <T extends Identifiable> Predicate<T> allIds(Collection<Integer> ids)
      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 implement Identifiable
      Parameters:
      ids - the collection of IDs that must all match
      Returns:
      a predicate that returns true if the entity's ID matches all IDs in the collection