Field implements Comparable<Field> { @Override public int compareTo(Field o) { return DEFAULT_SORT.compare(this, o); } Field(String id, Integer start, Integer length);  Field(String id, Integer start, Integer length, boolean composite);  Field(String id, Integer start, Integer length, boolean composite, boolean input, String alias);  Field(String id, Integer start, Integer length, boolean composite, boolean input, String alias,
            boolean whitespace); void write(ByteBuffer buffer); void write(Object value, ByteBuffer buffer); String read(ByteBuffer buffer); boolean isComposite(); String getAlias(); boolean isAliased(); boolean isInput(); boolean isWhitespaceSignificant(); @Override int compareTo(Field o); @Override int hashCode(); @Override boolean equals(Object obj); Integer getLength(); String getId(); Integer getStart(); @Override String toString(); final static Comparator<Field> DEFAULT_SORT; final static Comparator<Field> NAME_SORT; }
@Test public void testCompareTo() { String baseName = field.getId(); int baseStart = field.getStart(); int baseLength = field.getLength(); Field fieldIsEqual = new Field(baseName, baseStart, baseLength); assertTrue(field.compareTo(fieldIsEqual)==0); assertTrue(fieldIsEqual.compareTo(field)==0); assertTrue(field.compareTo(field)==0); Field startIsLess = new Field(baseName, baseStart - 1, baseLength); assertTrue(field.compareTo(startIsLess)>0); assertTrue(startIsLess.compareTo(field)<0); Field startIsMore = new Field(baseName, baseStart + 1, baseLength); assertTrue(field.compareTo(startIsMore)<0); assertTrue(startIsMore.compareTo(field)>0); Field lengthIsLess = new Field(baseName, baseStart, baseLength - 1); assertTrue(field.compareTo(lengthIsLess)>0); assertTrue(lengthIsLess.compareTo(field)<0); Field lengthIsMore = new Field(baseName, baseStart, baseLength + 1); assertTrue(field.compareTo(lengthIsMore)<0); assertTrue(lengthIsMore.compareTo(field)>0); Field onlyNameIsDifferent = new Field("A"+baseName, baseStart, baseLength); assertTrue(field.compareTo(onlyNameIsDifferent)==0); }