Package org.ametys.plugins.repository
Class CollatingUniqueAmetysObjectIterable<A extends AmetysObject>
- java.lang.Object
-
- org.ametys.plugins.repository.CollatingUniqueAmetysObjectIterable<A>
-
- Type Parameters:
A- the actual type ofAmetysObjects.
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<A>,AmetysObjectIterable<A>
public class CollatingUniqueAmetysObjectIterable<A extends AmetysObject> extends Object implements AmetysObjectIterable<A>
Implementation of aAmetysObjectIterablebased on a list of othersAmetysObjectIterable, which returns the objects in a given order, removing duplicates. Each iterable must be sorted. The "collating" part is copied and adapted from Apache Commons Lang's CollatingIterator class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classCollatingUniqueAmetysObjectIterable.CollatingIterator
-
Field Summary
Fields Modifier and Type Field Description (package private) Comparator<A>_comparatorTheComparatorused to evaluate order.private List<AmetysObjectIterable<A>>_iterablesThe list of iterables.
-
Constructor Summary
Constructors Constructor Description CollatingUniqueAmetysObjectIterable(List<AmetysObjectIterable<A>> iterables, Comparator<A> comparator)Creates aCollatingUniqueAmetysObjectIterable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the associated resources.
AnAmetysObjectIterablemust NOT be closed if any of the containedAmetysObjectis still in use.longgetSize()Returns the number of elements only if there is only oneAmetysObjectIterablein the list.AmetysObjectIterator<A>iterator()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.plugins.repository.AmetysObjectIterable
spliterator, stream
-
-
-
-
Field Detail
-
_comparator
Comparator<A extends AmetysObject> _comparator
TheComparatorused to evaluate order.
-
_iterables
private List<AmetysObjectIterable<A extends AmetysObject>> _iterables
The list of iterables.
-
-
Constructor Detail
-
CollatingUniqueAmetysObjectIterable
public CollatingUniqueAmetysObjectIterable(List<AmetysObjectIterable<A>> iterables, Comparator<A> comparator)
Creates aCollatingUniqueAmetysObjectIterable.- Parameters:
iterables- a list ofAmetysObjectIterable.comparator- a comparator.
-
-
Method Detail
-
getSize
public long getSize()
Returns the number of elements only if there is only oneAmetysObjectIterablein the list. If there is more than 1AmetysObjectIterable, this always returns -1.- Specified by:
getSizein interfaceAmetysObjectIterable<A extends AmetysObject>- Returns:
- The size of the unique iterable or -1 if there is more than 1 iterable.
-
iterator
public AmetysObjectIterator<A> iterator()
- Specified by:
iteratorin interfaceAmetysObjectIterable<A extends AmetysObject>- Specified by:
iteratorin interfaceIterable<A extends AmetysObject>
-
close
public void close()
Description copied from interface:AmetysObjectIterableClose the associated resources.
AnAmetysObjectIterablemust NOT be closed if any of the containedAmetysObjectis still in use.- Specified by:
closein interfaceAmetysObjectIterable<A extends AmetysObject>- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-