|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection<E> java.util.AbstractList<E> org.eclipse.emf.common.util.BasicEList<E>
public class BasicEList<E>
A highly extensible list implementation.
Nested Class Summary | |
---|---|
protected static class |
BasicEList.BasicIndexOutOfBoundsException
An IndexOutOfBoundsException that constructs a message from the argument data. |
protected class |
BasicEList.EIterator<E1>
An extensible iterator implementation. |
protected class |
BasicEList.EListIterator<E1>
An extensible list iterator implementation. |
static class |
BasicEList.FastCompare<E>
A BasicEList that uses == instead of equals to compare members. |
protected class |
BasicEList.NonResolvingEIterator<E1>
An extended read-only iterator that does not resolve objects. |
protected class |
BasicEList.NonResolvingEListIterator<E1>
An extended read-only list iterator that does not resolve objects. |
static class |
BasicEList.UnmodifiableEList<E>
An unmodifiable version of BasicEList . |
Field Summary | |
---|---|
protected java.lang.Object[] |
data
The underlying data storage of the list. |
protected int |
size
The size of the list. |
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
|
BasicEList()
Creates an empty instance with no initial capacity. |
|
BasicEList(java.util.Collection<? extends E> collection)
Creates an instance that is a copy of the collection. |
|
BasicEList(int initialCapacity)
Creates an empty instance with the given capacity. |
protected |
BasicEList(int size,
java.lang.Object[] data)
Creates an initialized instance that directly uses the given arguments. |
Method Summary | ||
---|---|---|
boolean |
add(E object)
Adds the object at the end of the list and returns whether the object was added; if uniqueness is required,
duplicates will be ignored and false will be returned. |
|
void |
add(int index,
E object)
Adds the object at the given index in the list. |
|
boolean |
addAll(java.util.Collection<? extends E> collection)
Adds each object of the collection to the end of the list. |
|
boolean |
addAll(int index,
java.util.Collection<? extends E> collection)
Adds each object of the collection at each successive index in the list and returns whether any objects were added. |
|
boolean |
addAllUnique(java.util.Collection<? extends E> collection)
Adds each object of the collection to the end of the list; it does no uniqueness checking. |
|
boolean |
addAllUnique(int index,
java.util.Collection<? extends E> collection)
Adds each object of the collection at each successive index in the list and returns whether any objects were added; it does no ranging checking or uniqueness checking. |
|
boolean |
addAllUnique(int index,
java.lang.Object[] objects,
int start,
int end)
Adds each object from start to end of the array at each successive index in the list and returns whether any objects were added; it does no ranging checking or uniqueness checking. |
|
boolean |
addAllUnique(java.lang.Object[] objects,
int start,
int end)
Adds each object from start to end of the array at the index of list and returns whether any objects were added; it does no ranging checking or uniqueness checking. |
|
void |
addUnique(E object)
Adds the object at the end of the list; it does no uniqueness checking. |
|
void |
addUnique(int index,
E object)
Adds the object at the given index in the list; it does no ranging checking or uniqueness checking. |
|
protected E |
assign(int index,
E object)
Assigns the object into the data storage at the given index and returns the object that's been stored. |
|
E |
basicGet(int index)
Returns the object at the index without resolving it. |
|
protected java.util.Iterator<E> |
basicIterator()
Returns a read-only iterator that does not resolve objects. |
|
protected java.util.List<E> |
basicList()
Returns an unsafe list that provides a non-resolving view of the underlying data storage. |
|
protected java.util.ListIterator<E> |
basicListIterator()
Returns a read-only list iterator that does not resolve objects. |
|
protected java.util.ListIterator<E> |
basicListIterator(int index)
Returns a read-only list iterator advanced to the given index that does not resolve objects. |
|
protected boolean |
canContainNull()
Returns whether null is a valid object for the list. |
|
void |
clear()
Clears the list of all objects. |
|
java.lang.Object |
clone()
Returns a shallow copy of this list. |
|
boolean |
contains(java.lang.Object object)
Returns whether the list contains the object. |
|
boolean |
containsAll(java.util.Collection<?> collection)
Returns whether the list contains each object in the collection. |
|
java.lang.Object[] |
data()
Returns direct unsafe access to the underlying data storage. |
|
protected void |
didAdd(int index,
E newObject)
Called to indicate that an object has been added to the data storage. |
|
protected void |
didChange()
Called to indicate that the data storage has been changed. |
|
protected void |
didClear(int size,
java.lang.Object[] oldObjects)
Called to indicate that the data storage has been cleared. |
|
protected void |
didMove(int index,
E movedObject,
int oldIndex)
Called to indicate that an object has been moved in the data storage. |
|
protected void |
didRemove(int index,
E oldObject)
Called to indicate that an object has been removed from the data storage. |
|
protected void |
didSet(int index,
E newObject,
E oldObject)
Called to indicate that the data storage has been set. |
|
protected boolean |
equalObjects(java.lang.Object firstObject,
java.lang.Object secondObject)
Returns whether two objects are equal using the appropriate comparison mechanism. |
|
boolean |
equals(java.lang.Object object)
Returns whether the object is a list with corresponding equal objects. |
|
E |
get(int index)
Returns the object at the index. |
|
protected java.util.Collection<E> |
getDuplicates(java.util.Collection<?> collection)
Returns the collection of objects in the given collection that are also contained by this list. |
|
protected java.util.Collection<E> |
getNonDuplicates(java.util.Collection<? extends E> collection)
Returns the collection of objects in the given collection that are not also contained by this list. |
|
void |
grow(int minimumCapacity)
Grows the capacity of the list to ensure that no additional growth is needed until the size exceeds the specified minimum capacity. |
|
int |
hashCode()
Returns a hash code computed from each object's hash code. |
|
int |
indexOf(java.lang.Object object)
Returns the position of the first occurrence of the object in the list. |
|
boolean |
isEmpty()
Returns whether the list has zero size. |
|
protected boolean |
isUnique()
Returns whether objects are constrained to appear at most once in the list. |
|
java.util.Iterator<E> |
iterator()
Returns an iterator. |
|
int |
lastIndexOf(java.lang.Object object)
Returns the position of the last occurrence of the object in the list. |
|
java.util.ListIterator<E> |
listIterator()
Returns a list iterator. |
|
java.util.ListIterator<E> |
listIterator(int index)
Returns a list iterator advanced to the given index. |
|
void |
move(int index,
E object)
Moves the object to the index of the list. |
|
E |
move(int targetIndex,
int sourceIndex)
Moves the object at the source index of the list to the target index of the list and returns the moved object. |
|
protected java.lang.Object[] |
newData(int capacity)
Returns new allocated data storage. |
|
E |
remove(int index)
Removes the object at the index from the list and returns it. |
|
boolean |
remove(java.lang.Object object)
Removes the object from the list and returns whether the object was actually contained by the list. |
|
boolean |
removeAll(java.util.Collection<?> collection)
Removes each object of the collection from the list and returns whether any object was actually contained by the list. |
|
protected E |
resolve(int index,
E object)
Resolves the object at the index and returns the result. |
|
boolean |
retainAll(java.util.Collection<?> collection)
Removes from the list each object not contained by the collection and returns whether any object was actually removed. |
|
E |
set(int index,
E object)
Sets the object at the index and returns the old object at the index. |
|
void |
setData(int size,
java.lang.Object[] data)
Updates directly and unsafely the underlying data storage. |
|
E |
setUnique(int index,
E object)
Sets the object at the index and returns the old object at the index; it does no ranging checking or uniqueness checking. |
|
void |
shrink()
Shrinks the capacity of the list to the minimal requirements. |
|
int |
size()
Returns the number of objects in the list. |
|
java.lang.Object[] |
toArray()
Returns an array containing all the objects in sequence. |
|
|
toArray(T[] array)
Returns an array containing all the objects in sequence. |
|
java.lang.String |
toString()
Returns a string of the form "[object1, object2]" . |
|
protected boolean |
useEquals()
Returns whether equals rather than == should be used to compare members. |
|
protected E |
validate(int index,
E object)
Validates a new content object and returns the validated object. |
Methods inherited from class java.util.AbstractList |
---|
removeRange, subList |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
subList |
Field Detail |
---|
protected int size
protected transient java.lang.Object[] data
Constructor Detail |
---|
public BasicEList()
public BasicEList(int initialCapacity)
initialCapacity
- the initial capacity of the list before it must grow.
java.lang.IllegalArgumentException
- if the initialCapacity
is negative.public BasicEList(java.util.Collection<? extends E> collection)
collection
- the initial contents of the list.protected BasicEList(int size, java.lang.Object[] data)
size
- the size of the list.data
- the underlying storage of the list.Method Detail |
---|
protected java.lang.Object[] newData(int capacity)
protected boolean useEquals()
equals
rather than ==
should be used to compare members.
The default is to return true
but clients can optimize performance by returning false
.
The performance difference is highly significant.
equals
rather than ==
should be used.protected boolean equalObjects(java.lang.Object firstObject, java.lang.Object secondObject)
appropriate
comparison mechanism.
protected boolean canContainNull()
null
is a valid object for the list.
The default is to return true
, but clients can override this to exclude null
.
null
is a valid object for the list.protected boolean isUnique()
false
, but clients can override this to ensure uniqueness of contents.
The performance impact is significant: operations such as add
are O(n) as a result requiring uniqueness.
protected E validate(int index, E object)
necessary
and returns the argument object.
Clients may throw additional types of runtime exceptions
in order to handle constraint violations.
index
- the position of the new content.object
- the new content.
java.lang.IllegalArgumentException
- if a constraint prevents the object from being added.protected E assign(int index, E object)
index
- the position of the new content.object
- the new content.
protected E resolve(int index, E object)
object
;
clients can use this to transform objects as they are fetched.
index
- the position of the content.object
- the content.
protected void didSet(int index, E newObject, E oldObject)
index
- the position that was set.newObject
- the new object at the position.oldObject
- the old object at the position.protected void didAdd(int index, E newObject)
index
- the position object the new object.newObject
- the new object at the position.protected void didRemove(int index, E oldObject)
index
- the position of the old object.oldObject
- the old object at the position.protected void didClear(int size, java.lang.Object[] oldObjects)
didRemove
for each object;
clients can use this to monitor clearing of the data storage.
size
- the original size of the list.oldObjects
- the old data storage being discarded.didRemove(int, E)
protected void didMove(int index, E movedObject, int oldIndex)
index
- the position of the moved object.movedObject
- the moved object at the position.oldIndex
- the position the object was at before the move.protected void didChange()
public int size()
size
in interface java.util.Collection<E>
size
in interface java.util.List<E>
size
in class java.util.AbstractCollection<E>
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E>
isEmpty
in interface java.util.List<E>
isEmpty
in class java.util.AbstractCollection<E>
public boolean contains(java.lang.Object object)
equals
or "=="
depending on useEquals
.
contains
in interface java.util.Collection<E>
contains
in interface java.util.List<E>
contains
in class java.util.AbstractCollection<E>
object
- the object in question.
useEquals()
public boolean containsAll(java.util.Collection<?> collection)
contains
,
which may use either equals
or "=="
depending on useEquals
.
containsAll
in interface java.util.Collection<E>
containsAll
in interface java.util.List<E>
containsAll
in class java.util.AbstractCollection<E>
collection
- the collection of objects in question.
contains(java.lang.Object)
,
useEquals()
public int indexOf(java.lang.Object object)
equals
or "=="
depending on useEquals
.
indexOf
in interface java.util.List<E>
indexOf
in class java.util.AbstractList<E>
object
- the object in question.
public int lastIndexOf(java.lang.Object object)
equals
or "=="
depending on useEquals
.
lastIndexOf
in interface java.util.List<E>
lastIndexOf
in class java.util.AbstractList<E>
object
- the object in question.
public java.lang.Object[] toArray()
newData
to create typed storage in this case.
toArray
in interface java.util.Collection<E>
toArray
in interface java.util.List<E>
toArray
in class java.util.AbstractCollection<E>
newData(int)
public <T> T[] toArray(T[] array)
toArray
in interface java.util.Collection<E>
toArray
in interface java.util.List<E>
toArray
in class java.util.AbstractCollection<E>
array
- the array that will be filled and returned, if it's big enough;
otherwise, a suitably large array of the same type will be allocated and used instead.
newData(int)
public java.lang.Object[] data()
public void setData(int size, java.lang.Object[] data)
public E get(int index)
resolve
so that clients may transform the fetched object.
get
in interface java.util.List<E>
get
in class java.util.AbstractList<E>
index
- the position in question.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range.resolve(int, E)
,
basicGet(int)
public E basicGet(int index)
resolving
it.
index
- the position in question.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range.resolve(int, E)
,
get(int)
public E set(int index, E object)
setUnique
after range checking and after uniqueness
checking.
set
in interface java.util.List<E>
set
in class java.util.AbstractList<E>
index
- the position in question.object
- the object to set.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range.
java.lang.IllegalArgumentException
- if there is a constraint violation, e.g., non-uniqueness.setUnique(int, E)
public E setUnique(int index, E object)
assign
, didSet
, and didChange
.
index
- the position in question.object
- the object to set.
set(int, E)
public boolean add(E object)
uniqueness
is required,
duplicates will be ignored and false
will be returned.
This implementation delegates to addUnique(E)
after uniqueness checking.
add
in interface java.util.Collection<E>
add
in interface java.util.List<E>
add
in class java.util.AbstractList<E>
object
- the object to be added.
addUnique(Object)
public void addUnique(E object)
assign
, didAdd
, and didChange
.
after uniqueness checking.
object
- the object to be added.add(Object)
public void add(int index, E object)
uniqueness
is required,
duplicates will be ignored.
This implementation delegates to addUnique(int, E)
after uniqueness checking.
add
in interface java.util.List<E>
add
in class java.util.AbstractList<E>
object
- the object to be added.
java.lang.IllegalArgumentException
- if uniqueness
is required,
and the object is a duplicate.addUnique(int, Object)
public void addUnique(int index, E object)
assign
, didAdd
, and didChange
.
object
- the object to be added.add(int, Object)
public boolean addAll(java.util.Collection<? extends E> collection)
uniqueness
is required,
duplicates will be removed
from the collection,
which could even result in an empty collection.
This implementation delegates to addAllUnique(Collection)
after uniqueness checking.
addAll
in interface java.util.Collection<E>
addAll
in interface java.util.List<E>
addAll
in class java.util.AbstractCollection<E>
collection
- the collection of objects to be added.addAllUnique(Collection)
public boolean addAllUnique(java.util.Collection<? extends E> collection)
assign
, didAdd
, and didChange
.
collection
- the collection of objects to be added.addAll(Collection)
public boolean addAll(int index, java.util.Collection<? extends E> collection)
uniqueness
is required,
duplicates will be removed
from the collection,
which could even result in an empty collection.
This implementation delegates to addAllUnique(int, Collection)
after uniqueness checking.
addAll
in interface java.util.List<E>
addAll
in class java.util.AbstractList<E>
index
- the index at which to add.collection
- the collection of objects to be added.
addAllUnique(int, Collection)
public boolean addAllUnique(int index, java.util.Collection<? extends E> collection)
assign
, didAdd
, and didChange
.
index
- the index at which to add.collection
- the collection of objects to be added.
addAll(int, Collection)
public boolean addAllUnique(java.lang.Object[] objects, int start, int end)
assign
, didAdd
, and didChange
.
objects
- the objects to be added.start
- the index of first object to be added.end
- the index past the last object to be added.
addAllUnique(Object[], int, int)
public boolean addAllUnique(int index, java.lang.Object[] objects, int start, int end)
assign
, didAdd
, and didChange
.
index
- the index at which to add.objects
- the objects to be added.start
- the index of first object to be added.end
- the index past the last object to be added.
addAllUnique(Object[], int, int)
public boolean remove(java.lang.Object object)
indexOf
to find the object
and delegates to remove(int)
in the case that it finds the object.
remove
in interface java.util.Collection<E>
remove
in interface java.util.List<E>
remove
in class java.util.AbstractCollection<E>
object
- the object to be removed.
public boolean removeAll(java.util.Collection<?> collection)
removeAll
in interface java.util.Collection<E>
removeAll
in interface java.util.List<E>
removeAll
in class java.util.AbstractCollection<E>
collection
- the collection of objects to be removed.
public E remove(int index)
didRemove
and didChange
.
remove
in interface java.util.List<E>
remove
in class java.util.AbstractList<E>
index
- the position of the object to remove.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range.public boolean retainAll(java.util.Collection<?> collection)
remove(int)
in the case that it finds an object that isn't retained.
retainAll
in interface java.util.Collection<E>
retainAll
in interface java.util.List<E>
retainAll
in class java.util.AbstractCollection<E>
collection
- the collection of objects to be retained.
public void clear()
didClear
and didChange
.
clear
in interface java.util.Collection<E>
clear
in interface java.util.List<E>
clear
in class java.util.AbstractList<E>
public void move(int index, E object)
indexOf(java.lang.Object)
of find the object
and delegates to move(int, int)
.
move
in interface EList<E>
index
- the new position for the object in the list.object
- the object to be moved.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range or the object isn't contained by the list.public E move(int targetIndex, int sourceIndex)
assign
, didMove
, and didChange
.
move
in interface EList<E>
targetIndex
- the new position for the object in the list.sourceIndex
- the old position of the object in the list.
BasicEList.BasicIndexOutOfBoundsException
- if either index isn't within the size range.public void shrink()
grow(int)
public void grow(int minimumCapacity)
shrink()
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object object)
equals
or "=="
depending on useEquals
.
equals
in interface java.util.Collection<E>
equals
in interface java.util.List<E>
equals
in class java.util.AbstractList<E>
useEquals()
public int hashCode()
hashCode
in interface java.util.Collection<E>
hashCode
in interface java.util.List<E>
hashCode
in class java.util.AbstractList<E>
public java.lang.String toString()
"[object1, object2]"
.
toString
in class java.util.AbstractCollection<E>
"[object1, object2]"
.public java.util.Iterator<E> iterator()
BasicEList.EIterator
.
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.List<E>
iterator
in class java.util.AbstractList<E>
BasicEList.EIterator
protected java.util.Iterator<E> basicIterator()
resolve
objects.
This implementation allocates a BasicEList.NonResolvingEIterator
.
public java.util.ListIterator<E> listIterator()
BasicEList.EListIterator
.
listIterator
in interface java.util.List<E>
listIterator
in class java.util.AbstractList<E>
BasicEList.EListIterator
public java.util.ListIterator<E> listIterator(int index)
BasicEList.EListIterator
.
listIterator
in interface java.util.List<E>
listIterator
in class java.util.AbstractList<E>
index
- the starting index.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range.BasicEList.EListIterator
protected java.util.ListIterator<E> basicListIterator()
resolve
objects.
This implementation allocates a BasicEList.NonResolvingEListIterator
.
protected java.util.ListIterator<E> basicListIterator(int index)
resolve
objects.
This implementation allocates a BasicEList.NonResolvingEListIterator
.
index
- the starting index.
BasicEList.BasicIndexOutOfBoundsException
- if the index isn't within the size range.protected java.util.List<E> basicList()
non-resolving
view of the underlying data storage.
protected java.util.Collection<E> getDuplicates(java.util.Collection<?> collection)
collection
- the other collection.
protected java.util.Collection<E> getNonDuplicates(java.util.Collection<? extends E> collection)
collection
- the other collection.
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |