@Test public void testCompareTo() { IeeeAddress address1 = new IeeeAddress("17880100dc880b"); IeeeAddress address2 = new IeeeAddress("17880100dc880b"); assertEquals(0, address1.compareTo(address2)); address2 = new IeeeAddress("17880100dc880c"); assertEquals(-1, address1.compareTo(address2)); address2 = new IeeeAddress("17880100dc880a"); assertEquals(1, address1.compareTo(address2)); address2 = new IeeeAddress("27880100dc880c"); assertEquals(-1, address1.compareTo(address2)); address2 = new IeeeAddress("17880120dc880c"); assertEquals(-1, address1.compareTo(address2)); address2 = new IeeeAddress("16880100dc880b"); assertEquals(1, address1.compareTo(address2)); }
@Override public int compareTo(IeeeAddress other) { if (other == null) { return -1; } if (!IeeeAddress.class.isAssignableFrom(other.getClass())) { return -1; } for (int cnt = 0; cnt < 8; cnt++) { if (other.getValue()[cnt] == address[cnt]) { continue; } return other.getValue()[cnt] < address[cnt] ? 1 : -1; } return 0; }
IeeeAddress implements Comparable<IeeeAddress> { @Override public int compareTo(IeeeAddress other) { if (other == null) { return -1; } if (!IeeeAddress.class.isAssignableFrom(other.getClass())) { return -1; } for (int cnt = 0; cnt < 8; cnt++) { if (other.getValue()[cnt] == address[cnt]) { continue; } return other.getValue()[cnt] < address[cnt] ? 1 : -1; } return 0; } }
IeeeAddress implements Comparable<IeeeAddress> { @Override public int compareTo(IeeeAddress other) { if (other == null) { return -1; } if (!IeeeAddress.class.isAssignableFrom(other.getClass())) { return -1; } for (int cnt = 0; cnt < 8; cnt++) { if (other.getValue()[cnt] == address[cnt]) { continue; } return other.getValue()[cnt] < address[cnt] ? 1 : -1; } return 0; } IeeeAddress();  IeeeAddress(BigInteger address);  IeeeAddress(String address);  IeeeAddress(int[] address); }
IeeeAddress implements Comparable<IeeeAddress> { @Override public int compareTo(IeeeAddress other) { if (other == null) { return -1; } if (!IeeeAddress.class.isAssignableFrom(other.getClass())) { return -1; } for (int cnt = 0; cnt < 8; cnt++) { if (other.getValue()[cnt] == address[cnt]) { continue; } return other.getValue()[cnt] < address[cnt] ? 1 : -1; } return 0; } IeeeAddress();  IeeeAddress(BigInteger address);  IeeeAddress(String address);  IeeeAddress(int[] address); int[] getValue(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(IeeeAddress other); }
IeeeAddress implements Comparable<IeeeAddress> { @Override public int compareTo(IeeeAddress other) { if (other == null) { return -1; } if (!IeeeAddress.class.isAssignableFrom(other.getClass())) { return -1; } for (int cnt = 0; cnt < 8; cnt++) { if (other.getValue()[cnt] == address[cnt]) { continue; } return other.getValue()[cnt] < address[cnt] ? 1 : -1; } return 0; } IeeeAddress();  IeeeAddress(BigInteger address);  IeeeAddress(String address);  IeeeAddress(int[] address); int[] getValue(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(IeeeAddress other);  }