com.googlecode.ipv6
Class IPv6Address

java.lang.Object
  extended by com.googlecode.ipv6.IPv6Address
All Implemented Interfaces:
Comparable<IPv6Address>

public final class IPv6Address
extends Object
implements Comparable<IPv6Address>

Immutable representation of an IPv6 address.

Author:
Jan Van Besien

Method Summary
 IPv6Address add(int value)
          Addition.
 int compareTo(IPv6Address that)
           
 boolean equals(Object o)
           
static IPv6Address fromInetAddress(InetAddress inetAddress)
          Create an IPv6 address from a java.net.Inet6Address.
static IPv6Address fromString(String string)
          Create an IPv6 address from its String representation.
 long getHighBits()
           
 long getLowBits()
           
 int hashCode()
           
 IPv6Address maskWithNetworkMask(IPv6NetworkMask networkMask)
          Mask the address with the given network mask.
 IPv6Address maximumAddressWithNetworkMask(IPv6NetworkMask networkMask)
          Calculate the maximum address with the given network mask.
 int numberOfLeadingOnes()
           
 int numberOfLeadingZeroes()
           
 int numberOfTrailingOnes()
           
 int numberOfTrailingZeroes()
           
 IPv6Address subtract(int value)
          Subtraction.
 InetAddress toInetAddress()
           
 String toLongString()
           
 short[] toShortArray()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

fromString

public static IPv6Address fromString(String string)
Create an IPv6 address from its String representation. For example "1234:5678:abcd:0000:9876:3210:ffff:ffff" or "2001::ff" or even "::".

Parameters:
string - string representation
Returns:
IPv6 address

fromInetAddress

public static IPv6Address fromInetAddress(InetAddress inetAddress)
Create an IPv6 address from a java.net.Inet6Address.

Parameters:
inetAddress - Inet6Address representation
Returns:
IPv6 address

toInetAddress

public InetAddress toInetAddress()
                          throws UnknownHostException
Throws:
UnknownHostException

add

public IPv6Address add(int value)
Addition. Will never overflow, but wraps around when the highest ip address has been reached.

Parameters:
value - value to add
Returns:
new IPv6 address

subtract

public IPv6Address subtract(int value)
Subtraction. Will never underflow, but wraps around when the lowest ip address has been reached.

Parameters:
value - value to substract
Returns:
new IPv6 address

maskWithNetworkMask

public IPv6Address maskWithNetworkMask(IPv6NetworkMask networkMask)
Mask the address with the given network mask.

Parameters:
networkMask - network mask
Returns:
an address of which the last 128 - networkMask.asPrefixLength() bits are zero

maximumAddressWithNetworkMask

public IPv6Address maximumAddressWithNetworkMask(IPv6NetworkMask networkMask)
Calculate the maximum address with the given network mask.

Parameters:
networkMask - network mask
Returns:
an address of which the last 128 - networkMask.asPrefixLength() bits are one

toString

public String toString()
Overrides:
toString in class Object
Returns:
String representation of the IPv6 address, using shorthand notation whenever possible.

toLongString

public String toLongString()
Returns:
String representation of the IPv6 address, never using shorthand notation.

toShortArray

public short[] toShortArray()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(IPv6Address that)
Specified by:
compareTo in interface Comparable<IPv6Address>

getHighBits

public long getHighBits()

getLowBits

public long getLowBits()

numberOfTrailingZeroes

public int numberOfTrailingZeroes()

numberOfTrailingOnes

public int numberOfTrailingOnes()

numberOfLeadingZeroes

public int numberOfLeadingZeroes()

numberOfLeadingOnes

public int numberOfLeadingOnes()


Copyright © 2012. All Rights Reserved.