|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection
java.util.AbstractSet
com.taco.data.ListSet
public class ListSet
A list of objects presented as a set. Unlike a set, its elements are
random-accessible.
Attempts to add a duplicate (according to the equals()
method
of the object to be added) of an object already in the list will have no
effect, except possibly to change the order in the list.
Null objects may NOT be added to this collection.
Field Summary | |
---|---|
protected java.util.LinkedList |
_list
The list that backs this collection. |
static ICollectionFactory |
LIST_SET_FACTORY
A factory that creates instances of ListSet . |
Constructor Summary | |
---|---|
ListSet()
Create an initially empty instance. |
|
ListSet(java.util.Collection collection)
Copy the elements of the argument collection into a new list that will back this instance. |
|
ListSet(java.util.LinkedList list)
Use the argument list to back this instance. |
Method Summary | |
---|---|
void |
add(int index,
java.lang.Object obj)
This implementation throws an UnsupportedOperationException
if an equivalent element already exists. |
boolean |
add(java.lang.Object obj)
Add obj to the end of the list. |
boolean |
add(java.lang.Object obj,
boolean replace)
Add obj to the end of the list. |
boolean |
addAll(java.util.Collection c)
Add all the elements to this list in the order returned by the iterator of the argument collection. |
boolean |
addAll(int index,
java.util.Collection c)
If any of the elements exist in the collection already, keep trying to elements before returning false . |
boolean |
addFirst(java.lang.Object obj)
Add obj to the front of the list. |
boolean |
addFirst(java.lang.Object obj,
boolean replace)
Add obj to the front of the list. |
boolean |
addLast(java.lang.Object obj)
Add obj to the end of the list. |
boolean |
addLast(java.lang.Object obj,
boolean replace)
Add obj to the end of the list. |
void |
clear()
Clear all elements from the list. |
java.lang.Object |
clone()
Clone this instance by cloning the list that backs this instance. |
static ListSet |
fromArray(java.lang.Object[] array)
Create a new instance with the elements in the argument array. |
java.lang.Object |
get(int i)
Return the ith object in the list. |
int |
indexOf(java.lang.Object obj)
|
java.util.Iterator |
iterator()
|
int |
lastIndexOf(java.lang.Object obj)
|
java.util.ListIterator |
listIterator()
|
java.util.ListIterator |
listIterator(int i)
|
java.lang.Object |
remove(int index)
|
boolean |
remove(java.lang.Object obj)
Remove obj from the list. |
boolean |
removeAll(java.util.Collection c)
Remove all elements in c . |
boolean |
retainAll(java.util.Collection c)
Remove all elements not in c . |
java.lang.Object |
set(int i,
java.lang.Object obj)
If the set does not contain an equivalent element, replace the i th element with obj and return
obj . |
java.lang.Object |
set(int i,
java.lang.Object obj,
boolean replace)
|
int |
size()
|
java.util.List |
subList(int start,
int end)
The returned value is not a ListSet nor does it implement
the Set interface! |
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode |
Methods inherited from class java.util.AbstractCollection |
---|
contains, containsAll, isEmpty, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
contains, containsAll, equals, hashCode, isEmpty, toArray, toArray |
Methods inherited from interface java.util.Set |
---|
contains, containsAll, isEmpty, toArray, toArray |
Field Detail |
---|
public static final ICollectionFactory LIST_SET_FACTORY
ListSet
.
protected java.util.LinkedList _list
Constructor Detail |
---|
public ListSet()
public ListSet(java.util.LinkedList list)
public ListSet(java.util.Collection collection)
Method Detail |
---|
public java.lang.Object clone()
clone
in class java.lang.Object
public int size()
size
in interface java.util.Collection
size
in interface java.util.List
size
in interface java.util.Set
size
in class java.util.AbstractCollection
public java.lang.Object get(int i)
get
in interface java.util.List
public java.lang.Object set(int i, java.lang.Object obj)
i
th element with obj
and return
obj
. If the i
th element is equivalent, return
the original element without modifying the list. Otherwise throw an
UnsupportedOperationException
.
set
in interface java.util.List
public java.lang.Object set(int i, java.lang.Object obj, boolean replace)
public int indexOf(java.lang.Object obj)
indexOf
in interface java.util.List
public int lastIndexOf(java.lang.Object obj)
lastIndexOf
in interface java.util.List
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in interface java.util.List
iterator
in interface java.util.Set
iterator
in class java.util.AbstractCollection
public java.util.ListIterator listIterator()
listIterator
in interface java.util.List
public java.util.ListIterator listIterator(int i)
listIterator
in interface java.util.List
public java.util.List subList(int start, int end)
ListSet
nor does it implement
the Set
interface!
subList
in interface java.util.List
public boolean addAll(java.util.Collection c)
false
. However, keep trying to add elements even on a
previous failure. If all the elements are added, return
true
.
addAll
in interface java.util.Collection
addAll
in interface java.util.List
addAll
in interface java.util.Set
addAll
in class java.util.AbstractCollection
public boolean addAll(int index, java.util.Collection c)
false
.
addAll
in interface java.util.List
public void add(int index, java.lang.Object obj)
UnsupportedOperationException
if an equivalent element already exists.
add
in interface java.util.List
public boolean addFirst(java.lang.Object obj)
obj
to the front of the list. Leave the list unchanged
if an equivalent object exists in the list.
Return true
if the list is changed (if a duplicate of
obj
is not already at the front of the list).
Note: null may not be added to this list!
This implementation is O(n).
public boolean addFirst(java.lang.Object obj, boolean replace)
obj
to the front of the list. If replace
is true and an
equivalent object exists in the list already, remove it first.
Otherwise, leave the list unchanged if an equivalent object exists
in the list.
Return true if the list is changed
(if a duplicate of obj is not already at the front of the list).
Note: null
may not be added to this list!
This implementation is O(n).
public boolean addLast(java.lang.Object obj)
obj
to the end of the list.
Leave the list unchanged if an equivalent object exists in the list.
Return true if the list is changed
(if a duplicate of obj is not already at the front of the list).
Note: null may not be added to this list!
This implementation is O(n).
public boolean addLast(java.lang.Object obj, boolean replace)
obj
to the end of the list. If replace
is true and an
equivalent object exists in the list already, remove it first.
Otherwise, leave the list unchanged if an equivalent object exists
in the list.
Return true if the list is changed
(if a duplicate of obj is not already at the front of the list).
Note: null may not be added to this list!
This implementation is O(n).
public boolean add(java.lang.Object obj)
obj
to the end of the list. If a duplicate of obj
already exists
in the set, don't add obj
. Return true if the set is changed (if
a duplicate of obj
is not already in the set).
Note: null
may not be added to this set!
This implementation is O(n).
add
in interface java.util.Collection
add
in interface java.util.List
add
in interface java.util.Set
add
in class java.util.AbstractCollection
public boolean add(java.lang.Object obj, boolean replace)
obj
to the end of the list. If replace
is true and an
equivalent object exists in the list already, remove it first.
Otherwise, if a duplicate of obj
already exists in the set,
don't add obj
. Return true if the set is changed (if a duplicate of
obj
is not already in the set).
Note: null
may not be added to this set!
This implementation is O(n).
public java.lang.Object remove(int index)
remove
in interface java.util.List
public boolean remove(java.lang.Object obj)
obj
from the list. Overridden for efficiency.
remove
in interface java.util.Collection
remove
in interface java.util.List
remove
in interface java.util.Set
remove
in class java.util.AbstractCollection
public boolean removeAll(java.util.Collection c)
c
. Overridden for efficiency.
removeAll
in interface java.util.Collection
removeAll
in interface java.util.List
removeAll
in interface java.util.Set
removeAll
in class java.util.AbstractSet
public boolean retainAll(java.util.Collection c)
c
. Overridden for efficiency.
retainAll
in interface java.util.Collection
retainAll
in interface java.util.List
retainAll
in interface java.util.Set
retainAll
in class java.util.AbstractCollection
public void clear()
clear
in interface java.util.Collection
clear
in interface java.util.List
clear
in interface java.util.Set
clear
in class java.util.AbstractCollection
public static ListSet fromArray(java.lang.Object[] array)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |