- Type Parameters:
E
- the address type
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,NavigableSet<E>
,SequencedCollection<E>
,SequencedSet<E>
,Set<E>
,SortedSet<E>
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
.
- Author:
- scfoley
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionAddressTrieSet
(AddressTrie<E> trie) AddressTrieSet
(AddressTrie<E> trie, Collection<? extends E> collection) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the given single address or prefix block subnet to this set.asTrie()
Returns a trie representing this set.Iterates from largest prefix blocks to smallest to individual addresses.void
clear()
clone()
Clones the set along with the backing trie.Returns an iterator that visits contained addresses and subnet blocks before their containing subnet blocks.Returns an iterator that visits containing subnet blocks before their contained addresses and subnet blocks.boolean
boolean
elementContains
(E addr) Returns true if a subnet or address in the set contains the given subnet or address.elementsContainedBy
(E addr) Returns a subset consisting of those addresses in the set contained by the given address.elementsContaining
(E addr) Returns a subset consisting of those addresses in the set that contain the given address.boolean
first()
getRange()
Returns the range if this set has a restricted range, seehasRestrictedRange()
.int
hashCode()
boolean
Returns whether this set is the result of a call toheadSet(Address)
,tailSet(Address)
,subSet(Address, Address)
or any of the other six methods with the same names.boolean
isEmpty()
iterator()
last()
longestPrefixMatch
(E addr) Returns the element with the longest prefix match with the given address.pollLast()
boolean
boolean
removeAll
(Collection<?> collection) int
size()
Returns the number of elements in this set.Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.NavigableSet
removeFirst, removeLast, reversed
-
Constructor Details
-
AddressTrieSet
-
AddressTrieSet
-
-
Method Details
-
descendingSet
- Specified by:
descendingSet
in interfaceNavigableSet<E extends Address>
-
asTrie
Returns a trie representing this set.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.
-
hasRestrictedRange
public boolean hasRestrictedRange()Returns whether this set is the result of a call toheadSet(Address)
,tailSet(Address)
,subSet(Address, Address)
or any of the other six methods with the same names.- Returns:
-
getRange
Returns the range if this set has a restricted range, seehasRestrictedRange()
. Otherwise returns null.- Returns:
-
size
public int size()Returns the number of elements in this set. This is a constant time operation, unless the set has a restricted range, seehasRestrictedRange()
, in which case it is a linear time operation proportional to the number of elements. -
isEmpty
public boolean isEmpty() -
contains
-
add
Adds the given single address or prefix block subnet to this set.If the given address is not a single address nor prefix block, then this method throws IllegalArgumentException.
See
AddressTrie
-
remove
-
clear
public void clear() -
hashCode
public int hashCode() -
equals
-
clone
Clones the set along with the backing trie. If the set had a restricted range, the clone does not. -
removeAll
-
iterator
- Specified by:
iterator
in interfaceCollection<E extends Address>
- Specified by:
iterator
in interfaceIterable<E extends Address>
- Specified by:
iterator
in interfaceNavigableSet<E extends Address>
- Specified by:
iterator
in interfaceSet<E extends Address>
- Specified by:
iterator
in classAbstractCollection<E extends Address>
-
descendingIterator
- Specified by:
descendingIterator
in interfaceNavigableSet<E extends Address>
-
containingFirstIterator
Returns an iterator that visits containing subnet blocks before their contained addresses and subnet blocks. -
containedFirstIterator
Returns an iterator that visits contained addresses and subnet blocks before their containing subnet blocks. -
spliterator
- Specified by:
spliterator
in interfaceCollection<E extends Address>
- Specified by:
spliterator
in interfaceIterable<E extends Address>
- Specified by:
spliterator
in interfaceSet<E extends Address>
- Specified by:
spliterator
in interfaceSortedSet<E extends Address>
-
comparator
- Specified by:
comparator
in interfaceSortedSet<E extends Address>
-
blockSizeIterator
Iterates from largest prefix blocks to smallest to individual addresses. Blocks of equal size are iterated in set order.- Returns:
-
subSet
-
subSet
public AddressTrieSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) - Specified by:
subSet
in interfaceNavigableSet<E extends Address>
-
headSet
-
headSet
- Specified by:
headSet
in interfaceNavigableSet<E extends Address>
-
tailSet
-
tailSet
- Specified by:
tailSet
in interfaceNavigableSet<E extends Address>
-
first
-
last
-
lower
- Specified by:
lower
in interfaceNavigableSet<E extends Address>
-
floor
- Specified by:
floor
in interfaceNavigableSet<E extends Address>
-
ceiling
- Specified by:
ceiling
in interfaceNavigableSet<E extends Address>
-
higher
- Specified by:
higher
in interfaceNavigableSet<E extends Address>
-
pollFirst
- Specified by:
pollFirst
in interfaceNavigableSet<E extends Address>
-
pollLast
- Specified by:
pollLast
in interfaceNavigableSet<E extends Address>
-
toTrieString
-
elementsContainedBy
Returns a subset consisting of those addresses in the set contained by the given address. The subset will have a restricted range matching the range of the given subnet or address.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.
- Parameters:
addr
-- Returns:
-
elementsContaining
Returns a subset consisting of those addresses in the set that contain the given address. The subset will have the same restricted range (if any) as this set.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.
- Parameters:
addr
-- Returns:
-
elementContains
Returns true if a subnet or address in the set contains the given subnet or address.- Parameters:
addr
-- Returns:
-
longestPrefixMatch
Returns the element with the longest prefix match with the given address.- Parameters:
addr
-- Returns:
-