public abstract class IPAddressSection extends IPAddressSegmentGrouping
IPAddressSection objects are immutable. Some of the derived state is created upon demand and cached. This also makes them thread-safe. Almost all operations that can be performed on IPAddress objects can also be performed on IPAddressSection objects and vice-versa.
Modifier and Type | Class and Description |
---|---|
static class |
IPAddressSection.IPStringBuilderOptions
This user-facing class is designed to be a clear way to create a collection of strings.
|
static class |
IPAddressSection.StringOptions
Represents a clear way to create a specific type of string.
|
static class |
IPAddressSection.WildcardOptions |
IPAddressSegmentGrouping.Range, IPAddressSegmentGrouping.RangeList
Modifier and Type | Method and Description |
---|---|
static int |
bitsPerSegment(IPAddress.IPVersion version) |
static int |
bytesPerSegment(IPAddress.IPVersion version) |
boolean |
contains(IPAddressSection other) |
void |
copySegments(int start,
int end,
IPAddressSegment[] segs,
int index) |
int |
getBitCount() |
abstract int |
getBitsPerSegment() |
int |
getByteCount() |
abstract int |
getByteIndex(java.lang.Integer networkPrefixLength) |
byte[] |
getBytes() |
abstract int |
getBytesPerSegment() |
java.lang.Integer |
getEquivalentPrefix()
Returns a prefix length for which the range of this address section can be specified only using the section's lower value and the prefix length
If no such prefix exists, returns null
If this address section represents a single value, returns the bit length
|
java.lang.Integer |
getHostBits() |
abstract IPAddressSection |
getHostSection(int networkPrefixLength) |
abstract IPAddress.IPVersion |
getIPVersion() |
abstract IPAddressSection |
getLowerSection()
If this represents an address section with ranging values, returns an address section representing the lower values of the range
If this represents an address section with a single value in each segment, returns this.
|
abstract IPAddressSegment[] |
getLowerSegments()
If this represents an address section with ranging values, returns an array of address segments representing the lower values of the range
If this represents an address section with a single value in each segment, returns an array containing the segments for this section.
|
byte[] |
getLowestBytes()
Gets the bytes for the lowest address in the range represented by this address.
|
java.lang.Integer |
getMaskPrefixLength(boolean network)
If this address section is equivalent to the mask for a CIDR prefix, it returns that prefix length.
|
int |
getMinPrefix()
Returns the smallest CIDR prefix possible (largest network),
such that this address paired with that prefix represents the exact same range of addresses.
|
abstract IPAddressNetwork |
getNetwork() |
abstract IPAddressSection |
getNetworkSection(int networkPrefixLength) |
abstract IPAddressSection |
getNetworkSection(int networkPrefixLength,
boolean withPrefixLength) |
IPAddressPart[] |
getParts(IPAddressSection.IPStringBuilderOptions options)
Get all representations of this address including this IPAddressSection.
|
IPAddressSegment |
getSegment(int index) |
int |
getSegmentCount() |
abstract int |
getSegmentIndex(java.lang.Integer networkPrefixLength) |
static java.lang.Integer |
getSegmentPrefixLength(int bitsPerSegment,
int segmentBits)
Across the address prefixes are:
IPv6: (null):...:(null):(1 to 16):(0):...:(0)
or IPv4: ...(null).(1 to 8).(0)...
|
static java.lang.Integer |
getSegmentPrefixLength(int bitsPerSegment,
java.lang.Integer networkPrefixLength,
int segmentIndex)
Across the address prefixes are:
IPv6: (null):...:(null):(1 to 16):(0):...:(0)
or IPv4: ...(null).(1 to 8).(0)...
|
abstract IPAddressSegment[] |
getSegments() |
java.lang.String[] |
getSegmentStrings() |
void |
getStartsWithSQLClause(java.lang.StringBuilder builder,
java.lang.String expression)
This method gives you an SQL clause that allows you to search the database for the front part of an address or
addresses in a given network.
|
void |
getStartsWithSQLClause(java.lang.StringBuilder builder,
java.lang.String expression,
IPAddressSQLTranslator translator) |
abstract IPAddressSection |
getUpperSection()
If this represents an address section with ranging values, returns an address section representing the upper values of the range
If this represents an address section with a single value in each segment, returns this.
|
abstract IPAddressSegment[] |
getUpperSegments()
If this represents an address section with ranging values, returns an an array of address segments representing the upper values of the rang
If this represents an address section with a single value in each segment, returns an array containing the segments for this section.
|
boolean |
isContainedBy(IPAddressSection other) |
static boolean |
isDecimalSameAsOctal(boolean checkRange,
IPAddressPart part) |
boolean |
isEntireAddress() |
boolean |
isIPv4() |
boolean |
isIPv6() |
boolean |
isMaskCompatibleWithRange(IPAddressSection mask,
java.lang.Integer networkPrefixLength)
Returns whether the given mask and prefix combination can be used to generate a subnet.
|
abstract java.util.Iterator<? extends IPAddressSegment[]> |
iterator() |
abstract java.util.Iterator<? extends IPAddressSection> |
sectionIterator() |
abstract IPAddressSection[] |
subtract(IPAddressSection other)
Subtract the give subnet from this subnet, returning an array of sections for the result (the subnets will not be contiguous so an array is required).
|
IPAddressPartStringCollection |
toAllStringCollection()
Use this method with care...
|
abstract java.lang.String |
toCanonicalString()
This produces a canonical string.
|
abstract java.lang.String |
toCanonicalWildcardString()
This produces a string similar to the canonical string and avoids the CIDR prefix.
|
abstract java.lang.String |
toCompressedString()
This produces the shortest valid string.
|
abstract java.lang.String |
toCompressedWildcardString()
This is similar to toNormalizedWildcardString, avoiding the CIDR prefix, but with compression as well.
|
IPAddressPartStringCollection |
toDatabaseSearchStringCollection()
Returns a set of strings for search the standard string representations in a database
-compress the largest compressible segments or no compression (a:0:0:c:d:0:e:f or a::c:d:0:e:f)
-upper/lowercase is not considered because many databases are case-insensitive
|
abstract java.lang.String |
toFullString()
This produces a string with no compressed segments and all segments of full length,
which is 4 characters for IPv6 segments and 3 characters for IPv4 segments.
|
java.lang.String |
toHexString(boolean withPrefix)
Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.
|
IPAddressSection |
toMinimalPrefixed()
Constructs an equivalent address section with the smallest CIDR prefix length possible (largest network),
such that the address represents the exact same range of addresses.
|
abstract java.lang.String |
toNetworkPrefixLengthString()
Returns a string with a CIDR prefix length if this section has a network prefix length.
|
abstract java.lang.String |
toNormalizedString()
The normalized string returned by this method is consistent with java.net.Inet4Address and java.net.Inet6address.
|
java.lang.String |
toNormalizedString(IPAddressSection.StringOptions stringOptions) |
static java.lang.String |
toNormalizedString(IPAddressSection.StringOptions opts,
IPAddressPart section) |
abstract java.lang.String |
toNormalizedWildcardString()
This produces a string similar to the normalized string and avoids the CIDR prefix.
|
IPAddressSection |
toPrefixedEquivalent()
Returns the CIDR address section for which the range of addresses
in this section is specified using just a single value and a prefix length in the returned section.
|
abstract java.lang.String |
toSQLWildcardString()
This is the same as the string from toNormalizedWildcardString except that:
-it uses IPAddress.SEGMENT_SQL_WILDCARD instead of IPAddress.SEGMENT_WILDCARD
-it uses IPAddress.SEGMENT_SQL_SINGLE_WILDCARD
|
IPAddressPartStringCollection |
toStandardStringCollection()
Returns at most a couple dozen string representations:
-mixed (1:2:3:4:5:6:1.2.3.4)
-upper and lower case
-full compressions or no compression (a:0:0:c:d:0:e:f or a::c:d:0:e:f or a:0:b:c:d::e:f)
-full leading zeros (000a:0000:000b:000c:000d:0000:000e:000f)
-combinations thereof
|
java.lang.String |
toString() |
abstract IPAddressPartStringCollection |
toStringCollection(IPAddressSection.IPStringBuilderOptions options) |
abstract IPAddressSection |
toSubnet(int networkPrefixLength)
Creates a subnet address using the given CIDR prefix bits.
|
abstract IPAddressSection |
toSubnet(IPAddressSection mask)
Creates a subnet address using the given mask.
|
abstract IPAddressSection |
toSubnet(IPAddressSection mask,
java.lang.Integer networkPrefixLength)
Creates a subnet address using the given mask.
|
abstract java.lang.String |
toSubnetString()
Produces a consistent subnet string.
|
IPAddressSection |
toSupernet()
Return an address section for the network encompassing this address section,
with the network portion of the returned address extending to the furthest segment boundary
located entirely within but not matching the network portion of this address,
unless the network portion has no bits in which case the same address is returned.
|
IPAddressSection |
toSupernet(java.lang.Integer prefixLengthDecrement)
Return an address section for the network encompassing this address section.
|
compareTo, equals, getCount, getDivision, getDivisionCount, getNetworkPrefixLength, getZeroRangeSegments, getZeroSegments, hashCode, isMultiple, isMultipleByNetworkPrefix, isPrefixed, isRangeEquivalentToPrefix, isZero
getPrefixStringLength
public abstract int getBitsPerSegment()
public int getBitCount()
getBitCount
in class IPAddressSegmentGrouping
public int getByteCount()
getByteCount
in interface IPAddressPart
getByteCount
in class IPAddressSegmentGrouping
public static int bitsPerSegment(IPAddress.IPVersion version)
public abstract int getBytesPerSegment()
public static int bytesPerSegment(IPAddress.IPVersion version)
public boolean isIPv4()
public boolean isIPv6()
public abstract IPAddress.IPVersion getIPVersion()
public abstract int getByteIndex(java.lang.Integer networkPrefixLength)
public abstract int getSegmentIndex(java.lang.Integer networkPrefixLength)
public abstract IPAddressSection getNetworkSection(int networkPrefixLength, boolean withPrefixLength)
public abstract IPAddressSection getNetworkSection(int networkPrefixLength)
public abstract IPAddressSection getHostSection(int networkPrefixLength)
public java.lang.Integer getMaskPrefixLength(boolean network)
network
- whether to check for a network mask or a host maskpublic java.lang.Integer getHostBits()
public static java.lang.Integer getSegmentPrefixLength(int bitsPerSegment, java.lang.Integer networkPrefixLength, int segmentIndex)
public static java.lang.Integer getSegmentPrefixLength(int bitsPerSegment, int segmentBits)
public abstract IPAddressNetwork getNetwork()
public byte[] getBytes()
IPAddressTypeException
- if this address does not map to a single address.
If you want to get subnet bytes or mask bytes, call getLowestBytespublic byte[] getLowestBytes()
public int getSegmentCount()
public IPAddressSegment getSegment(int index)
public void copySegments(int start, int end, IPAddressSegment[] segs, int index)
public static boolean isDecimalSameAsOctal(boolean checkRange, IPAddressPart part)
public boolean isContainedBy(IPAddressSection other)
public boolean contains(IPAddressSection other)
other
- public abstract IPAddressSection[] subtract(IPAddressSection other)
other
- IPAddressTypeException
- if the two sections are not comparablepublic boolean isMaskCompatibleWithRange(IPAddressSection mask, java.lang.Integer networkPrefixLength)
IPAddress.isMaskCompatibleWithRange(IPAddress, Integer)
mask
- networkPrefixLength
- public abstract IPAddressSection toSubnet(IPAddressSection mask) throws IPAddressTypeException
IPAddressTypeException
public abstract IPAddressSection toSubnet(int networkPrefixLength) throws IPAddressTypeException
IPAddressTypeException
public abstract IPAddressSection toSubnet(IPAddressSection mask, java.lang.Integer networkPrefixLength) throws IPAddressTypeException
IPAddressTypeException
- if the mask is not compatible, see IPAddress.isMaskCompatibleWithRange(IPAddress, Integer)
public IPAddressSection toPrefixedEquivalent()
public IPAddressSection toMinimalPrefixed()
public IPAddressSection toSupernet(java.lang.Integer prefixLengthDecrement)
prefixLengthDecrement
- the number to reduce the network bits in order to create a larger network.
If null, then this method has the same behaviour as toSupernet()public IPAddressSection toSupernet()
public int getMinPrefix()
IPAddressDivision.getMaskPrefixLength(boolean)
public java.lang.Integer getEquivalentPrefix()
public abstract IPAddressSection getLowerSection()
public abstract IPAddressSection getUpperSection()
public abstract IPAddressSegment[] getLowerSegments()
public abstract IPAddressSegment[] getUpperSegments()
public abstract IPAddressSegment[] getSegments()
public abstract java.util.Iterator<? extends IPAddressSection> sectionIterator()
public abstract java.util.Iterator<? extends IPAddressSegment[]> iterator()
public boolean isEntireAddress()
public java.lang.String[] getSegmentStrings()
public java.lang.String toString()
toString
in class IPAddressSegmentGrouping
public abstract java.lang.String toCanonicalString()
public abstract java.lang.String toFullString()
public abstract java.lang.String toNormalizedString()
public abstract java.lang.String toCompressedString()
public abstract java.lang.String toNetworkPrefixLengthString()
public abstract java.lang.String toSubnetString()
public abstract java.lang.String toNormalizedWildcardString()
public abstract java.lang.String toCanonicalWildcardString()
public abstract java.lang.String toCompressedWildcardString()
public abstract java.lang.String toSQLWildcardString()
public java.lang.String toHexString(boolean withPrefix)
public java.lang.String toNormalizedString(IPAddressSection.StringOptions stringOptions)
public static java.lang.String toNormalizedString(IPAddressSection.StringOptions opts, IPAddressPart section)
public IPAddressPartStringCollection toStandardStringCollection()
public IPAddressPartStringCollection toAllStringCollection()
public IPAddressPartStringCollection toDatabaseSearchStringCollection()
public abstract IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions options)
public IPAddressPart[] getParts(IPAddressSection.IPStringBuilderOptions options)
options
- public void getStartsWithSQLClause(java.lang.StringBuilder builder, java.lang.String expression)
getStartsWithSQLClause(StringBuilder, String, IPAddressSQLTranslator)
builder
- expression
- the expression that must match the condition, whether a column name or otherpublic void getStartsWithSQLClause(java.lang.StringBuilder builder, java.lang.String expression, IPAddressSQLTranslator translator)