Class LineRangeList
- All Implemented Interfaces:
Serializable,Iterable<LineRange>,Collection<LineRange>,List<LineRange>
List of LineRange that stores values more efficiently at runtime.
This class thinks of LineRange as two integers (start and end-start), hence a list of LineRange
becomes a list of integers. The class then stores those integers in byte[]. Each number is packed to UTF-8
like variable length format. To store a long value N, we first split into 7 bit chunk, and store each 7 bit chunk as
a byte, in the little endian order. The last byte gets its 8th bit set to indicate that that's the last byte. Thus in
this format, 0x0 gets stored as 0x80, 0x1234 gets stored as {0x34,0xA4(0x24|0x80)}.
This variable length mode stores data most efficiently, since most line numbers are small. Access characteristic gets
close to that of LinkedList, since we can only traverse this packed byte[] from the start or from the end.
- Author:
- Kohsuke Kawaguchi
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyLineRangeList.LineRangeList(int capacity) Creates an emptyLineRangeListwith the specified capacity.LineRangeList(LineRange... initialElements) Creates a newLineRangeListwith the specified elements.LineRangeList(Collection<LineRange> copy) Creates a newLineRangeListwith the specified elements. -
Method Summary
Modifier and TypeMethodDescriptionvoidfinal booleanfinal booleanAppends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).final booleanaddAll(Collection<? extends LineRange> c) voidclear()booleanget(int index) iterator()listIterator(int index) remove(int index) intsize()voidtrim()Minimizes the memory waste by throwing away excess capacity.Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, lastIndexOf, removeRange, subListMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Constructor Details
-
LineRangeList
public LineRangeList()Creates an emptyLineRangeList. It uses a capacity ofDEFAULT_CAPACITY. -
LineRangeList
public LineRangeList(int capacity) Creates an emptyLineRangeListwith the specified capacity.- Parameters:
capacity- the initial capacity of the list
-
LineRangeList
Creates a newLineRangeListwith the specified elements.- Parameters:
copy- the initial elements
-
LineRangeList
Creates a newLineRangeListwith the specified elements.- Parameters:
initialElements- the initial elements
-
-
Method Details
-
addAll
- Specified by:
addAllin interfaceCollection<LineRange>- Specified by:
addAllin interfaceList<LineRange>- Overrides:
addAllin classAbstractCollection<LineRange>
-
addAll
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (Note that this will occur if the specified collection is this list, and it's nonempty.)- Parameters:
ranges- collection containing elements to be added to this list- Returns:
trueif this list changed as a result of the call- Throws:
NullPointerException- if the specified collection contains one or more null elements and this list does not permit null elements, or if the specified collection is nullIllegalArgumentException- if some property of an element of the specified collection prevents it from being added to this list- See Also:
-
contains
- Specified by:
containsin interfaceCollection<LineRange>- Specified by:
containsin interfaceList<LineRange>- Overrides:
containsin classAbstractCollection<LineRange>
-
get
-
size
public int size()- Specified by:
sizein interfaceCollection<LineRange>- Specified by:
sizein interfaceList<LineRange>- Specified by:
sizein classAbstractCollection<LineRange>
-
set
-
add
-
add
- Specified by:
addin interfaceCollection<LineRange>- Specified by:
addin interfaceList<LineRange>- Overrides:
addin classAbstractList<LineRange>
-
remove
-
clear
public void clear()- Specified by:
clearin interfaceCollection<LineRange>- Specified by:
clearin interfaceList<LineRange>- Overrides:
clearin classAbstractList<LineRange>
-
iterator
-
listIterator
- Specified by:
listIteratorin interfaceList<LineRange>- Overrides:
listIteratorin classAbstractList<LineRange>
-
listIterator
- Specified by:
listIteratorin interfaceList<LineRange>- Overrides:
listIteratorin classAbstractList<LineRange>
-
trim
public void trim()Minimizes the memory waste by throwing away excess capacity.
-