com.alibaba.druid.support.http.util
Class IPAddress

java.lang.Object
  extended by com.alibaba.druid.support.http.util.IPAddress
All Implemented Interfaces:
Cloneable

public class IPAddress
extends Object
implements Cloneable

This class represents an IP address represented by an 32 bits integer value. Dotted-decimal notation divides the 32-bit Internet address into four 8-bit (byte) fields and specifies the value of each field independently as a decimal number with the fields separated by dots :

    10010001 . 00001010 . 00100010 . 00000011
       145        10         34          3

                -> 145.10.34.3


IP address are classified into three classes :

class A:

    bit#   0  1                 7 8                           31
          +--+-------------------+------------------------------+
          |0 |                   |                              |
          +--+-------------------+------------------------------+
           <-- network number --> <------- host number -------->


class B:

    bit#   0  2                      15 16                    31
          +--+-------------------------+------------------------+
          |10|                         |                        |
          +--+-------------------------+------------------------+
           <----- network number -----> <---- host number ----->


class C:

    bit#   0   3                          23 24               31
          +---+-----------------------------+-------------------+
          |110|                             |                   |
          +---+-----------------------------+-------------------+
           <------- network number --------> <-- host number -->


Version:
1.0
Author:
Marcel Dullaart

Constructor Summary
IPAddress(int address)
          Constructor.
IPAddress(String ipAddressStr)
          Constructor.
 
Method Summary
 boolean equals(Object another)
           
 int getIPAddress()
          Return the integer representation of the IP address.
 int hashCode()
           
 boolean isClassA()
          Check if the IP address is belongs to a Class A IP address.
 boolean isClassB()
          Check if the IP address is belongs to a Class B IP address.
 boolean isClassC()
          Check if the IP address is belongs to a Class C IP address.
 String toString()
          Return the string representation of the IP Address following the common decimal-dotted notation xxx.xxx.xxx.xxx.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IPAddress

public IPAddress(String ipAddressStr)
Constructor.

Parameters:
ip - String representation of the IP address. The format of the ip's string representation must follow the decimal-dotted notation xxx.xxx.xxx.xxx.
Throws:
InvalidIPAddressException - Throws this exception when the specified string doesn't represent a valid IP address.

IPAddress

public IPAddress(int address)
Constructor.

Parameters:
ip - Binary representation of the IP address.
Method Detail

getIPAddress

public final int getIPAddress()
Return the integer representation of the IP address.

Returns:
The IP address.

toString

public String toString()
Return the string representation of the IP Address following the common decimal-dotted notation xxx.xxx.xxx.xxx.

Overrides:
toString in class Object
Returns:
Return the string representation of the IP address.

isClassA

public final boolean isClassA()
Check if the IP address is belongs to a Class A IP address.

Returns:
Return true if the encapsulated IP address belongs to a class A IP address, otherwise returne false.

isClassB

public final boolean isClassB()
Check if the IP address is belongs to a Class B IP address.

Returns:
Return true if the encapsulated IP address belongs to a class B IP address, otherwise returne false.

isClassC

public final boolean isClassC()
Check if the IP address is belongs to a Class C IP address.

Returns:
Return true if the encapsulated IP address belongs to a class C IP address, otherwise returne false.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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


Copyright © 2012 Alibaba Group. All Rights Reserved.