Class DistinctDataBag<E>
- java.lang.Object
-
- org.apache.jena.atlas.data.AbstractDataBag<E>
-
- org.apache.jena.atlas.data.SortedDataBag<E>
-
- org.apache.jena.atlas.data.DistinctDataBag<E>
-
- All Implemented Interfaces:
java.lang.Iterable<E>,DataBag<E>,org.apache.jena.atlas.lib.Closeable,org.apache.jena.atlas.lib.Sink<E>
- Direct Known Subclasses:
DistinctDataNet
public class DistinctDataBag<E> extends SortedDataBag<E>
This data bag will gather distinct items in memory until a size threshold is passed, at which point it will write out all of the items to disk using the supplied serializer.
After adding is finished, call
iterator()to set up the data bag for reading back items and iterating over them. The iterator will retrieve only distinct items.IMPORTANT: You may not add any more items after this call. You may subsequently call
iterator()multiple times which will give you a new iterator for each invocation. If you do not consume the entire iterator, you should callIter.close(Iterator)to close any FileInputStreams associated with the iterator.Additionally, make sure to call
SortedDataBag.close()when you are finished to free any system resources (preferably in a finally block).Implementation Notes: Data is stored without duplicates as it comes in in a HashSet. When it is time to spill, that data is sorted and written to disk. An iterator that eliminates adjacent duplicates is used in conjunction with the SortedDataBag's iterator.
-
-
Constructor Summary
Constructors Constructor Description DistinctDataBag(ThresholdPolicy<E> policy, SerializationFactory<E> serializerFactory, java.util.Comparator<E> comparator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisDistinct()Find out if the bag is distinct.booleanisSorted()Find out if the bag is sorted.java.util.Iterator<E>iterator()Returns an iterator over a set of elements of type E.-
Methods inherited from class org.apache.jena.atlas.data.SortedDataBag
add, cancel, close, flush, isCancelled, isClosed
-
Methods inherited from class org.apache.jena.atlas.data.AbstractDataBag
isEmpty, send, size
-
-
-
-
Constructor Detail
-
DistinctDataBag
public DistinctDataBag(ThresholdPolicy<E> policy, SerializationFactory<E> serializerFactory, java.util.Comparator<E> comparator)
-
-
Method Detail
-
isSorted
public boolean isSorted()
Description copied from interface:DataBagFind out if the bag is sorted.
-
isDistinct
public boolean isDistinct()
Description copied from interface:DataBagFind out if the bag is distinct.- Specified by:
isDistinctin interfaceDataBag<E>- Overrides:
isDistinctin classSortedDataBag<E>- Returns:
- true if the bag is a distinct bag, false otherwise.
-
iterator
public java.util.Iterator<E> iterator()
Description copied from class:SortedDataBagReturns an iterator over a set of elements of type E. If you do not exhaust the iterator, you should callIter.close(Iterator)to be sure any open file handles are closed.- Specified by:
iteratorin interfacejava.lang.Iterable<E>- Overrides:
iteratorin classSortedDataBag<E>- Returns:
- an Iterator
-
-