public interface AddressSegment extends AddressComponent, java.lang.Comparable<AddressDivision>
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 segments, such as dotted representation for MAC like 1111.2222.3333, embedded IPv4 representation for IPv6 like f:f:f:f:f:f:1.2.3.4, 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 thos 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(java.lang.Object other) |
java.lang.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 |
getLowerSegmentValue()
returns the lower value
|
int |
getMaxSegmentValue()
Gets the maximum possible value for this type of segment (for the highest range value of this particular segment, use
getUpper() |
AddressNetwork<?> |
getNetwork() |
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() |
java.util.Iterator<? extends AddressSegment> |
iterator()
Iterates through the individual elements of this address component.
|
boolean |
matches(int value) |
boolean |
matchesWithMask(int value,
int mask) |
boolean |
matchesWithMask(int lowerValue,
int upperValue,
int mask) |
AddressSegment |
reverseBits(boolean perByte)
Returns a new AddressComponent with the bits reversed.
|
AddressSegment |
reverseBytes()
Returns an AddressComponent with the bytes reversed.
|
getByteCount, toHexString, toNormalizedString
getBitCount, getBytes, getBytes, getCount, getUpperBytes, getUpperBytes, includesMax, includesZero, isFullRange, isMax, isMultiple, isZero
AddressNetwork<?> getNetwork()
int getValueCount()
AddressItem.getCount()
as an integerint getLowerSegmentValue()
int getUpperSegmentValue()
AddressSegment getLower()
getLower
in interface AddressComponent
AddressSegment getUpper()
getUpper
in interface AddressComponent
AddressSegment 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
perByte
- if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedAddressSegment 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
java.lang.Iterable<? extends AddressSegment> getIterable()
AddressComponent
AddressComponent.iterator()
directly.getIterable
in interface AddressComponent
java.util.Iterator<? extends AddressSegment> iterator()
AddressComponent
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.
Call AddressItem.isMultiple()
to determine if this instance represents multiple.
iterator
in interface AddressComponent
boolean matches(int value)
boolean matchesWithMask(int value, int mask)
boolean matchesWithMask(int lowerValue, int upperValue, int mask)
boolean contains(AddressSegment other)
boolean equals(java.lang.Object other)
equals
in class java.lang.Object
int getMaxSegmentValue()
getUpper()