Class LineRangeList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<LineRange>
-
- edu.hm.hafner.analysis.LineRangeList
-
- All Implemented Interfaces:
Serializable,Iterable<LineRange>,Collection<LineRange>,List<LineRange>
public class LineRangeList extends AbstractList<LineRange> implements Serializable
ListofLineRangethat stores values more efficiently at runtime.This class thinks of
LineRangeas two integers (start and end-start), hence a list ofLineRangebecomes a list of integers. The class then stores those integers inbyte[]. 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:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description LineRangeList()Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, LineRange element)booleanadd(LineRange lr)booleanaddAll(Iterable<? extends LineRange> ranges)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).booleanaddAll(Collection<? extends LineRange> c)voidclear()booleancontains(Object o)LineRangeget(int index)Iterator<LineRange>iterator()ListIterator<LineRange>listIterator()ListIterator<LineRange>listIterator(int index)LineRangeremove(int index)LineRangeset(int index, LineRange element)intsize()voidtrim()Minimizes the memory waste by throwing away excess capacity.-
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, lastIndexOf, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Constructor Detail
-
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
public LineRangeList(Collection<LineRange> copy)
Creates a newLineRangeListwith the specified elements.- Parameters:
copy- the initial elements
-
LineRangeList
public LineRangeList(LineRange... initialElements)
Creates a newLineRangeListwith the specified elements.- Parameters:
initialElements- the initial elements
-
-
Method Detail
-
addAll
public final boolean addAll(Collection<? extends LineRange> c)
- Specified by:
addAllin interfaceCollection<LineRange>- Specified by:
addAllin interfaceList<LineRange>- Overrides:
addAllin classAbstractCollection<LineRange>
-
addAll
public final boolean addAll(Iterable<? extends LineRange> ranges)
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:
AbstractList.add(Object)
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<LineRange>- Specified by:
containsin interfaceList<LineRange>- Overrides:
containsin classAbstractCollection<LineRange>
-
get
public LineRange get(int index)
-
size
public int size()
- Specified by:
sizein interfaceCollection<LineRange>- Specified by:
sizein interfaceList<LineRange>- Specified by:
sizein classAbstractCollection<LineRange>
-
add
public void add(int index, LineRange element)
-
add
public final boolean add(LineRange lr)
- Specified by:
addin interfaceCollection<LineRange>- Specified by:
addin interfaceList<LineRange>- Overrides:
addin classAbstractList<LineRange>
-
remove
public LineRange remove(int index)
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<LineRange>- Specified by:
clearin interfaceList<LineRange>- Overrides:
clearin classAbstractList<LineRange>
-
listIterator
public ListIterator<LineRange> listIterator()
- Specified by:
listIteratorin interfaceList<LineRange>- Overrides:
listIteratorin classAbstractList<LineRange>
-
listIterator
public ListIterator<LineRange> listIterator(int index)
- Specified by:
listIteratorin interfaceList<LineRange>- Overrides:
listIteratorin classAbstractList<LineRange>
-
trim
public void trim()
Minimizes the memory waste by throwing away excess capacity.
-
-