public final class MacPrefix extends CacheableDataType implements Comparable<MacPrefix>
Instances of this class are created using the valueOf(byte[])
factory
methods.
A string specification may be used to define the fixed bytes (with either colon or hyphen as the delimiter):
{byte} [ : {byte} [ : ... ] ] or {byte} [ - {byte} [ - ... ] ]where byte represents a hex value in the range 00 to FF.
For example, the specification "FE:00:45"
declares a MAC prefix
where the top 3 bytes are FE, 00, and 45,
and the bottom three bytes may be any value.
Another example, the specification "FE-00-45-12-AB"
declares a MAC
prefix where the top 5 bytes are FE, 00, 45,
12, and AB,
and the bottom byte may be any value.
Alternatively, a byte array may be used to specify the prefix. The byte arrays to produce the prefixes equivalent to the above examples are:
final int B = 256; // makes it easier to read the declared byte arrays byte[] b1 = { 0xfe-B, 00, 0x45 }; byte[] b2 = { 0xfe-B, 00, 0x45, 0x12, 0xab-B };
Modifier and Type | Method and Description |
---|---|
int |
compareTo(MacPrefix o)
Implements the Comparable interface, to return prefixes in
natural order.
|
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
prefixes(MacAddress mac)
Returns true if this MAC prefix applies to the specified MAC address.
|
int |
size()
Returns the number of bytes in this prefix.
|
String |
toString() |
static MacPrefix |
valueOf(byte[] prefixBytes)
Returns an object that represents the value of the MAC prefix defined
by the specified MAC prefix bytes.
|
static MacPrefix |
valueOf(String prefixStr)
Returns an object that represents the value of the MAC prefix defined
by the specified string.
|
getRefQ, keyFromBytes
public int compareTo(MacPrefix o)
compareTo
in interface Comparable<MacPrefix>
o
- the other MAC prefixComparable.compareTo(T)
public int size()
public boolean prefixes(MacAddress mac)
mac
- the address to examinepublic static MacPrefix valueOf(byte[] prefixBytes)
prefixBytes
- the prefix bytesNullPointerException
- if prefixBytes is nullIllegalArgumentException
- if prefixBytes is not an
acceptable lengthpublic static MacPrefix valueOf(String prefixStr)
prefixStr
- the string representation of the MAC prefixNullPointerException
- if prefixStr is nullIllegalArgumentException
- if prefixStr is not an
acceptable formatCopyright © 2015. All Rights Reserved.