GridCell implements Comparable<GridCell> { @Override public int compareTo(GridCell other) { int rowComp = Integer.compare(_row, other._row); if (rowComp != 0) { return rowComp; } int colComp = Integer.compare(_column, other._column); if (colComp != 0) { return colComp; } return _format.compareTo(other._format); } GridCell(String cell);  GridCell(int row, int column, TypeFormatter.Format format); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(GridCell other); @Override String toString();  }
@Test public void testCompareTo() throws Exception { List<GridCell> cells = Lists.newArrayList( new GridCell(1, 0, TypeFormatter.Format.CELL), new GridCell(1, 1, TypeFormatter.Format.EXPANDED), new GridCell(2, 1, TypeFormatter.Format.CELL), new GridCell(0, 1, TypeFormatter.Format.CELL), new GridCell(1, 1, TypeFormatter.Format.CELL), new GridCell(0, 3, TypeFormatter.Format.CELL), new GridCell(2, 0, TypeFormatter.Format.CELL)); Collections.sort(cells); ImmutableList<GridCell> expected = ImmutableList.of( new GridCell(0, 1, TypeFormatter.Format.CELL), new GridCell(0, 3, TypeFormatter.Format.CELL), new GridCell(1, 0, TypeFormatter.Format.CELL), new GridCell(1, 1, TypeFormatter.Format.CELL), new GridCell(1, 1, TypeFormatter.Format.EXPANDED), new GridCell(2, 0, TypeFormatter.Format.CELL), new GridCell(2, 1, TypeFormatter.Format.CELL)); assertEquals(expected, cells); }