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, toNormalizedString
containsPrefixBlock, containsSinglePrefixBlock, getBlockMaskPrefixLength, getDivisionPrefixLength, getLeadingBitCount, getPrefixAdjustedRangeString, getString, getTrailingBitCount, getWildcardString, isPrefixed, isSinglePrefixBlock, matchesWithPrefixMask
bitwiseOrRange, getDigitCount, getMaxDigitCount, getPrefixLengthForSingleBlock, getUpperValue, getValue, hasUppercaseVariations, isBitwiseOrCompatibleWithRange, isMaskCompatibleWithRange, isMax, isZero, maskRange, matches, matchesWithMask, matchesWithMask
getBytes, getBytes, getBytes, getDigitCount, getDigitCount, getLowerStandardString, getStandardString, getUpperBytes, getUpperBytes, getUpperBytes, toString
isOneBit, testBit
stream, stream
compareTo, containsPrefixBlock, containsSinglePrefixBlock, getBitsForCount, getBlockSize, getBytes, getBytes, getBytes, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, isFullRange, isMax, isZero
getDigitCount, getLowerStandardString, getMaxDigitCount, getStandardString
isFullRange
public 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 IPAddressSegment
public boolean isIPv4()
isIPv4
in class IPAddressSegment
public IPAddress.IPVersion getIPVersion()
getIPVersion
in class IPAddressSegment
public int getMaxSegmentValue()
AddressSegment
AddressSegment.getUpper()
getMaxSegmentValue
in interface AddressSegment
public IPv4AddressSegment toNetworkSegment(Integer segmentPrefixLength)
IPAddressSegment
IPAddressSegmentSeries.getNetworkSection(int, boolean)
toNetworkSegment
in class IPAddressSegment
public IPv4AddressSegment toNetworkSegment(Integer segmentPrefixLength, boolean withPrefixLength)
IPAddressSegment
IPAddressSegmentSeries.getNetworkSection(int, boolean)
toNetworkSegment
in class IPAddressSegment
public IPv4AddressSegment toHostSegment(Integer bits)
IPAddressSegment
IPAddressSegmentSeries.getHostSection(int)
toHostSegment
in class IPAddressSegment
public IPv4AddressSegment getLower()
IPAddressSegment
getLower
in interface AddressSegment
getLower
in interface AddressComponentRange
getLower
in class IPAddressSegment
public IPv4AddressSegment getUpper()
IPAddressSegment
getUpper
in interface AddressSegment
getUpper
in interface AddressComponentRange
getUpper
in class IPAddressSegment
public IPv4AddressNetwork getNetwork()
AddressComponent
getNetwork
in interface AddressComponent
getNetwork
in class IPAddressSegment
public IPv4AddressNetwork.IPv4AddressCreator getSegmentCreator()
public Iterable<IPv4AddressSegment> getIterable()
AddressComponentRange
AddressComponentRange.iterator()
directly.getIterable
in interface AddressSegment
getIterable
in interface AddressComponentRange
getIterable
in class IPAddressSegment
public Iterator<IPv4AddressSegment> iterator()
AddressComponentRange
An 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 AddressSegment
iterator
in interface AddressComponentRange
iterator
in interface Iterable<IPv4AddressSegment>
iterator
in class IPAddressSegment
public AddressComponentSpliterator<IPv4AddressSegment> spliterator()
AddressComponentRange
spliterator
in interface AddressComponent
spliterator
in interface AddressSegment
spliterator
in interface AddressComponentRange
spliterator
in interface Iterable<IPv4AddressSegment>
spliterator
in class IPAddressSegment
public Stream<IPv4AddressSegment> stream()
AddressComponentRange
BaseStream.parallel()
on the returned stream.stream
in interface AddressSegment
stream
in interface AddressComponentRange
stream
in class IPAddressSegment
public Iterator<IPv4AddressSegment> prefixBlockIterator()
IPAddressSegment
If the series has no prefix length, then this is equivalent to IPAddressSegment.iterator()
prefixBlockIterator
in class IPAddressSegment
public AddressComponentSpliterator<IPv4AddressSegment> prefixBlockSpliterator()
IPAddressSegment
prefixBlockSpliterator
in class IPAddressSegment
public Stream<IPv4AddressSegment> prefixBlockStream()
IPAddressSegment
BaseStream.parallel()
on the returned stream.prefixBlockStream
in class IPAddressSegment
public Iterator<IPv4AddressSegment> prefixIterator()
IPAddressSegment
If the series has no prefix length, then this is equivalent to IPAddressSegment.iterator()
prefixIterator
in class IPAddressSegment
public AddressComponentSpliterator<IPv4AddressSegment> prefixSpliterator()
IPAddressSegment
prefixSpliterator
in class IPAddressSegment
public Stream<IPv4AddressSegment> prefixStream()
IPAddressSegment
BaseStream.parallel()
on the returned stream.prefixStream
in class IPAddressSegment
public Iterator<IPv4AddressSegment> prefixBlockIterator(int prefixLength)
IPAddressSegment
prefixBlockIterator
in class IPAddressSegment
public AddressComponentSpliterator<IPv4AddressSegment> prefixBlockSpliterator(int segPrefLength)
IPAddressSegment
prefixBlockSpliterator
in class IPAddressSegment
public Stream<IPv4AddressSegment> prefixBlockStream(int segPrefLength)
IPAddressSegment
BaseStream.parallel()
on the returned stream.prefixBlockStream
in class IPAddressSegment
public int getBitCount()
AddressItem
getBitCount
in interface AddressItem
getBitCount
in interface IPAddressStringDivision
public int getByteCount()
AddressItem
getByteCount
in interface AddressItem
public int getDefaultTextualRadix()
public int getMaxDigitCount()
public IPv4AddressSegment reverseBits(boolean perByte)
AddressComponent
IncompatibleAddressException
. 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 AddressComponent
reverseBits
in interface AddressSegment
reverseBits
in class IPAddressSegment
perByte
- 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()
AddressComponent
IncompatibleAddressException
. 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 AddressComponent
reverseBytes
in interface AddressSegment
reverseBytes
in class IPAddressSegment
public IPv4AddressSegment toZeroHost()
IPAddressSegment
If 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 IPAddressSegment
public IPv4AddressSegment withoutPrefixLength()
IPAddressSegment
withoutPrefixLength
in class IPAddressSegment
public boolean prefixContains(IPAddressSegment other, int segmentPrefixLength)
IPAddressSegment
prefixContains
in class IPAddressSegment
public boolean prefixEquals(AddressSegment other, int segmentPrefixLength)
AddressSegment
prefixEquals
in interface AddressSegment
prefixEquals
in class IPAddressSegment
public boolean overlaps(AddressSegment other)
overlaps
in interface AddressSegment
public boolean contains(AddressSegment other)
contains
in interface AddressSegment
public boolean equals(Object other)
AddressDivisionBase
equals
in interface AddressSegment
equals
in class AddressDivision
public IPv6AddressSegment join(IPv6AddressNetwork.IPv6AddressCreator creator, IPv4AddressSegment low) throws IncompatibleAddressException
creator
- low
- IncompatibleAddressException