MacAddressUtil { static int compareAddresses(byte[] current, byte[] candidate) { if (candidate == null || candidate.length < EUI48_MAC_ADDRESS_LENGTH) { return 1; } boolean onlyZeroAndOne = true; for (byte b: candidate) { if (b != 0 && b != 1) { onlyZeroAndOne = false; break; } } if (onlyZeroAndOne) { return 1; } if ((candidate[0] & 1) != 0) { return 1; } if ((candidate[0] & 2) == 0) { if (current.length != 0 && (current[0] & 2) == 0) { return 0; } else { return -1; } } else { if (current.length != 0 && (current[0] & 2) == 0) { return 1; } else { return 0; } } } private  MacAddressUtil(); static byte[] bestAvailableMac(); static byte[] defaultMachineId(); static byte[] parseMAC(String value); static String formatAddress(byte[] addr);  }
@Test public void testCompareAddresses() { assertEquals( 0, MacAddressUtil.compareAddresses( EMPTY_BYTES, new byte[]{(byte) 0x52, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd})); assertEquals( -1, MacAddressUtil.compareAddresses( EMPTY_BYTES, new byte[]{(byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd})); assertEquals( -1, MacAddressUtil.compareAddresses( new byte[]{(byte) 0x52, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd}, new byte[]{(byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd})); assertEquals( 1, MacAddressUtil.compareAddresses( new byte[]{(byte) 0x52, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd}, EMPTY_BYTES)); assertEquals( 1, MacAddressUtil.compareAddresses( new byte[]{(byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd}, new byte[]{(byte) 0x52, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd})); assertEquals( 0, MacAddressUtil.compareAddresses( new byte[]{(byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xf9, (byte) 0x32, (byte) 0xbd}, new byte[]{(byte) 0x50, (byte) 0x55, (byte) 0x01, (byte) 0xfa, (byte) 0x33, (byte) 0xbe})); }