Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util

public Class RefList<T extends Ref>

extends Object
implements Iterable<Ref>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Known Direct Subclasses
org.eclipse.jgit.internal.storage.file.RefDirectory.PackedRefList
Type Parameters
<T>
the type of reference being stored in the collection.
Imports
java.util.Arrays, .Collections, .Iterator, .List, .NoSuchElementException, java.util.function.BinaryOperator, java.util.stream.Collector, org.eclipse.jgit.annotations.Nullable, org.eclipse.jgit.lib.Ref, .RefComparator

Specialized variant of an ArrayList to support a RefDatabase.

This list is a hybrid of a Map<String,Ref> and of a List<Ref>. It tracks reference instances by name by keeping them sorted and performing binary search to locate an entry. Lookup time is O(log N), but addition and removal is O(N + log N) due to the list expansion or contraction costs.

This list type is copy-on-write. Mutation methods return a new copy of the list, leaving this unmodified. As a result we cannot easily implement the java.util.List interface contract.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
RefList.Builder<
type of reference being stored.
T extends Ref
>

Builder to facilitate fast construction of an immutable RefList.

Field Summary

Modifier and TypeField and Description
pack-priv final int
private static final RefList<Ref>
pack-priv final Ref[]

Constructor Summary

AccessConstructor and Description
pack-priv
RefList(Ref[] list, int cnt)

protected
RefList(RefList<T>
the source list.
src
)

Initialize this list to use the same backing array as another list.

Method Summary

Modifier and TypeMethod and Description
public final RefList<T>

Returns:

copy of this list, after making space for and adding ref.
add
(int
position to add the item at. If negative the method assumes it was a direct return value from find(String) and will adjust it to the correct position.
idx
,
T
the new reference to insert.
ref
)

Add an item at a specific index.

public final List<Ref>

Returns:

this as an immutable, standard java.util.List.
asList
()

Cast this as an immutable, standard java.util.List.

public final boolean

Returns:

true if the reference is present; false if it is not.
contains
(String
name of the reference to find.
name
)

Determine if a reference is present.

public final RefList.Builder<T>

Returns:

a new builder with the first n elements already added.
copy
(int
the number of elements to copy.
n
)

Obtain a builder initialized with the first n elements.

public static <
type of reference being stored.
T extends Ref
>
RefList<T>

Returns:

an empty unmodifiable reference list.
emptyList
()

Create an empty unmodifiable reference list.

public final int

Returns:

the index the reference is at. If the entry is not present returns a negative value. The insertion position for the given name can be computed from -(index + 1).
find
(String
the name of the reference to find.
name
)

Locate an entry by name.

public final T

Returns:

the reference object; null if it does not exist in this list.
get
(String
the name of the reference.
name
)

Get a reference object by name.

public final T

Returns:

the reference value, never null.
get
(int
the index to obtain. Must be 0 <= idx < size().
idx
)

Get the reference at a particular index.

public final boolean

Returns:

true if the size of this list is 0.
isEmpty
()

Get if this list is empty.

public Iterator<Ref>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

public final RefList<T>

Returns:

copy of this list, after performing the addition or replacement.
put
(T
the reference to store.
ref
)

Store a reference, adding or replacing as necessary.

public final RefList<T>

Returns:

copy of this list, after making removing the item at idx.
remove
(int
position to remove the item from.
idx
)

Remove an item at a specific index.

public final RefList<T>

Returns:

copy of this list, after replacing idx with ref .
set
(int
index of the element to change.
idx
,
T
the new value, must not be null.
ref
)

Obtain a new copy of the list after changing one element.

public final int

Returns:

number of items in this list.
size
()

Get number of items in this list.

public static <
type of reference being stored.
T extends Ref
>
Collector<T, ?, RefList<T>>

Returns:

Collector for Ref
toRefList
(BinaryOperator<T>
if specified the result will be sorted and deduped.
mergeFunction
)

Create a Collector for Ref.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

