public class IPv4AddressSegment extends IPAddressSegment implements Iterable<IPv4AddressSegment>
AddressDivision.BitwiseOrResult, AddressDivision.MaskResult| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_CHARS
When printed with the default radix of 10, the max number of characters per segment
|
EXTENDED_DIGITS| Constructor and Description |
|---|
IPv4AddressSegment(int value)
Constructs a segment of an IPv4 address with the given value.
|
IPv4AddressSegment(int value,
Integer segmentPrefixLength)
Constructs a segment of an IPv4 address.
|
IPv4AddressSegment(int lower,
int upper,
Integer segmentPrefixLength)
Constructs a segment of an IPv4 address that represents a range of values.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(AddressSegment other) |
boolean |
equals(Object other)
Two divisions are equal if they:
- they match type/version (ipv4, ipv6, mac, or a specific division class)
- match bit counts
- match values
Prefix lengths, for those divisions that have them, are ignored.
|
int |
getBitCount()
Provides the number of bits comprising this address item
|
int |
getByteCount()
Provides the number of bytes required for this address item, rounding up if the bit count is not a multiple of 8
|
int |
getDefaultTextualRadix() |
IPAddress.IPVersion |
getIPVersion() |
Iterable<IPv4AddressSegment> |
getIterable()
Useful for using an instance in a "for-each loop".
|
IPv4AddressSegment |
getLower()
If this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.
|
int |
getMaxDigitCount() |
int |
getMaxSegmentValue()
Gets the maximum possible value for this type of segment (for the highest range value of this particular segment, use
AddressSegment.getUpper() |
long |
getMaxValue() |
IPv4AddressNetwork |
getNetwork()
Returns the network object for components of the same version (eg IPv4, IPv6 and MAC each have their own network object)
|
IPv4AddressNetwork.IPv4AddressCreator |
getSegmentCreator() |
IPv4AddressSegment |
getUpper()
If this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.
|
boolean |
isIPv4() |
Iterator<IPv4AddressSegment> |
iterator()
Iterates through the individual address components.
|
IPv6AddressSegment |
join(IPv6AddressNetwork.IPv6AddressCreator creator,
IPv4AddressSegment low)
Joins with another IPv4 segment to produce a IPv6 segment.
|
boolean |
overlaps(AddressSegment other) |
Iterator<IPv4AddressSegment> |
prefixBlockIterator()
Iterates through the individual prefix blocks.
|
Iterator<IPv4AddressSegment> |
prefixBlockIterator(int prefixLength)
Iterates through the individual prefix blocks according to the given segment prefix length.
|
AddressComponentSpliterator<IPv4AddressSegment> |
prefixBlockSpliterator()
Partitions and traverses through the individual prefix blocks of this segment for its prefix length.
|
AddressComponentSpliterator<IPv4AddressSegment> |
prefixBlockSpliterator(int segPrefLength)
Partitions and traverses through the individual prefix blocks for the given prefix length.
|
Stream<IPv4AddressSegment> |
prefixBlockStream()
Returns a sequential stream of the individual prefix blocks of this segment.
|
Stream<IPv4AddressSegment> |
prefixBlockStream(int segPrefLength)
Returns a sequential stream of the individual prefix blocks for the given prefix length.
|
boolean |
prefixContains(IPAddressSegment other,
int segmentPrefixLength)
Returns whether the given prefix bit value ranges contain the same bits of the given segment.
|
boolean |
prefixEquals(AddressSegment other,
int segmentPrefixLength)
Returns whether the given prefix bits match the same bits of the given segment.
|
Iterator<IPv4AddressSegment> |
prefixIterator()
Iterates through the individual prefixes.
|
AddressComponentSpliterator<IPv4AddressSegment> |
prefixSpliterator()
Partitions and traverses through the individual prefixes of this segment for its prefix length.
|
Stream<IPv4AddressSegment> |
prefixStream()
Returns a sequential stream of the individual prefixes of this segment.
|
IPv4AddressSegment |
removePrefixLength()
Deprecated.
|
IPv4AddressSegment |
removePrefixLength(boolean zeroed)
Deprecated.
|
IPv4AddressSegment |
reverseBits() |
IPv4AddressSegment |
reverseBits(boolean perByte)
Returns a new AddressComponent with the bits reversed.
|
IPv4AddressSegment |
reverseBytes()
Returns an AddressComponent with the bytes reversed.
|
AddressComponentSpliterator<IPv4AddressSegment> |
spliterator()
Partitions and traverses through the individual address components.
|
Stream<IPv4AddressSegment> |
stream()
Returns a sequential stream of the individual address components.
|
IPv4AddressSegment |
toHostSegment(Integer bits)
used by getHostSection, see
IPAddressSegmentSeries.getHostSection(int) |
IPv4AddressSegment |
toNetworkSegment(Integer segmentPrefixLength)
used by constructors of IPAddressSection, see
IPAddressSegmentSeries.getNetworkSection(int, boolean) |
IPv4AddressSegment |
toNetworkSegment(Integer segmentPrefixLength,
boolean withPrefixLength)
used by getNetworkSection and by constructors of IPAddressSection, see
IPAddressSegmentSeries.getNetworkSection(int, boolean) |
IPv4AddressSegment |
toZeroHost()
Returns a segment with the same network bits as this segment,
but with the host bits changed to 0.
|
IPv4AddressSegment |
withoutPrefixLength()
Returns a segment with the same values but without a prefix length.
|
bitwiseOrRange, getBitCount, getByteCount, getCount, getDefaultTextualRadix, getDivisionValue, getMaxSegmentValue, getMinPrefixLengthForBlock, getPrefixCount, getPrefixValueCount, getPrefixValueCount, getSegmentPrefixLength, getSegmentValue, getUpperDivisionValue, getUpperSegmentValue, getValueCount, hashCode, includesMax, includesZero, isBoundedBy, isIPv6, isMultiple, isPrefixBlock, maskRange, matches, matchesWithMask, matchesWithMask, matchesWithPrefixMask, prefixContains, prefixEquals, toHexString, toNormalizedString, toNormalizedStringcontainsPrefixBlock, containsSinglePrefixBlock, getBlockMaskPrefixLength, getDivisionPrefixLength, getLeadingBitCount, getPrefixAdjustedRangeString, getString, getTrailingBitCount, getWildcardString, isPrefixed, isSinglePrefixBlock, matchesWithPrefixMaskbitwiseOrRange, getDigitCount, getMaxDigitCount, getPrefixLengthForSingleBlock, getUpperValue, getValue, hasUppercaseVariations, isBitwiseOrCompatibleWithRange, isMaskCompatibleWithRange, isMax, isZero, maskRange, matches, matchesWithMask, matchesWithMaskgetBytes, getBytes, getBytes, getDigitCount, getDigitCount, getLowerStandardString, getStandardString, getUpperBytes, getUpperBytes, getUpperBytes, toStringisOneBit, testBitstream, streamcompareTo, containsPrefixBlock, containsSinglePrefixBlock, getBitsForCount, getBlockSize, getBytes, getBytes, getBytes, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, isFullRange, isMax, isZerogetDigitCount, getLowerStandardString, getMaxDigitCount, getStandardStringisFullRangepublic static final int MAX_CHARS
public IPv4AddressSegment(int value)
throws AddressValueException
value - the value of the segmentAddressValueException - if value is negative or too largepublic IPv4AddressSegment(int value,
Integer segmentPrefixLength)
throws AddressValueException
value - the value of the segment. If the segmentPrefixLength is non-null, the network prefix of the value is used, and the segment represents all segment values with the same network prefix.segmentPrefixLength - the segment prefix, which can be nullAddressValueException - if value or prefix length is negative or too largepublic IPv4AddressSegment(int lower,
int upper,
Integer segmentPrefixLength)
throws AddressValueException
segmentPrefixLength - the segment prefix length, which can be null. If segmentPrefixLength is non-null, this segment represents a range of segment values with the given network prefix length.lower - the lower value of the range of values represented by the segment. If segmentPrefixLength is non-null, the lower value becomes the smallest value with the same network prefix.upper - the upper value of the range of values represented by the segment. If segmentPrefixLength is non-null, the upper value becomes the largest value with the same network prefix.AddressValueException - if either lower or upper value or prefix length is negative or too largepublic long getMaxValue()
getMaxValue in class IPAddressSegmentpublic boolean isIPv4()
isIPv4 in class IPAddressSegmentpublic IPAddress.IPVersion getIPVersion()
getIPVersion in class IPAddressSegmentpublic int getMaxSegmentValue()
AddressSegmentAddressSegment.getUpper()getMaxSegmentValue in interface AddressSegmentpublic IPv4AddressSegment toNetworkSegment(Integer segmentPrefixLength)
IPAddressSegmentIPAddressSegmentSeries.getNetworkSection(int, boolean)toNetworkSegment in class IPAddressSegmentpublic IPv4AddressSegment toNetworkSegment(Integer segmentPrefixLength, boolean withPrefixLength)
IPAddressSegmentIPAddressSegmentSeries.getNetworkSection(int, boolean)toNetworkSegment in class IPAddressSegmentpublic IPv4AddressSegment toHostSegment(Integer bits)
IPAddressSegmentIPAddressSegmentSeries.getHostSection(int)toHostSegment in class IPAddressSegmentpublic IPv4AddressSegment getLower()
IPAddressSegmentgetLower in interface AddressSegmentgetLower in interface AddressComponentRangegetLower in class IPAddressSegmentpublic IPv4AddressSegment getUpper()
IPAddressSegmentgetUpper in interface AddressSegmentgetUpper in interface AddressComponentRangegetUpper in class IPAddressSegmentpublic IPv4AddressNetwork getNetwork()
AddressComponentgetNetwork in interface AddressComponentgetNetwork in class IPAddressSegmentpublic IPv4AddressNetwork.IPv4AddressCreator getSegmentCreator()
public Iterable<IPv4AddressSegment> getIterable()
AddressComponentRangeAddressComponentRange.iterator() directly.getIterable in interface AddressSegmentgetIterable in interface AddressComponentRangegetIterable in class IPAddressSegmentpublic Iterator<IPv4AddressSegment> iterator()
AddressComponentRangeAn address component can represent an individual segment, address, or section, or it can represent multiple, typically a subnet of addresses or a range of segment or section values.
Call AddressItem.isMultiple() to determine if this instance represents multiple, or AddressItem.getCount() for the count.
iterator in interface AddressSegmentiterator in interface AddressComponentRangeiterator in interface Iterable<IPv4AddressSegment>iterator in class IPAddressSegmentpublic AddressComponentSpliterator<IPv4AddressSegment> spliterator()
AddressComponentRangespliterator in interface AddressComponentspliterator in interface AddressSegmentspliterator in interface AddressComponentRangespliterator in interface Iterable<IPv4AddressSegment>spliterator in class IPAddressSegmentpublic Stream<IPv4AddressSegment> stream()
AddressComponentRangeBaseStream.parallel() on the returned stream.stream in interface AddressSegmentstream in interface AddressComponentRangestream in class IPAddressSegmentpublic Iterator<IPv4AddressSegment> prefixBlockIterator()
IPAddressSegment
If the series has no prefix length, then this is equivalent to IPAddressSegment.iterator()
prefixBlockIterator in class IPAddressSegmentpublic AddressComponentSpliterator<IPv4AddressSegment> prefixBlockSpliterator()
IPAddressSegmentprefixBlockSpliterator in class IPAddressSegmentpublic Stream<IPv4AddressSegment> prefixBlockStream()
IPAddressSegmentBaseStream.parallel() on the returned stream.prefixBlockStream in class IPAddressSegmentpublic Iterator<IPv4AddressSegment> prefixIterator()
IPAddressSegment
If the series has no prefix length, then this is equivalent to IPAddressSegment.iterator()
prefixIterator in class IPAddressSegmentpublic AddressComponentSpliterator<IPv4AddressSegment> prefixSpliterator()
IPAddressSegmentprefixSpliterator in class IPAddressSegmentpublic Stream<IPv4AddressSegment> prefixStream()
IPAddressSegmentBaseStream.parallel() on the returned stream.prefixStream in class IPAddressSegmentpublic Iterator<IPv4AddressSegment> prefixBlockIterator(int prefixLength)
IPAddressSegmentprefixBlockIterator in class IPAddressSegmentpublic AddressComponentSpliterator<IPv4AddressSegment> prefixBlockSpliterator(int segPrefLength)
IPAddressSegmentprefixBlockSpliterator in class IPAddressSegmentpublic Stream<IPv4AddressSegment> prefixBlockStream(int segPrefLength)
IPAddressSegmentBaseStream.parallel() on the returned stream.prefixBlockStream in class IPAddressSegmentpublic int getBitCount()
AddressItemgetBitCount in interface AddressItemgetBitCount in interface IPAddressStringDivisionpublic int getByteCount()
AddressItemgetByteCount in interface AddressItempublic int getDefaultTextualRadix()
public int getMaxDigitCount()
public IPv4AddressSegment reverseBits(boolean perByte)
AddressComponentIncompatibleAddressException. In a range the most significant bits stay constant
while the least significant bits range over different values, so reversing that scenario results in a series of non-consecutive values, in most cases,
which cannot be represented with a single AddressComponent object.
In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to break the series down into a series representing a single value.
reverseBits in interface AddressComponentreverseBits in interface AddressSegmentreverseBits in class IPAddressSegmentperByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedpublic IPv4AddressSegment reverseBits()
public IPv4AddressSegment reverseBytes()
AddressComponentIncompatibleAddressException. In a range the most significant bits stay constant
while the least significant bits range over different values, so reversing that scenario results in a series of non-consecutive values, in most cases,
which cannot be represented with a single AddressComponent object.
In such cases where isMultiple() is true, call iterator(), getLower(), getUpper() or some other methods to break the series down into a series representing a single value.
reverseBytes in interface AddressComponentreverseBytes in interface AddressSegmentreverseBytes in class IPAddressSegmentpublic IPv4AddressSegment toZeroHost()
IPAddressSegmentIf there is no prefix length associated with this segment, returns an all-zero segment.
This is nearly equivalent to doing the mask (see IPAddressSegment.maskRange(int)) of this segment
with the network mask for the given prefix length,
but when applying a mask to a range of values you can have a non-sequential result.
With this method, if the resulting series has a range of values, then the resulting series range boundaries will have host values of 0, but not necessarily all the intervening values.
For instance, the 1-byte segment range 4-7 with prefix length 6, when masked with 252 (the network mask) results in just the single value 4, matching the result of this method. The 1-byte segment range 4-8 with prefix length 6, when masked with 252 results in the two non-sequential values, 4 and 8, but the result of this method with prefix length 6 results in the range 4-8, the same as the original segment.
The default behaviour is that the resultant series will have the same prefix length.
The resultant series will not have a prefix length if AddressNetwork.getPrefixConfiguration() is AddressNetwork.PrefixConfiguration.ALL_PREFIXED_ADDRESSES_ARE_SUBNETS.
toZeroHost in class IPAddressSegment@Deprecated public IPv4AddressSegment removePrefixLength(boolean zeroed)
removePrefixLength in class IPAddressSegment@Deprecated public IPv4AddressSegment removePrefixLength()
removePrefixLength in class IPAddressSegmentpublic IPv4AddressSegment withoutPrefixLength()
IPAddressSegmentwithoutPrefixLength in class IPAddressSegmentpublic boolean prefixContains(IPAddressSegment other, int segmentPrefixLength)
IPAddressSegmentprefixContains in class IPAddressSegmentpublic boolean prefixEquals(AddressSegment other, int segmentPrefixLength)
AddressSegmentprefixEquals in interface AddressSegmentprefixEquals in class IPAddressSegmentpublic boolean overlaps(AddressSegment other)
overlaps in interface AddressSegmentpublic boolean contains(AddressSegment other)
contains in interface AddressSegmentpublic boolean equals(Object other)
AddressDivisionBaseequals in interface AddressSegmentequals in class AddressDivisionpublic IPv6AddressSegment join(IPv6AddressNetwork.IPv6AddressCreator creator, IPv4AddressSegment low) throws IncompatibleAddressException
creator - low - IncompatibleAddressException