T
- the type of reference being stored in the collection.public class RefList<T extends Ref> extends Object implements Iterable<Ref>
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 List
interface contract.
Modifier and Type | Class and Description |
---|---|
static class |
RefList.Builder<T extends Ref>
Builder to facilitate fast construction of an immutable RefList.
|
Modifier | Constructor and Description |
---|---|
protected |
RefList(RefList<T> src)
Initialize this list to use the same backing array as another list.
|
Modifier and Type | Method and Description |
---|---|
RefList<T> |
add(int idx,
T ref)
Add an item at a specific index.
|
List<Ref> |
asList() |
boolean |
contains(String name)
Determine if a reference is present.
|
RefList.Builder<T> |
copy(int n)
Obtain a builder initialized with the first
n elements. |
static <T extends Ref> |
emptyList() |
int |
find(String name)
Locate an entry by name.
|
T |
get(int idx)
Get the reference at a particular index.
|
T |
get(String name)
Get a reference object by name.
|
boolean |
isEmpty() |
Iterator<Ref> |
iterator() |
RefList<T> |
put(T ref)
Store a reference, adding or replacing as necessary.
|
RefList<T> |
remove(int idx)
Remove an item at a specific index.
|
RefList<T> |
set(int idx,
T ref)
Obtain a new copy of the list after changing one element.
|
int |
size() |
String |
toString() |
public static <T extends Ref> RefList<T> emptyList()
T
- the type of reference being stored in the collection.public final int size()
public final boolean isEmpty()
public final int find(String name)
name
- the name of the reference to find.-(index + 1)
.public final boolean contains(String name)
name
- name of the reference to find.public final T get(String name)
name
- the name of the reference.public final T get(int idx)
idx
- the index to obtain. Must be 0 <= idx < size()
.public final RefList.Builder<T> copy(int n)
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.
n
- the number of elements to copy.n
elements already added.public final RefList<T> set(int idx, T ref)
This list instance is not affected by the replacement. Because this method copies the entire list, it runs in O(N) time.
idx
- index of the element to change.ref
- the new value, must not be null.idx
with ref
.public final RefList<T> add(int idx, T ref)
This list instance is not affected by the addition. Because this method copies the entire list, it runs in O(N) time.
idx
- 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
- the new reference to insert.ref
.public final RefList<T> remove(int idx)
This list instance is not affected by the addition. Because this method copies the entire list, it runs in O(N) time.
idx
- position to remove the item from.idx
.public final RefList<T> put(T ref)
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.
ref
- the reference to store.Copyright © 2016 Eclipse JGit Project. All rights reserved.