示例#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();
 }