org.doomdark.uuid
Class EthernetAddress

java.lang.Object
  extended by org.doomdark.uuid.EthernetAddress
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class EthernetAddress
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

EthernetAddress encapsulates the 6-byte Mac address defined in IEEE 802.1 standard.

See Also:
Serialized Form

Constructor Summary
EthernetAddress(byte[] addr)
          Binary constructor that constructs an instance given the 6 byte (48-bit) address.
EthernetAddress(long addr)
          Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.
EthernetAddress(java.lang.String addrStr)
          String constructor; given a 'standard' ethernet MAC address string (like '00:C0:F0:3D:5B:7C'), constructs an EthernetAddress instance.
 
Method Summary
 byte[] asByteArray()
          Returns 6 byte byte array that contains the binary representation of this ethernet address; byte 0 is the most significant byte (and so forth)
 java.lang.Object clone()
          Default cloning behaviour (bitwise copy) is just fine...
 int compareTo(java.lang.Object o)
          Method that compares this EthernetAddress to one passed in as argument.
 boolean equals(java.lang.Object o)
           
static void main(java.lang.String[] args)
           
 byte[] toByteArray()
          Synonym to 'asByteArray()'
 void toByteArray(byte[] array)
           
 void toByteArray(byte[] array, int pos)
           
 long toLong()
           
 java.lang.String toString()
          Returns the canonical string representation of this ethernet address.
static EthernetAddress valueOf(byte[] addr)
          Constructs a new EthernetAddress given the byte array that contains binary representation of the address.
static EthernetAddress valueOf(int[] addr)
          Constructs a new EthernetAddress given the byte array that contains binary representation of the address.
static EthernetAddress valueOf(long addr)
          Constructs a new EthernetAddress given the long int value (64-bit) representation of the ethernet address (of which 48 LSB contain the definition) Note that calling this method returns the same result as would using the matching constructor.
static EthernetAddress valueOf(java.lang.String addrStr)
          Constructs a new EthernetAddress given a string representation of the ethernet address.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EthernetAddress

public EthernetAddress(java.lang.String addrStr)
                throws java.lang.NumberFormatException
String constructor; given a 'standard' ethernet MAC address string (like '00:C0:F0:3D:5B:7C'), constructs an EthernetAddress instance. Note that string is case-insensitive, and also that leading zeroes may be omitted. Thus '00:C0:F0:3D:5B:7C' and '0:c0:f0:3d:5b:7c' are equivalent, and a 'null' address could be passed as ':::::' as well as '00:00:00:00:00:00' (or any other intermediate combination).

Parameters:
addrStr - String representation of the ethernet address
Throws:
java.lang.NumberFormatException

EthernetAddress

public EthernetAddress(byte[] addr)
                throws java.lang.NumberFormatException
Binary constructor that constructs an instance given the 6 byte (48-bit) address. Useful if an address is saved in binary format (for saving space for example).

Throws:
java.lang.NumberFormatException

EthernetAddress

public EthernetAddress(long addr)
Another binary constructor; constructs an instance from the given long argument; the lowest 6 bytes contain the address.

Parameters:
addr - long that contains the MAC address in 6 least significant bytes.
Method Detail

clone

public java.lang.Object clone()
Default cloning behaviour (bitwise copy) is just fine...

Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Method that compares this EthernetAddress to one passed in as argument. Comparison is done simply by comparing individual address bytes in the order.

Specified by:
compareTo in interface java.lang.Comparable
Returns:
-1 if this EthernetAddress should be sorted before the one passed in, 1 if after and 0 if they are equal.

toString

public java.lang.String toString()
Returns the canonical string representation of this ethernet address. Canonical means that all characters are lower-case and string length is always 17 characters (ie. leading zeroes are not omitted).

Overrides:
toString in class java.lang.Object
Returns:
Canonical string representation of this ethernet address.

asByteArray

public byte[] asByteArray()
Returns 6 byte byte array that contains the binary representation of this ethernet address; byte 0 is the most significant byte (and so forth)

Returns:
6 byte byte array that contains the binary representation

toByteArray

public byte[] toByteArray()
Synonym to 'asByteArray()'

Returns:
6 byte byte array that contains the binary representation

toByteArray

public void toByteArray(byte[] array)

toByteArray

public void toByteArray(byte[] array,
                        int pos)

toLong

public long toLong()

valueOf

public static EthernetAddress valueOf(byte[] addr)
                               throws java.lang.NumberFormatException
Constructs a new EthernetAddress given the byte array that contains binary representation of the address. Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addr - Binary representation of the ethernet address
Throws:
java.lang.NumberFormatException - if addr is invalid (less or more than 6 bytes in array)

valueOf

public static EthernetAddress valueOf(int[] addr)
                               throws java.lang.NumberFormatException
Constructs a new EthernetAddress given the byte array that contains binary representation of the address. Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addr - Binary representation of the ethernet address
Throws:
java.lang.NumberFormatException - if addr is invalid (less or more than 6 ints in array)

valueOf

public static EthernetAddress valueOf(java.lang.String addrStr)
                               throws java.lang.NumberFormatException
Constructs a new EthernetAddress given a string representation of the ethernet address. Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addrStr - String representation of the ethernet address
Throws:
java.lang.NumberFormatException - if addr representation is invalid

valueOf

public static EthernetAddress valueOf(long addr)
Constructs a new EthernetAddress given the long int value (64-bit) representation of the ethernet address (of which 48 LSB contain the definition) Note that calling this method returns the same result as would using the matching constructor.

Parameters:
addr - Long int representation of the ethernet address

main

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


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.