Brooklyn

brooklyn.util.net
[Java] Class Cidr

java.lang.Object
  brooklyn.util.net.Cidr

public class Cidr

represents a CIDR (classless inter-domain routing) token, i.e. 10.0.0.0/8 or 192.168.4.0/24


Field Summary
static Cidr CLASS_A

static Cidr CLASS_B

static Cidr CLASS_C

static Cidr LINK_LOCAL

static Cidr LOOPBACK

static java.util.List NON_PUBLIC_CIDRS

static java.util.List PRIVATE_NETWORKS_RFC_1918

static Cidr UNIVERSAL

static Cidr _10

static Cidr _127

static Cidr _169_254

static Cidr _172_16

static Cidr _192_168

 
Constructor Summary
Cidr(java.lang.String cidr)

Cidr(int... unsignedBytes)

allows creation as Cidr(192, 168) for 192.168.0.0/16; zero bits or ints included are significant, i.e.

Cidr(int[] subnetBytes, int length)

 
Method Summary
java.net.InetAddress addressAtOffset(int offset)

taking the addresses in the CIDR in order, returns the one in the offset^th position (starting with the CIDR itself, even if final bits are 0)

BitList asBitList()

returns list of bits for the significant (length) bits of this CIDR

Cidr commonPrefix(Cidr other)

int commonPrefixLength(Cidr other)

returns length of the prefix in common between the two cidrs

boolean contains(Cidr target)

boolean equals(java.lang.Object obj)

int[] getBytes()

int getLength()

int hashCode()

static boolean isCanonical(java.lang.String cidr)

returns true iff this CIDR is well-formed and canonical, i.e. 4 dot-separated bytes followed by a slash and a length, where length is <= 32, and the preceding 4 bytes don't include any 1 bits beyond the indicated length; e.g. 10.0.0.0/8 -- but not 10.0.0.1/8 or 10.../8 (although the latter ones are accepted by the constructor and converted to the canonical CIDR)

java.net.InetAddress netmask()

returns the netmask for this cidr; e.g. for a /24 cidr returns 255.255.255.0

Cidr subnet(int... extraUnsignedBytes)

java.lang.String toString()

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

CLASS_A

public static final Cidr CLASS_A


CLASS_B

public static final Cidr CLASS_B


CLASS_C

public static final Cidr CLASS_C


LINK_LOCAL

public static final Cidr LINK_LOCAL


LOOPBACK

public static final Cidr LOOPBACK


NON_PUBLIC_CIDRS

public static final java.util.List NON_PUBLIC_CIDRS


PRIVATE_NETWORKS_RFC_1918

public static final java.util.List PRIVATE_NETWORKS_RFC_1918


UNIVERSAL

public static final Cidr UNIVERSAL


_10

public static final Cidr _10


_127

public static final Cidr _127


_169_254

public static final Cidr _169_254


_172_16

public static final Cidr _172_16


_192_168

public static final Cidr _192_168


 
Constructor Detail

Cidr

public Cidr(java.lang.String cidr)


Cidr

public Cidr(int... unsignedBytes)
allows creation as Cidr(192, 168) for 192.168.0.0/16; zero bits or ints included are significant, i.e. Cidr(10, 0) gives 10.0.0.0/16


Cidr

public Cidr(int[] subnetBytes, int length)


 
Method Detail

addressAtOffset

public java.net.InetAddress addressAtOffset(int offset)
taking the addresses in the CIDR in order, returns the one in the offset^th position (starting with the CIDR itself, even if final bits are 0)


asBitList

public BitList asBitList()
returns list of bits for the significant (length) bits of this CIDR


commonPrefix

public Cidr commonPrefix(Cidr other)


commonPrefixLength

public int commonPrefixLength(Cidr other)
returns length of the prefix in common between the two cidrs


contains

public boolean contains(Cidr target)


equals

@Override
public boolean equals(java.lang.Object obj)


getBytes

public int[] getBytes()


getLength

public int getLength()


hashCode

@Override
public int hashCode()


isCanonical

public static boolean isCanonical(java.lang.String cidr)
returns true iff this CIDR is well-formed and canonical, i.e. 4 dot-separated bytes followed by a slash and a length, where length is <= 32, and the preceding 4 bytes don't include any 1 bits beyond the indicated length; e.g. 10.0.0.0/8 -- but not 10.0.0.1/8 or 10.../8 (although the latter ones are accepted by the constructor and converted to the canonical CIDR)


netmask

public java.net.InetAddress netmask()
returns the netmask for this cidr; e.g. for a /24 cidr returns 255.255.255.0


subnet

public Cidr subnet(int... extraUnsignedBytes)


toString

@Override
public java.lang.String toString()


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.