|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xshare.base.collections.SortedCollection
Collection
implementation which sorts its
elements according to their natural order or according to the
order specified by a custom Comparator
.
In contrast to java.util.TreeSet
, this
collection can contain duplicates.
At first a example without a custom comparator:
... Collection c = new SortedCollection(); c.add("B"); c.add("C"); c.add("A"); c.add("A"); System.out.println(c.toString());
Executing this code will print to following to stdout
:
[A, A, B, C]
remove(Object)
and removeAll(Collection)
. remove(Object)
removes a single element from the collection and
removeAll(Collection)
removes all elements from the
collection which are equal to elements of the specified collection.
iterator()
returns the elements
according to their natural order (if they implement
java.lang.Comparable
) respectively
according to the specification of the custom comparator.
iterator()
supports the
Iterator.remove()
method.
Comparable
interface if the collection
was created without a custom comparator or must be compatible
to the custom comparator. If not, a ClassCastException
will be thrown.
Collections.synchronizedCollection(Collection)
.
iterator()
are fail-fast
and will throw an ConcurrentModificationException if the
collection changes will the iterator is still in use.
Constructor Summary | |
SortedCollection()
Constructs a new sorted collection of elements. |
|
SortedCollection(java.util.Collection pMaster)
|
|
SortedCollection(java.util.Collection pMaster,
java.util.Comparator pSorter)
Creates a new instance of this collection containing all the elements of another Collection sorted according
to a given Comparator . |
|
SortedCollection(java.util.Comparator pSorter)
Creates a new empty sorted collection. |
|
SortedCollection(java.util.Iterator pSource)
Constructs a new sorted collection containing the elements referenced by a given iterator. |
|
SortedCollection(java.util.Iterator pSource,
java.util.Comparator pSorter)
Creates a new sorted collection containing all the elements of a given iteration sorted according to the specification of a custom comparator. |
Method Summary | |
boolean |
add(java.lang.Object pNewObj)
|
boolean |
addAll(java.util.Collection c)
|
void |
clear()
Removes all references to the current referenced objects in this instance. |
java.lang.Object |
clone()
Creates a copy of this instance. |
boolean |
contains(java.lang.Object o)
Checks if a given Object is contained by this
SortedCollection . |
boolean |
containsAll(java.util.Collection c)
|
protected org.xshare.base.collections.LinkedNode |
findFirstGreater(java.lang.Object pCompareObj)
|
protected org.xshare.base.collections.LinkedNode |
internalContains(java.lang.Object pToLookUp)
|
boolean |
isEmpty()
Checks if this instance is empty or not. |
java.util.Iterator |
iterator()
Returns a Iterator over all elements in this
collection starting from the first element. |
boolean |
remove(java.lang.Object o)
Removes a single object instance from the collection. |
boolean |
removeAll(java.util.Collection c)
Removes all elements from the collection which are equal to the elements of a given collection. |
boolean |
retainAll(java.util.Collection c)
|
int |
size()
Returns the number of elements in this collection. |
java.lang.Object[] |
toArray()
Returns a array containing all objects of this collection. |
java.lang.Object[] |
toArray(java.lang.Object[] target)
This method fullfills the specification of Collection.toArray(Object[]) . |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
equals, hashCode |
Constructor Detail |
public SortedCollection()
Comparable
interface.
public SortedCollection(java.util.Iterator pSource, java.util.Comparator pSorter)
pSource
- a Iterator
object pointing to all
elements which should be contained by this sorted collection.pSorter
- a Comparator
object specifing
the order of the elements of this sorted collection.
java.lang.NullPointerException
- if one of both parameters is null
.public SortedCollection(java.util.Iterator pSource)
Comparable
interface.
pSource
- a Iterator
object pointing to all
elements which should be added to the collection.
java.lang.NullPointerException
- if the given Iterator
is null
.
java.lang.ClassCastException
- if the elements provided by the given
Iterator
don't implement Comparable
public SortedCollection(java.util.Comparator pSorter)
Comparator
passed to the constructor.
pSorter
- a Comparator
object responsible for
the sorting of the elements of this collection.
java.lang.NullPointerException
- if the given Comparator
is null
.public SortedCollection(java.util.Collection pMaster, java.util.Comparator pSorter)
Collection
sorted according
to a given Comparator
.
pMaster
- a Collection
object containing all the
elements which should be contained in this instance of the
SortedCollection
.pSorter
- a Comparator
object used for sorting
all the elements of this collection.
java.lang.NullPointerException
- if one of both parameters is null
.public SortedCollection(java.util.Collection pMaster)
java.lang.ClassCastException
- if the objects contained in the given
Collection
don't implement the Comparable
interface
java.lang.NullPointerException
- if the given Collection
is null
.Method Detail |
public void clear()
clear
in interface java.util.Collection
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection
boolean
value which is true
if the collection changed because of this method call.remove(Object)
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
java.lang.ClassCastException
- if one element of
the given collection
does't implement Comparable
and this collection doesn't have a custom
Comparator
.public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
contains(Object)
public boolean remove(java.lang.Object o)
A
and you call
instance.remove("A")
one instance of A
is removed and two are kept.
remove
in interface java.util.Collection
boolean
value which is true
if
the collection changed because of this method call.removeAll(Collection)
public boolean add(java.lang.Object pNewObj)
add
in interface java.util.Collection
java.lang.ClassCastException
- if the element
does't implement Comparable
and this collection doesn't have a custom
Comparator
.public java.lang.Object[] toArray(java.lang.Object[] target)
Collection.toArray(Object[])
.
toArray
in interface java.util.Collection
Object[]
containing all elements
of this collection in the same order as they are returned by the
iterator
of this collection.public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
Object[]
containing all elements
of this collection.public java.util.Iterator iterator()
Iterator
over all elements in this
collection starting from the first element. The returned
iterator works on the underlying collection directly.
iterator
in interface java.util.Collection
Iterator
over all elements in the
collection with support for Iterator.remove()
which is fail-fast.public boolean contains(java.lang.Object o)
Object
is contained by this
SortedCollection
.
contains
in interface java.util.Collection
boolean
value which is true
if
at least one Object
is containted by this list. This
is true is one object fills in the condition
ObjectFromList.equals(givenObject)
. Otherwise
this method returns false
.protected org.xshare.base.collections.LinkedNode internalContains(java.lang.Object pToLookUp)
protected org.xshare.base.collections.LinkedNode findFirstGreater(java.lang.Object pCompareObj)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection
boolean
value which is true
if the collections doesn't contain elements. Otherwise false
is the expected return value.public int size()
size
in interface java.util.Collection
int
value containing the current number of
stored elements.public java.lang.Object clone()
clone
in class java.lang.Object
Object
object, which is a instance
of SortedCollection
and constains the same elements as
this instance and uses the same comparator instance if a
custom comparator has been provided at creationtime.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |