diff --git a/src/main/java/com/reandroid/utils/collection/CollectionUtil.java b/src/main/java/com/reandroid/utils/collection/CollectionUtil.java index fc1f3a44f..e0f53ba21 100644 --- a/src/main/java/com/reandroid/utils/collection/CollectionUtil.java +++ b/src/main/java/com/reandroid/utils/collection/CollectionUtil.java @@ -15,6 +15,8 @@ */ package com.reandroid.utils.collection; +import com.reandroid.utils.ObjectsUtil; + import java.util.*; import java.util.function.Predicate; @@ -199,6 +201,16 @@ public static Iterator copyOf(Iterator iterator){ List results = toList(iterator); return results.iterator(); } + public static Iterator uniqueOf(Iterator iterator){ + boolean hasNext = iterator.hasNext(); + if(!hasNext){ + return EmptyIterator.of(); + } + return new UniqueIterator(ObjectsUtil.cast(iterator)); + } + public static Iterator copyOfUniqueOf(Iterator iterator){ + return copyOf(uniqueOf(iterator)); + } public static Iterator reversedOf(Iterator iterator){ boolean hasNext = iterator.hasNext(); if (!hasNext) {