Package com.googlecode.ipv6
Class IPv6AddressRange
- java.lang.Object
-
- com.googlecode.ipv6.IPv6AddressRange
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<IPv6AddressRange>,java.lang.Iterable<IPv6Address>
- Direct Known Subclasses:
IPv6Network
public class IPv6AddressRange extends java.lang.Object implements java.lang.Comparable<IPv6AddressRange>, java.lang.Iterable<IPv6Address>, java.io.Serializable
Immutable representation of a continuous range of IPv6 addresses (bounds included).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classIPv6AddressRange.IPv6AddressRangeAsSubnetsIteratorprivate classIPv6AddressRange.IPv6AddressRangeIterator
-
Field Summary
Fields Modifier and Type Field Description private IPv6Addressfirstprivate IPv6Addresslast
-
Constructor Summary
Constructors Constructor Description IPv6AddressRange(IPv6Address first, IPv6Address last)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(IPv6AddressRange that)The natural order ofIPv6AddressRanges orders them on increasing first addresses, and on increasing last address if the first address would be equal.booleancontains(IPv6Address address)booleancontains(IPv6AddressRange range)booleanequals(java.lang.Object o)IPv6AddressRangeextend(IPv6Address address)Extend the range just enough at its head or tail such that the given address is included.static IPv6AddressRangefromFirstAndLast(IPv6Address first, IPv6Address last)IPv6AddressgetFirst()IPv6AddressgetLast()inthashCode()java.util.Iterator<IPv6Address>iterator()booleanoverlaps(IPv6AddressRange range)java.util.List<IPv6AddressRange>remove(IPv6Address address)Remove an address from the range, resulting in one, none or two new ranges.java.util.List<IPv6AddressRange>remove(IPv6Network network)Remove a network from the range, resulting in one, none or two new ranges.java.math.BigIntegersize()java.lang.StringtoLongString()java.lang.StringtoString()java.util.Iterator<IPv6Network>toSubnets()Deaggregate a range of IPv6 addresses (which is not necessarily aligned with a single IPv6 network) into a minimal set of non overlapping consecutive subnets.
-
-
-
Field Detail
-
first
private final IPv6Address first
-
last
private final IPv6Address last
-
-
Constructor Detail
-
IPv6AddressRange
IPv6AddressRange(IPv6Address first, IPv6Address last)
-
-
Method Detail
-
fromFirstAndLast
public static IPv6AddressRange fromFirstAndLast(IPv6Address first, IPv6Address last)
-
contains
public boolean contains(IPv6Address address)
-
contains
public boolean contains(IPv6AddressRange range)
-
overlaps
public boolean overlaps(IPv6AddressRange range)
-
iterator
public java.util.Iterator<IPv6Address> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<IPv6Address>- Returns:
- an iterator which iterates all addresses in this range, in order.
-
size
public java.math.BigInteger size()
- Returns:
- number of addresses in the range
-
toSubnets
public java.util.Iterator<IPv6Network> toSubnets()
Deaggregate a range of IPv6 addresses (which is not necessarily aligned with a single IPv6 network) into a minimal set of non overlapping consecutive subnets.- Returns:
- iterator of IPv6 networks that all together define the minimal set of subnets by which the range can be represented.
-
remove
public java.util.List<IPv6AddressRange> remove(IPv6Address address)
Remove an address from the range, resulting in one, none or two new ranges. If an address outside the range is removed, this has no effect. If the first or last address is removed, a single new range is returned (potentially empty if the range only contained a single address). If an address somewhere else in the range is removed, two new ranges are returned.- Parameters:
address- adddress to remove from the range- Returns:
- list of resulting ranges
-
extend
public IPv6AddressRange extend(IPv6Address address)
Extend the range just enough at its head or tail such that the given address is included.- Parameters:
address- address to extend the range to- Returns:
- new (bigger) range
-
remove
public java.util.List<IPv6AddressRange> remove(IPv6Network network)
Remove a network from the range, resulting in one, none or two new ranges. If a network outside (or partially outside) the range is removed, this has no effect. If the network which is removed is aligned with the beginning or end of the range, a single new ranges is returned (potentially empty if the range was equal to the network which is removed from it). If a network somewhere else in the range is removed, two new ranges are returned.- Parameters:
network- network to remove from the range- Returns:
- list of resulting ranges
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toLongString
public java.lang.String toLongString()
- Returns:
- like
toStringbut without using shorthand notations for addresses
-
compareTo
public int compareTo(IPv6AddressRange that)
The natural order ofIPv6AddressRanges orders them on increasing first addresses, and on increasing last address if the first address would be equal.Note that the natural order does thus not compare sizes of ranges.
- Specified by:
compareToin interfacejava.lang.Comparable<IPv6AddressRange>- Parameters:
that- range to compare with- Returns:
- negative, zero or positive depending on whether this is smaller, equal or greater than that
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getFirst
public IPv6Address getFirst()
-
getLast
public IPv6Address getLast()
-
-