public abstract class IPAddressSection extends IPAddressDivisionGrouping implements AddressSection
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.IPStringOptions
Represents a clear way to create a specific type of string.
|
static interface |
IPAddressSection.SegFunction<R,S> |
static class |
IPAddressSection.WildcardOptions |
IPAddressDivisionGrouping.Range, IPAddressDivisionGrouping.RangeList
AddressDivisionGrouping.StringOptions
Modifier and Type | Method and Description |
---|---|
IPAddressSection |
adjustPrefixBySegment(boolean nextSegment)
Increases or decreases prefix length to the next segment boundary.
|
abstract IPAddressSection |
adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.
|
abstract IPAddressSection |
applyPrefixLength(int networkPrefixLength)
Applies the given network prefix bit length.
|
static int |
bitsPerSegment(IPAddress.IPVersion version) |
static int |
bytesPerSegment(IPAddress.IPVersion version) |
boolean |
contains(IPAddressSection other) |
int |
getBitCount() |
int |
getByteCount()
returns the number of bytes in each of the address components represented by this instance
|
abstract int |
getByteIndex(int networkPrefixLength) |
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 java.lang.Iterable<? extends IPAddressSection> |
getIterable()
Useful for using an instance in a "for-each loop".
|
abstract IPAddressSection |
getLower()
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.
|
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) |
IPAddressStringDivisionSeries[] |
getParts(IPAddressSection.IPStringBuilderOptions options)
Get all representations of this address including this IPAddressSection.
|
abstract IPAddressSection |
getSection(int index)
Gets the subsection from the series starting from the given index
|
abstract IPAddressSection |
getSection(int index,
int endIndex)
Gets the subsection from the series starting from the given index and ending just before the give endIndex
|
IPAddressSegment |
getSegment(int index) |
int |
getSegmentCount() |
abstract int |
getSegmentIndex(int networkPrefixLength) |
static java.lang.Integer |
getSegmentPrefixLength(int bitsPerSegment,
int segmentPrefixedBits)
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 prefixLength,
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() |
void |
getSegments(AddressSegment[] segs) |
void |
getSegments(int start,
int end,
AddressSegment[] segs,
int destIndex)
get the segments from start to end and insert into the segs array at the the given index
|
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 |
getUpper()
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.
|
boolean |
isEntireAddress() |
boolean |
isFullRange() |
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 IPAddressSection> |
iterator()
An address component can represent a single segment, address, or section, or it can represent multiple,
typically a subnet or range of segment, address, or section values.
|
abstract IPAddressSection |
removePrefixLength()
Removes the prefix.
|
abstract IPAddressSection |
removePrefixLength(boolean zeroed) |
abstract IPAddressSection |
reverseBits(boolean perByte)
Returns a new segment series with the bits reversed.
|
abstract IPAddressSection |
reverseBytes()
Returns a new segment series with the bytes reversed.
|
abstract IPAddressSection |
reverseBytesPerSegment()
Returns a new segment series with the bytes reversed within each segment.
|
abstract IPAddressSection |
reverseSegments()
Returns a new segment series with the segments reversed.
|
abstract java.util.Iterator<? extends IPAddressSegment[]> |
segmentsIterator() |
abstract IPAddressSection |
setPrefixLength(int prefixLength)
Sets the prefix length.
|
abstract IPAddressSection |
setPrefixLength(int prefixLength,
boolean zeroed) |
IPAddressPartStringCollection |
toAllStringCollection()
Use this method with care...
|
java.lang.String |
toBinaryString()
Writes this address section as a single binary value with always the exact same number of characters
If this section represents a range of values outside of the network prefix length, then this is printed as a range of two hex values.
|
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 with0xPrefix)
Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x prefix.
|
IPAddressSection |
toMinPrefixedEquivalent()
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.
|
java.lang.String |
toNormalizedString(IPAddressSection.IPStringOptions stringOptions) |
static java.lang.String |
toNormalizedString(IPAddressSection.IPStringOptions opts,
IPAddressStringDivisionSeries section) |
abstract java.lang.String |
toNormalizedWildcardString()
This produces a string similar to the normalized string and avoids the CIDR prefix.
|
java.lang.String |
toOctalString(boolean with0Prefix)
Writes this address as a single hexadecimal value with always the exact same number of characters, with or without a preceding 0x 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 |
toPrefixLengthString()
Returns a string with a CIDR prefix length if this section has a network prefix length.
|
abstract java.lang.String |
toReverseDNSLookupString()
Generates the reverse DNS lookup string
For 8.255.4.4 it is 4.4.255.8.in-addr.arpa
For 2001:db8::567:89ab it is b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa
|
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 java.lang.String |
toSubnetString()
Produces a consistent subnet string.
|
equals, getDivision, getNetworkPrefixLength, getPrefixLength, getZeroRangeSegments, getZeroSegments, isMore, isMultipleByNetworkPrefix, isMultipleByPrefix, isPrefixed, isRangeEquivalentToPrefix
compareTo, getBytes, getBytes, getCount, getDivisionCount, getUpperBytes, getUpperBytes, hashCode, isMultiple, isRangeEquivalent, isZero
contains
getBitsPerSegment, getBytesPerSegment, toCanonicalString
getDivision, getPrefixLength, isMore, isMultipleByPrefix, isPrefixed, isRangeEquivalentToPrefix
getDivisionCount
toNormalizedString
getBytes, getBytes, getCount, getUpperBytes, getUpperBytes, isMultiple, isZero
public int getBitCount()
getBitCount
in interface AddressItem
getBitCount
in class AddressDivisionGrouping
public int getByteCount()
AddressComponent
getByteCount
in interface AddressComponent
public static int bitsPerSegment(IPAddress.IPVersion version)
public static int bytesPerSegment(IPAddress.IPVersion version)
public boolean isIPv4()
public boolean isIPv6()
public abstract IPAddress.IPVersion getIPVersion()
public abstract int getByteIndex(int networkPrefixLength)
public abstract int getSegmentIndex(int 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 prefixLength, int segmentIndex)
public static java.lang.Integer getSegmentPrefixLength(int bitsPerSegment, int segmentPrefixedBits)
public abstract IPAddressNetwork getNetwork()
public int getSegmentCount()
getSegmentCount
in interface AddressSegmentSeries
public IPAddressSegment getSegment(int index)
getSegment
in interface AddressSegmentSeries
public boolean contains(IPAddressSection other)
other
- public boolean isFullRange()
isFullRange
in interface AddressItem
isFullRange
in class AddressDivisionGrouping
public boolean isMaskCompatibleWithRange(IPAddressSection mask, java.lang.Integer networkPrefixLength)
IPAddress#isMaskCompatibleWithRange(IPAddress, Integer)
mask
- networkPrefixLength
- public abstract IPAddressSection applyPrefixLength(int networkPrefixLength) throws AddressTypeException
applyPrefixLength
in interface AddressSection
applyPrefixLength
in interface AddressSegmentSeries
AddressTypeException
public IPAddressSection toPrefixedEquivalent()
public IPAddressSection toMinPrefixedEquivalent()
public abstract IPAddressSection removePrefixLength(boolean zeroed)
public abstract IPAddressSection removePrefixLength()
AddressSegmentSeries
removePrefixLength
in interface AddressSection
removePrefixLength
in interface AddressSegmentSeries
public IPAddressSection adjustPrefixBySegment(boolean nextSegment)
AddressSegmentSeries
adjustPrefixBySegment
in interface AddressSection
adjustPrefixBySegment
in interface AddressSegmentSeries
public abstract IPAddressSection adjustPrefixLength(int adjustment)
AddressSegmentSeries
adjustPrefixLength
in interface AddressSection
adjustPrefixLength
in interface AddressSegmentSeries
public abstract IPAddressSection setPrefixLength(int prefixLength)
AddressSegmentSeries
setPrefixLength
in interface AddressSection
setPrefixLength
in interface AddressSegmentSeries
public abstract IPAddressSection setPrefixLength(int prefixLength, boolean zeroed)
public int getMinPrefix()
getMinPrefix
in interface AddressDivisionSeries
getMinPrefix
in class AddressDivisionGrouping
IPAddressDivision.getMaskPrefixLength(boolean)
public java.lang.Integer getEquivalentPrefix()
getEquivalentPrefix
in interface AddressDivisionSeries
getEquivalentPrefix
in class IPAddressDivisionGrouping
public abstract IPAddressSection getLower()
getLower
in interface AddressComponent
getLower
in interface AddressSection
getLower
in interface AddressSegmentSeries
public abstract IPAddressSection getUpper()
getUpper
in interface AddressComponent
getUpper
in interface AddressSection
getUpper
in interface AddressSegmentSeries
public abstract IPAddressSection reverseSegments()
AddressSegmentSeries
reverseSegments
in interface AddressSection
reverseSegments
in interface AddressSegmentSeries
public abstract IPAddressSection reverseBits(boolean perByte)
AddressSegmentSeries
reverseBits
in interface AddressComponent
reverseBits
in interface AddressSection
reverseBits
in interface AddressSegmentSeries
perByte
- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedpublic abstract IPAddressSection reverseBytes()
AddressSegmentSeries
reverseBytes
in interface AddressComponent
reverseBytes
in interface AddressSection
reverseBytes
in interface AddressSegmentSeries
public abstract IPAddressSection reverseBytesPerSegment()
AddressSegmentSeries
reverseBytesPerSegment
in interface AddressSection
reverseBytesPerSegment
in interface AddressSegmentSeries
public abstract IPAddressSegment[] getSegments()
getSegments
in interface AddressSegmentSeries
public abstract IPAddressSection getSection(int index)
AddressSegmentSeries
getSection
in interface AddressSection
getSection
in interface AddressSegmentSeries
public abstract IPAddressSection getSection(int index, int endIndex)
AddressSegmentSeries
getSection
in interface AddressSection
getSection
in interface AddressSegmentSeries
public void getSegments(AddressSegment[] segs)
getSegments
in interface AddressSegmentSeries
public void getSegments(int start, int end, AddressSegment[] segs, int destIndex)
AddressSegmentSeries
getSegments
in interface AddressSegmentSeries
public abstract java.lang.Iterable<? extends IPAddressSection> getIterable()
AddressComponent
AddressComponent.iterator()
directly.getIterable
in interface AddressComponent
getIterable
in interface AddressSection
getIterable
in interface AddressSegmentSeries
public abstract java.util.Iterator<? extends IPAddressSection> iterator()
AddressComponent
AddressItem.isMultiple()
to determine if this instance represents multiple.
This method iterates through the individual elements.iterator
in interface AddressComponent
iterator
in interface AddressSection
iterator
in interface AddressSegmentSeries
public abstract java.util.Iterator<? extends IPAddressSegment[]> segmentsIterator()
segmentsIterator
in interface AddressSegmentSeries
public boolean isEntireAddress()
public java.lang.String[] getSegmentStrings()
public java.lang.String toString()
toString
in class AddressDivisionGrouping
public abstract java.lang.String toFullString()
public abstract java.lang.String toCompressedString()
toCompressedString
in interface AddressSegmentSeries
public abstract java.lang.String toPrefixLengthString()
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 abstract java.lang.String toReverseDNSLookupString()
public java.lang.String toBinaryString()
public java.lang.String toOctalString(boolean with0Prefix)
public java.lang.String toHexString(boolean with0xPrefix)
toHexString
in interface AddressComponent
public java.lang.String toNormalizedString(IPAddressSection.IPStringOptions stringOptions)
public static java.lang.String toNormalizedString(IPAddressSection.IPStringOptions opts, IPAddressStringDivisionSeries section)
public IPAddressPartStringCollection toStandardStringCollection()
public IPAddressPartStringCollection toAllStringCollection()
public IPAddressPartStringCollection toDatabaseSearchStringCollection()
public abstract IPAddressPartStringCollection toStringCollection(IPAddressSection.IPStringBuilderOptions options)
public IPAddressStringDivisionSeries[] getParts(IPAddressSection.IPStringBuilderOptions options)
IPAddressDivisionGrouping
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)