Java 11 migrate 7 remaining f (#1115)
* Moves facade to Java 11 * Moves factory-kit to Java 11 * Moves factory-method to Java 11 * Moves feature-toggle to Java 11 * Moves fluentinterface to Java 11 * Moves flux to Java 11 * Moves flyweight to Java 11 * Moves front-controller to Java 11 * Uses stream properly * Resolves issues with ci
This commit is contained in:
		
				
					committed by
					
						
						Ilkka Seppälä
					
				
			
			
				
	
			
			
			
						parent
						
							f835d3d516
						
					
				
				
					commit
					670c4e43f3
				
			@@ -28,8 +28,6 @@ import static java.lang.String.valueOf;
 | 
			
		||||
import com.iluwatar.fluentinterface.fluentiterable.FluentIterable;
 | 
			
		||||
import com.iluwatar.fluentinterface.fluentiterable.lazy.LazyFluentIterable;
 | 
			
		||||
import com.iluwatar.fluentinterface.fluentiterable.simple.SimpleFluentIterable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.StringJoiner;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
@@ -57,19 +55,23 @@ public class App {
 | 
			
		||||
   */
 | 
			
		||||
  public static void main(String[] args) {
 | 
			
		||||
 | 
			
		||||
    List<Integer> integerList = new ArrayList<>();
 | 
			
		||||
    integerList.addAll(List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2,
 | 
			
		||||
        -68, 45));
 | 
			
		||||
    var integerList = List.of(1, -61, 14, -22, 18, -87, 6, 64, -82, 26, -98, 97, 45, 23, 2, -68);
 | 
			
		||||
 | 
			
		||||
    prettyPrint("The initial list contains: ", integerList);
 | 
			
		||||
 | 
			
		||||
    List<Integer> firstFiveNegatives =
 | 
			
		||||
        SimpleFluentIterable.fromCopyOf(integerList).filter(negatives()).first(3).asList();
 | 
			
		||||
    var firstFiveNegatives = SimpleFluentIterable
 | 
			
		||||
        .fromCopyOf(integerList)
 | 
			
		||||
        .filter(negatives())
 | 
			
		||||
        .first(3)
 | 
			
		||||
        .asList();
 | 
			
		||||
    prettyPrint("The first three negative values are: ", firstFiveNegatives);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    List<Integer> lastTwoPositives =
 | 
			
		||||
        SimpleFluentIterable.fromCopyOf(integerList).filter(positives()).last(2).asList();
 | 
			
		||||
    var lastTwoPositives = SimpleFluentIterable
 | 
			
		||||
        .fromCopyOf(integerList)
 | 
			
		||||
        .filter(positives())
 | 
			
		||||
        .last(2)
 | 
			
		||||
        .asList();
 | 
			
		||||
    prettyPrint("The last two positive values are: ", lastTwoPositives);
 | 
			
		||||
 | 
			
		||||
    SimpleFluentIterable
 | 
			
		||||
@@ -79,15 +81,21 @@ public class App {
 | 
			
		||||
        .ifPresent(evenNumber -> LOGGER.info("The first even number is: {}", evenNumber));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    List<String> transformedList =
 | 
			
		||||
        SimpleFluentIterable.fromCopyOf(integerList).filter(negatives()).map(transformToString())
 | 
			
		||||
            .asList();
 | 
			
		||||
    var transformedList = SimpleFluentIterable
 | 
			
		||||
        .fromCopyOf(integerList)
 | 
			
		||||
        .filter(negatives())
 | 
			
		||||
        .map(transformToString())
 | 
			
		||||
        .asList();
 | 
			
		||||
    prettyPrint("A string-mapped list of negative numbers contains: ", transformedList);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    List<String> lastTwoOfFirstFourStringMapped =
 | 
			
		||||
        LazyFluentIterable.from(integerList).filter(positives()).first(4).last(2)
 | 
			
		||||
            .map(number -> "String[" + valueOf(number) + "]").asList();
 | 
			
		||||
    var lastTwoOfFirstFourStringMapped = LazyFluentIterable
 | 
			
		||||
        .from(integerList)
 | 
			
		||||
        .filter(positives())
 | 
			
		||||
        .first(4)
 | 
			
		||||
        .last(2)
 | 
			
		||||
        .map(number -> "String[" + valueOf(number) + "]")
 | 
			
		||||
        .asList();
 | 
			
		||||
    prettyPrint("The lazy list contains the last two of the first four positive numbers "
 | 
			
		||||
        + "mapped to Strings: ", lastTwoOfFirstFourStringMapped);
 | 
			
		||||
 | 
			
		||||
@@ -96,12 +104,11 @@ public class App {
 | 
			
		||||
        .filter(negatives())
 | 
			
		||||
        .first(2)
 | 
			
		||||
        .last()
 | 
			
		||||
        .ifPresent(lastOfFirstTwo -> LOGGER
 | 
			
		||||
            .info("The last of the first two negatives is: {}", lastOfFirstTwo));
 | 
			
		||||
        .ifPresent(number -> LOGGER.info("Last amongst first two negatives: {}", number));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static Function<Integer, String> transformToString() {
 | 
			
		||||
    return integer -> "String[" + valueOf(integer) + "]";
 | 
			
		||||
    return integer -> "String[" + integer + "]";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static Predicate<? super Integer> negatives() {
 | 
			
		||||
@@ -116,14 +123,12 @@ public class App {
 | 
			
		||||
    prettyPrint(", ", prefix, iterable);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private static <E> void prettyPrint(String delimiter, String prefix,
 | 
			
		||||
                                      Iterable<E> iterable) {
 | 
			
		||||
    StringJoiner joiner = new StringJoiner(delimiter, prefix, ".");
 | 
			
		||||
    Iterator<E> iterator = iterable.iterator();
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      joiner.add(iterator.next().toString());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  private static <E> void prettyPrint(
 | 
			
		||||
      String delimiter, String prefix,
 | 
			
		||||
      Iterable<E> iterable
 | 
			
		||||
  ) {
 | 
			
		||||
    var joiner = new StringJoiner(delimiter, prefix, ".");
 | 
			
		||||
    iterable.forEach(e -> joiner.add(e.toString()));
 | 
			
		||||
    LOGGER.info(joiner.toString());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,6 @@
 | 
			
		||||
package com.iluwatar.fluentinterface.fluentiterable;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
@@ -102,11 +101,8 @@ public interface FluentIterable<E> extends Iterable<E> {
 | 
			
		||||
   * @return a list with all objects of the given iterator
 | 
			
		||||
   */
 | 
			
		||||
  static <E> List<E> copyToList(Iterable<E> iterable) {
 | 
			
		||||
    List<E> copy = new ArrayList<>();
 | 
			
		||||
    Iterator<E> iterator = iterable.iterator();
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      copy.add(iterator.next());
 | 
			
		||||
    }
 | 
			
		||||
    var copy = new ArrayList<E>();
 | 
			
		||||
    iterable.forEach(copy::add);
 | 
			
		||||
    return copy;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -65,7 +65,7 @@ public abstract class DecoratingIterator<E> implements Iterator<E> {
 | 
			
		||||
    if (next == null) {
 | 
			
		||||
      return fromIterator.next();
 | 
			
		||||
    } else {
 | 
			
		||||
      final E result = next;
 | 
			
		||||
      final var result = next;
 | 
			
		||||
      next = null;
 | 
			
		||||
      return result;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -67,14 +67,14 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public FluentIterable<E> filter(Predicate<? super E> predicate) {
 | 
			
		||||
    return new LazyFluentIterable<E>() {
 | 
			
		||||
    return new LazyFluentIterable<>() {
 | 
			
		||||
      @Override
 | 
			
		||||
      public Iterator<E> iterator() {
 | 
			
		||||
        return new DecoratingIterator<E>(iterable.iterator()) {
 | 
			
		||||
          @Override
 | 
			
		||||
          public E computeNext() {
 | 
			
		||||
            while (fromIterator.hasNext()) {
 | 
			
		||||
              E candidate = fromIterator.next();
 | 
			
		||||
              var candidate = fromIterator.next();
 | 
			
		||||
              if (predicate.test(candidate)) {
 | 
			
		||||
                return candidate;
 | 
			
		||||
              }
 | 
			
		||||
@@ -94,7 +94,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public Optional<E> first() {
 | 
			
		||||
    Iterator<E> resultIterator = first(1).iterator();
 | 
			
		||||
    var resultIterator = first(1).iterator();
 | 
			
		||||
    return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -116,7 +116,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
          @Override
 | 
			
		||||
          public E computeNext() {
 | 
			
		||||
            if (currentIndex < count && fromIterator.hasNext()) {
 | 
			
		||||
              E candidate = fromIterator.next();
 | 
			
		||||
              var candidate = fromIterator.next();
 | 
			
		||||
              currentIndex++;
 | 
			
		||||
              return candidate;
 | 
			
		||||
            }
 | 
			
		||||
@@ -134,7 +134,7 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public Optional<E> last() {
 | 
			
		||||
    Iterator<E> resultIterator = last(1).iterator();
 | 
			
		||||
    var resultIterator = last(1).iterator();
 | 
			
		||||
    return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -162,25 +162,20 @@ public class LazyFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
          public E computeNext() {
 | 
			
		||||
            initialize();
 | 
			
		||||
 | 
			
		||||
            E candidate = null;
 | 
			
		||||
            while (currentIndex < stopIndex && fromIterator.hasNext()) {
 | 
			
		||||
              currentIndex++;
 | 
			
		||||
              fromIterator.next();
 | 
			
		||||
            }
 | 
			
		||||
            if (currentIndex >= stopIndex && fromIterator.hasNext()) {
 | 
			
		||||
              candidate = fromIterator.next();
 | 
			
		||||
              return fromIterator.next();
 | 
			
		||||
            }
 | 
			
		||||
            return candidate;
 | 
			
		||||
            return null;
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          private void initialize() {
 | 
			
		||||
            if (list == null) {
 | 
			
		||||
              list = new ArrayList<>();
 | 
			
		||||
              Iterator<E> newIterator = iterable.iterator();
 | 
			
		||||
              while (newIterator.hasNext()) {
 | 
			
		||||
                list.add(newIterator.next());
 | 
			
		||||
              }
 | 
			
		||||
 | 
			
		||||
              iterable.forEach(list::add);
 | 
			
		||||
              totalElementsCount = list.size();
 | 
			
		||||
              stopIndex = totalElementsCount - count;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -62,9 +62,9 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public final FluentIterable<E> filter(Predicate<? super E> predicate) {
 | 
			
		||||
    Iterator<E> iterator = iterator();
 | 
			
		||||
    var iterator = iterator();
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      E nextElement = iterator.next();
 | 
			
		||||
      var nextElement = iterator.next();
 | 
			
		||||
      if (!predicate.test(nextElement)) {
 | 
			
		||||
        iterator.remove();
 | 
			
		||||
      }
 | 
			
		||||
@@ -79,7 +79,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public final Optional<E> first() {
 | 
			
		||||
    Iterator<E> resultIterator = first(1).iterator();
 | 
			
		||||
    var resultIterator = first(1).iterator();
 | 
			
		||||
    return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -92,8 +92,8 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public final FluentIterable<E> first(int count) {
 | 
			
		||||
    Iterator<E> iterator = iterator();
 | 
			
		||||
    int currentCount = 0;
 | 
			
		||||
    var iterator = iterator();
 | 
			
		||||
    var currentCount = 0;
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      iterator.next();
 | 
			
		||||
      if (currentCount >= count) {
 | 
			
		||||
@@ -111,7 +111,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public final Optional<E> last() {
 | 
			
		||||
    List<E> list = last(1).asList();
 | 
			
		||||
    var list = last(1).asList();
 | 
			
		||||
    if (list.isEmpty()) {
 | 
			
		||||
      return Optional.empty();
 | 
			
		||||
    }
 | 
			
		||||
@@ -127,9 +127,9 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public final FluentIterable<E> last(int count) {
 | 
			
		||||
    int remainingElementsCount = getRemainingElementsCount();
 | 
			
		||||
    Iterator<E> iterator = iterator();
 | 
			
		||||
    int currentIndex = 0;
 | 
			
		||||
    var remainingElementsCount = getRemainingElementsCount();
 | 
			
		||||
    var iterator = iterator();
 | 
			
		||||
    var currentIndex = 0;
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      iterator.next();
 | 
			
		||||
      if (currentIndex < remainingElementsCount - count) {
 | 
			
		||||
@@ -150,11 +150,8 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   */
 | 
			
		||||
  @Override
 | 
			
		||||
  public final <T> FluentIterable<T> map(Function<? super E, T> function) {
 | 
			
		||||
    List<T> temporaryList = new ArrayList<>();
 | 
			
		||||
    Iterator<E> iterator = iterator();
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      temporaryList.add(function.apply(iterator.next()));
 | 
			
		||||
    }
 | 
			
		||||
    var temporaryList = new ArrayList<T>();
 | 
			
		||||
    this.forEach(e -> temporaryList.add(function.apply(e)));
 | 
			
		||||
    return from(temporaryList);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -178,7 +175,7 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public static <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) {
 | 
			
		||||
    List<E> copy = FluentIterable.copyToList(iterable);
 | 
			
		||||
    var copy = FluentIterable.copyToList(iterable);
 | 
			
		||||
    return new SimpleFluentIterable<>(copy);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -204,10 +201,8 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   * @return the count of remaining objects of the current Iterable
 | 
			
		||||
   */
 | 
			
		||||
  public final int getRemainingElementsCount() {
 | 
			
		||||
    int counter = 0;
 | 
			
		||||
    Iterator<E> iterator = iterator();
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      iterator.next();
 | 
			
		||||
    var counter = 0;
 | 
			
		||||
    for (var ignored : this) {
 | 
			
		||||
      counter++;
 | 
			
		||||
    }
 | 
			
		||||
    return counter;
 | 
			
		||||
@@ -219,10 +214,8 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
 | 
			
		||||
   * @return a new List with the remaining objects.
 | 
			
		||||
   */
 | 
			
		||||
  public static <E> List<E> toList(Iterator<E> iterator) {
 | 
			
		||||
    List<E> copy = new ArrayList<>();
 | 
			
		||||
    while (iterator.hasNext()) {
 | 
			
		||||
      copy.add(iterator.next());
 | 
			
		||||
    }
 | 
			
		||||
    var copy = new ArrayList<E>();
 | 
			
		||||
    iterator.forEachRemaining(copy::add);
 | 
			
		||||
    return copy;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,6 @@ public class AppTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void test() {
 | 
			
		||||
    String[] args = {};
 | 
			
		||||
    App.main(args);
 | 
			
		||||
    App.main(new String[]{});
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,16 +23,19 @@
 | 
			
		||||
 | 
			
		||||
package com.iluwatar.fluentinterface.fluentiterable;
 | 
			
		||||
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertEquals;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertFalse;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.assertTrue;
 | 
			
		||||
import static org.mockito.Mockito.mock;
 | 
			
		||||
import static org.mockito.Mockito.times;
 | 
			
		||||
import static org.mockito.Mockito.verify;
 | 
			
		||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.Spliterator;
 | 
			
		||||
import java.util.function.Consumer;
 | 
			
		||||
 | 
			
		||||
import static org.junit.jupiter.api.Assertions.*;
 | 
			
		||||
import static org.mockito.Mockito.*;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Date: 12/12/15 - 7:00 PM
 | 
			
		||||
@@ -50,28 +53,28 @@ public abstract class FluentIterableTest {
 | 
			
		||||
  protected abstract FluentIterable<Integer> createFluentIterable(final Iterable<Integer> integers);
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testFirst() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final Optional<Integer> first = createFluentIterable(integers).first();
 | 
			
		||||
  public void testFirst() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final var first = createFluentIterable(integers).first();
 | 
			
		||||
    assertNotNull(first);
 | 
			
		||||
    assertTrue(first.isPresent());
 | 
			
		||||
    assertEquals(integers.get(0), first.get());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testFirstEmptyCollection() throws Exception {
 | 
			
		||||
    final List<Integer> integers = Collections.emptyList();
 | 
			
		||||
    final Optional<Integer> first = createFluentIterable(integers).first();
 | 
			
		||||
  public void testFirstEmptyCollection() {
 | 
			
		||||
    final var integers = Collections.<Integer>emptyList();
 | 
			
		||||
    final var first = createFluentIterable(integers).first();
 | 
			
		||||
    assertNotNull(first);
 | 
			
		||||
    assertFalse(first.isPresent());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testFirstCount() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final List<Integer> first4 = createFluentIterable(integers)
 | 
			
		||||
            .first(4)
 | 
			
		||||
            .asList();
 | 
			
		||||
  public void testFirstCount() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final var first4 = createFluentIterable(integers)
 | 
			
		||||
        .first(4)
 | 
			
		||||
        .asList();
 | 
			
		||||
 | 
			
		||||
    assertNotNull(first4);
 | 
			
		||||
    assertEquals(4, first4.size());
 | 
			
		||||
@@ -83,11 +86,11 @@ public abstract class FluentIterableTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testFirstCountLessItems() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3);
 | 
			
		||||
    final List<Integer> first4 = createFluentIterable(integers)
 | 
			
		||||
            .first(4)
 | 
			
		||||
            .asList();
 | 
			
		||||
  public void testFirstCountLessItems() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3);
 | 
			
		||||
    final var first4 = createFluentIterable(integers)
 | 
			
		||||
        .first(4)
 | 
			
		||||
        .asList();
 | 
			
		||||
 | 
			
		||||
    assertNotNull(first4);
 | 
			
		||||
    assertEquals(3, first4.size());
 | 
			
		||||
@@ -98,28 +101,28 @@ public abstract class FluentIterableTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testLast() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final Optional<Integer> last = createFluentIterable(integers).last();
 | 
			
		||||
  public void testLast() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final var last = createFluentIterable(integers).last();
 | 
			
		||||
    assertNotNull(last);
 | 
			
		||||
    assertTrue(last.isPresent());
 | 
			
		||||
    assertEquals(integers.get(integers.size() - 1), last.get());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testLastEmptyCollection() throws Exception {
 | 
			
		||||
    final List<Integer> integers = Collections.<Integer>emptyList();
 | 
			
		||||
    final Optional<Integer> last = createFluentIterable(integers).last();
 | 
			
		||||
  public void testLastEmptyCollection() {
 | 
			
		||||
    final var integers = Collections.<Integer>emptyList();
 | 
			
		||||
    final var last = createFluentIterable(integers).last();
 | 
			
		||||
    assertNotNull(last);
 | 
			
		||||
    assertFalse(last.isPresent());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testLastCount() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final List<Integer> last4 = createFluentIterable(integers)
 | 
			
		||||
            .last(4)
 | 
			
		||||
            .asList();
 | 
			
		||||
  public void testLastCount() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final var last4 = createFluentIterable(integers)
 | 
			
		||||
        .last(4)
 | 
			
		||||
        .asList();
 | 
			
		||||
 | 
			
		||||
    assertNotNull(last4);
 | 
			
		||||
    assertEquals(4, last4.size());
 | 
			
		||||
@@ -130,11 +133,11 @@ public abstract class FluentIterableTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testLastCountLessItems() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3);
 | 
			
		||||
    final List<Integer> last4 = createFluentIterable(integers)
 | 
			
		||||
            .last(4)
 | 
			
		||||
            .asList();
 | 
			
		||||
  public void testLastCountLessItems() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3);
 | 
			
		||||
    final var last4 = createFluentIterable(integers)
 | 
			
		||||
        .last(4)
 | 
			
		||||
        .asList();
 | 
			
		||||
 | 
			
		||||
    assertNotNull(last4);
 | 
			
		||||
    assertEquals(3, last4.size());
 | 
			
		||||
@@ -145,11 +148,11 @@ public abstract class FluentIterableTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testFilter() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final List<Integer> evenItems = createFluentIterable(integers)
 | 
			
		||||
            .filter(i -> i % 2 == 0)
 | 
			
		||||
            .asList();
 | 
			
		||||
  public void testFilter() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3, 10, 9, 8);
 | 
			
		||||
    final var evenItems = createFluentIterable(integers)
 | 
			
		||||
        .filter(i -> i % 2 == 0)
 | 
			
		||||
        .asList();
 | 
			
		||||
 | 
			
		||||
    assertNotNull(evenItems);
 | 
			
		||||
    assertEquals(3, evenItems.size());
 | 
			
		||||
@@ -159,11 +162,11 @@ public abstract class FluentIterableTest {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testMap() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3);
 | 
			
		||||
    final List<Long> longs = createFluentIterable(integers)
 | 
			
		||||
            .map(Integer::longValue)
 | 
			
		||||
            .asList();
 | 
			
		||||
  public void testMap() {
 | 
			
		||||
    final var integers = List.of(1, 2, 3);
 | 
			
		||||
    final var longs = createFluentIterable(integers)
 | 
			
		||||
        .map(Integer::longValue)
 | 
			
		||||
        .asList();
 | 
			
		||||
 | 
			
		||||
    assertNotNull(longs);
 | 
			
		||||
    assertEquals(integers.size(), longs.size());
 | 
			
		||||
@@ -174,7 +177,7 @@ public abstract class FluentIterableTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testForEach() {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3);
 | 
			
		||||
    final var integers = List.of(1, 2, 3);
 | 
			
		||||
 | 
			
		||||
    final Consumer<Integer> consumer = mock(Consumer.class);
 | 
			
		||||
    createFluentIterable(integers).forEach(consumer);
 | 
			
		||||
@@ -188,8 +191,8 @@ public abstract class FluentIterableTest {
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  public void testSpliterator() throws Exception {
 | 
			
		||||
    final List<Integer> integers = List.of(1, 2, 3);
 | 
			
		||||
    final Spliterator<Integer> split = createFluentIterable(integers).spliterator();
 | 
			
		||||
    final var integers = List.of(1, 2, 3);
 | 
			
		||||
    final var split = createFluentIterable(integers).spliterator();
 | 
			
		||||
    assertNotNull(split);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user