Example #1
0
 public static int[] arrayFromIndexedInts(IndexedInts ints) {
   int[] retVal = new int[ints.size()];
   for (int i = 0; i < ints.size(); ++i) {
     retVal[i] = ints.get(i);
   }
   return retVal;
 }
  private void assertIndexMatchesVals() {
    Assert.assertEquals(vals.length, indexed.size());

    // sequential access
    int[] indices = new int[vals.length];
    for (int i = 0; i < indexed.size(); ++i) {
      final int expected = vals[i];
      final int actual = indexed.get(i);
      Assert.assertEquals(expected, actual);
      indices[i] = i;
    }

    Collections.shuffle(Arrays.asList(indices));
    // random access
    for (int i = 0; i < indexed.size(); ++i) {
      int k = indices[i];
      Assert.assertEquals(vals[k], indexed.get(k));
    }
  }