cntback to summary
pack-priv final int cnt
EMPTYback to summary
private static final RefList<Ref> EMPTY
listback to summary
pack-priv final Ref[] list

Constructor Detail

RefListback to summary
pack-priv RefList(Ref[] list, int cnt)
RefListback to summary
protected RefList(RefList<T> src)

Initialize this list to use the same backing array as another list.

Parameters
src:RefList<T>

the source list.

Method Detail

addback to summary
public final RefList<T> add(int idx, T ref)

Add an item at a specific index.

This list instance is not affected by the addition. Because this method copies the entire list, it runs in O(N) time.

Parameters
idx:int

position to add the item at. If negative the method assumes it was a direct return value from find(String) and will adjust it to the correct position.

ref:T

the new reference to insert.

Returns:RefList<T>

copy of this list, after making space for and adding ref.

asListback to summary
public final List<Ref> asList()

Cast this as an immutable, standard java.util.List.

Returns:List<Ref>

this as an immutable, standard java.util.List.

containsback to summary
public final boolean contains(String name)

Determine if a reference is present.

Parameters
name:String

name of the reference to find.

Returns:boolean

true if the reference is present; false if it is not.

copyback to summary
public final RefList.Builder<T> copy(int n)

Obtain a builder initialized with the first n elements.

Copies the first n elements from this list into a new builder, which can be used by the caller to add additional elements.

Parameters
n:int

the number of elements to copy.

Returns:RefList.Builder<T>

a new builder with the first n elements already added.

emptyListback to summary
public static <T extends Ref> RefList<T> emptyList()

Create an empty unmodifiable reference list.

Parameters
<T>
type of reference being stored.
Returns:RefList<T>

an empty unmodifiable reference list.

Annotations
@SuppressWarnings:unchecked
findback to summary
public final int find(String name)

Locate an entry by name.

Parameters
name:String

the name of the reference to find.

Returns:int

the index the reference is at. If the entry is not present returns a negative value. The insertion position for the given name can be computed from -(index + 1).

getback to summary
public final T get(String name)

Get a reference object by name.

Parameters
name:String

the name of the reference.

Returns:T

the reference object; null if it does not exist in this list.

getback to summary
public final T get(int idx)

Get the reference at a particular index.

Parameters
idx:int

the index to obtain. Must be 0 <= idx < size().

Returns:T

the reference value, never null.

Annotations
@SuppressWarnings:unchecked
isEmptyback to summary
public final boolean isEmpty()

Get if this list is empty.

Returns:boolean

true if the size of this list is 0.

iteratorback to summary
public Iterator<Ref> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Ref>

an Iterator.

Annotations
@Override
putback to summary
public final RefList<T> put(T ref)

Store a reference, adding or replacing as necessary.

This list instance is not affected by the store. The correct position is determined, and the item is added if missing, or replaced if existing. Because this method copies the entire list, it runs in O(N + log N) time.

Parameters
ref:T

the reference to store.

Returns:RefList<T>

copy of this list, after performing the addition or replacement.

removeback to summary
public final RefList<T> remove(int idx)

Remove an item at a specific index.

This list instance is not affected by the addition. Because this method copies the entire list, it runs in O(N) time.

Parameters
idx:int

position to remove the item from.

Returns:RefList<T>

copy of this list, after making removing the item at idx.

setback to summary
public final RefList<T> set(int idx, T ref)

Obtain a new copy of the list after changing one element.

This list instance is not affected by the replacement. Because this method copies the entire list, it runs in O(N) time.

Parameters
idx:int

index of the element to change.

ref:T

the new value, must not be null.

Returns:RefList<T>

copy of this list, after replacing idx with ref .

sizeback to summary
public final int size()

Get number of items in this list.

Returns:int

number of items in this list.

toRefListback to summary
public static <T extends Ref> Collector<T, ?, RefList<T>> toRefList(BinaryOperator<T> mergeFunction)

Create a Collector for Ref.

Parameters
<T>
type of reference being stored.
mergeFunction:BinaryOperator<T>

