Class Query<T,​Q extends Query<T,​Q>>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      KSContext ctx  
    • Constructor Summary

      Constructors 
      Constructor Description
      Query​(java.util.Collection<T> ts)
      Initializes the query with a collection of objects.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int count()
      Counts the total number of matching objects.
      boolean empty()
      Checks if the query matches no objects.
      boolean exists()
      Checks if any objects match the query.
      Q filter​(java.util.function.Predicate<? super T> predicate)
      Filters objects based on a given predicate.
      T first()
      Returns the first matching object.
      T first​(java.util.function.Predicate<T> filter)
      Finds the first object that matches a given predicate.
      T last()
      Returns the last matching object.
      java.util.List<T> list()
      Returns a list of all filtered objects.
      java.util.List<T> list​(int limit)
      Returns a limited list of the first N filtered objects.
      T max​(java.util.Comparator<T> comparator)
      Finds the object with the maximum value based on a comparator.
      T min​(java.util.Comparator<T> comparator)
      Finds the object with the minimum value based on a comparator.
      Q omit​(int... id)
      Excludes items that match any of the provided IDs.
      Q omit​(java.lang.String... str)
      Excludes items that match any of the provided names.
      Q omit​(java.util.function.Predicate<? super T> predicate)
      Excludes objects that match a given predicate.
      T random()
      Returns a random object from the filtered list.
      java.util.List<T> shuffledList()
      Returns a shuffled list of all filtered objects.
      java.util.List<T> shuffledList​(int limit)
      Returns a shuffled list of a limited number of filtered objects.
      Q sorted​(java.util.Comparator<T> comparator)
      Sorts the objects using a given comparator.
      java.util.stream.Stream<T> stream()  
      Q unique()
      Filters unique items based on their IDs.
      Q withId​(int... id)
      Filters objects by matching their IDs.
      Q withName​(java.lang.String... name)
      Filters objects by matching their names.
      Q withNameOrId​(java.lang.String namesOrIds)
      Filters objects by matching either names or IDs.
      Q withOption​(java.lang.String... option)
      Filters objects by matching any of the specified options.
      Q withoutId​(int... id)
      Excludes objects with specified IDs.
      Q withoutName​(java.lang.String... name)
      Excludes objects that match specified names.
      Q withoutNameOrId​(java.lang.String namesOrIds)
      Excludes objects that match specified names or IDs.
      Q withoutOption​(java.lang.String... option)
      Excludes objects that match any of the specified options.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Query

        public Query​(java.util.Collection<T> ts)
        Initializes the query with a collection of objects.
        Parameters:
        ts - the collection of objects to query.
    • Method Detail

      • filter

        public Q filter​(java.util.function.Predicate<? super T> predicate)
        Filters objects based on a given predicate.
        Parameters:
        predicate - the condition to filter objects.
        Returns:
        the current query instance with filtered objects.
      • withoutId

        public Q withoutId​(int... id)
        Excludes objects with specified IDs.
        Parameters:
        id - the array of IDs to exclude.
        Returns:
        the current query instance with objects filtered out.
      • withId

        public Q withId​(int... id)
        Filters objects by matching their IDs.
        Parameters:
        id - the array of IDs to match.
        Returns:
        the current query instance with filtered objects.
      • withName

        public Q withName​(java.lang.String... name)
        Filters objects by matching their names.
        Parameters:
        name - the array of names to match.
        Returns:
        the current query instance with filtered objects.
      • withoutName

        public Q withoutName​(java.lang.String... name)
        Excludes objects that match specified names.
        Parameters:
        name - the array of names to exclude.
        Returns:
        the current query instance with objects filtered out.
      • withNameOrId

        public Q withNameOrId​(java.lang.String namesOrIds)
        Filters objects by matching either names or IDs.
        Parameters:
        namesOrIds - a comma-separated string of names or IDs to match.
        Returns:
        the current query instance with filtered objects.
      • withoutNameOrId

        public Q withoutNameOrId​(java.lang.String namesOrIds)
        Excludes objects that match specified names or IDs.
        Parameters:
        namesOrIds - a comma-separated string of names or IDs to exclude.
        Returns:
        the current query instance with objects filtered out.
      • withOption

        public Q withOption​(java.lang.String... option)
        Filters objects by matching any of the specified options.
        Parameters:
        option - the array of options to match.
        Returns:
        the current query instance with filtered objects.
      • withoutOption

        public Q withoutOption​(java.lang.String... option)
        Excludes objects that match any of the specified options.
        Parameters:
        option - the array of options to exclude.
        Returns:
        the current query instance with objects filtered out.
      • omit

        public Q omit​(java.util.function.Predicate<? super T> predicate)
        Excludes objects that match a given predicate.
        Parameters:
        predicate - the condition to exclude objects.
        Returns:
        the current query instance with objects filtered out.
      • omit

        public Q omit​(java.lang.String... str)
        Excludes items that match any of the provided names.
        Parameters:
        str - the array of names to exclude.
        Returns:
        the current query instance with filtered items.
      • omit

        public Q omit​(int... id)
        Excludes items that match any of the provided IDs.
        Parameters:
        id - the array of IDs to exclude.
        Returns:
        the current query instance with filtered items.
      • sorted

        public Q sorted​(java.util.Comparator<T> comparator)
        Sorts the objects using a given comparator.
        Parameters:
        comparator - the comparator to sort objects.
        Returns:
        the current query instance with sorted objects.
      • first

        public T first​(java.util.function.Predicate<T> filter)
        Finds the first object that matches a given predicate.
        Parameters:
        filter - the condition to find the first object.
        Returns:
        the first matching object, or null if none exist.
      • random

        public T random()
        Returns a random object from the filtered list.
        Returns:
        a random object, or null if the list is empty.
      • list

        public java.util.List<T> list()
        Returns a list of all filtered objects.
        Returns:
        a list of matching objects.
      • list

        public java.util.List<T> list​(int limit)
        Returns a limited list of the first N filtered objects.
        Parameters:
        limit - the maximum number of objects to return.
        Returns:
        a list of the first N matching objects.
      • unique

        public Q unique()
        Filters unique items based on their IDs.
        Returns:
        the current query instance with unique items.
      • stream

        public java.util.stream.Stream<T> stream()
      • shuffledList

        public java.util.List<T> shuffledList​(int limit)
        Returns a shuffled list of a limited number of filtered objects.
        Parameters:
        limit - the maximum number of objects to include.
        Returns:
        a shuffled list of the first N objects.
      • shuffledList

        public java.util.List<T> shuffledList()
        Returns a shuffled list of all filtered objects.
        Returns:
        a shuffled list of matching objects.
      • count

        public int count()
        Counts the total number of matching objects.
        Returns:
        the count of matching objects.
      • empty

        public boolean empty()
        Checks if the query matches no objects.
        Returns:
        true if no objects match; false otherwise.
      • exists

        public boolean exists()
        Checks if any objects match the query.
        Returns:
        true if there are matching objects; false otherwise.
      • first

        public T first()
        Returns the first matching object.
        Returns:
        the first matching object, or null if none exist.
      • last

        public T last()
        Returns the last matching object.
        Returns:
        the last matching object, or null if none exist.
      • min

        public T min​(java.util.Comparator<T> comparator)
        Finds the object with the minimum value based on a comparator.
        Parameters:
        comparator - the comparator to determine the minimum value.
        Returns:
        the object with the minimum value, or null if none exist.
      • max

        public T max​(java.util.Comparator<T> comparator)
        Finds the object with the maximum value based on a comparator.
        Parameters:
        comparator - the comparator to determine the maximum value.
        Returns:
        the object with the maximum value, or null if none exist.