com.foxsmart.ic.net
Class MacAddress

java.lang.Object
  extended by com.foxsmart.ic.net.MacAddress
All Implemented Interfaces:
java.io.Serializable

public class MacAddress
extends java.lang.Object
implements java.io.Serializable

This class represents a 48-bit hardware MAC (Medium Access Control Layer) address. The 48-bit address is comprised of 3 double octets, each double octet representing 16 bits (e.g. ffff). Single octet (e.g. NN-NN-NN-NN-NN-NN) and double octet (e.g. NNNN.NNNN.NNNN) formats are both supported.

See Also:
Serialized Form

Field Summary
static Hexadecimal MAX_DOUBLE_OCTET_RANGE
           
static Hexadecimal MIN_DOUBLE_OCTET_RANGE
           
 
Constructor Summary
MacAddress()
          Constructs an empty Mac Address (i.e.
MacAddress(java.lang.String macAddress)
          Constructs a Mac Address based on either an octet or double octet string.
 
Method Summary
 Hexadecimal getDoubleOctet1()
          Gets the first double octet.
 Hexadecimal getDoubleOctet2()
          Gets the second double octet.
 Hexadecimal getDoubleOctet3()
          Gets the third double octet.
 boolean getUppercase()
          Returns whether the toString method will return upper case or not.
static void main(java.lang.String[] args)
          Test driver.
 void setDoubleOctet1(Hexadecimal doubleOctet1)
          Sets the first double octet.
 void setDoubleOctet2(Hexadecimal doubleOctet2)
          Sets the second double octet.
 void setDoubleOctet3(Hexadecimal doubleOctet3)
          Sets the third double octet.
 void setDoubleOctetAddress(java.lang.String doubleOctet)
          Sets the Mac Address based on a double octet string representation (e.g.
 void setOctetAddress(java.lang.String doubleOctet)
          Sets the Mac Address based on an octet string representation (e.g.
 void setUppercase(boolean uppercase)
          Determines whether the toString return value will be in upper case or lower case.
 java.lang.String toDoubleOctetString()
          Returns a string representation of this Mac Address.
 java.lang.String toOctetString()
          Returns a string representation of this Mac Address.
 java.lang.String toString()
          Returns a string representation of this Mac Address.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_DOUBLE_OCTET_RANGE

public static final Hexadecimal MIN_DOUBLE_OCTET_RANGE

MAX_DOUBLE_OCTET_RANGE

public static final Hexadecimal MAX_DOUBLE_OCTET_RANGE
Constructor Detail

MacAddress

public MacAddress()
Constructs an empty Mac Address (i.e. all zeros).


MacAddress

public MacAddress(java.lang.String macAddress)
Constructs a Mac Address based on either an octet or double octet string. See the setOctetAddress or setDoubleOctetAddress methods for more information on formatting.

Parameters:
macAddress - The string representation of the mac address.
Throws:
java.lang.NumberFormatException - if the string can't be converted to a MacAddress.
Method Detail

setDoubleOctetAddress

public void setDoubleOctetAddress(java.lang.String doubleOctet)
                           throws java.lang.NumberFormatException
Sets the Mac Address based on a double octet string representation (e.g. NNNN.NNNN.NNNN).

Parameters:
doubleOctet - the double octet address.
Throws:
java.lang.NumberFormatException - if the string can't be converted to a MacAddress.

setOctetAddress

public void setOctetAddress(java.lang.String doubleOctet)
                     throws java.lang.NumberFormatException
Sets the Mac Address based on an octet string representation (e.g. NN-NN-NN-NN-NN-NN).

Parameters:
doubleOctet - the double octet address.
Throws:
java.lang.NumberFormatException - if the string can't be converted to a MacAddress.

setDoubleOctet1

public void setDoubleOctet1(Hexadecimal doubleOctet1)
                     throws java.lang.NumberFormatException
Sets the first double octet.

Parameters:
doubleOctet1 - The first double octet.
Throws:
java.lang.NumberFormatException - if the hexadecimal value is out of range.

getDoubleOctet1

public Hexadecimal getDoubleOctet1()
Gets the first double octet.

Returns:
the first double octet.

setDoubleOctet2

public void setDoubleOctet2(Hexadecimal doubleOctet2)
                     throws java.lang.NumberFormatException
Sets the second double octet.

Parameters:
doubleOctet2 - The second double octet.
Throws:
java.lang.NumberFormatException - if the hexadecimal value is out of range.

getDoubleOctet2

public Hexadecimal getDoubleOctet2()
Gets the second double octet.

Returns:
the second double octet.

setDoubleOctet3

public void setDoubleOctet3(Hexadecimal doubleOctet3)
                     throws java.lang.NumberFormatException
Sets the third double octet.

Parameters:
doubleOctet3 - The third double octet.
Throws:
java.lang.NumberFormatException - if the hexadecimal value is out of range.

getDoubleOctet3

public Hexadecimal getDoubleOctet3()
Gets the third double octet.

Returns:
the third double octet.

toString

public java.lang.String toString()
Returns a string representation of this Mac Address. The Octet string version is used (see toOctetString).

Overrides:
toString in class java.lang.Object

toOctetString

public java.lang.String toOctetString()
Returns a string representation of this Mac Address. The format returned is NN-NN-NN-NN-NN-NN (e.g. AC-DE-48-00-00-80).

Returns:
the octet string.

toDoubleOctetString

public java.lang.String toDoubleOctetString()
Returns a string representation of this Mac Address. The format returned is NNNN.NNNN.NNNN (e.g. ACDE.4800.0080).

Returns:
the octet string.

setUppercase

public void setUppercase(boolean uppercase)
Determines whether the toString return value will be in upper case or lower case. The default is upper case.

Parameters:
uppercase - Set to true for upper case or false for lower case.

getUppercase

public boolean getUppercase()
Returns whether the toString method will return upper case or not.

Returns:
True if all upper case or false if lower case.

main

public static void main(java.lang.String[] args)
Test driver.

Parameters:
args - The arguments.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.