예제 #1
0
 @Test
 public void testForEachWith() {
   MutableList<String> result = Lists.mutable.of();
   MutableList<String> source = Lists.fixedSize.of("1", "2", "3", "4", "5", "6");
   source.forEachWith(Procedures2.fromProcedure(CollectionAddProcedure.on(result)), null);
   Assert.assertEquals(FastList.newListWith("1", "2", "3", "4", "5", "6"), result);
 }
예제 #2
0
 @Test
 public void without() {
   MutableList<Integer> list = new SextupletonList<Integer>(1, 2, 3, 2, 3, 4);
   Assert.assertSame(list, list.without(9));
   list = list.without(2);
   Verify.assertListsEqual(FastList.newListWith(1, 3, 2, 3, 4), list);
   Verify.assertInstanceOf(QuintupletonList.class, list);
 }
예제 #3
0
 @Override
 @Test
 public void keySet() {
   MutableList<Integer> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   for (Integer key : map.keySet()) {
     result.add(key);
   }
   Assert.assertEquals(FastList.newListWith(1), result);
 }
예제 #4
0
 @Override
 @Test
 public void values() {
   MutableList<String> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   for (String value : map.values()) {
     result.add(value);
   }
   Assert.assertEquals(FastList.newListWith("One"), result);
 }
예제 #5
0
 @Override
 @Test
 public void entrySet() {
   MutableList<String> result = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "One");
   for (Map.Entry<Integer, String> entry : map.entrySet()) {
     result.add(entry.getValue());
   }
   Assert.assertEquals(FastList.newListWith("One"), result);
 }
예제 #6
0
 @Override
 @Test
 public void iterator() {
   MutableList<String> collection = Lists.mutable.of();
   MutableMap<Integer, String> map = new SingletonMap<Integer, String>(1, "1");
   for (String eachValue : map) {
     collection.add(eachValue);
   }
   Assert.assertEquals(FastList.newListWith("1"), collection);
 }
예제 #7
0
 @Test
 public void testSubList() {
   MutableList<String> list = Lists.fixedSize.of("one", "two", "three", "four", "five", "six");
   MutableList<String> subList = list.subList(0, 5);
   MutableList<String> upperList =
       Lists.fixedSize.of("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX");
   for (String each : subList) {
     Verify.assertContains(each.toUpperCase(), upperList);
   }
 }
예제 #8
0
 @Test
 public void testForEachWithIndex() {
   final int[] indexSum = new int[1];
   final MutableList<String> result = Lists.mutable.of();
   MutableList<String> source = Lists.fixedSize.of("1", "2", "3", "4", "5", "6");
   source.forEachWithIndex(
       new ObjectIntProcedure<String>() {
         public void value(String each, int index) {
           result.add(each);
           indexSum[0] += index;
         }
       });
   Assert.assertEquals(FastList.newListWith("1", "2", "3", "4", "5", "6"), result);
   Assert.assertEquals(15, indexSum[0]);
 }
예제 #9
0
 @Test
 public void testSet() {
   final MutableList<String> list = Lists.fixedSize.of("1", "2", "3", "4", "5", "6");
   Assert.assertEquals("1", list.set(0, "6"));
   Assert.assertEquals("2", list.set(1, "5"));
   Assert.assertEquals("3", list.set(2, "4"));
   Assert.assertEquals("4", list.set(3, "3"));
   Assert.assertEquals("5", list.set(4, "2"));
   Assert.assertEquals("6", list.set(5, "1"));
   Assert.assertEquals(FastList.newListWith("6", "5", "4", "3", "2", "1"), list);
   Verify.assertThrows(
       IndexOutOfBoundsException.class,
       new Runnable() {
         public void run() {
           list.set(6, "0");
         }
       });
 }
예제 #10
0
 public <V> ImmutableList<V> flatTransform(Function<? super T, ? extends Iterable<V>> function) {
   MutableList<V> result = Lists.mutable.of();
   this.forEach(new FlatTransformProcedure<T, V>(function, result));
   return result.toImmutable();
 }
예제 #11
0
 public <V> ImmutableList<V> transformIf(
     Predicate<? super T> predicate, Function<? super T, ? extends V> function) {
   MutableList<V> result = Lists.mutable.of();
   this.forEach(new TransformIfProcedure<T, V>(result, function, predicate));
   return result.toImmutable();
 }
예제 #12
0
 @Test
 public void testGetFirstGetLast() {
   MutableList<String> list6 = Lists.fixedSize.of("1", "2", "3", "4", "5", "6");
   Assert.assertEquals("1", list6.getFirst());
   Assert.assertEquals("6", list6.getLast());
 }