/** * Construct a new instance. * * @param mac A byte array which represents a MAC address. * {@code null} and all-zeroed byte array are treated as * undefined value. * @param vlan VLAN ID. Only lower 12 bits in the value is used. */ public MacVlan(byte[] mac, int vlan) { this((mac == null) ? UNDEFINED : EtherAddress.toLong(mac), vlan); }
/** * Set a hex string which represents an ethernet address. * * <p> * This method is called by JAXB. * </p> * * @param hex A hex strin which represents an ethernet address. */ void setText(String hex) { address = toLong(hex.trim()); }
/** * Construct a new instance. * * @param bytes A byte array which represents an ethernet address. * @throws NullPointerException * {@code bytes} is {@code null}. * @throws IllegalArgumentException * The length of {@code bytes} is not 6. */ public EtherAddress(byte[] bytes) { byteAddress = bytes.clone(); address = toLong(byteAddress); }
/** * Construct a new instance. * * @param hex A hex string which represents an ethernet address. * @throws NullPointerException * {@code hex} is {@code null}. * @throws IllegalArgumentException * The given string is not a string representation of an ethernet * address. */ public EtherAddress(String hex) { // Enforce lower case. String lhex = hex.toLowerCase(Locale.ENGLISH); macAddress = new MacAddress(lhex); address = toLong(lhex); }
/** * Construct a new instance. * * @param mac A {@link MacAddress} instance. * @throws NullPointerException * {@code mac} is {@code null}. * @throws IllegalArgumentException * The given instance contains an invalid value. */ public EtherAddress(MacAddress mac) { // Enforce lower case. String hex = mac.getValue(); String lhex = hex.toLowerCase(Locale.ENGLISH); if (hex.equals(lhex)) { macAddress = mac; } else { macAddress = new MacAddress(lhex); } address = toLong(lhex); }