Class NoopCacheView<T>

java.lang.Object
com.mewna.catnip.cache.view.NoopCacheView<T>
Type Parameters:
T - Type of the element contained by this cache.
All Implemented Interfaces:
CacheView<T>, MutableCacheView<T>, MutableNamedCacheView<T>, NamedCacheView<T>, Iterable<T>

public class NoopCacheView<T> extends Object implements MutableNamedCacheView<T>
Helper class for noop caches. All mutation methods are noop. Always empty.
  • Field Details

  • Constructor Details

    • NoopCacheView

      public NoopCacheView()
  • Method Details

    • removeIf

      public void removeIf(@Nonnull LongPredicate predicate)
      Specified by:
      removeIf in interface MutableCacheView<T>
    • put

      @Nullable public T put(long key, @Nonnull T value)
      Specified by:
      put in interface MutableCacheView<T>
    • remove

      @Nullable public T remove(long key)
      Specified by:
      remove in interface MutableCacheView<T>
    • findByName

      @Nonnull public Collection<T> findByName(@Nonnull String name, boolean ignoreCase)
      Description copied from interface: NamedCacheView
      Finds all entities with a name equal to the provided value.
      Specified by:
      findByName in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      Returns:
      All elements that have a name equal to the provided.
      See Also:
    • findByName

      @Nonnull public <C extends Collection<T>> C findByName(@Nonnull String name, boolean ignoreCase, @Nonnull Supplier<C> supplier)
      Description copied from interface: NamedCacheView
      Finds all entities with a name equal to the provided value.
      Specified by:
      findByName in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      supplier - Supplier for the collection to add the elements to. The returned collection must be mutable.
      Returns:
      The collection returned by supplier, after adding the matching elements. May be empty.
      See Also:
    • findByNameContains

      @Nonnull public Collection<T> findByNameContains(@Nonnull String name, boolean ignoreCase)
      Description copied from interface: NamedCacheView
      Finds all entities whose name contains the provided value.
      Specified by:
      findByNameContains in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      Returns:
      All elements that have a name containing the provided.
      See Also:
    • findByNameContains

      @Nonnull public <C extends Collection<T>> C findByNameContains(@Nonnull String name, boolean ignoreCase, @Nonnull Supplier<C> supplier)
      Description copied from interface: NamedCacheView
      Finds all entities whose name contains the provided value.
      Specified by:
      findByNameContains in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      supplier - Supplier for the collection to add the elements to. The returned collection must be mutable.
      Returns:
      The collection returned by supplier, after adding the matching elements. May be empty.
      See Also:
    • findByNameStartsWith

      @Nonnull public Collection<T> findByNameStartsWith(@Nonnull String name, boolean ignoreCase)
      Description copied from interface: NamedCacheView
      Finds all entities whose name starts with the provided value.
      Specified by:
      findByNameStartsWith in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      Returns:
      All elements that have a name starting with the provided.
      See Also:
    • findByNameStartsWith

      @Nonnull public <C extends Collection<T>> C findByNameStartsWith(@Nonnull String name, boolean ignoreCase, @Nonnull Supplier<C> supplier)
      Description copied from interface: NamedCacheView
      Finds all entities whose name starts with the provided value.
      Specified by:
      findByNameStartsWith in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      supplier - Supplier for the collection to add the elements to. The returned collection must be mutable.
      Returns:
      The collection returned by supplier, after adding the matching elements. May be empty.
      See Also:
    • findByNameEndsWith

      @Nonnull public Collection<T> findByNameEndsWith(@Nonnull String name, boolean ignoreCase)
      Description copied from interface: NamedCacheView
      Finds all entities whose name ends with the provided value.
      Specified by:
      findByNameEndsWith in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      Returns:
      All elements that have a name ending with the provided.
      See Also:
    • findByNameEndsWith

      @Nonnull public <C extends Collection<T>> C findByNameEndsWith(@Nonnull String name, boolean ignoreCase, @Nonnull Supplier<C> supplier)
      Description copied from interface: NamedCacheView
      Finds all entities whose name ends with the provided value.
      Specified by:
      findByNameEndsWith in interface NamedCacheView<T>
      Parameters:
      name - Name to search for.
      ignoreCase - Ignore casing differences between the entity names and the provided name.
      supplier - Supplier for the collection to add the elements to. The returned collection must be mutable.
      Returns:
      The collection returned by supplier, after adding the matching elements. May be empty.
      See Also:
    • iterator

      @Nonnull public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • forEach

      public void forEach(Consumer<? super T> action)
      Description copied from interface: CacheView
      Iterates this view, providing all elements to the given consumer.
      Specified by:
      forEach in interface CacheView<T>
      Specified by:
      forEach in interface Iterable<T>
      Parameters:
      action - Action to execute on each element.
    • size

      public long size()
      Specified by:
      size in interface CacheView<T>
      Returns:
      The size of this cache.
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface CacheView<T>
      Returns:
      Whether or not this view is empty. Equivalent to size() == 0.
    • getById

      public T getById(long id)
      Specified by:
      getById in interface CacheView<T>
      Parameters:
      id - ID of the entity to fetch.
      Returns:
      The element with the provided ID, or null if it isn't cached.
    • findAny

      public T findAny(@Nonnull Predicate<? super T> filter)
      Description copied from interface: CacheView
      Returns any element in this cache that matches the given filter. There are no order guarantees if multiple elements match. Use with caution.
      Specified by:
      findAny in interface CacheView<T>
      Parameters:
      filter - Filter to find matching elements.
      Returns:
      Any element that matches the provided filter, or null if none match.
    • find

      @Nonnull public Collection<T> find(@Nonnull Predicate<? super T> filter)
      Description copied from interface: CacheView
      Returns all elements in this cache that matches the given filter. There are no order guarantees if multiple elements match.
      Specified by:
      find in interface CacheView<T>
      Parameters:
      filter - Filter to find matching elements.
      Returns:
      A collection with all the matching elements. May be empty.
    • find

      @Nonnull public <C extends Collection<T>> C find(@Nonnull Predicate<? super T> filter, @Nonnull Supplier<C> supplier)
      Description copied from interface: CacheView
      Returns all elements in this cache that matches the given filter. There are no order guarantees if multiple elements match.
      Specified by:
      find in interface CacheView<T>
      Parameters:
      filter - Filter to find matching elements.
      supplier - Supplier for the collection to add the elements to. The returned collection must be mutable.
      Returns:
      The collection returned by supplier, after adding the matching elements. May be empty.
    • collect

      @Nonnull public <A, R> R collect(@Nonnull Collector<? super T,A,R> collector)
      Description copied from interface: CacheView
      Performs a mutable reduction operation on the elements of this cache using a Collector.
      Specified by:
      collect in interface CacheView<T>
      Type Parameters:
      A - The intermediate accumulation type of the Collector.
      R - The type of the result.
      Parameters:
      collector - The Collector describing the reduction.
      Returns:
      The result of the reduction.
      See Also:
    • collect

      @Nonnull public <R> R collect(@Nonnull Supplier<R> supplier, @Nonnull BiConsumer<R,? super T> accumulator, @Nonnull BiConsumer<R,R> combiner)
      Description copied from interface: CacheView
      Performs a mutable reduction operation on the elements of this cache.
      Specified by:
      collect in interface CacheView<T>
      Type Parameters:
      R - The type of the result.
      Parameters:
      supplier - A function that creates a new result container. For a parallel execution, this function may be called multiple times and must return a fresh value each time.
      accumulator - An associative, non-interfering, stateless function for incorporating an additional element into a result.
      combiner - An associative, non-interfering, stateless function for combining two values, which must be compatible with the accumulator function.
      Returns:
      The result of the reduction.
      See Also:
    • reduce

      @Nonnull public <U> U reduce(U identity, @Nonnull BiFunction<U,? super T,U> accumulator, @Nonnull BinaryOperator<U> combiner)
      Description copied from interface: CacheView
      Performs a reduction on the elements of this cache, using the provided identity, accumulation and combining functions.
      Specified by:
      reduce in interface CacheView<T>
      Type Parameters:
      U - The type of the result.
      Parameters:
      identity - The identity value for the combiner function.
      accumulator - An associative, non-interfering, stateless function for incorporating an additional element into a result.
      combiner - An associative, non-interfering, stateless function for combining two values, which must be compatible with the accumulator function
      Returns:
      the result of the reduction
      See Also:
    • reduce

      @Nonnull public Optional<T> reduce(@Nonnull BinaryOperator<T> accumulator)
      Description copied from interface: CacheView
      Performs a reduction on the elements of this cache, using an associative accumulation function, and returns an Optional describing the reduced value, if any.
      Specified by:
      reduce in interface CacheView<T>
      Parameters:
      accumulator - An associative, non-interfering, stateless function for combining two values.
      Returns:
      An Optional describing the result of the reduction.
      See Also:
    • reduce

      @Nonnull public T reduce(@Nonnull T identity, @Nonnull BinaryOperator<T> accumulator)
      Description copied from interface: CacheView
      Performs a reduction on the elements of this cache, using the provided identity value and an associative accumulation function, and returns the reduced value.
      Specified by:
      reduce in interface CacheView<T>
      Parameters:
      identity - The identity value for the accumulating function.
      accumulator - An associative, non-interfering, stateless function for combining two values.
      Returns:
      the result of the reduction
      See Also:
    • anyMatch

      public boolean anyMatch(@Nonnull Predicate<? super T> predicate)
      Description copied from interface: CacheView
      Returns whether any elements of this cache match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the cache is empty then false is returned and the predicate is not evaluated.
      Specified by:
      anyMatch in interface CacheView<T>
      Parameters:
      predicate - A non-interfering, stateless predicate to apply to elements of this cache.
      Returns:
      true if any elements of the cache match the provided predicate, otherwise false.
      See Also:
    • allMatch

      public boolean allMatch(@Nonnull Predicate<? super T> predicate)
      Description copied from interface: CacheView
      Returns whether all elements of this cache match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the cache is empty then true is returned and the predicate is not evaluated.
      Specified by:
      allMatch in interface CacheView<T>
      Parameters:
      predicate - A non-interfering, stateless predicate to apply to elements of this cache.
      Returns:
      true if either all elements of the cache match the provided predicate or the cache is empty, otherwise false.
      See Also:
    • noneMatch

      public boolean noneMatch(@Nonnull Predicate<? super T> predicate)
      Description copied from interface: CacheView
      Returns whether no elements of this cache match the provided predicate. May not evaluate the predicate on all elements if not necessary for determining the result. If the cache is empty then true is returned and the predicate is not evaluated.
      Specified by:
      noneMatch in interface CacheView<T>
      Parameters:
      predicate - A non-interfering, stateless predicate to apply to elements of this cache.
      Returns:
      true if either no elements of the cache match the provided predicate or the cache is empty, otherwise false.
      See Also:
    • min

      @Nonnull public Optional<T> min(@Nonnull Comparator<? super T> comparator)
      Description copied from interface: CacheView
      Returns the minimum element of this cache according to the provided Comparator. This is a special case of a reduction.
      Specified by:
      min in interface CacheView<T>
      Parameters:
      comparator - A non-interfering, stateless Comparator to compare elements of this stream.
      Returns:
      An Optional describing the minimum element of this cache, or an empty Optional if the cache is empty.
      See Also:
    • max

      @Nonnull public Optional<T> max(@Nonnull Comparator<? super T> comparator)
      Description copied from interface: CacheView
      Returns the maximum element of this cache according to the provided Comparator. This is a special case of a reduction.
      Specified by:
      max in interface CacheView<T>
      Parameters:
      comparator - A non-interfering, stateless Comparator to compare elements of this stream.
      Returns:
      An Optional describing the maximum element of this cache, or an empty Optional if the cache is empty.
      See Also:
    • count

      public long count(@Nonnull Predicate<? super T> filter)
      Description copied from interface: CacheView
      Returns the amount of elements that match the provided predicate.
      Specified by:
      count in interface CacheView<T>
      Parameters:
      filter - Filter to find matching elements.
      Returns:
      Amount of matching elements.
    • keys

      @Nonnull public Set<Long> keys()
      Specified by:
      keys in interface CacheView<T>
      Returns:
      A view of all the keys in this cache. Updated if this cache is modified.
      See Also:
    • values

      @Nonnull public Collection<T> values()
      Specified by:
      values in interface CacheView<T>
      Returns:
      A view of all the values in this cache. Updated if this cache is modified.
      See Also:
    • snapshot

      @Nonnull public Collection<T> snapshot()
      Specified by:
      snapshot in interface CacheView<T>
      Returns:
      A snapshot of all the values in this cache. Not updated if this cache is modified.
      See Also:
    • snapshot

      @Nonnull public <C extends Collection<T>> C snapshot(@Nonnull Supplier<C> supplier)
      Specified by:
      snapshot in interface CacheView<T>
      Parameters:
      supplier - Supplier for the collection to add the elements to. The returned collection must be mutable.
      Returns:
      The collection returned by supplier, after adding the cached elements. May be empty.
      See Also: