public ImmutableList<E> a(int paramInt1, int paramInt2)
 {
   Preconditions.checkPositionIndexes(paramInt1, paramInt2, 1);
   if (paramInt1 == paramInt2)
     this = ImmutableList.d();
   return this;
 }
 @Override
 public ImmutableList<E> subList(int fromIndex, int toIndex) {
   Preconditions.checkPositionIndexes(fromIndex, toIndex, size);
   return (fromIndex == toIndex)
       ? ImmutableList.<E>of()
       : new RegularImmutableList<E>(array, offset + fromIndex, toIndex - fromIndex);
 }
Example #3
0
 /**
  * Copies bytes from this hash code into {@code dest}.
  *
  * @param dest the byte array into which the hash code will be written
  * @param offset the start offset in the data
  * @param maxLength the maximum number of bytes to write
  * @return the number of bytes written to {@code dest}
  * @throws IndexOutOfBoundsException if there is not enough room in {@code dest}
  */
 public int writeBytesTo(byte[] dest, int offset, int maxLength) {
   byte[] hash = asBytes();
   maxLength = Ints.min(maxLength, hash.length);
   Preconditions.checkPositionIndexes(offset, offset + maxLength, dest.length);
   System.arraycopy(hash, 0, dest, offset, maxLength);
   return maxLength;
 }
Example #4
0
 public void testCheckPositionIndexes_badSize() {
   try {
     Preconditions.checkPositionIndexes(1, 1, -1);
     fail();
   } catch (IllegalArgumentException expected) {
   }
 }
Example #5
0
 public void testCheckPositionIndexes_endTooHigh() {
   try {
     Preconditions.checkPositionIndexes(0, 2, 1);
     fail();
   } catch (IndexOutOfBoundsException expected) {
     assertThat(expected).hasMessage("end index (2) must not be greater than size (1)");
   }
 }
Example #6
0
 public void testCheckPositionIndexes_reversed() {
   try {
     Preconditions.checkPositionIndexes(1, 0, 1);
     fail();
   } catch (IndexOutOfBoundsException expected) {
     assertThat(expected).hasMessage("end index (0) must not be less than start index (1)");
   }
 }
Example #7
0
 public void testCheckPositionIndex_startNegative() {
   try {
     Preconditions.checkPositionIndexes(-1, 1, 1);
     fail();
   } catch (IndexOutOfBoundsException expected) {
     assertThat(expected).hasMessage("start index (-1) must not be negative");
   }
 }
 public List subList(int i, int j)
 {
     Preconditions.checkPositionIndexes(i, j, size());
     if (i == j)
     {
         return Collections.emptyList();
     } else
     {
         return new <init>(array, start + i, start + j);
 @Override
 public List<Float> subList(int fromIndex, int toIndex) {
   int size = size();
   checkPositionIndexes(fromIndex, toIndex, size);
   if (fromIndex == toIndex) {
     return Collections.emptyList();
   }
   return new FloatArrayAsList(array, start + fromIndex, start + toIndex);
 }
Example #10
0
 /**
  * Returns an immutable list of the elements between the specified {@code fromIndex}, inclusive,
  * and {@code toIndex}, exclusive. (If {@code fromIndex} and {@code toIndex} are equal, the empty
  * immutable list is returned.)
  */
 @Override
 public ImmutableList<E> subList(int fromIndex, int toIndex) {
   checkPositionIndexes(fromIndex, toIndex, size());
   int length = toIndex - fromIndex;
   switch (length) {
     case 0:
       return of();
     case 1:
       return of(get(fromIndex));
     default:
       return subListUnchecked(fromIndex, toIndex);
   }
 }
Example #11
0
 public ImmutableList<E> subList(int paramInt1, int paramInt2) {
   int i = size();
   Preconditions.checkPositionIndexes(paramInt1, paramInt2, i);
   if (paramInt1 != paramInt2) ;
   ImmutableList localImmutableList2;
   Comparator localComparator;
   for (ImmutableList localImmutableList1 = ImmutableList.of();
       ;
       localImmutableList1 =
           new RegularImmutableSortedSet(localImmutableList2, localComparator).asList()) {
     return localImmutableList1;
     localImmutableList2 = this.backingList.subList(paramInt1, paramInt2);
     localComparator = this.backingSet.comparator();
   }
 }
Example #12
0
  /**
   * Returns a list iterator containing the elements in the specified range of {@code array} in
   * order, starting at the specified index.
   *
   * <p>The {@code Iterable} equivalent of this method is {@code
   * Arrays.asList(array).subList(offset, offset + length).listIterator(index)}.
   */
  static <T> UnmodifiableListIterator<T> forArray(
      final T[] array, final int offset, int length, int index) {
    checkArgument(length >= 0);
    int end = offset + length;

    // Technically we should give a slightly more descriptive error on overflow
    Preconditions.checkPositionIndexes(offset, end, array.length);

    /*
     * We can't use call the two-arg constructor with arguments (offset, end)
     * because the returned Iterator is a ListIterator that may be moved back
     * past the beginning of the iteration.
     */
    return new AbstractIndexedListIterator<T>(length, index) {
      @Override
      protected T get(int index) {
        return array[offset + index];
      }
    };
  }
 @Override
 public ImmutableList<E> subList(int fromIndex, int toIndex) {
   Preconditions.checkPositionIndexes(fromIndex, toIndex, 1);
   return (fromIndex == toIndex) ? ImmutableList.<E>of() : this;
 }
 public ImmutableList<Object> subList(int paramInt1, int paramInt2) {
   Preconditions.checkPositionIndexes(paramInt1, paramInt2, 0);
   return this;
 }
Example #15
0
 @Override
 public ImmutableList<E> subList(int fromIndex, int toIndex) {
   checkPositionIndexes(fromIndex, toIndex, size());
   return forwardList.subList(reversePosition(toIndex), reversePosition(fromIndex)).reverse();
 }
Example #16
0
 @Override
 public ImmutableList<E> subList(int fromIndex, int toIndex) {
   checkPositionIndexes(fromIndex, toIndex, length);
   return ImmutableList.this.subList(fromIndex + offset, toIndex + offset);
 }
Example #17
0
 @Override
 public ImmutableList<Character> subList(int fromIndex, int toIndex) {
   checkPositionIndexes(fromIndex, toIndex, size()); // for GWT
   return charactersOf(string.substring(fromIndex, toIndex));
 }
Example #18
0
 @Override
 public List<T> subList(int fromIndex, int toIndex) {
   checkPositionIndexes(fromIndex, toIndex, size());
   return reverse(forwardList.subList(reversePosition(toIndex), reversePosition(fromIndex)));
 }
Example #19
0
 public void testCheckPositionIndexes_ok() {
   Preconditions.checkPositionIndexes(0, 0, 0);
   Preconditions.checkPositionIndexes(0, 0, 1);
   Preconditions.checkPositionIndexes(0, 1, 1);
   Preconditions.checkPositionIndexes(1, 1, 1);
 }