if specified the result will be sorted and deduped.

Returns:Collector<T, ?, RefList<T>>

Collector for Ref

Since
5.4
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jgit.util back to summary

public Class RefList.Builder<T extends Ref>

extends Object
Class Inheritance
Type Parameters
<T>
type of reference being stored.

Builder to facilitate fast construction of an immutable RefList.

Field Summary

Modifier and TypeField and Description
private Ref[]
private int

Constructor Summary

AccessConstructor and Description
public
Builder()

Create an empty list ready for items to be added.

public
Builder(int
the new capacity; if zero or negative, behavior is the same as Builder().
capacity
)

Create an empty list with at least the specified capacity.

Method Summary

Modifier and TypeMethod and Description
public void
add(T
reference to add
ref
)

Add the reference to the end of the array.

public void
addAll(RefList.Builder<T extends Ref>
another builder
other
)

Add all items from another builder.

public void
addAll(Ref[]
the source array.
src
,
int
position within src to start copying from.
off
,
int
number of items to copy from src.
cnt
)

Add all items from a source array.

pack-priv void
dedupe(BinaryOperator<T>
function used for de-duplication
mergeFunction
)

Dedupe the refs in place.

public T

Returns:

the reference value, never null.
get
(int
the index to obtain. Must be 0 <= idx < size().
idx
)

Get the reference at a particular index.

public void
remove(int
position to remove the item from.
idx
)

Remove an item at a specific index.

public void
set(int
index, must have already been added previously.
idx
,
T
the new reference.
ref
)

Replace a single existing element.

public int

Returns:

number of items in this builder's internal collection.
size
()

Get size

public void
sort()

Sort the list's backing array in-place.

public RefList<T>

Returns:

an unmodifiable list using this collection's backing array.
toRefList
()

Get unmodifiable list based on this list

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

listback to summary
private Ref[] list
sizeback to summary
private int size

Constructor Detail

Builderback to summary
public Builder()

Create an empty list ready for items to be added.

Builderback to summary
public Builder(int capacity)

Create an empty list with at least the specified capacity.

Parameters
capacity:int

the new capacity; if zero or negative, behavior is the same as Builder().

Method Detail

addback to summary
public void add(T ref)

Add the reference to the end of the array.

References must be added in sort order, or the array must be sorted after additions are complete using sort().

Parameters
ref:T

reference to add

addAllback to summary
public void addAll(RefList.Builder<T extends Ref> other)

Add all items from another builder.

Parameters
other:RefList.Builder<T extends Ref>

another builder

Since
5.4
addAllback to summary
public void addAll(Ref[] src, int off, int cnt)

Add all items from a source array.

References must be added in sort order, or the array must be sorted after additions are complete using sort().

Parameters
src:Ref[]

the source array.

off:int

position within src to start copying from.

cnt:int

number of items to copy from src.

dedupeback to summary
pack-priv void dedupe(BinaryOperator<T> mergeFunction)

Dedupe the refs in place. Must be called after sort.

Parameters
mergeFunction:BinaryOperator<T>

function used for de-duplication

Annotations
@SuppressWarnings:unchecked
getback to summary
public T get(int idx)

Get the reference at a particular index.

Parameters
idx:int

the index to obtain. Must be 0 <= idx < size().

Returns:T

the reference value, never null.

Annotations
@SuppressWarnings:unchecked
removeback to summary
public void remove(int idx)

Remove an item at a specific index.

Parameters
idx:int

position to remove the item from.

setback to summary
public void set(int idx, T ref)

Replace a single existing element.

Parameters
idx:int

index, must have already been added previously.

ref:T

the new reference.

sizeback to summary
public int size()

Get size

Returns:int

number of items in this builder's internal collection.

sortback to summary
public void sort()

Sort the list's backing array in-place.

toRefListback to summary
public RefList<T> toRefList()

Get unmodifiable list based on this list

Returns:RefList<T>

an unmodifiable list using this collection's backing array.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override