Exemple #1
1
 @Override
 public Tuple2<Vector<T>, Vector<T>> partition(Predicate<? super T> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   final java.util.List<T> left = new ArrayList<>(), right = new ArrayList<>();
   for (int i = 0; i < length(); i++) {
     T t = get(i);
     (predicate.test(t) ? left : right).add(t);
   }
   return Tuple.of(Vector.ofAll(left), Vector.ofAll(right));
 }
Exemple #2
1
 @Override
 public Vector<Object> flatten() {
   return flatMap(
       t ->
           (t instanceof java.lang.Iterable)
               ? Vector.ofAll((java.lang.Iterable<?>) t).flatten()
               : Vector.of(t));
 }
Exemple #3
1
 @Override
 public Vector<T> retainAll(java.lang.Iterable<? extends T> elements) {
   Objects.requireNonNull(elements, "elements is null");
   final Vector<T> keeped = Vector.ofAll(elements).distinct();
   HashArrayMappedTrie<Integer, T> result = HashArrayMappedTrie.empty();
   for (T element : this) {
     if (keeped.contains(element)) {
       result = result.put(result.size(), element);
     }
   }
   return result.isEmpty() ? empty() : new Vector<>(result);
 }
Exemple #4
1
 @Override
 public <C> Map<C, Vector<T>> groupBy(Function<? super T, ? extends C> classifier) {
   Objects.requireNonNull(classifier, "classifier is null");
   return iterator().groupBy(classifier).map((c, it) -> Map.Entry.of(c, Vector.ofAll(it)));
 }
Exemple #5
1
 /**
  * Creates a Vector of long numbers starting from {@code from}, extending to {@code toInclusive}.
  *
  * <p>Examples:
  *
  * <pre>
  * <code>
  * Vector.rangeClosed(0L, 0L)  // = Vector(0L)
  * Vector.rangeClosed(2L, 0L)  // = Vector()
  * Vector.rangeClosed(-2L, 2L) // = Vector(-2L, -1L, 0L, 1L, 2L)
  * </code>
  * </pre>
  *
  * @param from the first number
  * @param toInclusive the last number
  * @return a range of long values as specified or the empty range if {@code from > toInclusive}
  */
 public static Vector<Long> rangeClosed(long from, long toInclusive) {
   return Vector.ofAll(Iterator.rangeClosed(from, toInclusive));
 }
Exemple #6
1
 /**
  * Creates a Vector of long numbers starting from {@code from}, extending to {@code toExclusive -
  * 1}.
  *
  * <p>Examples:
  *
  * <pre>
  * <code>
  * Vector.range(0L, 0L)  // = Vector()
  * Vector.range(2L, 0L)  // = Vector()
  * Vector.range(-2L, 2L) // = Vector(-2L, -1L, 0L, 1L)
  * </code>
  * </pre>
  *
  * @param from the first number
  * @param toExclusive the last number + 1
  * @return a range of long values as specified or the empty range if {@code from >= toExclusive}
  */
 public static Vector<Long> range(long from, long toExclusive) {
   return Vector.ofAll(Iterator.range(from, toExclusive));
 }
Exemple #7
1
 /**
  * Creates a Vector of int numbers starting from {@code from}, extending to {@code toExclusive -
  * 1}.
  *
  * <p>Examples:
  *
  * <pre>
  * <code>
  * Vector.range(0, 0)  // = Vector()
  * Vector.range(2, 0)  // = Vector()
  * Vector.range(-2, 2) // = Vector(-2, -1, 0, 1)
  * </code>
  * </pre>
  *
  * @param from the first number
  * @param toExclusive the last number + 1
  * @return a range of int values as specified or the empty range if {@code from >= toExclusive}
  */
 public static Vector<Integer> range(int from, int toExclusive) {
   return Vector.ofAll(Iterator.range(from, toExclusive));
 }
Exemple #8
0
 @Override
 public <U> Vector<Tuple2<T, U>> crossProduct(java.lang.Iterable<? extends U> that) {
   Objects.requireNonNull(that, "that is null");
   final Vector<? extends U> other = Vector.ofAll(that);
   return flatMap(a -> other.map(b -> Tuple.of(a, b)));
 }
