View Javadoc

1   /* This file is part of the project "Hilbert II" - http://www.qedeq.org" target="alexandria_uri">http://www.qedeq.org
2    *
3    * Copyright 2000-2014,  Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU General Public License for more details.
14   */
15  
16  package org.qedeq.base.io;
17  
18  import java.io.Serializable;
19  
20  /**
21   * Describes a file position within a text file.
22   *
23   * @author  Michael Meyling
24   */
25  public final class SourcePosition implements Serializable {
26  
27      /** Begin of file. */
28      public static final SourcePosition BEGIN = new SourcePosition(1, 1);
29  
30      /** Line number, starting with 1. */
31      private int row;
32  
33      /** Column number, starting with 1. */
34      private int column;
35  
36      /**
37       * Constructs source position object.
38       *
39       * @param   row     Line number, starting with 1.
40       * @param   column  Column number, starting with 1.
41       */
42      public SourcePosition(final int row, final int column) {
43          this.row = row;
44          this.column = column;
45      }
46  
47      /**
48       * Get line number, starting with 1.
49       *
50       * @return  Line number.
51       */
52      public final int getRow() {
53          return row;
54      }
55  
56      /**
57       * Get column number, starting with 1.
58       *
59       * @return  column number
60       */
61      public final int getColumn() {
62          return column;
63      }
64  
65      public final int hashCode() {
66          return getRow() ^ (getColumn() * 13);
67      }
68  
69      public final boolean equals(final Object obj) {
70          if (!(obj instanceof SourcePosition)) {
71              return false;
72          }
73          final SourcePosition other = (SourcePosition) obj;
74          return (getRow() == other.getRow())
75              && (getColumn() == other.getColumn());
76      }
77  
78      public final String toString() {
79          return getRow() + ":" + getColumn();
80      }
81  
82  }