package pollseed.util.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * List class Extension (for updating java7 to java8).
 * 
 * @version java8
 */
public class ListEx {

    /**
     * To count the list removed by {@code excludes} list.
     * 
     * @param list
     *            {@code List<T>} target list
     * @param excludes
     *            {@code List<T>} Removing excludes list
     * @param isNotNull
     *            {@code true} if {@code NOT NULL (target list) }
     * @return size of target list
     * @since v0.1
     */
    public static <T> int countList(
            final List<T> list,
            final List<T> excludes,
            final boolean isNotNull) {
        return Optional.ofNullable(toNotNullList(list)).map(
                e -> {
                    Optional.ofNullable(excludes).ifPresent(
                            optionalExcludes -> optionalExcludes.forEach(exclude -> e.removeAll(Collections.singleton(exclude))));
                    return toNotNullElementsList(e, isNotNull);
                }).get().size();
    }

    /**
     * To count the list.
     * 
     * @param list
     *            {@code List<T>} target list
     * @param isNotNull
     *            {@code true} if NOT NULL (target list)
     * @return size of target list
     * @since v0.1
     */
    public static <T> int countList(final List<T> list, final boolean isNotNull) {
        return Optional.ofNullable(toNotNullList(list)).map(
                e -> toNotNullElementsList(e, isNotNull)).get().size();
    }

    private static <T> List<T> toNotNullElementsList(final List<T> list, final boolean isNotNull) {
        if (isNotNull) {
            return toNotNullElementsList(list);
        }
        return list;
    }

    /**
     * To get the list remove {@code NULL} elements.
     * 
     * @param list
     *            {@code List<T>} target list
     * @return {@code NULL} elements {@code List<T>}
     * @since v0.1
     */
    public static <T> List<T> toNotNullElementsList(final List<T> list) {
        final List<T> tmp = toNotNullList(list);
        tmp.removeAll(Collections.singleton(null));
        return tmp;
    }

    /**
     * To get the {@code Not Null List<T>}
     * 
     * @param list
     *            {@code List<T>} target list
     * @return {@code Not Null List<T>}
     * @since v0.1
     */
    public static <T> List<T> toNotNullList(final List<T> list) {
        return Optional.ofNullable(list).isPresent() ? new ArrayList<>(list) : new ArrayList<>();
    }
}

@@ -641,31 +641,13 @@
 int 
-countList(%0A            
+size(
 fina
@@ -661,28 +661,16 @@
 T%3E list,
-%0A           
  final L
@@ -685,28 +685,16 @@
 xcludes,
-%0A           
  final b
@@ -720,32 +720,37 @@
 %0A        return 
+size(
 Optional.ofNulla
@@ -1076,28 +1076,16 @@
       %7D)
-.get().size(
 );%0A    %7D
@@ -1366,17 +1366,12 @@
 int 
-countList
+size
 (fin
@@ -1421,32 +1421,37 @@
 %0A        return 
+size(
 Optional.ofNulla
@@ -1537,16 +1537,140 @@
 otNull))
+);%0A    %7D%0A%0A    private static %3CT%3E int size(final Optional%3CList%3CT%3E%3E optional) %7B%0A        return optional.isPresent() ? optional
 .get().s
@@ -1674,16 +1674,20 @@
 ).size()
+ : 0
 ;%0A    %7D%0A

Update ListEx.java