E
- The type of elements in the set.public class FrequencySortedSet<E> extends AbstractSet<E> implements SortedSet<E>, Comparator<E>, Serializable
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
<T> T[] |
toArray(T[] array)
Returns the content of this set as an array.
|
equals, hashCode, removeAll
addAll, containsAll, retainAll, toString
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
spliterator
parallelStream, removeIf, stream
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
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).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 occurence) 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.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.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 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()
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 overrided.
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 overrided.
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.Copyright © 1996–2019 Geotools. All rights reserved.