Skip to content

Commit

Permalink
Unique iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Dec 5, 2024
1 parent 8137e98 commit 55780ad
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/reandroid/utils/collection/CollectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.reandroid.utils.collection;

import com.reandroid.utils.ObjectsUtil;

import java.util.*;
import java.util.function.Predicate;

Expand Down Expand Up @@ -199,6 +201,16 @@ public static<T> Iterator<T> copyOf(Iterator<? extends T> iterator){
List<T> results = toList(iterator);
return results.iterator();
}
public static<T> Iterator<T> uniqueOf(Iterator<? extends T> iterator){
boolean hasNext = iterator.hasNext();
if(!hasNext){
return EmptyIterator.of();
}
return new UniqueIterator<T>(ObjectsUtil.cast(iterator));
}
public static<T> Iterator<T> copyOfUniqueOf(Iterator<? extends T> iterator){
return copyOf(uniqueOf(iterator));
}
public static<T> Iterator<T> reversedOf(Iterator<? extends T> iterator){
boolean hasNext = iterator.hasNext();
if (!hasNext) {
Expand Down

0 comments on commit 55780ad

Please sign in to comment.