Lines Matching refs:Iterators
19 import static com.google.common.collect.Iterators.get;
20 import static com.google.common.collect.Iterators.getLast;
21 import static com.google.common.collect.Iterators.skip;
61 * Unit test for {@code Iterators}.
77 Iterator<String> iterator = Iterators.emptyIterator();
92 Iterator<String> iterator = Iterators.emptyIterator();
93 assertEquals(0, Iterators.size(iterator));
98 assertEquals(1, Iterators.size(iterator));
105 assertEquals(3, Iterators.size(iterator));
110 assertTrue(Iterators.contains(set, "b"));
115 assertFalse(Iterators.contains(set, "c"));
120 assertTrue(Iterators.contains(set, null));
125 assertFalse(Iterators.contains(set, null));
130 assertEquals("foo", Iterators.getOnlyElement(iterator));
134 Iterator<String> iterator = Iterators.emptyIterator();
136 Iterators.getOnlyElement(iterator);
145 Iterators.getOnlyElement(iterator);
157 Iterators.getOnlyElement(iterator);
170 Iterators.getOnlyElement(iterator);
181 assertEquals("foo", Iterators.getOnlyElement(iterator, "bar"));
185 Iterator<String> iterator = Iterators.emptyIterator();
186 assertEquals("bar", Iterators.getOnlyElement(iterator, "bar"));
190 Iterator<String> iterator = Iterators.emptyIterator();
191 assertNull(Iterators.getOnlyElement(iterator, null));
197 Iterators.getOnlyElement(iterator, "x");
205 @GwtIncompatible("Iterators.toArray(Iterator, Class)")
208 String[] array = Iterators.toArray(iterator, String.class);
212 @GwtIncompatible("Iterators.toArray(Iterator, Class)")
215 String[] array = Iterators.toArray(iterator, String.class);
219 @GwtIncompatible("Iterators.toArray(Iterator, Class)")
223 String[] newArray = Iterators.toArray(iterator, String.class);
229 Iterator<String> filtered = Iterators.filter(unfiltered,
238 Iterator<String> filtered = Iterators.filter(unfiltered,
247 Iterator<String> filtered = Iterators.filter(unfiltered,
256 Iterator<String> filtered = Iterators.filter(unfiltered,
282 return Iterators.filter(list.iterator(), isEven);
291 assertFalse(Iterators.any(list.iterator(), predicate));
293 assertFalse(Iterators.any(list.iterator(), predicate));
295 assertTrue(Iterators.any(list.iterator(), predicate));
302 assertTrue(Iterators.all(list.iterator(), predicate));
304 assertTrue(Iterators.all(list.iterator(), predicate));
306 assertFalse(Iterators.all(list.iterator(), predicate));
312 assertEquals("cool", Iterators.find(iterator, Predicates.equalTo("cool")));
319 assertEquals("pants", Iterators.find(iterator,
328 Iterators.find(iterator, Predicates.alwaysFalse());
338 assertEquals("cool", Iterators.find(iterator, Predicates.alwaysTrue()));
345 Iterators.find(iterator, Predicates.equalTo("cool"), "woot"));
353 Iterators.find(iterator, Predicates.equalTo("pants"), "woot"));
361 Iterators.find(iterator, Predicates.alwaysFalse(), "woot"));
369 Iterators.find(iterator, Predicates.alwaysFalse(), null));
377 Iterators.find(iterator, Predicates.alwaysTrue(), "woot"));
385 Iterators.tryFind(iterator, Predicates.equalTo("cool")).get());
392 Iterators.tryFind(iterator, Predicates.equalTo("pants")).get());
399 Iterators.tryFind(iterator, Predicates.alwaysTrue()).get());
406 Iterators.tryFind(iterator, Predicates.alwaysFalse()).or("woot"));
414 Iterators.tryFind(iterator, Predicates.alwaysFalse()).isPresent());
420 Iterator<Integer> result = Iterators.transform(input,
436 Iterator<Integer> iterator = Iterators.transform(input,
452 Iterator<Integer> result = Iterators.transform(input,
471 Iterator<String> result = Iterators.transform(input,
486 Iterator<String> cycle = Iterators.<String>cycle();
491 Iterator<String> cycle = Iterators.cycle("a");
500 Iterator<String> cycle = Iterators.cycle(iterable);
509 Iterator<String> cycle = Iterators.cycle("a", "b");
520 Iterator<String> cycle = Iterators.cycle(iterable);
539 Iterator<String> cycle = Iterators.cycle("a", "b");
549 Iterator<String> cycle = Iterators.cycle("a", "b");
561 Iterator<String> cycle = Iterators.cycle(iterable);
572 Iterator<String> cycle = Iterators.cycle(iterable);
583 Iterator<String> cycle = Iterators.cycle(iterable);
599 return Iterators.cycle(asList(1, 2));
609 return Iterators.concat();
619 return Iterators.concat(iterateOver());
628 return Iterators.concat(iterateOver(), iterateOver());
638 return Iterators.concat(iterateOver(1));
647 return Iterators.concat(iterateOver(), iterateOver(1), iterateOver());
656 return Iterators.concat(iterateOver(1), iterateOver(2));
665 return Iterators.concat(
676 return Iterators.concat(asList(1).iterator(),
689 Iterator<Integer> result = Iterators.concat(input);
708 Iterators.concat(iterateOver(1, 2), null, iterateOver(3), iterateOver(4),
718 boolean changed = Iterators.addAll(alreadyThere,
719 Iterators.<String>emptyIterator());
728 boolean changed = Iterators.addAll(alreadyThere, freshlyAdded.iterator());
739 boolean changed = Iterators.addAll(alreadyThere, oneMore.iterator());
747 tester.testAllPublicStaticMethods(Iterators.class);
787 assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator()));
792 assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator()));
797 assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator()));
802 assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator()));
807 assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator()));
812 assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator()));
813 assertFalse(Iterators.elementsEqual(b.iterator(), a.iterator()));
818 assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator()));
819 assertFalse(Iterators.elementsEqual(b.iterator(), a.iterator()));
824 assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator()));
825 assertFalse(Iterators.elementsEqual(b.iterator(), a.iterator()));
829 Iterator<Integer> source = Iterators.singletonIterator(1);
831 Iterators.partition(source, 0);
838 Iterator<Integer> source = Iterators.emptyIterator();
839 Iterator<List<Integer>> partitions = Iterators.partition(source, 1);
844 Iterator<Integer> source = Iterators.singletonIterator(1);
845 Iterator<List<Integer>> partitions = Iterators.partition(source, 1);
853 Iterator<Integer> source = Iterators.singletonIterator(1);
854 Iterator<List<Integer>> partitions = Iterators.partition(source, 2);
871 Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7);
872 return Iterators.partition(source, 3);
880 = Iterators.partition(list.iterator(), 1);
896 Iterator<List<Integer>> partitions = Iterators.partition(source, 2);
902 Iterator<Integer> source = Iterators.singletonIterator(1);
904 Iterators.paddedPartition(source, 0);
911 Iterator<Integer> source = Iterators.emptyIterator();
912 Iterator<List<Integer>> partitions = Iterators.paddedPartition(source, 1);
917 Iterator<Integer> source = Iterators.singletonIterator(1);
918 Iterator<List<Integer>> partitions = Iterators.paddedPartition(source, 1);
926 Iterator<Integer> source = Iterators.singletonIterator(1);
927 Iterator<List<Integer>> partitions = Iterators.paddedPartition(source, 2);
944 Iterator<Integer> source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7);
945 return Iterators.paddedPartition(source, 3);
953 = Iterators.paddedPartition(list.iterator(), 1);
967 Iterator<List<Integer>> partitions = Iterators.paddedPartition(source, 2);
974 Iterator<String> iterator = Iterators.forArray(array);
984 Iterator<String> iterator = Iterators.forArray(array);
1002 Iterator<String> iterator = Iterators.forArray(array, 1, 2);
1009 Iterators.forArray(array, 2, 3);
1016 assertFalse(Iterators.forArray(array, 0, 0).hasNext());
1017 assertFalse(Iterators.forArray(array, 1, 0).hasNext());
1018 assertFalse(Iterators.forArray(array, 2, 0).hasNext());
1020 Iterators.forArray(array, -1, 0);
1024 Iterators.forArray(array, 3, 0);
1034 return Iterators.forArray(1, 2, 3);
1044 return Iterators.forArray(new Integer[] { 0, 1, 2, 3, 4 }, 1, 3);
1051 Iterator<Integer> iter = Iterators.forEnumeration(enumer);
1063 Iterator<Integer> iter = Iterators.forEnumeration(enumer);
1083 Iterator<Integer> iter = Iterators.forEnumeration(enumer);
1095 Iterator<Integer> iter = Iterators.emptyIterator();
1096 Enumeration<Integer> enumer = Iterators.asEnumeration(iter);
1108 Enumeration<Integer> enumer = Iterators.asEnumeration(iter);
1123 Enumeration<Integer> enumer = Iterators.asEnumeration(iter);
1142 assertEquals("[]", Iterators.toString(list.iterator()));
1145 assertEquals("[yam, bam, jam, ham]", Iterators.toString(list.iterator()));
1151 Iterators.limit(list.iterator(), -1);
1157 assertFalse(Iterators.limit(list.iterator(), 0).hasNext());
1158 assertFalse(Iterators.limit(list.iterator(), 1).hasNext());
1161 assertFalse(Iterators.limit(list.iterator(), 0).hasNext());
1162 assertEquals(list, newArrayList(Iterators.limit(list.iterator(), 1)));
1163 assertEquals(list, newArrayList(Iterators.limit(list.iterator(), 2)));
1166 assertFalse(Iterators.limit(list.iterator(), 0).hasNext());
1168 newArrayList(Iterators.limit(list.iterator(), 1)));
1169 assertEquals(list, newArrayList(Iterators.limit(list.iterator(), 2)));
1170 assertEquals(list, newArrayList(Iterators.limit(list.iterator(), 3)));
1177 Iterator<String> iterator = Iterators.limit(list.iterator(), 1);
1191 return Iterators.limit(Lists.newArrayList(list).iterator(), 3);
1198 assertEquals("foo", Iterators.getNext(iterator, "bar"));
1202 Iterator<String> iterator = Iterators.emptyIterator();
1203 assertEquals("bar", Iterators.getNext(iterator, "bar"));
1207 Iterator<String> iterator = Iterators.emptyIterator();
1208 assertNull(Iterators.getNext(iterator, null));
1213 assertEquals("foo", Iterators.getNext(iterator, "x"));
1234 assertEquals("foo", Iterators.getLast(iterator, "bar"));
1238 Iterator<String> iterator = Iterators.emptyIterator();
1239 assertEquals("bar", Iterators.getLast(iterator, "bar"));
1243 Iterator<String> iterator = Iterators.emptyIterator();
1244 assertNull(Iterators.getLast(iterator, null));
1249 assertEquals("bar", Iterators.getLast(iterator, "x"));
1374 assertEquals(2, Iterators.frequency(list.iterator(), "a"));
1375 assertEquals(1, Iterators.frequency(list.iterator(), "b"));
1376 assertEquals(0, Iterators.frequency(list.iterator(), "c"));
1377 assertEquals(0, Iterators.frequency(list.iterator(), 4.2));
1378 assertEquals(3, Iterators.frequency(list.iterator(), null));
1386 return Iterators.singletonIterator(1);
1393 assertTrue(Iterators.removeAll(
1396 assertFalse(Iterators.removeAll(
1403 assertTrue(Iterators.removeIf(
1412 assertFalse(Iterators.removeIf(
1425 assertTrue(Iterators.retainAll(
1428 assertFalse(Iterators.retainAll(
1444 return Iterators.removeAll(iterator(), c);
1448 return Iterators.retainAll(iterator(), c);
1453 .named("ArrayList with Iterators.removeAll and retainAll")
1467 Iterators.consumingIterator(list.iterator());
1490 Iterator<String> i1 = Iterators.consumingIterator(list.iterator());
1491 Iterator<String> i2 = Iterators.consumingIterator(list.iterator());
1505 assertEquals(1, Iterators.indexOf(iterator, Predicates.equalTo("mo")));
1513 assertEquals(1, Iterators.indexOf(iterator, Predicates.equalTo("mo")));
1522 assertEquals(-1, Iterators.indexOf(iterator, Predicates.equalTo("bob")));
1529 UnmodifiableIterator<String> unmod = Iterators.unmodifiableIterator(mod);
1531 assertSame(unmod, Iterators.unmodifiableIterator(unmod));
1532 assertSame(unmod, Iterators.unmodifiableIterator((Iterator<String>) unmod));
1538 PeekingIterator<String> peek = Iterators.peekingIterator(nonpeek);
1540 assertSame(peek, Iterators.peekingIterator(peek));
1541 assertSame(peek, Iterators.peekingIterator((Iterator<String>) peek));