示例#1
0
 @Override
 default boolean startsWith(Iterable<? extends T> that, int offset) {
   Objects.requireNonNull(that, "that is null");
   if (offset < 0) return false;
   if (that instanceof IndexedSeq) {
     IndexedSeq<? extends T> dhat = (IndexedSeq<? extends T>) that;
     int i = offset;
     int j = 0;
     int thisLen = length();
     int thatLen = dhat.length();
     while (i < thisLen && j < thatLen && Objects.equals(this.get(i), dhat.get(j))) {
       i++;
       j++;
     }
     return j == thatLen;
   } else {
     int i = offset;
     int thisLen = length();
     java.util.Iterator<? extends T> thatElems = that.iterator();
     while (i < thisLen && thatElems.hasNext()) {
       if (!Objects.equals(this.get(i), thatElems.next())) {
         return false;
       }
       i++;
     }
     return !thatElems.hasNext();
   }
 }
示例#2
0
 private static <T> int findSlice(IndexedSeq<T> t, int p, int maxPtr, IndexedSeq<T> slice) {
   while (p <= maxPtr) {
     if (t.startsWith(slice, p)) {
       return p;
     }
     p++;
   }
   return -1;
 }
示例#3
0
 static <T> int lastIndexOfSlice(IndexedSeq<T> t, IndexedSeq<T> slice, int end) {
   if (end < 0) {
     return -1;
   }
   if (t.isEmpty()) {
     return slice.isEmpty() ? 0 : -1;
   }
   if (slice.isEmpty()) {
     int len = t.length();
     return len < end ? len : end;
   }
   int p = 0;
   int result = -1;
   final int maxPtr = t.length() - slice.length();
   while (p <= maxPtr) {
     int r = findSlice(t, p, maxPtr, slice);
     if (r < 0) {
       return result;
     }
     if (r <= end) {
       result = r;
       p = r + 1;
     } else {
       return result;
     }
   }
   return result;
 }
示例#4
0
 public final V getValueAt(int index) {
   return values.get(index);
 }
示例#5
0
 public final Stream<V> valueStream() {
   return values.toStream();
 }
示例#6
0
 @Override
 public final int getRowCount() {
   return values.length();
 }