Example #1
0
 @GwtIncompatible("ObjectArrays.concat(Object[], Object[], Class)")
 public void testConcatBasic() {
   String[] result =
       ObjectArrays.concat(new String[] {"a", "b"}, new String[] {"c", "d"}, String.class);
   assertEquals(String[].class, result.getClass());
   ASSERT.that(result).hasContentsInOrder("a", "b", "c", "d");
 }
Example #2
0
 @GwtIncompatible("ObjectArrays.newArray(Class, int)")
 public void testNewArray_fromClass_OfArray() {
   String[][] array = ObjectArrays.newArray(String[].class, 1);
   assertEquals(String[][].class, array.getClass());
   assertEquals(1, array.length);
   assertNull(array[0]);
 }
  private void doTestToArrayImpl2(List<Integer> list, Integer[] array1, boolean expectModify) {
    Integer[] starting = ObjectArrays.arraysCopyOf(array1, array1.length);
    Integer[] array2 = ObjectArrays.arraysCopyOf(array1, array1.length);
    Object[] reference = list.toArray(array1);

    Object[] target = ObjectArrays.toArrayImpl(list, array2);

    assertEquals(reference.getClass(), target.getClass());
    assertTrue(Arrays.equals(reference, target));
    assertTrue(Arrays.equals(reference, target));

    Object[] expectedArray1 = expectModify ? reference : starting;
    Object[] expectedArray2 = expectModify ? target : starting;
    assertTrue(Arrays.equals(expectedArray1, array1));
    assertTrue(Arrays.equals(expectedArray2, array2));
  }
 private void ensureCapacity(int minCapacity) {
   if (minCapacity > entries.length) {
     entries =
         ObjectArrays.arraysCopyOf(
             entries, ImmutableCollection.Builder.expandedCapacity(entries.length, minCapacity));
   }
 }
Example #5
0
 @Test
 public void testCollectionInstance() {
   Maps.newLinkedHashMap();
   Lists.newArrayList();
   Sets.newHashSet();
   ObjectArrays.newArray(Integer.class, 10);
 }
Example #6
0
 public IAndroidTarget[] getTargets(boolean includeMissing) {
   IAndroidTarget[] result = getTargets();
   if (includeMissing) {
     result = ObjectArrays.concat(result, getMissingTargets(), IAndroidTarget.class);
   }
   return result;
 }
/*     */   public void clear()
/*     */   {
/* 368 */     if (this.size == 0) return;
/* 369 */     this.size = 0;
/* 370 */     BooleanArrays.fill(this.used, false);
/*     */ 
/* 372 */     ObjectArrays.fill(this.key, null);
/*     */   }
Example #8
0
 @Override
 public <T> T[] toArray(T[] other) {
   if (other.length < size) {
     other = ObjectArrays.newArray(other, size);
   } else if (other.length > size) {
     other[size] = null;
   }
   System.arraycopy(array, offset, other, 0, size);
   return other;
 }
Example #9
0
 // TODO: Move to ObjectArrays (same code in ImmutableList).
 @Override
 public <T> T[] toArray(T[] array) {
   int size = size();
   if (array.length < size) {
     array = ObjectArrays.newArray(array, size);
   } else if (array.length > size) {
     array[size] = null;
   }
   System.arraycopy(elements, fromIndex, array, 0, size);
   return array;
 }
Example #10
0
 static ImmutableSortedSet construct(Comparator paramComparator, int paramInt, Object... paramVarArgs)
 {
   int i = sortAndUnique(paramComparator, paramInt, paramVarArgs);
   if (i == 0) {
     return emptySet(paramComparator);
   }
   if (i < paramVarArgs.length) {
     paramVarArgs = ObjectArrays.arraysCopyOf(paramVarArgs, i);
   }
   return new RegularImmutableSortedSet(ImmutableList.asImmutableList(paramVarArgs), paramComparator);
 }
 @Test
 public void should_fail_if_actual_is_empty() {
   AssertionInfo info = someInfo();
   try {
     arrays.assertNotEmpty(info, emptyArray());
   } catch (AssertionError e) {
     verify(failures).failure(info, shouldNotBeEmpty());
     return;
   }
   failBecauseExpectedAssertionErrorWasNotThrown();
 }
 @Override
 public <T> T[] toArray(T[] array) {
   if (array.length == 0) {
     array = ObjectArrays.newArray(array, 1);
   } else if (array.length > 1) {
     array[1] = null;
   }
   // Writes will produce ArrayStoreException when the toArray() doc requires.
   Object[] objectArray = array;
   objectArray[0] = element;
   return array;
 }
 public <T> T[] toArray(T[] paramArrayOfT)
 {
   if (paramArrayOfT.length == 0)
     paramArrayOfT = ObjectArrays.a(paramArrayOfT, 1);
   while (true)
   {
     paramArrayOfT[0] = this.a;
     return paramArrayOfT;
     if (paramArrayOfT.length > 1)
       paramArrayOfT[1] = null;
   }
 }
 public <T> T[] toArray(T[] paramArrayOfT) {
   Object localObject;
   if (paramArrayOfT.length == 0) {
     localObject = ObjectArrays.newArray(paramArrayOfT, 1);
   }
   for (; ; ) {
     localObject[0] = element;
     return (T[]) localObject;
     localObject = paramArrayOfT;
     if (paramArrayOfT.length > 1) {
       paramArrayOfT[1] = null;
       localObject = paramArrayOfT;
     }
   }
 }
