java.lang.Object
uk.ipfreely.sets.AddressSets
Static factory methods for creating AddressSets, Ranges and Blocks.
-
Method Summary
Modifier and TypeMethodDescriptionaddress(A address) Single address asBlock.block(A first, int maskSize) CreatesBlockfrom network address and mask size.block(A first, A last) Creates a block from the given addresses which MUST form a valid CIDR block.static <A extends Addr<A>>
Collector<AddressSet<A>, Collection<AddressSet<A>>, AddressSet<A>> static <A extends Addr<A>,S extends AddressSet<A>>
AddressSet<A> Version ofof(AddressSet[])intended for standard collections.static <A extends Addr<A>,S extends AddressSet<A>>
AddressSet<A> of(S... sets) Factory method forAddressSet.static Block<?> Parses a CIDR string form as defined by RFC4632.AsparseCidr(String)with version expectation.range(A first, A last) CreatesRangeinstance.
-
Method Details
-
of
Factory method for
AddressSet.If all members form a contiguous range, returns
Range. If all members form CIDR block, returnsBlock.// EXAMPLE Range<V4> classA = AddressSets.parseCidr(Family.v4(), "10.0.0.0/8"); Range<V4> classB = AddressSets.parseCidr(Family.v4(), "176.16.0.0/12"); Range<V4> classC = AddressSets.parseCidr(Family.v4(), "192.168.0.0/16"); // RFC-1918 Address Allocation for Private Internets AddressSet<V4> privateRanges = AddressSets.of(classA, classB, classC);- Type Parameters:
A- address typeS- range type- Parameters:
sets- source sets- Returns:
- union of given sets
-
from
Version of
of(AddressSet[])intended for standard collections.// EXAMPLE AddressSet<V4> empty = AddressSets.from(Set.of());// EXAMPLE // 4 entries: "192.168.0.1/32", "192.168.0.10/32", "192.168.0.11/32", "192.168.0.12/32" List<String> addresses = Arrays.asList("192.168.0.1", "192.168.0.10", "192.168.0.11", "192.168.0.12"); // 2 entries: "192.168.0.1/32", "192.168.0.10-192.168.0.12" AddressSet<V4> rationalized = addresses.stream() .map(Family.v4()::parse) .map(AddressSets::address) .collect(AddressSets.collector());- Type Parameters:
A- address typeS- set type- Parameters:
sets- source sets- Returns:
- union of given sets
-
address
Single address asBlock.- Type Parameters:
A- IP version- Parameters:
address- IP- Returns:
- immutable instance
-
block
Creates
Blockfrom network address and mask size. ThemaskSizemust be greater or equal to zero and less than or equal toFamily.width(). The mask must cover all the true bits of the address.- Type Parameters:
A- the Ip type- Parameters:
first- the first IP in the blockmaskSize- the number of mask bits- Returns:
- the block instance
-
block
Creates a block from the given addresses which MUST form a valid CIDR block.
Use
Subnets.maskBits(Addr, Addr)to test for valid blocks.- Type Parameters:
A- IP version- Parameters:
first- addresslast- address which must be greater or equal to the first address- Returns:
- block
-
range
- Type Parameters:
A- the IP type- Parameters:
first- first elementlast- last element which MUST be greater or equal to first- Returns:
- an immutable range of IP addresses
-
parseCidr
Parses a CIDR string form as defined by RFC4632. Example:"127.0.0.1/32".- Parameters:
cidrBlock- the CIDR notation string- Returns:
- the block instance
- Throws:
ParseException- on invalid expression
-
parseCidr
AsparseCidr(String)with version expectation.- Type Parameters:
A- the address type- Parameters:
family- the IP familycidrBlock- the CIDR notation string- Returns:
- block instance
- Throws:
ParseException- on invalid expression or wrong IP version
-
collector
public static <A extends Addr<A>> Collector<AddressSet<A>,Collection<AddressSet<A>>, collector()AddressSet<A>> Collectorfor creatingAddressSetfromStream. This collector reduces intermediate states when the number of sets reaches a threshold.- Type Parameters:
A- address family- Returns:
- collector
-