Пример #1
0
 @Test
 public void works_with_a_single_type() {
   final Stream<Integer> stream = Streams.of(6, 3, 2, 7);
   assertThat(stream.foldLeft(summation(), 0), is(18));
 }
Пример #2
0
 @Test
 public void works_with_multiple_types() {
   final Stream<Integer> stream = Streams.of(6, 3, 2, 7);
   assertThat(stream.foldLeft(joinAsString(), ""), is(", 6, 3, 2, 7"));
 }
Пример #3
0
 @Test
 public void retains_order() {
   final Stream<Integer> stream = Streams.of(3, 2, 1);
   assertThat(stream.toList(), contains(3, 2, 1));
 }
Пример #4
0
 @Test
 public void retains_duplicates() {
   final Stream<Integer> stream = Streams.of(2, 3, 2, 1);
   assertThat(stream.toList(), contains(2, 3, 2, 1));
 }
Пример #5
0
 @Test
 public void strips_duplicates_out_of_a_stream() {
   final Stream<Integer> stream = Streams.of(7, 2, 5, 7, 7, 9, 4, 5, 2);
   assertThat(stream.unique(), contains(7, 2, 5, 9, 4));
 }
Пример #6
0
 @Test
 public void converts_a_stream_to_an_equivalent_list() {
   final Stream<Integer> stream = Streams.of(1, 2, 3);
   assertThat(stream.toList(), contains(1, 2, 3));
 }
Пример #7
0
 @Test
 public void makes_no_changes_to_an_already_unique_stream() {
   final Stream<Integer> stream = Streams.of(7, 2, 5, 9, 4);
   assertThat(stream.unique(), contains(7, 2, 5, 9, 4));
 }
Пример #8
0
 @Test
 public void is_lazy() {
   final Stream<Object> stream = Streams.wrap(new ThrowingIterator());
   stream.unique();
 }
Пример #9
0
 @Override
 public Stream<T> determineTail() {
   return !one.isEmpty() ? new Concat<T>(one.tail(), two) : two.tail();
 }
Пример #10
0
 @Override
 public T determineHead() {
   return !one.isEmpty() ? one.head() : two.head();
 }
Пример #11
0
 @Override
 public boolean determineIsEmpty() {
   return one.isEmpty() && two.isEmpty();
 }