Class FileLinesList

All Implemented Interfaces:
ObjectCollection<MutableString>, ObjectIterable<MutableString>, ObjectList<MutableString>, Stack<MutableString>, Serializable, Comparable<List<? extends MutableString>>, Iterable<MutableString>, Collection<MutableString>, List<MutableString>, RandomAccess

public class FileLinesList extends AbstractObjectList<MutableString> implements RandomAccess, Serializable
A wrapper exhibiting the lines of a file as a list.

An instance of this class allows to access the lines of a file as a List. Contrarily to a FileLinesMutableStringIterable, direct access is possible and reasonably efficient, in particular when accessing nearby lines, and all returned mutable strings are separate, independent instances.

Similarly to FileLinesMutableStringIterable, instead, AbstractObjectList.iterator() can be called any number of times, as it opens an independent input stream at each call. For the same reason, the returned iterator type (FileLinesList.FileLinesIterator) is Closeable, and should be closed after usage.

Note that toString() will return a single string containing all file lines separated by the string associated to the system property line.separator.

Warning: this class is not synchronised. Separate iterators use separate input streams, and can be accessed concurrently, but all calls to get(int) refer to the same input stream.

Implementation details

Instances of this class perform a full scan of the specified file at construction time, representing the list of pointers to the start of each line using the Elias–Fano representation. The memory occupation per line is thus bounded by 2 + log ℓ bits, where ℓ is the average line length.

Since:
1.1
Author:
Sebastiano Vigna
See Also: