01: /*
02: * Position.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.storage;
13:
14: /**
15: * A class to identify the position of a row/column in a datastore
16: *
17: * @author support@sql-workbench.net
18: */
19: public class Position {
20: /**
21: * A Position instance identifying a non-existing position
22: */
23: public static final Position NO_POSITION = new Position(-1, -1);
24:
25: private final int row;
26: private final int column;
27:
28: public Position(int line, int col) {
29: this .row = line;
30: this .column = col;
31: }
32:
33: public int getRow() {
34: return row;
35: }
36:
37: public int getColumn() {
38: return column;
39: }
40:
41: /**
42: * Check if this object identifies a valid position inside
43: * a DataStore or table. If either row or column are < 0
44: * this method returns false.
45: * @return true if row and column identify a non negative location
46: */
47: public boolean isValid() {
48: return (this .column > -1 && this .row > -1);
49: }
50:
51: @Override
52: public boolean equals(Object other) {
53: if (other instanceof Position) {
54: Position op = (Position) other;
55: return (op.column == this .column && op.row == this .row);
56: }
57: return false;
58: }
59:
60: @Override
61: public String toString() {
62: return "[" + Integer.toString(row) + ","
63: + Integer.toString(column) + "]";
64: }
65:
66: @Override
67: public int hashCode() {
68: int result = 37 * column;
69: result ^= 37 * row;
70: return result;
71: }
72:
73: }
|