Package it.unimi.dsi.io
Class OfflineIterable<T,U extends T>
- java.lang.Object
-
- it.unimi.dsi.io.OfflineIterable<T,U>
-
- All Implemented Interfaces:
it.unimi.dsi.fastutil.Size64
,SafelyCloseable
,java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Iterable<U>
public class OfflineIterable<T,U extends T> extends java.lang.Object implements java.lang.Iterable<U>, SafelyCloseable, it.unimi.dsi.fastutil.Size64
An iterable that offers elements that were previously stored offline using specialized serialization methods. At construction, you provide a serializer that establishes how elements are written offline; after that, you can add elements one at a time or in a bulk way. At any moment, you can get anOfflineIterator
on this object that returns all the elements added so far. Note that the returned iterator caches the current number of elements, so each iterator will return just the elements added at the time of its creation.Warning: The store object provided at construction time is shared by all iterators.
Closing
Both
OfflineIterable
andOfflineIterator
areSafelyCloseable
(the latter will close its input stream whenhasNext()
returns false), but for better resource management you should close them after usage.- Since:
- 0.9.2
- Author:
- Sebastiano Vigna
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OfflineIterable.OfflineIterator<A,B extends A>
An iterator returned by anOfflineIterable
.static interface
OfflineIterable.Serializer<A,B extends A>
Determines a strategy to serialize and deserialize elements.
-
Field Summary
Fields Modifier and Type Field Description static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description OfflineIterable(OfflineIterable.Serializer<? super T,U> serializer, U store)
Creates an offline iterable with given serializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(T x)
Adds a new element at the end of this iterable.void
addAll(java.lang.Iterable<T> it)
Adds all the elements of the given iterable at the end of this iterable.void
clear()
void
close()
protected void
finalize()
OfflineIterable.OfflineIterator<T,U>
iterator()
int
size()
Deprecated.Usesize64()
instead.long
size64()
Returns the number of elements added so far.
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OfflineIterable
public OfflineIterable(OfflineIterable.Serializer<? super T,U> serializer, U store) throws java.io.IOException
Creates an offline iterable with given serializer.- Parameters:
serializer
- the serializer to be used.store
- an object that is (re)used by the iterator(s) iterating on this iterable.- Throws:
java.io.IOException
-
-
Method Detail
-
add
public void add(T x) throws java.io.IOException
Adds a new element at the end of this iterable.- Parameters:
x
- the element to be added.- Throws:
java.io.IOException
-
addAll
public void addAll(java.lang.Iterable<T> it) throws java.io.IOException
Adds all the elements of the given iterable at the end of this iterable.- Parameters:
it
- the iterable producing the elements to be added.- Throws:
java.io.IOException
-
iterator
public OfflineIterable.OfflineIterator<T,U> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
clear
public void clear() throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
size
@Deprecated public int size()
Deprecated.Usesize64()
instead.Returns the number of elements added so far, unless it is too big to fit in an integer (in which case this method will throw an exception).- Specified by:
size
in interfaceit.unimi.dsi.fastutil.Size64
- Returns:
- the number of elements added so far.
-
size64
public long size64()
Returns the number of elements added so far.- Specified by:
size64
in interfaceit.unimi.dsi.fastutil.Size64
- Returns:
- the number of elements added so far.
-
-