ResultCodes implements Comparable<ResultCodes> { @Override @SuppressWarnings("PMD.CyclomaticComplexity") public int compareTo(final ResultCodes o) { if (o.resultCodes.length == 0 && this.resultCodes.length == 0) { return 0; } if (o.resultCodes.length == 0) { return -1; } if (this.resultCodes.length == 0) { return 1; } final boolean isSameSize = o.resultCodes.length == this.resultCodes.length; if (isSameSize) { for (int i = 0; i < this.resultCodes.length; i++) { final int oResultCode = o.resultCodes[i]; final int resultCode = this.resultCodes[i]; if (oResultCode != resultCode) { return oResultCode > resultCode ? -1 : 1; } } return 0; } if (o.resultCodes.length > this.resultCodes.length) { return -1; } return 1; } ResultCodes(final int... resultCodes); @Override boolean equals(final Object o); @Override int hashCode(); @Override @SuppressWarnings("PMD.CyclomaticComplexity") int compareTo(final ResultCodes o);  }
@Test public void comparable() { assertEquals(0, new ResultCodes().compareTo(new ResultCodes())); assertEquals(1, new ResultCodes().compareTo(new ResultCodes(1))); assertEquals(-1, new ResultCodes(1).compareTo(new ResultCodes())); assertEquals(-1, new ResultCodes(0).compareTo(new ResultCodes(1))); assertEquals(0, new ResultCodes(0).compareTo(new ResultCodes(0))); assertEquals(1, new ResultCodes(1).compareTo(new ResultCodes(0))); assertEquals(-1, new ResultCodes(-1).compareTo(new ResultCodes(0))); assertEquals(0, new ResultCodes(-1).compareTo(new ResultCodes(-1))); assertEquals(1, new ResultCodes(1).compareTo(new ResultCodes(-1))); assertEquals(0, new ResultCodes(-1, 0).compareTo(new ResultCodes(-1, 0))); assertEquals(-1, new ResultCodes(0).compareTo(new ResultCodes(-1, 0))); assertEquals(1, new ResultCodes(-1, 1).compareTo(new ResultCodes(1))); }