name:
src/main/java/io/protobase/f7/models/ColumnRowKey.java
-rw-r--r--
1334
1package io.protobase.f7.models;
2
3import com.google.common.base.MoreObjects;
4
5/**
6 * Represents a single location in a 2D grid - usually {@link Grid}.
7 */
8public class ColumnRowKey extends BaseObject {
9 private Integer column;
10 private Integer row;
11
12 /**
13 * Create a new key from 0-indexed column and 0-indexed row.
14 *
15 * @param column int greater than or equal to 0.
16 * @param row int greater than or equal to 0.
17 */
18 public ColumnRowKey(Integer column, Integer row) {
19 this.column = column;
20 this.row = row;
21 }
22
23 /**
24 * Column index.
25 *
26 * @return column index.
27 */
28 public Integer getColumnIndex() {
29 return column;
30 }
31
32 /**
33 * Row index.
34 *
35 * @return row index.
36 */
37 public Integer getRowIndex() {
38 return row;
39 }
40
41 @Override
42 public String toString() {
43 return MoreObjects.toStringHelper(this)
44 .add("column", column)
45 .add("row", row)
46 .toString();
47 }
48
49 @Override
50 public Object[] significantAttributes() {
51 return new Object[]{
52 column,
53 row
54 };
55 }
56
57 public int compareTo(ColumnRowKey other) {
58 if (this.equals(other)) {
59 return 0;
60 }
61 if (this.column.equals(other.getColumnIndex())) {
62 return this.row.compareTo(other.getRowIndex());
63 }
64 return this.column.compareTo(other.getColumnIndex());
65 }
66}