Example #15
0
    /*
     * TODO(hhchan): Revert once we have a separate, manual emulation of this
     * class.
     */
    @Override
    public <T> T[] toArray(T[] other) {
      int size = size();
      if (other.length < size) {
        other = ObjectArrays.newArray(other, size);
      } else if (other.length > size) {
        other[size] = null;
      }

      // Writes will produce ArrayStoreException when the toArray() doc requires
      Object[] otherAsObjectArray = other;
      int index = 0;
      for (Entry<?> element : this) {
        otherAsObjectArray[index++] = element;
      }
      return other;
    }
  @Override
  @SuppressWarnings("nullness")
  // Suppressed due to annotations of toArray
  public <T> /*@Nullable*/ T[] toArray(T[] other) {
    int size = size();
    if (other.length < size) {
      other = ObjectArrays.newArray(other, size);
    } else if (other.length > size) {
      other[size] = null;
    }

    // Writes will produce ArrayStoreException when the toArray() doc requires.
    Object[] otherAsObjectArray = other;
    int index = 0;
    for (E element : this) {
      otherAsObjectArray[index++] = element;
    }
    return other;
  }
Example #17
0
 static int sortAndUnique(Comparator paramComparator, int paramInt, Object... paramVarArgs)
 {
   if (paramInt == 0) {
     return 0;
   }
   for (int i = 0; i < paramInt; i++) {
     ObjectArrays.checkElementNotNull(paramVarArgs[i], i);
   }
   Arrays.sort(paramVarArgs, 0, paramInt, paramComparator);
   i = 1;
   for (int j = 1; j < paramInt; j++)
   {
     Object localObject1 = paramVarArgs[j];
     Object localObject2 = paramVarArgs[(i - 1)];
     if (paramComparator.compare(localObject1, localObject2) != 0) {
       paramVarArgs[(i++)] = localObject1;
     }
   }
   Arrays.fill(paramVarArgs, i, paramInt, null);
   return i;
 }
Example #18
0
 public void testPrependOneElement() {
   String[] result = ObjectArrays.concat("foo", new String[] {"bar"});
   ASSERT.that(result).hasContentsInOrder("foo", "bar");
 }
 public void testNonEmptyToLonger() {
   checkArrayEquals(
       new String[10], ObjectArrays.newArray(new String[] {"a", "b", "c", "d", "e"}, 10));
 }
 @GwtIncompatible("ObjectArrays.concat(Object[], Object[], Class)")
 public void testConcatEmptyNonempty() {
   String[] result = ObjectArrays.concat(new String[0], new String[] {"a", "b"}, String.class);
   assertEquals(String[].class, result.getClass());
   ASSERT.that(result).has().exactly("a", "b").inOrder();
 }
 private static void doTestNewArrayEquals(Object[] expected, int length) {
   checkArrayEquals(expected, ObjectArrays.newArray(expected, length));
 }
Example #22
0
 private void doTestToArrayImpl1(List<Integer> list) {
   Object[] reference = list.toArray();
   Object[] target = ObjectArrays.toArrayImpl(list);
   assertEquals(reference.getClass(), target.getClass());
   assertTrue(Arrays.equals(reference, target));
 }
Example #23
0
 @GwtIncompatible("ObjectArrays.concat(Object[], Object[], Class)")
 public void testConcatWithMoreGeneralType() {
   Serializable[] result = ObjectArrays.concat(new String[0], new String[0], Serializable.class);
   assertEquals(Serializable[].class, result.getClass());
 }
Example #24
0
 @GwtIncompatible("ObjectArrays.concat(Object[], Object[], Class)")
 public void testConcatEmptyEmpty() {
   String[] result = ObjectArrays.concat(new String[0], new String[0], String.class);
   assertEquals(String[].class, result.getClass());
   assertEquals(0, result.length);
 }
 /**
  * Creates a new tree set and fills it with the elements of a given array using a given {@link
  * Comparator}.
  *
  * @param a an array whose elements will be used to fill the set.
  * @param offset the first element to use.
  * @param length the number of elements to use.
  * @param c a {@link Comparator} (even better, a type-specific comparator).
  */
 public ObjectRBTreeSet(
     final K[] a, final int offset, final int length, final Comparator<? super K> c) {
   this(c);
   ObjectArrays.ensureOffsetLength(a, offset, length);
   for (int i = 0; i < length; i++) add(a[offset + i]);
 }
Example #26
0
 public void testNewArray_fromArray_OfArray() {
   String[][] array = ObjectArrays.newArray(new String[0][0], 1);
   assertEquals(String[][].class, array.getClass());
   assertEquals(1, array.length);
   assertNull(array[0]);
 }
Example #27
0
 public void testNewArray_fromArray_Empty() {
   String[] in = new String[0];
   String[] empty = ObjectArrays.newArray(in, 0);
   assertEquals(0, empty.length);
 }
Example #28
0
 public void testPrependZeroElements() {
   String[] result = ObjectArrays.concat("foo", new String[] {});
   ASSERT.that(result).hasContentsInOrder("foo");
 }
Example #29
0
 @GwtIncompatible("ObjectArrays.newArray(Class, int)")
 public void testNewArray_fromClass_Empty() {
   String[] empty = ObjectArrays.newArray(String.class, 0);
   assertEquals(String[].class, empty.getClass());
   assertEquals(0, empty.length);
 }
Example #30
0
 public void testAppendTwoElements() {
   String[] result = ObjectArrays.concat(new String[] {"foo", "bar"}, "baz");
   ASSERT.that(result).hasContentsInOrder("foo", "bar", "baz");
 }