Class AddressTrieSet<E extends Address>
- 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 TypeMethodDescriptionbooleanAdds 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.voidclear()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.booleanbooleanelementContains(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.booleanfirst()getRange()Returns the range if this set has a restricted range, seehasRestrictedRange().inthashCode()booleanReturns 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.booleanisEmpty()iterator()last()longestPrefixMatch(E addr) Returns the element with the longest prefix match with the given address.pollLast()booleanbooleanremoveAll(Collection<?> collection) intsize()Returns the number of elements in this set.Methods inherited from class AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface NavigableSet
removeFirst, removeLast, reversed
-
Constructor Details
-
AddressTrieSet
-
AddressTrieSet
-
-
Method Details
-
descendingSet
- Specified by:
descendingSetin 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
-
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
-
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:
iteratorin interfaceCollection<E extends Address>- Specified by:
iteratorin interfaceIterable<E extends Address>- Specified by:
iteratorin interfaceNavigableSet<E extends Address>- Specified by:
iteratorin interfaceSet<E extends Address>- Specified by:
iteratorin classAbstractCollection<E extends Address>
-
descendingIterator
- Specified by:
descendingIteratorin interfaceNavigableSet<E extends Address>
-
containingFirstIterator
-
containedFirstIterator
-
spliterator
- Specified by:
spliteratorin interfaceCollection<E extends Address>- Specified by:
spliteratorin interfaceIterable<E extends Address>- Specified by:
spliteratorin interfaceSet<E extends Address>- Specified by:
spliteratorin interfaceSortedSet<E extends Address>
-
comparator
- Specified by:
comparatorin interfaceSortedSet<E extends Address>
-
blockSizeIterator
-
subSet
-
subSet
public AddressTrieSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) - Specified by:
subSetin interfaceNavigableSet<E extends Address>
-
headSet
-
headSet
- Specified by:
headSetin interfaceNavigableSet<E extends Address>
-
tailSet
-
tailSet
- Specified by:
tailSetin interfaceNavigableSet<E extends Address>
-
first
-
last
-
lower
-
floor
-
ceiling
-
higher
-
pollFirst
- Specified by:
pollFirstin interfaceNavigableSet<E extends Address>
-
pollLast
- Specified by:
pollLastin 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
-