E
- the type being partitionedpublic class Partition<E> extends Object
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)
Modifier and Type | Field and Description |
---|---|
Iterator<? extends E> |
blocks
An iterator supplying the partitioned addresses.
|
BigInteger |
count
The address or block count.
|
E |
original
The partitioned address.
|
E |
single
A field containing a partition into a single value.
|
Constructor and Description |
---|
Partition(E original) |
Partition(E original,
E single) |
Partition(E original,
Iterator<? extends E> blocks,
BigInteger count) |
Partition(E original,
Iterator<? extends E> blocks,
int count) |
Modifier and Type | Method and Description |
---|---|
<R> Map<E,R> |
applyForEach(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> |
checkBlockOrAddress(E addr)
If the given address is a single prefix block, it is returned.
|
void |
forEach(Consumer<? super E> action)
Supplies to the consumer each element of this partition.
|
static <E extends AddressSegmentSeries> |
partitionWithSingleBlockSize(E newAddr)
Partitions the address series into prefix blocks and single addresses.
|
static <E extends IPAddress> |
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 otherwise
|
boolean |
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
|
public final E original
public final E single
public final Iterator<? extends E> blocks
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
.
public final BigInteger count
public Partition(E original)
public Partition(E original, Iterator<? extends E> blocks, BigInteger count)
public <R> Map<E,R> applyForEach(Function<? super E,? extends R> func)
R
- func
- public void forEach(Consumer<? super E> action)
action
- public boolean predicateForEach(Predicate<? super E> predicate)
predicate
- public boolean predicateForEach(Predicate<? super E> predicate, boolean returnEarly)
predicate
- returnEarly
- returns as soon as one application of the predicate returns false (determining the overall result)public boolean predicateForAny(Predicate<? super E> predicate, boolean returnEarly)
predicate
- returnEarly
- returns as soon as one call to the predicate returns truepublic boolean predicateForAny(Predicate<? super E> predicate)
predicate
- public static <E extends IPAddress> Partition<E> partitionWithSpanningBlocks(E newAddr)
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.
newAddr
- public static <E extends AddressSegmentSeries> Partition<E> partitionWithSingleBlockSize(E newAddr)
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.
newAddr
- public static <E extends Address> E checkBlockOrAddress(E addr)
E
- addr
-