verinec.netsim.addresses
Class MACAddress

java.lang.Object
  extended by verinec.netsim.addresses.MACAddress
All Implemented Interfaces:
Comparable, IAddress

public class MACAddress
extends Object
implements IAddress

This class is an MACAddress that uses a six byte representation divided by semicolons. e.g. ef:01:12:55:4f:02

Version:
$Revision: 616 $
Author:
Dominik Jungo

Field Summary
private  byte[] address
           
 
Constructor Summary
MACAddress()
          Constructs a new MACAddress with the Value 00:00:00:00:00:00
MACAddress(byte m0, byte m1, byte m2, byte m3, byte m4, byte m5)
          Constructs a new MACAddress with the Value m0:m1:m2:m3:m4:m5
MACAddress(String address)
          Constructs a new MACAddress form a String.
 
Method Summary
static MACAddress broadcastAddress()
          gets the MAC broadcast address
private  int compareTo(MACAddress address, int part)
          Starts comparing recursively this Address with address from the part'th byte on.
 int compareTo(Object arg0)
           
static MACAddress createRandomAddress()
          Creates a random MAC Address.
 boolean equals(IAddress address)
          Tests if an address is equal to this address.
private  int getPart(int part)
           
private  char hexLowerChar(byte b)
           
private  char hexUpperChar(byte b)
           
 String toString()
          Converts this MACAddress into the semicolon separated String format xx:xx:xx:xx:xx:xx
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

address

private byte[] address
Constructor Detail

MACAddress

public MACAddress()
Constructs a new MACAddress with the Value 00:00:00:00:00:00


MACAddress

public MACAddress(byte m0,
                  byte m1,
                  byte m2,
                  byte m3,
                  byte m4,
                  byte m5)
Constructs a new MACAddress with the Value m0:m1:m2:m3:m4:m5

Parameters:
m0 - first byte of the Address
m1 - second byte of the Address
m2 - third byte of the Address
m3 - fourth byte of the Address
m4 - fifth byte of the Address
m5 - sixth byte of the Address

MACAddress

public MACAddress(String address)
Constructs a new MACAddress form a String.

Parameters:
address - in String representation with colons between the six bytes.
Method Detail

broadcastAddress

public static MACAddress broadcastAddress()
gets the MAC broadcast address

Returns:
the MAC broadcast address

createRandomAddress

public static MACAddress createRandomAddress()
Creates a random MAC Address. The Address will may be not unique, if someone else creates the same address by chance.

Returns:
a randomly created MAC Address

compareTo

private int compareTo(MACAddress address,
                      int part)
Starts comparing recursively this Address with address from the part'th byte on. Comparing is byte-wise.

Parameters:
address -
part - value
Returns:
0 if the adresses are equal, -1 if this address is smaller and 1 if this address is bigger.

compareTo

public int compareTo(Object arg0)
Specified by:
compareTo in interface Comparable
See Also:
Comparable.compareTo(java.lang.Object)

equals

public boolean equals(IAddress address)
Description copied from interface: IAddress
Tests if an address is equal to this address. Equal in this case does not mean the same address object but both represent the same address.

Specified by:
equals in interface IAddress
Parameters:
address - an address to compare with this Address
Returns:
true if both adresses have an equal String represenation, false otherwise.
See Also:
IAddress.equals(verinec.netsim.addresses.IAddress)

getPart

private int getPart(int part)

hexLowerChar

private char hexLowerChar(byte b)

hexUpperChar

private char hexUpperChar(byte b)

toString

public String toString()
Converts this MACAddress into the semicolon separated String format xx:xx:xx:xx:xx:xx

Specified by:
toString in interface IAddress
Overrides:
toString in class Object
Returns:
this Address.
See Also:
IAddress.toString()

Copyright © 2005 Verinec, DIUF