public interface AddressSegment extends AddressComponent, AddressGenericDivision
The current implementations of this class are the most common representations of IPv4, IPv6 and MAC; segments are 1 byte for Ipv4, they are two bytes for Ipv6, and they are 1 byte for MAC addresses.
There are alternative forms of dividing addresses into divisions, such as the dotted representation for MAC like 1111.2222.3333, the embedded IPv4 representation for IPv6 like f:f:f:f:f:f:1.2.3.4, the inet_aton formats like 1.2 for IPv4, and so on.
If those alternative representations were to follow the general rules for segment representation, then you could reuse this class for those alternative representations.
The general rules are that segments have a whole number of bytes, and in a given address all segments have the same length.
When alternatives forms do not follow the general rules for segments,
you can use the AddressDivision interface instead.
Divisions do not have the restriction that divisions of an address are equal length and a whole number of bytes.
Divisions can be grouped using AddressDivisionGrouping.
AddressSegment objects are immutable and thus also thread-safe.
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(AddressSegment other) |
boolean |
equals(Object other)
Indicates whether some other object is "equal to" this one.
|
Iterable<? extends AddressSegment> |
getIterable()
Useful for using an instance in a "for-each loop".
|
AddressSegment |
getLower()
If this segment represents a range of values, returns a segment representing just the lowest value in the range, otherwise returns this.
|
int |
getMaxSegmentValue()
Gets the maximum possible value for this type of segment (for the highest range value of this particular segment, use
getUpper() |
int |
getPrefixValueCount(int segmentPrefixLength)
Returns the count of prefix values in this address segment for the given prefix bit count.
|
int |
getSegmentValue()
returns the lower value
|
AddressSegment |
getUpper()
If this segment represents a range of values, returns a segment representing just the highest value in the range, otherwise returns this.
|
int |
getUpperSegmentValue()
returns the upper value
|
int |
getValueCount()
Returns the count of values in this address segment.
|
default boolean |
isOneBit(int segmentBitIndex)
Returns true if the bit in the lower value of this segment at the given index is 1, where index 0 is the most significant bit.
|
Iterator<? extends AddressSegment> |
iterator()
Iterates through the individual address components.
|
boolean |
matches(int value) |
boolean |
matchesWithMask(int value,
int mask) |
boolean |
matchesWithMask(int lowerValue,
int upperValue,
int mask) |
boolean |
prefixEquals(AddressSegment other,
int prefixLength)
Returns whether the given prefix bits match the same bits of the given segment.
|
AddressSegment |
reverseBits(boolean perByte)
Returns a new AddressComponent with the bits reversed.
|
AddressSegment |
reverseBytes()
Returns an AddressComponent with the bytes reversed.
|
AddressComponentSpliterator<? extends AddressSegment> |
spliterator()
Partitions and traverses through the individual address components.
|
Stream<? extends AddressSegment> |
stream()
Returns a sequential stream of the individual address components.
|
default boolean |
testBit(int n)
Analogous to
BigInteger.testBit(int),
Computes (this & (1 << n)) != 0), using the lower value of this segment. |
getNetwork, toHexString, toNormalizedStringstream, streamcompareTo, containsPrefixBlock, containsSinglePrefixBlock, getBitCount, getByteCount, getBytes, getBytes, getBytes, getCount, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLengthForSingleBlock, getUpperBytes, getUpperBytes, getUpperBytes, getUpperValue, getValue, includesMax, includesZero, isFullRange, isMax, isMultiple, isZerogetDigitCount, getLowerStandardString, getMaxDigitCount, getStandardString, isBoundedByint getValueCount()
AddressItem.getCount() as an integerint getPrefixValueCount(int segmentPrefixLength)
int getSegmentValue()
int getUpperSegmentValue()
AddressSegment getLower()
getLower in interface AddressComponentRangeAddressSegment getUpper()
getUpper in interface AddressComponentRangeAddressSegment 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 AddressComponentperByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedAddressSegment 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 AddressComponentIterable<? extends AddressSegment> getIterable()
AddressComponentRangeAddressComponentRange.iterator() directly.getIterable in interface AddressComponentRangeIterator<? extends AddressSegment> 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 AddressComponentRangeAddressComponentSpliterator<? extends AddressSegment> spliterator()
AddressComponentRangespliterator in interface AddressComponentspliterator in interface AddressComponentRangeStream<? extends AddressSegment> stream()
AddressComponentRangeBaseStream.parallel() on the returned stream.stream in interface AddressComponentRangeboolean matches(int value)
boolean matchesWithMask(int value,
int mask)
boolean matchesWithMask(int lowerValue,
int upperValue,
int mask)
boolean contains(AddressSegment other)
boolean equals(Object other)
java.lang.Object
The equals method implements an equivalence relation
on non-null object references:
x, x.equals(x) should return
true.
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.
x and y, multiple invocations of
x.equals(y) consistently return true
or consistently return false, provided no
information used in equals comparisons on the
objects is modified.
x,
x.equals(null) should return false.
The equals method for class Object implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x and
y, this method returns true if and only
if x and y refer to the same object
(x == y has the value true).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode method, which states
that equal objects must have equal hash codes.
equals in class Objectother - the reference object with which to compare.true if this object is the same as the obj
argument; false otherwise.Object.hashCode(),
HashMapboolean prefixEquals(AddressSegment other, int prefixLength)
other - prefixLength - default boolean testBit(int n)
BigInteger.testBit(int),
Computes (this & (1 << n)) != 0), using the lower value of this segment.n - IndexOutOfBoundsException - if the index is negative or as large as the bit countAddressSegmentSeries.testBit(int),
isOneBit(int)default boolean isOneBit(int segmentBitIndex)
segmentBitIndex - IndexOutOfBoundsException - if the index is negative or as large as the bit countAddressSegmentSeries.isOneBit(int),
testBit(int)int getMaxSegmentValue()
getUpper()