public abstract class IPAddressSeqRange extends Object implements IPAddressRange
Note that the IPAddress and IPAddressString classes allow you to specify a range of values for each segment.
That allows you to represent single addresses, any address prefix subnet (eg 1.2.0.0/16 or 1:2:3:4::/64) or any subnet that can be represented with segment ranges (1.2.0-255.* or 1:2:3:4:*), see
IPAddressString for details.
IPAddressString and IPAddress cover all potential subnets and addresses that can be represented by a single address string of 4 or less segments for IPv4, and 8 or less segments for IPv6.
This class allows the representation of any sequential address range, including those that cannot be represented by IPAddress.
String representations include the full address for both the lower and upper bounds of the range.
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(IPAddress other)
Returns whether this range contains all addresses in the given address or subnet
|
boolean |
contains(IPAddressSeqRange other)
Returns whether this range contains all addresses in the given sequential range
|
boolean |
containsPrefixBlock(int prefixLen)
Returns whether the values of this series contains the prefix block for the given prefix length.
|
boolean |
containsSinglePrefixBlock(int prefixLen)
Returns whether the values of this series contains a single prefix block for the given prefix length.
|
abstract IPAddress |
coverWithPrefixBlock()
Returns the minimal-size prefix block that covers all the addresses in this range.
|
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
IPAddressSeqRange |
extend(IPAddressRange other)
Extend this sequential range to include all address in the given range, which can be an IPAddress or IPAddressSeqRange.
|
int |
getBitCount()
Provides the number of bits comprising this address item
|
byte[] |
getBytes() |
byte[] |
getBytes(byte[] bytes)
Copies the bytes of the lowest address item represented by this address item into the supplied array,
and returns that array.
|
byte[] |
getBytes(byte[] bytes,
int index)
Copies the bytes of the lowest address item represented by this address item into the supplied array starting at the given index,
and returns that array.
|
BigInteger |
getCount()
The count of possible distinct values for this AddressComponent.
|
abstract Iterable<? extends IPAddress> |
getIterable()
Useful for using an instance in a "for-each loop", as in
for(addr : address.getIterable()) { ... |
IPAddress |
getLower()
Returns the address in the range with the lowest numeric value.
|
IPAddress |
getUpper()
Returns the address in the range with the highest numeric value.
|
byte[] |
getUpperBytes() |
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.
|
byte[] |
getUpperBytes(byte[] bytes,
int index)
Copies the bytes of the largest address item represented by this address item into the supplied array at the given index,
and returns that array.
|
BigInteger |
getUpperValue()
Returns the highest value represented by this address item, the highest value included in the range of values
|
BigInteger |
getValue()
Returns the lowest value represented by this address item, the lowest value included in the range of values
|
int |
hashCode()
Returns a hash code value for the object.
|
boolean |
includesMax()
Returns whether this item includes the maximum possible value for the address type or version within its range
|
boolean |
includesZero()
Returns whether this item includes the value of zero within its range
|
IPAddressSeqRange |
intersect(IPAddressSeqRange other)
Returns the intersection of this range with the given range, a range which includes those addresses in both this and the given range.
|
boolean |
isMax()
Returns whether this item matches the maximum possible value for the address type or version
|
boolean |
isMore(IPAddressSeqRange other) |
boolean |
isMultiple()
Whether this represents multiple potential values (eg a prefixed address or a segment representing a range of values)
|
boolean |
isSequential()
Returns whether this range represents a range of values that are sequential.
|
boolean |
isZero()
Returns whether this item matches the value of zero
|
abstract Iterator<? extends IPAddress> |
iterator()
Iterates through the individual addresses of this address or subnet.
|
static IPAddressSeqRange[] |
join(IPAddressSeqRange... ranges)
Joins the given ranges into the fewest number of ranges.
|
IPAddressSeqRange |
join(IPAddressSeqRange other)
If this range overlaps with the given range,
or if the highest value of the lower range is one below the lowest value of the higher range,
then the two are joined into a new larger range that is returned.
|
boolean |
overlaps(IPAddressSeqRange other) |
abstract Iterator<? extends IPAddress> |
prefixBlockIterator(int prefLength)
Iterates through the range of prefix blocks in this range instance using the given prefix length.
|
abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> |
prefixBlockSpliterator(int prefLength)
Partitions and traverses through the individual prefix blocks for the given prefix length.
|
abstract Stream<? extends IPAddress> |
prefixBlockStream(int prefLength)
Returns a sequential stream of the prefix blocks for the given prefix length.
|
Iterator<? extends IPAddressSeqRange> |
prefixIterator(int prefixLength)
Iterates through the range of prefixes in this range instance using the given prefix length.
|
abstract AddressComponentSpliterator<? extends IPAddressSeqRange> |
prefixSpliterator(int prefLength)
Partitions and traverses through the individual prefixes for the given prefix length.
|
abstract Stream<? extends IPAddressSeqRange> |
prefixStream(int prefLength)
Returns a sequential stream of the individual prefixes for the given prefix length.
|
abstract IPAddress[] |
spanWithPrefixBlocks()
Produces an array of prefix blocks that spans the same set of addresses.
|
abstract IPAddress[] |
spanWithSequentialBlocks()
Produces an array of blocks that are sequential that cover the same set of addresses.
|
abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> |
spliterator()
Partitions and traverses through the individual addresses.
|
abstract Stream<? extends IPAddress> |
stream()
Returns a sequential stream of the individual address components.
|
IPAddressSeqRange[] |
subtract(IPAddressSeqRange other)
Subtracts the given range from this range, to produce either zero, one, or two address ranges that contain the addresses in this range and not in the given range.
|
String |
toCanonicalString()
Produces a string that is unique and uses the canonical representation for all instances.
|
String |
toCanonicalString(String separator) |
String |
toNormalizedString()
Produces a string that is unique and consistent for all instances.
|
String |
toNormalizedString(String separator) |
String |
toString()
Returns a string representation of the object.
|
String |
toString(Function<? super IPAddress,String> lowerStringer,
String separator,
Function<? super IPAddress,String> upperStringer) |
toSequentialRangestream, streamcompareTo, getByteCount, getMinPrefixLengthForBlock, getPrefixCount, getPrefixLengthForSingleBlock, isFullRangepublic BigInteger getCount()
AddressItemgetCount in interface AddressItempublic boolean isMultiple()
AddressItemisMultiple in interface AddressItempublic boolean isMore(IPAddressSeqRange other)
other - the range to compare, which does not need to range across the same address spacepublic abstract Iterable<? extends IPAddress> getIterable()
IPAddressRangefor(addr : address.getIterable()) { ... }
Otherwise just call IPAddressRange.iterator() directly.
getIterable in interface AddressComponentRangegetIterable in interface IPAddressRangepublic abstract Iterator<? extends IPAddress> prefixBlockIterator(int prefLength)
prefixBlockIterator in interface IPAddressRangeprefLength - public abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> prefixBlockSpliterator(int prefLength)
IPAddressRangeprefixBlockSpliterator in interface IPAddressRangepublic abstract Stream<? extends IPAddress> prefixBlockStream(int prefLength)
IPAddressRangeBaseStream.parallel() on the returned stream.prefixBlockStream in interface IPAddressRangepublic Iterator<? extends IPAddressSeqRange> prefixIterator(int prefixLength)
Since a range between two arbitrary addresses cannot always be represented with a single IPAddress instance, the returned iterator iterates through IPAddressRange instances.
For instance, if iterating from 1.2.3.4 to 1.2.4.5 with prefix 8, the range shares the same prefix 1, but the range cannot be represented by the address 1.2.3-4.4-5 which does not include 1.2.3.255 or 1.2.4.0 both of which are in the original range. Nor can the range be represented by 1.2.3-4.0-255 which includes 1.2.4.6 and 1.2.3.3, both of which were not in the original range. An IPAddressSeqRange is thus required to represent that prefixed range.
prefixIterator in interface IPAddressRangeprefixLength - public abstract AddressComponentSpliterator<? extends IPAddressSeqRange> prefixSpliterator(int prefLength)
IPAddressRangeprefixSpliterator in interface IPAddressRangepublic abstract Stream<? extends IPAddressSeqRange> prefixStream(int prefLength)
IPAddressRangeBaseStream.parallel() on the returned stream.prefixStream in interface IPAddressRangepublic abstract Iterator<? extends IPAddress> iterator()
IPAddressRange
Call AddressItem.isMultiple() to determine if this instance represents multiple, or AddressItem.getCount() for the count.
iterator in interface AddressComponentRangeiterator in interface IPAddressRangepublic abstract AddressComponentRangeSpliterator<? extends IPAddressSeqRange,? extends IPAddress> spliterator()
IPAddressRangespliterator in interface AddressComponentRangespliterator in interface IPAddressRangepublic abstract Stream<? extends IPAddress> stream()
AddressComponentRangeBaseStream.parallel() on the returned stream.stream in interface AddressComponentRangepublic IPAddress getLower()
IPAddressRangegetLower in interface AddressComponentRangegetLower in interface IPAddressRangepublic IPAddress getUpper()
IPAddressRangegetUpper in interface AddressComponentRangegetUpper in interface IPAddressRangepublic String toNormalizedString()
IPAddressRangetoNormalizedString in interface IPAddressRangepublic String toCanonicalString()
IPAddressRangetoCanonicalString in interface IPAddressRangepublic String toString(Function<? super IPAddress,String> lowerStringer, String separator, Function<? super IPAddress,String> upperStringer)
public String toString()
java.lang.ObjecttoString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public abstract IPAddress coverWithPrefixBlock()
IPAddressRangecoverWithPrefixBlock in interface IPAddressRangepublic abstract IPAddress[] spanWithPrefixBlocks()
IPAddressRangespanWithPrefixBlocks in interface IPAddressRangepublic abstract IPAddress[] spanWithSequentialBlocks()
IPAddressRangeIPAddressRange.spanWithPrefixBlocks() and is never longer.spanWithSequentialBlocks in interface IPAddressRangepublic static IPAddressSeqRange[] join(IPAddressSeqRange... ranges)
ranges - public boolean overlaps(IPAddressSeqRange other)
public boolean contains(IPAddress other)
IPAddressRangecontains in interface IPAddressRangepublic boolean contains(IPAddressSeqRange other)
IPAddressRangecontains in interface IPAddressRangepublic boolean isSequential()
IPAddressRangeisSequential in interface IPAddressRangepublic int hashCode()
java.lang.ObjectHashMap.
The general contract of hashCode is:
hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashCode in class ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public boolean equals(Object o)
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 Objecto - the reference object with which to compare.true if this object is the same as the obj
argument; false otherwise.Object.hashCode(),
HashMappublic IPAddressSeqRange intersect(IPAddressSeqRange other)
other - public IPAddressSeqRange join(IPAddressSeqRange other)
Otherwise null is returned.
other - public IPAddressSeqRange extend(IPAddressRange other)
other - public IPAddressSeqRange[] subtract(IPAddressSeqRange other)
other - public boolean containsPrefixBlock(int prefixLen)
AddressItem
Use AddressItem.getMinPrefixLengthForBlock() to determine the smallest prefix length for which this method returns true.
containsPrefixBlock in interface AddressItempublic boolean containsSinglePrefixBlock(int prefixLen)
AddressItem
Use AddressItem.getPrefixLengthForSingleBlock() to determine whether there is a prefix length for which this method returns true.
containsSinglePrefixBlock in interface AddressItempublic int getBitCount()
AddressItemgetBitCount in interface AddressItempublic byte[] getBytes()
getBytes in interface AddressItempublic byte[] getBytes(byte[] bytes)
AddressItemgetBytes in interface AddressItempublic byte[] getBytes(byte[] bytes,
int index)
AddressItemgetBytes in interface AddressItempublic byte[] getUpperBytes()
getUpperBytes in interface AddressItempublic byte[] getUpperBytes(byte[] bytes)
AddressItemgetUpperBytes in interface AddressItempublic byte[] getUpperBytes(byte[] bytes,
int index)
AddressItemgetUpperBytes in interface AddressItempublic BigInteger getValue()
AddressItemgetValue in interface AddressItempublic BigInteger getUpperValue()
AddressItemgetUpperValue in interface AddressItempublic boolean isZero()
AddressItemisZero in interface AddressItempublic boolean includesZero()
AddressItemincludesZero in interface AddressItempublic boolean isMax()
AddressItemisMax in interface AddressItempublic boolean includesMax()
AddressItemincludesMax in interface AddressItem