- Type Parameters:
E
- the type being partitioned
For instance, it can represent the partition of a subnet into prefix blocks, or a partition into individual addresses.
You can use the methods partitionWithSingleBlockSize(AddressSegmentSeries)
or partitionWithSpanningBlocks(IPAddress)
to create a partition, or you can create your own.
You can use this class with the trie classes to easily partition an address for applying an operation to the trie.
Given an address or subnet s, you can partition into addresses or blocks that can used with a trie class using
Partition.partitionWithSpanningBlocks(s)
or Partition.partitionWithSingleBlockSize(s)
.
Once you have your partition, you choose a method in the Partition class whose argument type matches the signature of the trie method you wish to use.
For instance, you can use methods like AddressTrieOps.contains(inet.ipaddr.Address)
or AddressTrieOps.remove(inet.ipaddr.Address)
with predicateForAny(Predicate)
or predicateForEach(Predicate)
since the contains or remove method matches the Predicate interface.
Methods that return non-boolean values would match the applyForEach(Function)
or forEach(Consumer)
methods, as in the following code example for a given subnet s of type E:
Map<E, TrieNode<E>> all = Partition.partitionWithSingleBlockSize(s).applyForEach(trie::getNode)
- Author:
- scfoley
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyForEach
(Function<? super E, ? extends R> func) Supplies to the given function each element of this partition, inserting non-null return values into the returned map.static <E extends Address>
EcheckBlockOrAddress
(E addr) If the given address is a single prefix block, it is returned.void
Supplies to the consumer each element of this partition.static <E extends AddressSegmentSeries>
Partition<E> partitionWithSingleBlockSize
(E newAddr) Partitions the address series into prefix blocks and single addresses.partitionWithSpanningBlocks
(E newAddr) Partitions the address series into prefix blocks and single addresses.boolean
predicateForAny
(Predicate<? super E> predicate) Applies the operation to each element of the partition, returning true if the given predicate returns true for any of the elements.boolean
predicateForAny
(Predicate<? super E> predicate, boolean returnEarly) Applies the operation to each element of the partition, returning true if the given predicate returns true for any of the elements.boolean
predicateForEach
(Predicate<? super E> predicate) Applies the operation to each element of the partition, returning true if they all return true, false otherwiseboolean
predicateForEach
(Predicate<? super E> predicate, boolean returnEarly) Applies the operation to each element of the partition, returning true if they all return true, false otherwise
-
Field Details
-
original
The partitioned address. -
single
-
blocks
An iterator supplying the partitioned addresses.When
single
is null, the partition result is stored in this field.If the partition result is multiple addresses or blocks, they are supplied by this iterator.
If the partition result is just a single address, the result may be supplied by this iterator, or optionally this iterator may be null, in which case the result is given by
single
. -
count
-
-
Constructor Details
-
Partition
-
Partition
-
Partition
-
Partition
-
-
Method Details
-
applyForEach
Supplies to the given function each element of this partition, inserting non-null return values into the returned map.- Type Parameters:
R
-- Parameters:
func
-- Returns:
-
forEach
Supplies to the consumer each element of this partition.- Parameters:
action
-
-
predicateForEach
Applies the operation to each element of the partition, returning true if they all return true, false otherwise- Parameters:
predicate
-- Returns:
-
predicateForEach
Applies the operation to each element of the partition, returning true if they all return true, false otherwise- Parameters:
predicate
-returnEarly
- returns as soon as one application of the predicate returns false (determining the overall result)- Returns:
-
predicateForAny
Applies the operation to each element of the partition, returning true if the given predicate returns true for any of the elements.- Parameters:
predicate
-returnEarly
- returns as soon as one call to the predicate returns true- Returns:
-
predicateForAny
Applies the operation to each element of the partition, returning true if the given predicate returns true for any of the elements.- Parameters:
predicate
-- Returns:
-
partitionWithSpanningBlocks
Partitions the address series into prefix blocks and single addresses.If null is returned, the argument is already an individual address or prefix block.
This method iterates through a list of prefix blocks of different sizes that span the entire subnet.
- Parameters:
newAddr
-- Returns:
-
partitionWithSingleBlockSize
Partitions the address series into prefix blocks and single addresses.If null is returned, the argument is already an individual address or prefix block.
This method chooses the maximum block size for a list of prefix blocks contained by the address or subnet, and then iterates to produce blocks of that size.
- Parameters:
newAddr
-- Returns:
-
checkBlockOrAddress
If the given address is a single prefix block, it is returned. If it can be converted to a single prefix block or address (by adjusting the prefix length), the converted block is returned. Otherwise, null is returned.- Type Parameters:
E
-- Parameters:
addr
-- Returns:
-