Esempio n. 1
0
 @Override
 public Array<T> slice(long beginIndex, long endIndex) {
   if (beginIndex >= endIndex || beginIndex >= length() || isEmpty()) {
     return empty();
   }
   if (beginIndex <= 0 && endIndex >= length()) {
     return this;
   }
   final int index = Math.max((int) beginIndex, 0);
   final int length = Math.min((int) endIndex, length()) - index;
   final Object[] arr = new Object[length];
   System.arraycopy(delegate, index, arr, 0, length);
   return wrap(arr);
 }
Esempio n. 2
0
 Array<T> with(int startIndex, int length) {
   length = Math.min(delegate.length - startIndex, length);
   if (length <= 0) {
     return empty();
   } else {
     return new Array<T>(delegate, startIndex, length);
   }
 }
Esempio n. 3
0
 @Override
 public int lastIndexOf(T element, int end) {
   for (int i = Math.min(end, length() - 1); i >= 0; i--) {
     if (Objects.equals(get(i), element)) {
       return i;
     }
   }
   return -1;
 }
Esempio n. 4
0
 @Override
 public Vector<Vector<T>> combinations(int k) {
   class Recursion {
     Vector<Vector<T>> combinations(Vector<T> elements, int k) {
       return (k == 0)
           ? Vector.of(Vector.empty())
           : elements
               .zipWithIndex()
               .flatMap(
                   t ->
                       combinations(elements.drop(t._2 + 1), (k - 1))
                           .map((Vector<T> c) -> c.prepend(t._1)));
     }
   }
   return new Recursion().combinations(this, Math.max(k, 0));
 }
Esempio n. 5
0
 @Override
 public Array<Array<T>> combinations(int k) {
   return Combinations.apply(this, Math.max(k, 0));
 }