|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.geotools.util.FrequencySortedSet<E>
E
- The type of elements in the set.public class FrequencySortedSet<E>
A set with elements ordered by the amount of time they were added. Less frequently added elements are first, and most frequently added ones are last. If some elements were added the same amount of time, then the iterator will traverse them in their insertion order.
An optional boolean argument in the constructor allows the construction of set in reversed
order (most frequently added elements first, less frequently added last). This is similar
but not identical to creating a defaut FrequencySortedSet
and iterating through it
in reverse order. The difference is that elements added the same amount of time will still
be traversed in their insertion order.
This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.
Constructor Summary | |
---|---|
FrequencySortedSet()
Creates an initially empty set with less frequent elements first. |
|
FrequencySortedSet(boolean reversed)
Creates an initially empty set with the default initial capacity. |
|
FrequencySortedSet(int initialCapacity,
boolean reversed)
Creates an initially empty set with the specified initial capacity. |
Method Summary | ||
---|---|---|
boolean |
add(E element)
Adds the specified element to this set. |
|
boolean |
add(E element,
int occurence)
Adds the specified element to this set. |
|
void |
clear()
Removes all elements from this set. |
|
java.util.Comparator<E> |
comparator()
Returns the comparator used to order the elements in this set. |
|
int |
compare(E o1,
E o2)
Compares the specified elements for frequency. |
|
boolean |
contains(java.lang.Object element)
Returns true if this set contains the specified element. |
|
E |
first()
Returns the first element in this set. |
|
int[] |
frequencies()
Returns the frequency of each element in this set, in iteration order. |
|
int |
frequency(E element)
Returns the frequency of the specified element in this set. |
|
java.util.SortedSet<E> |
headSet(E toElement)
|
|
boolean |
isEmpty()
Returns true if this set is empty. |
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements in this set in frequency order. |
|
E |
last()
Returns the last element in this set. |
|
boolean |
remove(java.lang.Object element)
Removes the specified element from this set, no matter how many time it has been added. |
|
int |
size()
Returns the number of elements in this set. |
|
java.util.SortedSet<E> |
subSet(E fromElement,
E toElement)
|
|
java.util.SortedSet<E> |
tailSet(E fromElement)
|
|
java.lang.Object[] |
toArray()
Returns the content of this set as an array. |
|
|
toArray(T[] array)
Returns the content of this set as an array. |
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, retainAll, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, equals, hashCode, removeAll, retainAll |
Methods inherited from interface java.util.Comparator |
---|
equals |
Constructor Detail |
---|
public FrequencySortedSet()
public FrequencySortedSet(boolean reversed)
reversed
- true
if the elements should be sorted in reverse order
(most frequent element first, less frequent last).public FrequencySortedSet(int initialCapacity, boolean reversed)
initialCapacity
- The initial capacity.reversed
- true
if the elements should be sorted in reverse order
(most frequent element first, less frequent last).Method Detail |
---|
public int size()
size
in interface java.util.Collection<E>
size
in interface java.util.Set<E>
size
in class java.util.AbstractCollection<E>
public boolean isEmpty()
true
if this set is empty.
isEmpty
in interface java.util.Collection<E>
isEmpty
in interface java.util.Set<E>
isEmpty
in class java.util.AbstractCollection<E>
public boolean add(E element, int occurence) throws java.lang.IllegalArgumentException
true
if this set changed as a
result of this operation. Changes in element order are not notified by the returned
value.
element
- The element to add.occurence
- The number of time to add the given elements. The default value is 1.
true
if this set changed as a result of this operation.
java.lang.IllegalArgumentException
- If occurence
is negative.public boolean add(E element)
true
if this set changed as a
result of this operation. Changes in element order are not notified by the returned
value.
add
in interface java.util.Collection<E>
add
in interface java.util.Set<E>
add
in class java.util.AbstractCollection<E>
element
- The element to add.
true
if this set changed as a result of this operation.public boolean contains(java.lang.Object element)
true
if this set contains the specified element.
contains
in interface java.util.Collection<E>
contains
in interface java.util.Set<E>
contains
in class java.util.AbstractCollection<E>
element
- The element whose presence in this set is to be tested.
true
if this set contains the specified element.public boolean remove(java.lang.Object element)
true
if this set changed as a result of this operation.
remove
in interface java.util.Collection<E>
remove
in interface java.util.Set<E>
remove
in class java.util.AbstractCollection<E>
element
- The element to remove.
true
if this set changed as a result of this operation.public void clear()
clear
in interface java.util.Collection<E>
clear
in interface java.util.Set<E>
clear
in class java.util.AbstractCollection<E>
public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.Set<E>
iterator
in class java.util.AbstractCollection<E>
public java.util.SortedSet<E> headSet(E toElement)
headSet
in interface java.util.SortedSet<E>
public java.util.SortedSet<E> tailSet(E fromElement)
tailSet
in interface java.util.SortedSet<E>
public java.util.SortedSet<E> subSet(E fromElement, E toElement)
subSet
in interface java.util.SortedSet<E>
public E first() throws java.util.NoSuchElementException
first
in interface java.util.SortedSet<E>
java.util.NoSuchElementException
- if this set is empty.public E last() throws java.util.NoSuchElementException
last
in interface java.util.SortedSet<E>
java.util.NoSuchElementException
- if this set is empty.public final java.util.Comparator<E> comparator()
FrequencySortedSet
, the comparator is always this
.
This method is final because the FrequencySortedSet
implementation makes
assumptions on the comparator that would not hold if this method were overrided.
comparator
in interface java.util.SortedSet<E>
public final int compare(E o1, E o2)
FrequencySortedSet
with default ordering, this method returns a positive
number if o1
has been added more frequently to this set than o2
,
a negative number if o1
has been added less frequently than o2
,
and 0 otherwise. For FrequencySortedSet
with reverse ordering, this is the
converse.
This method is final because the FrequencySortedSet
implementation makes
assumptions on the comparator that would not hold if this method were overrided.
compare
in interface java.util.Comparator<E>
public int frequency(E element)
element
- The element whose frequency is to be obtained.
0
if it doesn't occur in this set.public int[] frequencies()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
toArray
in interface java.util.Set<E>
toArray
in class java.util.AbstractCollection<E>
public <T> T[] toArray(T[] array)
toArray
in interface java.util.Collection<E>
toArray
in interface java.util.Set<E>
toArray
in class java.util.AbstractCollection<E>
T
- The type of the array elements.array
- The array where to copy the elements.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |