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) |
void |
clear() |
AddressTrieSet<E> |
clone()
Clones the set along with the backing trie.
|
Comparator<E> |
comparator() |
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) |
Iterator<E> |
descendingIterator() |
AddressTrieSet<E> |
descendingSet() |
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) |
E |
first() |
E |
floor(E e) |
AddressTrieSet.Range<E> |
getRange()
Returns the range if this set has a restricted range, see
hasRestrictedRange() . |
int |
hashCode() |
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) |
AddressTrieSet<E> |
headSet(E toElement,
boolean inclusive) |
E |
higher(E e) |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
E |
last() |
E |
longestPrefixMatch(E addr)
Returns the element with the longest prefix match with the given address.
|
E |
lower(E e) |
E |
pollFirst() |
E |
pollLast() |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> collection) |
int |
size()
Returns the number of elements in this set.
|
Spliterator<E> |
spliterator() |
AddressTrieSet<E> |
subSet(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive) |
AddressTrieSet<E> |
subSet(E fromElement,
E toElement) |
AddressTrieSet<E> |
tailSet(E fromElement) |
AddressTrieSet<E> |
tailSet(E fromElement,
boolean inclusive) |
String |
toTrieString() |
addAll, containsAll, retainAll, toArray, toArray, toString
parallelStream, removeIf, stream
public AddressTrieSet(AddressTrie<E> trie)
public AddressTrieSet(AddressTrie<E> trie, Collection<? extends E> collection)
public AddressTrieSet<E> descendingSet()
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()
public boolean contains(Object o)
public boolean add(E e)
If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
See AddressTrie
public boolean remove(Object o)
public void clear()
public int hashCode()
public boolean equals(Object o)
public AddressTrieSet<E> clone()
public boolean removeAll(Collection<?> collection)
public Iterator<E> iterator()
iterator
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()
descendingIterator
in interface NavigableSet<E extends Address>
public Iterator<E> containingFirstIterator()
public Iterator<E> containedFirstIterator()
public Spliterator<E> spliterator()
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>
public Comparator<E> comparator()
comparator
in interface SortedSet<E extends Address>
public Iterator<E> blockSizeIterator()
public AddressTrieSet<E> subSet(E fromElement, E toElement)
public AddressTrieSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
subSet
in interface NavigableSet<E extends Address>
public AddressTrieSet<E> headSet(E toElement)
public AddressTrieSet<E> headSet(E toElement, boolean inclusive)
headSet
in interface NavigableSet<E extends Address>
public AddressTrieSet<E> tailSet(E fromElement)
public AddressTrieSet<E> tailSet(E fromElement, boolean inclusive)
tailSet
in interface NavigableSet<E extends Address>
public E pollFirst()
pollFirst
in interface NavigableSet<E extends Address>
public E pollLast()
pollLast
in interface NavigableSet<E extends Address>
public 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
-