E - the address typepublic class AddressTrieSet<E extends Address> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, Serializable
AddressTrie to view it as a Java Collections Framework set,
implementing the Set, SortedSet and NavigableSet interfaces.
Like TreeSet, this set is backed by a binary tree and implements the same interfaces that TreeSet does.
But there are some significant differences between the two binary tree implementations.
See AddressTrieMap for a description of some of the differences.
TreeMap is backed by a TreeSet and
AddressTrieMap is backed by an AddressTrie just like AddressTrie,
so all of the same implementation comparisons apply equally between the map implementations and the set implementations.
With the trie set, only addresses that are either individual address or prefix block subnets of the same type and version can be added to the trie,
see AddressTrie.AddressComparator for a comparator for the ordering.
Should you wish to store, in a collection, address instances that are not individual address or prefix block subnets,
you can use TreeSet or any other Java collections framework set to store addresses of any type,
or addresses of different versions or types in the same set,
since all address items in this library are comparable with a natural ordering.
There are additional orderings provided by this library as well, see AddressComparator.
| Modifier and Type | Class and Description |
|---|---|
static class |
AddressTrieSet.Range<E extends Address> |
| Constructor and Description |
|---|
AddressTrieSet(AddressTrie<E> trie) |
AddressTrieSet(AddressTrie<E> trie,
Collection<? extends E> collection) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
Adds the given single address or prefix block subnet to this set.
|
AddressTrie<E> |
asTrie()
Returns a trie representing this set.
|
Iterator<E> |
blockSizeIterator()
Iterates from largest prefix blocks to smallest to individual addresses.
|
E |
ceiling(E e)
Returns the least element in this set greater than or equal to
the given element, or
null if there is no such element. |
void |
clear()
Removes all of the elements from this collection (optional operation).
|
AddressTrieSet<E> |
clone()
Clones the set along with the backing trie.
|
Comparator<E> |
comparator()
Returns the comparator used to order the elements in this set,
or null if this set uses the natural ordering of its elements.
|
Iterator<E> |
containedFirstIterator()
Returns an iterator that visits contained addresses and subnet blocks before their containing subnet blocks.
|
Iterator<E> |
containingFirstIterator()
Returns an iterator that visits containing subnet blocks before their contained addresses and subnet blocks.
|
boolean |
contains(Object o)
Returns true if this collection contains the specified element.
|
Iterator<E> |
descendingIterator()
Returns an iterator over the elements in this set, in descending order.
|
AddressTrieSet<E> |
descendingSet()
Returns a reverse order view of the elements contained in this set.
|
boolean |
elementContains(E addr)
Returns true if a subnet or address in the set contains the given subnet or address.
|
AddressTrieSet<E> |
elementsContainedBy(E addr)
Returns a subset consisting of those addresses in the set contained by the given address.
|
AddressTrieSet<E> |
elementsContaining(E addr)
Returns a subset consisting of those addresses in the set that contain the given address.
|
boolean |
equals(Object o)
Compares the specified object with this set for equality.
|
E |
first()
Returns the first (lowest) element currently in this set.
|
E |
floor(E e)
Returns the greatest element in this set less than or equal to
the given element, or
null if there is no such element. |
AddressTrieSet.Range<E> |
getRange()
Returns the range if this set has a restricted range, see
hasRestrictedRange(). |
int |
hashCode()
Returns the hash code value for this set.
|
boolean |
hasRestrictedRange()
Returns whether this set is the result of a call to
headSet(Address), tailSet(Address),
subSet(Address, Address) or any of the other six methods with the same names. |
AddressTrieSet<E> |
headSet(E toElement)
Returns a view of the portion of this set whose elements are
strictly less than toElement.
|
AddressTrieSet<E> |
headSet(E toElement,
boolean inclusive)
Returns a view of the portion of this set whose elements are less than
(or equal to, if
inclusive is true) toElement. |
E |
higher(E e)
Returns the least element in this set strictly greater than the
given element, or
null if there is no such element. |
boolean |
isEmpty()
Returns true if this collection contains no elements.
|
Iterator<E> |
iterator()
Returns an iterator over the elements contained in this collection.
|
E |
last()
Returns the last (highest) element currently in this set.
|
E |
longestPrefixMatch(E addr)
Returns the element with the longest prefix match with the given address.
|
E |
lower(E e)
Returns the greatest element in this set strictly less than the
given element, or
null if there is no such element. |
E |
pollFirst()
Retrieves and removes the first (lowest) element,
or returns
null if this set is empty. |
E |
pollLast()
Retrieves and removes the last (highest) element,
or returns
null if this set is empty. |
boolean |
remove(Object o)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
boolean |
removeAll(Collection<?> collection)
Removes from this set all of its elements that are contained in the
specified collection (optional operation).
|
int |
size()
Returns the number of elements in this set.
|
Spliterator<E> |
spliterator()
Creates a
Spliterator over the elements in this sorted set. |
AddressTrieSet<E> |
subSet(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive)
Returns a view of the portion of this set whose elements range from
fromElement to toElement. |
AddressTrieSet<E> |
subSet(E fromElement,
E toElement)
Returns a view of the portion of this set whose elements range
from fromElement, inclusive, to toElement,
exclusive.
|
AddressTrieSet<E> |
tailSet(E fromElement)
Returns a view of the portion of this set whose elements are
greater than or equal to fromElement.
|
AddressTrieSet<E> |
tailSet(E fromElement,
boolean inclusive)
Returns a view of the portion of this set whose elements are greater
than (or equal to, if
inclusive is true) fromElement. |
String |
toTrieString() |
addAll, containsAll, retainAll, toArray, toArray, toStringparallelStream, removeIf, streampublic AddressTrieSet(AddressTrie<E> trie)
public AddressTrieSet(AddressTrie<E> trie, Collection<? extends E> collection)
public AddressTrieSet<E> descendingSet()
java.util.NavigableSetremove operation), the results of
the iteration are undefined.
The returned set has an ordering equivalent to
Collections.reverseOrder(comparator()).
The expression s.descendingSet().descendingSet() returns a
view of s essentially equivalent to s.
descendingSet in interface NavigableSet<E extends Address>public AddressTrie<E> asTrie()
If this set has a restricted range, hasRestrictedRange(), this generates a new trie for the set with only the nodes pertaining to the subset.
Otherwise this returns the backing trie for this set.
When a new trie is generated, the original backing trie for this set remains the same, it is not changed to the new trie.
The returned trie will always have the same natural trie ordering, even if this set has the reverse ordering.
public boolean hasRestrictedRange()
headSet(Address), tailSet(Address),
subSet(Address, Address) or any of the other six methods with the same names.public AddressTrieSet.Range<E> getRange()
hasRestrictedRange(). Otherwise returns null.public int size()
hasRestrictedRange(),
in which case it is a linear time operation proportional to the number of elements.public boolean isEmpty()
java.util.AbstractCollectionThis implementation returns size() == 0.
public boolean contains(Object o)
java.util.AbstractCollectionThis implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
contains in interface Collection<E extends Address>contains in interface Set<E extends Address>contains in class AbstractCollection<E extends Address>o - element whose presence in this collection is to be testedpublic boolean add(E e)
If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
See AddressTrie
add in interface Collection<E extends Address>add in interface Set<E extends Address>add in class AbstractCollection<E extends Address>e - element whose presence in this collection is to be ensuredpublic boolean remove(Object o)
java.util.AbstractCollectionThis implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.
Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.
remove in interface Collection<E extends Address>remove in interface Set<E extends Address>remove in class AbstractCollection<E extends Address>o - element to be removed from this collection, if presentpublic void clear()
java.util.AbstractCollectionThis implementation iterates over this collection, removing each element using the Iterator.remove operation. Most implementations will probably choose to override this method for efficiency.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection is non-empty.
public int hashCode()
java.util.AbstractSetObject.hashCode().
This implementation iterates over the set, calling the hashCode method on each element in the set, and adding up the results.
hashCode in interface Collection<E extends Address>hashCode in interface Set<E extends Address>hashCode in class AbstractSet<E extends Address>Object.equals(Object),
Set.equals(Object)public boolean equals(Object o)
java.util.AbstractSetThis implementation first checks if the specified object is this set; if so it returns true. Then, it checks if the specified object is a set whose size is identical to the size of this set; if not, it returns false. If so, it returns containsAll((Collection) o).
equals in interface Collection<E extends Address>equals in interface Set<E extends Address>equals in class AbstractSet<E extends Address>o - object to be compared for equality with this setObject.hashCode(),
HashMappublic AddressTrieSet<E> clone()
public boolean removeAll(Collection<?> collection)
java.util.AbstractSetThis implementation determines which is the smaller of this set and the specified collection, by invoking the size method on each. If this set has fewer elements, then the implementation iterates over this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is so contained, it is removed from this set with the iterator's remove method. If the specified collection has fewer elements, then the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this set's remove method.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method.
removeAll in interface Collection<E extends Address>removeAll in interface Set<E extends Address>removeAll in class AbstractSet<E extends Address>collection - collection containing elements to be removed from this setAbstractCollection.remove(Object),
AbstractCollection.contains(Object)public Iterator<E> iterator()
java.util.AbstractCollectioniterator in interface Iterable<E extends Address>iterator in interface Collection<E extends Address>iterator in interface NavigableSet<E extends Address>iterator in interface Set<E extends Address>iterator in class AbstractCollection<E extends Address>public Iterator<E> descendingIterator()
java.util.NavigableSetdescendingSet().iterator().descendingIterator in interface NavigableSet<E extends Address>public Iterator<E> containingFirstIterator()
public Iterator<E> containedFirstIterator()
public Spliterator<E> spliterator()
java.util.SortedSetSpliterator over the elements in this sorted set.
The Spliterator reports Spliterator.DISTINCT,
Spliterator.SORTED and Spliterator.ORDERED.
Implementations should document the reporting of additional
characteristic values.
The spliterator's comparator (see
Spliterator.getComparator()) must be null if
the sorted set's comparator (see SortedSet.comparator()) is null.
Otherwise, the spliterator's comparator must be the same as or impose the
same total ordering as the sorted set's comparator.
spliterator in interface Iterable<E extends Address>spliterator in interface Collection<E extends Address>spliterator in interface Set<E extends Address>spliterator in interface SortedSet<E extends Address>Spliterator over the elements in this sorted setpublic Comparator<E> comparator()
java.util.SortedSetcomparator in interface SortedSet<E extends Address>public Iterator<E> blockSizeIterator()
public AddressTrieSet<E> subSet(E fromElement, E toElement)
java.util.NavigableSetThe returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.
Equivalent to subSet(fromElement, true, toElement, false).
subSet in interface NavigableSet<E extends Address>subSet in interface SortedSet<E extends Address>fromElement - low endpoint (inclusive) of the returned settoElement - high endpoint (exclusive) of the returned setpublic AddressTrieSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
java.util.NavigableSetfromElement to toElement. If fromElement and
toElement are equal, the returned set is empty unless fromInclusive and toInclusive are both true. The returned set
is backed by this set, so changes in the returned set are reflected in
this set, and vice-versa. The returned set supports all optional set
operations that this set supports.
The returned set will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
subSet in interface NavigableSet<E extends Address>fromElement - low endpoint of the returned setfromInclusive - true if the low endpoint
is to be included in the returned viewtoElement - high endpoint of the returned settoInclusive - true if the high endpoint
is to be included in the returned viewfromElement, inclusive, to toElement, exclusivepublic AddressTrieSet<E> headSet(E toElement)
java.util.NavigableSetThe returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.
Equivalent to headSet(toElement, false).
public AddressTrieSet<E> headSet(E toElement, boolean inclusive)
java.util.NavigableSetinclusive is true) toElement. The
returned set is backed by this set, so changes in the returned set are
reflected in this set, and vice-versa. The returned set supports all
optional set operations that this set supports.
The returned set will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
headSet in interface NavigableSet<E extends Address>toElement - high endpoint of the returned setinclusive - true if the high endpoint
is to be included in the returned viewinclusive is true) toElementpublic AddressTrieSet<E> tailSet(E fromElement)
java.util.NavigableSetThe returned set will throw an IllegalArgumentException on an attempt to insert an element outside its range.
Equivalent to tailSet(fromElement, true).
tailSet in interface NavigableSet<E extends Address>tailSet in interface SortedSet<E extends Address>fromElement - low endpoint (inclusive) of the returned setpublic AddressTrieSet<E> tailSet(E fromElement, boolean inclusive)
java.util.NavigableSetinclusive is true) fromElement.
The returned set is backed by this set, so changes in the returned set
are reflected in this set, and vice-versa. The returned set supports
all optional set operations that this set supports.
The returned set will throw an IllegalArgumentException
on an attempt to insert an element outside its range.
tailSet in interface NavigableSet<E extends Address>fromElement - low endpoint of the returned setinclusive - true if the low endpoint
is to be included in the returned viewfromElementpublic E first()
java.util.SortedSetpublic E last()
java.util.SortedSetpublic E lower(E e)
java.util.NavigableSetnull if there is no such element.lower in interface NavigableSet<E extends Address>e - the value to matche,
or null if there is no such elementpublic E floor(E e)
java.util.NavigableSetnull if there is no such element.floor in interface NavigableSet<E extends Address>e - the value to matche,
or null if there is no such elementpublic E ceiling(E e)
java.util.NavigableSetnull if there is no such element.ceiling in interface NavigableSet<E extends Address>e - the value to matche,
or null if there is no such elementpublic E higher(E e)
java.util.NavigableSetnull if there is no such element.higher in interface NavigableSet<E extends Address>e - the value to matche,
or null if there is no such elementpublic E pollFirst()
java.util.NavigableSetnull if this set is empty.pollFirst in interface NavigableSet<E extends Address>null if this set is emptypublic E pollLast()
java.util.NavigableSetnull if this set is empty.pollLast in interface NavigableSet<E extends Address>null if this set is emptypublic String toTrieString()
public AddressTrieSet<E> elementsContainedBy(E addr)
If the subset would be the same size as this set, then this set is returned. The subset will the same backing trie as this set.
addr - public AddressTrieSet<E> elementsContaining(E addr)
If the subset would be the same size as this set, then this set is returned. Otherwise, the subset is backed by a new trie.
addr - public boolean elementContains(E addr)
addr -