public class IPv4Address
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
int[] |
IParray |
Constructor and Description |
---|
IPv4Address()
Builds an uninitialized IP address
|
IPv4Address(java.lang.String ip)
Parses an ip adress from a string.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int number)
Increment the IP address by a number.
|
int |
compareTo(IPv4Address second)
A defacto compare to operation.
|
boolean |
equals(java.lang.Object secondIP)
A defacto equals operation.
|
int[] |
getIP()
Returns an array representing the IP object
|
void |
setIP(int[] IParray)
Set the whole IP array.
|
void |
setIP(int index,
int value)
set the IP array value on the given index 0-3
|
void |
setIP(java.lang.String ip)
Set the IP from an incoming String.
|
java.lang.String |
toString() |
boolean |
validate()
Validate the current IP.
|
public IPv4Address()
public IPv4Address(java.lang.String ip) throws java.lang.Exception
ip
- The incoming String IP in the form x.x.x.x where each
x makes up one octal of the IP address and is >&eq;0 and
<&eq;255.
java.lang.Exception
- Throws an exception if the string isn't
formatted as expectedpublic void setIP(java.lang.String ip) throws java.lang.NumberFormatException, java.lang.StringIndexOutOfBoundsException, java.lang.Exception
ip
- The incoming IP string in the form x.x.x.xjava.lang.NumberFormatException
- if there are illegal characters in
the incoming stringjava.lang.StringIndexOutOfBoundsException
- if the IP is formatted
incorrectlyjava.lang.Exception
- if all else failspublic void setIP(int[] IParray)
IParray
- the int array to setpublic void setIP(int index, int value)
index
- 0-3value
- 0-255public int[] getIP()
public java.lang.String toString()
toString
in class java.lang.Object
public void add(int number) throws java.lang.Exception
number
- The integer number to add to the IPjava.lang.Exception
- if the IP has exceeded the bounds 0.0.0.0 to
255.255.255.255public boolean validate()
public int compareTo(IPv4Address second)
second
- The second IP to compare.public boolean equals(java.lang.Object secondIP)
equals
in class java.lang.Object
secondIP
- IP object to test