diff --git a/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java b/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java index 64c6a62e05ed..e3fc29d05ef2 100644 --- a/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java +++ b/jps/jps-builders-6/src/org/jetbrains/jps/javac/Iterators.java @@ -19,10 +19,11 @@ public class Iterators { }; public static boolean isEmpty(Iterable iterable) { - if (iterable instanceof Collection) { - return ((Collection)iterable).isEmpty(); - } - return iterable == null || !iterable.iterator().hasNext(); + return isEmptyCollection(iterable) || !iterable.iterator().hasNext(); + } + + private static boolean isEmptyCollection(Iterable iterable) { + return iterable == null || iterable instanceof Collection && ((Collection)iterable).isEmpty(); } public static boolean contains(Iterable iterable, T obj) { @@ -48,10 +49,10 @@ public class Iterators { @SuppressWarnings("unchecked") public static Iterable flat(final Iterable first, final Iterable second) { - if (isEmpty(first)) { - return isEmpty(second)? Collections.emptyList() : (Iterable)second; + if (isEmptyCollection(first)) { + return isEmptyCollection(second)? Collections.emptyList() : (Iterable)second; } - if (isEmpty(second)) { + if (isEmptyCollection(second)) { return (Iterable)first; } return new Iterable() { @@ -88,7 +89,7 @@ public class Iterators { } public static Iterable flat(final Iterable> parts) { - return isEmpty(parts)? Collections.emptyList() : new Iterable() { + return isEmptyCollection(parts)? Collections.emptyList() : new Iterable() { @NotNull @Override public Iterator iterator() { @@ -168,7 +169,7 @@ public class Iterators { } public static Iterable map(final Iterable from, final Function mapper) { - return isEmpty(from)? Collections.emptyList() : new Iterable() { + return isEmptyCollection(from)? Collections.emptyList() : new Iterable() { @NotNull @Override public Iterator iterator() { @@ -192,7 +193,7 @@ public class Iterators { } public static Iterable filter(final Iterable it, final BooleanFunction predicate) { - return isEmpty(it)? Collections.emptyList() : new Iterable() { + return isEmptyCollection(it)? Collections.emptyList() : new Iterable() { @NotNull @Override public Iterator iterator() { @@ -247,7 +248,7 @@ public class Iterators { } public static Iterable filterWithOrder(final Iterable from, final Iterable> predicates) { - return isEmpty(predicates) || isEmpty(from)? Collections.emptyList() : new Iterable() { + return isEmptyCollection(predicates) || isEmptyCollection(from)? Collections.emptyList() : new Iterable() { @NotNull @Override public Iterator iterator() {