Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.33 KB | None | 0 0
  1. package com.jamieswhiteshirt.rtree3i;
  2.  
  3. import java.util.function.*;
  4. import java.util.stream.Collector;
  5.  
  6. public interface Selection<T> {
  7.     /**
  8.      * Returns a selection consisting of the elements of this selection that match the given predicate.
  9.      * @param predicate a non-interfering, stateless predicate to apply to each element to determine if it should be
  10.      *                  included
  11.      * @return the new selection
  12.      */
  13.     Selection<T> filter(Predicate<? super T> predicate);
  14.  
  15.     /**
  16.      * Performs an action for each element of this selection.
  17.      * @param action a non-interfering action to perform on the elements
  18.      */
  19.     void forEach(Consumer<? super T> action);
  20.  
  21.     /**
  22.      * Performs a reduction on the elements of this selection, using the provided identity value and an associative
  23.      * accumulation function, and returns the reduced value.
  24.      * @param identity the identity value for the accumulating function
  25.      * @param accumulator an associative, non-interfering, stateless function for combining two values
  26.      * @return the result of the reduction
  27.      */
  28.     T reduce(T identity, BinaryOperator<T> accumulator);
  29.  
  30.     /**
  31.      * Performs a mutable reduction operation on the elements of this selection.  A mutable reduction is one in which
  32.      * the reduced value is a mutable result container, such as an {@code ArrayList}, and elements are incorporated by
  33.      * updating the state of the result rather than by replacing the result.
  34.      * @param <R> type of the result
  35.      * @param supplier a function that creates a new result container. For a
  36.      *                 parallel execution, this function may be called
  37.      *                 multiple times and must return a fresh value each time.
  38.      * @param accumulator an associative, non-interfering, stateless function for incorporating an additional element
  39.      *                    into a result
  40.      * @param combiner an associative, non-interfering, stateless function for combining two values, which must be
  41.      *                 compatible with the accumulator function
  42.      * @return the result of the reduction
  43.      */
  44.     <R> R collect(Supplier<R> supplier,
  45.                   BiConsumer<R, ? super T> accumulator,
  46.                   BiConsumer<R, R> combiner);
  47.  
  48.     /**
  49.      * Performs a mutable reduction operation on the elements of this selection using a {@code Collector}. A
  50.      * {@code Collector} encapsulates the functions used as arguments to
  51.      * {@link #collect(Supplier, BiConsumer, BiConsumer)}, allowing for reuse of collection strategies and composition
  52.      * of collect operations such as multiple-level grouping or partitioning.
  53.      * @param <R> the type of the result
  54.      * @param <A> the intermediate accumulation type of the {@code Collector}
  55.      * @param collector the {@code Collector} describing the reduction
  56.      * @return the result of the reduction
  57.      */
  58.     <R, A> R collect(Collector<? super T, A, R> collector);
  59.  
  60.     /**
  61.      * Returns the count of elements in this selection.
  62.      * @return the count of elements in this selection
  63.      */
  64.     int count();
  65.  
  66.     /**
  67.      * Returns whether any elements of this selection match the provided predicate. May not evaluate the predicate on
  68.      * all elements if not necessary for determining the result. If the selection is empty then {@code false} is
  69.      * returned and the predicate is not evaluated.
  70.      * @param predicate a non-interfering, stateless predicate to apply to elements of this selection
  71.      * @return {@code true} if any elements of the selection match the provided predicate, otherwise {@code false}
  72.      */
  73.     boolean anyMatch(Predicate<? super T> predicate);
  74.  
  75.     /**
  76.      * Returns whether all elements of this selection match the provided predicate. May not evaluate the predicate on
  77.      * all elements if not necessary for determining the result. If the selection is empty then {@code true} is returned
  78.      * and the predicate is not evaluated.
  79.      * @param predicate a non-interfering, stateless predicate to apply to elements of this selection
  80.      * @return {@code true} if either all elements of the selection match the provided predicate or the selection is
  81.      * empty, otherwise {@code false}
  82.      */
  83.     boolean allMatch(Predicate<? super T> predicate);
  84.  
  85.     /**
  86.      * Returns whether no elements of this selection match the provided predicate. May not evaluate the predicate on
  87.      * all elements if not necessary for determining the result. If the selection is empty then {@code true} is returned
  88.      * and the predicate is not evaluated.
  89.      * @param predicate a non-interfering, stateless predicate to apply to elements of this selection
  90.      * @return {@code true} if either no elements of the selection match the provided predicate or the selection is
  91.      * empty, otherwise {@code false}
  92.      */
  93.     boolean noneMatch(Predicate<? super T> predicate);
  94.  
  95.     /**
  96.      * Returns whether the count of elements in this selection is zero.
  97.      * @return {@code true} if the count of elements in this selection is zero, otherwise {@code false}
  98.      */
  99.     boolean isEmpty();
  100.  
  101.     /**
  102.      * Returns whether the count of elements in this selection is not zero.
  103.      * @return {@code true} if the count of elements in this selection is not zero, otherwise {@code false}
  104.      */
  105.     boolean isNotEmpty();
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement