public abstract class Address extends java.lang.Object implements AddressSegmentSeries, java.lang.Comparable<Address>
| Modifier and Type | Class and Description |
|---|---|
static interface |
Address.AddressProvider |
static interface |
Address.SegmentValueProvider |
| Modifier and Type | Field and Description |
|---|---|
static char |
ALTERNATIVE_RANGE_SEPARATOR |
static java.lang.String |
ALTERNATIVE_RANGE_SEPARATOR_STR |
static java.lang.String |
ALTERNATIVE_SEGMENT_WILDCARD_STR |
static AddressComparator |
DEFAULT_ADDRESS_COMPARATOR |
static java.lang.String |
HEX_PREFIX |
static java.lang.String |
OCTAL_PREFIX |
static char |
RANGE_SEPARATOR |
static java.lang.String |
RANGE_SEPARATOR_STR |
static char |
SEGMENT_SQL_SINGLE_WILDCARD |
static java.lang.String |
SEGMENT_SQL_SINGLE_WILDCARD_STR |
static char |
SEGMENT_SQL_WILDCARD |
static java.lang.String |
SEGMENT_SQL_WILDCARD_STR |
static char |
SEGMENT_WILDCARD |
static java.lang.String |
SEGMENT_WILDCARD_STR |
| Modifier and Type | Method and Description |
|---|---|
abstract Address |
adjustPrefixBySegment(boolean nextSegment)
Increases or decreases prefix length to the next segment boundary.
|
abstract Address |
adjustPrefixBySegment(boolean nextSegment,
boolean zeroed)
Increases or decreases prefix length to the next segment boundary.
|
abstract Address |
adjustPrefixLength(int adjustment)
Increases or decreases prefix length by the given increment.
|
abstract Address |
adjustPrefixLength(int adjustment,
boolean zeroed)
Increases or decreases prefix length by the given increment.
|
abstract Address |
applyPrefixLength(int networkPrefixLength)
Applies the given prefix length to create a new segment series.
|
int |
compareTo(Address other) |
abstract boolean |
contains(Address other) |
boolean |
containsPrefixBlock(int prefixLength)
Returns whether the values of this series contains the prefix block for the given prefix length.
|
boolean |
containsSinglePrefixBlock(int prefixLength)
Returns whether the values of this series contains a single prefix block for the given prefix length.
|
static IPv4AddressNetwork |
defaultIpv4Network() |
static IPv6AddressNetwork |
defaultIpv6Network() |
static MACAddressNetwork |
defaultMACNetwork() |
boolean |
equals(java.lang.Object o)
Two Address objects are equal if they represent the same set of addresses.
|
int |
getBitCount() |
int |
getByteCount()
returns the number of bytes in each of the address components represented by this instance
|
byte[] |
getBytes() |
byte[] |
getBytes(byte[] bytes)
Copies the bytes of the smallest address item represented by this address item into the supplied array,
and returns that array.
|
java.math.BigInteger |
getCount()
Gets the count of addresses that this address may represent.
|
int |
getDivisionCount() |
java.lang.String[] |
getDivisionStrings()
Get standard-format strings for each of the divisions in the series.
|
abstract java.lang.Iterable<? extends Address> |
getIterable()
Useful for using an instance in a "for-each loop".
|
abstract Address |
getLower()
If this represents a series with ranging values, returns a series representing the lower values of the range.
|
abstract int |
getMaxSegmentValue() |
int |
getMinPrefixLengthForBlock()
Returns the smallest prefix length possible such that this includes the block of addresses for that prefix.
|
java.math.BigInteger |
getPrefixCount()
If this has a prefix length, the count of the range of values in the prefix.
|
java.lang.Integer |
getPrefixLength()
the largest number of high bits for which this address represents all addresses with the same set of high bits
|
java.lang.Integer |
getPrefixLengthForSingleBlock()
Returns a prefix length for which the range of this address subnet matches the the block of addresses for that prefix.
|
AddressSection |
getSection()
Gets the subsection from the series that comprises all segments
|
int |
getSegmentCount()
Returns the number of segments in this series.
|
void |
getSegments(AddressSegment[] segs)
Copies the existing segments into the given array.
|
void |
getSegments(int start,
int end,
AddressSegment[] segs,
int index)
get the segments from start to end and insert into the segs array at the the given index
|
java.lang.String[] |
getSegmentStrings()
Returns the an array with the values of each segment as they would appear in the normalized with wildcards string.
|
abstract Address |
getUpper()
If this represents a series with ranging values, returns a series representing the upper values of the range
If this represents a series with a single value in each segment, returns this.
|
byte[] |
getUpperBytes()
Gets the bytes for the highest address in the range of addresses represented by this address instance.
|
byte[] |
getUpperBytes(byte[] bytes)
Copies the bytes of the largest address item represented by this address item into the supplied array,
and returns that array.
|
java.math.BigInteger |
getUpperValue() |
java.math.BigInteger |
getValue() |
int |
hashCode() |
boolean |
includesMax() |
boolean |
includesZero() |
abstract Address |
increment(long increment)
Returns the series from the subnet that is the given increment upwards into the subnet range,
or if the given increment is negative the given increment downwards into the subnet range,
or if this is just an individual series, it simply adds the increment to this.
|
boolean |
isFullRange() |
abstract boolean |
isLocal()
Whether the address can be considered a local address (as opposed to a global one)
|
boolean |
isMax() |
int |
isMore(AddressDivisionSeries other)
Use this method to compare the counts of two address series.
|
abstract boolean |
isMulticast()
Whether the MAC address or IP address or other form of address is multicast.
|
boolean |
isMultiple()
Whether this represents multiple potential values (eg a prefixed address or a segment representing a range of values)
|
boolean |
isPrefixBlock()
Returns whether the address range has a prefix length and includes the block of values for its prefix length.
|
boolean |
isPrefixed()
Whether there exists a prefix.
|
boolean |
isSameAddress(Address other) |
boolean |
isSinglePrefixBlock()
Returns whether the address range the block of values for a single prefix identified by its prefix length.
|
boolean |
isZero() |
abstract java.util.Iterator<? extends Address> |
iterator()
Iterates through the individual segment series.
|
abstract java.util.Iterator<? extends Address> |
prefixBlockIterator()
Iterates through the individual prefix blocks.
|
abstract Address |
removePrefixLength()
Removes the prefix length.
|
abstract Address |
removePrefixLength(boolean zeroed)
Removes the prefix length.
|
abstract Address |
reverseBits(boolean perByte)
Returns a new segment series with the bits reversed.
|
abstract Address |
reverseBytes()
Returns a new segment series with the bytes reversed.
|
abstract Address |
reverseBytesPerSegment()
Returns a new segment series with the bytes reversed within each segment.
|
abstract Address |
reverseSegments()
Returns a new segment series with the segments reversed.
|
abstract Address |
setPrefixLength(int prefixLength)
Sets the prefix length.
|
abstract Address |
setPrefixLength(int prefixLength,
boolean zeroed)
Sets the prefix length.
|
HostIdentifierString |
toAddressString()
Returns a host identifier string representation for this address,
which will be already validated.
|
java.lang.String |
toCanonicalString()
This produces a canonical string.
|
java.lang.String |
toCompressedString()
Produce short strings for the address in the usual address format.
|
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.
|
java.lang.String |
toNormalizedString()
The normalized string returned by this method is a common and consistent representation of the address.
|
abstract Address |
toPrefixBlock()
If this series has a prefix length, returns the block for that prefix.
|
java.lang.String |
toString() |
getBitsPerSegment, getBytesPerSegment, getNetwork, getSection, getSection, getSegment, getSegments, segmentsIteratorgetDivisionpublic static final java.lang.String HEX_PREFIX
public static final java.lang.String OCTAL_PREFIX
public static final char RANGE_SEPARATOR
public static final java.lang.String RANGE_SEPARATOR_STR
public static final char ALTERNATIVE_RANGE_SEPARATOR
public static final java.lang.String ALTERNATIVE_RANGE_SEPARATOR_STR
public static final char SEGMENT_WILDCARD
public static final java.lang.String SEGMENT_WILDCARD_STR
public static final java.lang.String ALTERNATIVE_SEGMENT_WILDCARD_STR
public static final char SEGMENT_SQL_WILDCARD
public static final java.lang.String SEGMENT_SQL_WILDCARD_STR
public static final char SEGMENT_SQL_SINGLE_WILDCARD
public static final java.lang.String SEGMENT_SQL_SINGLE_WILDCARD_STR
public static final AddressComparator DEFAULT_ADDRESS_COMPARATOR
public static IPv6AddressNetwork defaultIpv6Network()
public static IPv4AddressNetwork defaultIpv4Network()
public static MACAddressNetwork defaultMACNetwork()
public int getSegmentCount()
AddressSegmentSeriesgetSegmentCount in interface AddressSegmentSeriespublic int getDivisionCount()
getDivisionCount in interface AddressStringDivisionSeriespublic int getBitCount()
getBitCount in interface AddressItempublic int getByteCount()
AddressComponentgetByteCount in interface AddressComponentpublic AddressSection getSection()
AddressSegmentSeriesgetSection in interface AddressSegmentSeriespublic void getSegments(AddressSegment[] segs)
AddressSegmentSeriesAddressSegmentSeries.getSegmentCount()getSegments in interface AddressSegmentSeriespublic void getSegments(int start,
int end,
AddressSegment[] segs,
int index)
AddressSegmentSeriesgetSegments in interface AddressSegmentSeriesstart - the first segment index from this series to be includedend - the first segment index to be excludedsegs - the target arrayindex - where to insert the segments in the segs arraypublic abstract int getMaxSegmentValue()
public abstract java.lang.Iterable<? extends Address> getIterable()
AddressComponentAddressComponent.iterator() directly.getIterable in interface AddressComponentgetIterable in interface AddressSegmentSeriespublic abstract java.util.Iterator<? extends Address> iterator()
AddressSegmentSeriesiterator in interface AddressComponentiterator in interface AddressSegmentSeriespublic abstract java.util.Iterator<? extends Address> prefixBlockIterator()
AddressSegmentSeriesAddressSegmentSeries.iterator()prefixBlockIterator in interface AddressSegmentSeriespublic abstract Address increment(long increment)
AddressSegmentSeriesIf the subnet has multiple values and the increment exceeds the subnet size, then the amount by which is exceeds the size is added to the upper series of the range (the final iterator value) or is subtracted from the lower series of the range (the first iterator value) if negative.
If the subnet is just a single address values, the series is simply incremented by the given value, positive or negative.
If a subnet has multiple values, a positive increment value is equivalent to the same number of values from the iterator. For instance, a increment of 1 is value 1 from the iterator, an increment of 2 is the second value from the iterator, and so on. A negative increment is equivalent to the same number of values preceding the upper bound of the iterator. For instance, an increment of -1 is the last value from the iterator, and increment of -2 is the second last value, and so on.
Therefore, to get the series just above the highest series of the subnet, use an increment of size:count > 1 ? count + 1 : 1 where count is the subnet size.
To get the series just below the lowest series of the subnet, use an increment of size:-(count > 1 ? count + 1 : 1) where count is the subnet size.
increment in interface AddressSegmentSeriespublic abstract Address getLower()
AddressSegmentSeriesgetLower in interface AddressComponentgetLower in interface AddressSegmentSeriespublic abstract Address getUpper()
AddressSegmentSeriesgetUpper in interface AddressComponentgetUpper in interface AddressSegmentSeriespublic boolean isMultiple()
AddressItemisMultiple in interface AddressItempublic boolean isPrefixed()
AddressDivisionSeriesisPrefixed in interface AddressDivisionSeriespublic java.lang.Integer getPrefixLength()
getPrefixLength in interface AddressDivisionSeriespublic int getMinPrefixLengthForBlock()
If the entire range can be dictated this way, then this method returns the same value as getPrefixLengthForSingleBlock().
Otherwise, this method will return the minimal possible prefix that can be paired with this address, while getPrefixLengthForSingleBlock() will return null.
In cases where the final bit in this address division series is constant, this returns the bit length of this address division series.
getMinPrefixLengthForBlock in interface AddressDivisionSeriespublic java.lang.Integer getPrefixLengthForSingleBlock()
If the range can be dictated this way, then this method returns the same value as getMinPrefixLengthForBlock().
If no such prefix exists, returns null.
If this segment grouping represents a single value, returns the bit length of this address division series.
IP address examples: 1.2.3.4 returns 32 1.2.*.* returns 16 1.2.*.0/24 returns 16 in the case of PrefixConfiguration == ALL_PREFIXES_ARE_SUBNETS, 32 otherwise 1.2.*.4 returns null 1.2.252-255.* returns 22 1.2.3.4/x returns x in the case of PrefixConfiguration == ALL_PREFIXES_ARE_SUBNETS, 32 otherwise 1.2.0.0/16 returns 16 in the case of PrefixConfiguration == ALL_PREFIXES_ARE_SUBNETS or PREFIXED_ZERO_HOSTS_ARE_SUBNETS, 32 otherwise
getPrefixLengthForSingleBlock in interface AddressDivisionSeriespublic abstract boolean isMulticast()
InetAddress.isMulticastAddress()public java.math.BigInteger getCount()
getCount in interface AddressItempublic java.math.BigInteger getPrefixCount()
getCount()getPrefixCount in interface AddressDivisionSeriespublic int isMore(AddressDivisionSeries other)
AddressDivisionSeriesisMore in interface AddressDivisionSeriespublic byte[] getBytes()
getBytes in interface AddressItempublic byte[] getBytes(byte[] bytes)
AddressItemgetBytes in interface AddressItempublic byte[] getUpperBytes()
getUpperBytes in interface AddressItempublic byte[] getUpperBytes(byte[] bytes)
AddressItemgetUpperBytes in interface AddressItempublic java.math.BigInteger getValue()
getValue in interface AddressDivisionSeriespublic java.math.BigInteger getUpperValue()
getUpperValue in interface AddressDivisionSeriespublic boolean isZero()
isZero in interface AddressItempublic boolean includesZero()
includesZero in interface AddressItempublic boolean isMax()
isMax in interface AddressItempublic boolean includesMax()
includesMax in interface AddressItempublic boolean isFullRange()
isFullRange in interface AddressItempublic abstract boolean isLocal()
public int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(Address other)
compareTo in interface java.lang.Comparable<Address>public boolean isSameAddress(Address other)
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic abstract boolean contains(Address other)
public HostIdentifierString toAddressString()
public java.lang.String toHexString(boolean with0xPrefix)
toHexString in interface AddressComponentpublic java.lang.String toNormalizedString()
toNormalizedString in interface AddressComponentpublic java.lang.String toCanonicalString()
toCanonicalString in interface AddressSegmentSeriespublic java.lang.String toCompressedString()
toCompressedString in interface AddressSegmentSeriespublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String[] getDivisionStrings()
AddressDivisionSeriesgetDivisionStrings in interface AddressDivisionSeriespublic java.lang.String[] getSegmentStrings()
AddressSegmentSeriesgetSegmentStrings in interface AddressSegmentSeriespublic abstract Address reverseSegments()
AddressSegmentSeriesIncompatibleAddressException since all address series can reverse their segments.reverseSegments in interface AddressSegmentSeriespublic abstract Address reverseBits(boolean perByte)
AddressSegmentSeriesreverseBits in interface AddressComponentreverseBits in interface AddressSegmentSeriesperByte - if true, only the bits in each byte are reversed, if false, then all bits in the component are reversedpublic abstract Address reverseBytes()
AddressSegmentSeriesreverseBytes in interface AddressComponentreverseBytes in interface AddressSegmentSeriespublic abstract Address reverseBytesPerSegment()
AddressSegmentSeriesreverseBytesPerSegment in interface AddressSegmentSeriespublic boolean isPrefixBlock()
isPrefixBlock in interface AddressDivisionSeriespublic boolean containsPrefixBlock(int prefixLength)
AddressDivisionSeriesAddressDivisionSeries.isPrefixBlock() is that AddressDivisionSeries.isPrefixBlock() returns
false if the series does not have a prefix length assigned to it,
even if there exists one or more prefix lengths for which AddressDivisionSeries.containsPrefixBlock(int)
returns true. This method simply returns whether it contains all the values for the given prefix length block
regardless of whether that prefix length has been assigned to this series.
Use AddressDivisionSeries.getMinPrefixLengthForBlock() to determine the smallest prefix length for which this method returns true.
containsPrefixBlock in interface AddressDivisionSeriespublic boolean isSinglePrefixBlock()
isPrefixBlock() except that it returns false when
the subnet has multiple prefixes.
For instance, 1.*.*.* /16 return false for this method and returns true for isPrefixBlock()isSinglePrefixBlock in interface AddressDivisionSeriespublic boolean containsSinglePrefixBlock(int prefixLength)
AddressDivisionSeriesAddressDivisionSeries.isSinglePrefixBlock() is that AddressDivisionSeries.isSinglePrefixBlock() returns
false if the series does not have a prefix length assigned to it,
even if there exists a prefix length for which AddressDivisionSeries.containsSinglePrefixBlock(int)
returns true. This method simply returns whether it contains exactly the values for the given prefix length block
regardless of whether that prefix length has been assigned to this series.
Use AddressDivisionSeries.getPrefixLengthForSingleBlock() to determine whether there is a prefix length for which this method returns true.
containsSinglePrefixBlock in interface AddressDivisionSeriespublic abstract Address toPrefixBlock()
AddressSegmentSeriestoPrefixBlock in interface AddressSegmentSeriespublic abstract Address removePrefixLength()
AddressSegmentSeriesIf the series already has a prefix length, the bits outside the prefix become zero.
removePrefixLength in interface AddressSegmentSeriespublic abstract Address removePrefixLength(boolean zeroed)
AddressSegmentSeriesremovePrefixLength in interface AddressSegmentSerieszeroed - whether the bits outside the prefix become zeropublic abstract Address adjustPrefixBySegment(boolean nextSegment)
AddressSegmentSeries
Follows the same rules as AddressSegmentSeries.adjustPrefixLength(int):
When prefix length is increased, the bits moved within the prefix become zero.
When a prefix length is decreased, the bits moved outside the prefix become zero.
adjustPrefixBySegment in interface AddressSegmentSeriesnextSegment - whether to move prefix to previous or following segment coundarypublic abstract Address adjustPrefixBySegment(boolean nextSegment, boolean zeroed)
AddressSegmentSeriesadjustPrefixBySegment in interface AddressSegmentSeriesnextSegment - whether to move prefix to previous or following segment coundaryzeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original valuespublic abstract Address adjustPrefixLength(int adjustment)
AddressSegmentSeriesWhen prefix length is increased, the bits moved within the prefix become zero. When the prefix is extended beyond the segment series boundary, it is removed. When a prefix length is decreased, the bits moved outside the prefix become zero.
adjustPrefixLength in interface AddressSegmentSeriespublic abstract Address adjustPrefixLength(int adjustment, boolean zeroed)
AddressSegmentSeriesadjustPrefixLength in interface AddressSegmentSeriesadjustment - the incrementzeroed - whether the bits that move from one side of the prefix to the other become zero or retain their original valuespublic abstract Address setPrefixLength(int prefixLength)
AddressSegmentSeriesIf this series has a prefix length, and the prefix length is increased, the bits moved within the prefix become zero.
When the prefix is extended beyond the segment series boundary, it is removed.
The bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.
setPrefixLength in interface AddressSegmentSeriesAddressSegmentSeries.applyPrefixLength(int)public abstract Address setPrefixLength(int prefixLength, boolean zeroed)
AddressSegmentSeriesWhen the prefix is extended beyond the segment series boundary, it is removed.
setPrefixLength in interface AddressSegmentSerieszeroed - whether the bits that move from one side of the prefix length to the other (ie bits moved into the prefix or outside the prefix) are zeroed.public abstract Address applyPrefixLength(int networkPrefixLength)
AddressSegmentSeries
Similar to AddressSegmentSeries.setPrefixLength(int) except that prefix lengths are never increased.
When this series already has a prefix length that is less than or equal to the requested prefix length, this series is returned.
Otherwise the returned series has the given prefix length.
The bits moved outside the prefix will become zero in the returned series.
applyPrefixLength in interface AddressSegmentSeriesAddressSegmentSeries.setPrefixLength(int)