|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectAbstractCollection<E>
AbstractSet<E>
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 default 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 responsibility.
| utility/geotk-utility (download) | View source code for this class |
| 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 occurrence)
Adds the specified element to this set. |
|
void |
clear()
Removes all elements from this set. |
|
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(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. |
|
SortedSet<E> |
headSet(E toElement)
|
|
boolean |
isEmpty()
Returns true if this set is empty. |
|
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(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. |
|
SortedSet<E> |
subSet(E fromElement,
E toElement)
|
|
SortedSet<E> |
tailSet(E fromElement)
|
|
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 AbstractSet |
|---|
equals, hashCode, removeAll |
| Methods inherited from class AbstractCollection |
|---|
addAll, containsAll, retainAll, toString |
| Methods inherited from class Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface Set |
|---|
addAll, containsAll, equals, hashCode, removeAll, retainAll |
| Methods inherited from interface 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 Collection<E>size in interface Set<E>size in class AbstractCollection<E>public boolean isEmpty()
true if this set is empty.
isEmpty in interface Collection<E>isEmpty in interface Set<E>isEmpty in class AbstractCollection<E>
public boolean add(E element,
int occurrence)
throws 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.occurrence - 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.
IllegalArgumentException - If occurrence 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 Collection<E>add in interface Set<E>add in class AbstractCollection<E>element - The element to add.
true if this set changed as a result of this operation.public boolean contains(Object element)
true if this set contains the specified element.
contains in interface Collection<E>contains in interface Set<E>contains in class 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(Object element)
true if this set changed as a result of this operation.
remove in interface Collection<E>remove in interface Set<E>remove in class AbstractCollection<E>element - The element to remove.
true if this set changed as a result of this operation.public void clear()
clear in interface Collection<E>clear in interface Set<E>clear in class AbstractCollection<E>public Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface Collection<E>iterator in interface Set<E>iterator in class AbstractCollection<E>public SortedSet<E> headSet(E toElement)
headSet in interface SortedSet<E>public SortedSet<E> tailSet(E fromElement)
tailSet in interface SortedSet<E>
public SortedSet<E> subSet(E fromElement,
E toElement)
subSet in interface SortedSet<E>
public E first()
throws NoSuchElementException
first in interface SortedSet<E>NoSuchElementException - if this set is empty.
public E last()
throws NoSuchElementException
last in interface SortedSet<E>NoSuchElementException - if this set is empty.public final 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 overridden.
comparator in interface 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 overridden.
compare in interface 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 Object[] toArray()
toArray in interface Collection<E>toArray in interface Set<E>toArray in class AbstractCollection<E>public <T> T[] toArray(T[] array)
toArray in interface Collection<E>toArray in interface Set<E>toArray in class 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 | |||||||||