Exemple #9
0
 /**
  * Creates a Vector of long numbers starting from {@code from}, extending to {@code toInclusive},
  * with {@code step}.
  *
  * <p>Examples:
  *
  * <pre>
  * <code>
  * Vector.rangeClosedBy(1L, 3L, 1L)  // = Vector(1L, 2L, 3L)
  * Vector.rangeClosedBy(1L, 4L, 2L)  // = Vector(1L, 3L)
  * Vector.rangeClosedBy(4L, 1L, -2L) // = Vector(4L, 2L)
  * Vector.rangeClosedBy(4L, 1L, 2L)  // = Vector()
  * </code>
  * </pre>
  *
  * @param from the first number
  * @param toInclusive the last number
  * @param step the step
  * @return a range of int values as specified or the empty range if<br>
  *     {@code from > toInclusive} and {@code step > 0} or<br>
  *     {@code from < toInclusive} and {@code step < 0}
  * @throws IllegalArgumentException if {@code step} is zero
  */
 public static Vector<Long> rangeClosedBy(long from, long toInclusive, long step) {
   return Vector.ofAll(Iterator.rangeClosedBy(from, toInclusive, step));
 }
Exemple #10
0
 /**
  * Creates a Vector of int numbers starting from {@code from}, extending to {@code toInclusive},
  * with {@code step}.
  *
  * <p>Examples:
  *
  * <pre>
  * <code>
  * Vector.rangeClosedBy(1, 3, 1)  // = Vector(1, 2, 3)
  * Vector.rangeClosedBy(1, 4, 2)  // = Vector(1, 3)
  * Vector.rangeClosedBy(4, 1, -2) // = Vector(4, 2)
  * Vector.rangeClosedBy(4, 1, 2)  // = Vector()
  * </code>
  * </pre>
  *
  * @param from the first number
  * @param toInclusive the last number
  * @param step the step
  * @return a range of int values as specified or the empty range if<br>
  *     {@code from > toInclusive} and {@code step > 0} or<br>
  *     {@code from < toInclusive} and {@code step < 0}
  * @throws IllegalArgumentException if {@code step} is zero
  */
 public static Vector<Integer> rangeClosedBy(int from, int toInclusive, int step) {
   return Vector.ofAll(Iterator.rangeClosedBy(from, toInclusive, step));
 }
Exemple #11
0
 /**
  * Creates a Vector based on the elements of a boolean array.
  *
  * @param array a boolean array
  * @return A new Vector of Boolean values
  */
 public static Vector<Boolean> ofAll(boolean[] array) {
   Objects.requireNonNull(array, "array is null");
   return Vector.ofAll(Iterator.ofAll(array));
 }
Exemple #12
0
 /**
  * Creates a Vector based on the elements of a short array.
  *
  * @param array a short array
  * @return A new Vector of Short values
  */
 public static Vector<Short> ofAll(short[] array) {
   Objects.requireNonNull(array, "array is null");
   return Vector.ofAll(Iterator.ofAll(array));
 }
Exemple #13
0
 /**
  * Creates a Vector based on the elements of a long array.
  *
  * @param array a long array
  * @return A new Vector of Long values
  */
 public static Vector<Long> ofAll(long[] array) {
   Objects.requireNonNull(array, "array is null");
   return Vector.ofAll(Iterator.ofAll(array));
 }
Exemple #14
0
 /**
  * Creates a Vector based on the elements of an int array.
  *
  * @param array an int array
  * @return A new Vector of Integer values
  */
 public static Vector<Integer> ofAll(int[] array) {
   Objects.requireNonNull(array, "array is null");
   return Vector.ofAll(Iterator.ofAll(array));
 }
Exemple #15
0
 /**
  * Creates a Vector based on the elements of a double array.
  *
  * @param array a double array
  * @return A new Vector of Double values
  */
 public static Vector<Double> ofAll(double[] array) {
   Objects.requireNonNull(array, "array is null");
   return Vector.ofAll(Iterator.ofAll(array));
 }
Exemple #16
0
 /**
  * Creates a Vector based on the elements of a char array.
  *
  * @param array a char array
  * @return A new Vector of Character values
  */
 public static Vector<Character> ofAll(char[] array) {
   Objects.requireNonNull(array, "array is null");
   return Vector.ofAll(Iterator.ofAll(array));
 }
Exemple #17
0
 /**
  * Creates a Vector of int numbers starting from {@code from}, extending to {@code toInclusive}.
  *
  * <p>Examples:
  *
  * <pre>
  * <code>
  * Vector.rangeClosed(0, 0)  // = Vector(0)
  * Vector.rangeClosed(2, 0)  // = Vector()
  * Vector.rangeClosed(-2, 2) // = Vector(-2, -1, 0, 1, 2)
  * </code>
  * </pre>
  *
  * @param from the first number
  * @param toInclusive the last number
  * @return a range of int values as specified or the empty range if {@code from > toInclusive}
  */
 public static Vector<Integer> rangeClosed(int from, int toInclusive) {
   return Vector.ofAll(Iterator.rangeClosed(from, toInclusive));
 }
Exemple #18
0
 @Override
 public <U> Vector<U> unit(java.lang.Iterable<? extends U> iterable) {
   return Vector.ofAll(iterable);
 }