001///////////////////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
003// Copyright (C) 2001-2025 the original author or authors.
004//
005// This library is free software; you can redistribute it and/or
006// modify it under the terms of the GNU Lesser General Public
007// License as published by the Free Software Foundation; either
008// version 2.1 of the License, or (at your option) any later version.
009//
010// This library is distributed in the hope that it will be useful,
011// but WITHOUT ANY WARRANTY; without even the implied warranty of
012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013// Lesser General Public License for more details.
014//
015// You should have received a copy of the GNU Lesser General Public
016// License along with this library; if not, write to the Free Software
017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018///////////////////////////////////////////////////////////////////////////////////////////////
019
020package com.puppycrawl.tools.checkstyle.api;
021
022import java.util.Objects;
023
024/**
025 * Immutable line and column numbers.
026 *
027 */
028public class LineColumn implements Comparable<LineColumn> {
029
030 /** The one-based line number. */
031 private final int line;
032
033 /** The zero-based column number. */
034 private final int column;
035
036 /**
037 * Constructs a new pair of line and column numbers.
038 *
039 * @param line the one-based line number
040 * @param column the zero-based column number
041 */
042 public LineColumn(int line, int column) {
043 this.line = line;
044 this.column = column;
045 }
046
047 /**
048 * Gets the one-based line number.
049 *
050 * @return the one-based line number
051 */
052 public int getLine() {
053 return line;
054 }
055
056 /**
057 * Gets the zero-based column number.
058 *
059 * @return the zero-based column number
060 */
061 public int getColumn() {
062 return column;
063 }
064
065 @Override
066 public int compareTo(LineColumn lineColumn) {
067 final int result;
068 if (line == lineColumn.line) {
069 result = Integer.compare(column, lineColumn.column);
070 }
071 else {
072 result = Integer.compare(line, lineColumn.line);
073 }
074 return result;
075 }
076
077 @Override
078 public boolean equals(Object other) {
079 if (this == other) {
080 return true;
081 }
082 if (other == null || getClass() != other.getClass()) {
083 return false;
084 }
085 final LineColumn lineColumn = (LineColumn) other;
086 return Objects.equals(line, lineColumn.line)
087 && Objects.equals(column, lineColumn.column);
088 }
089
090 @Override
091 public int hashCode() {
092 return Objects.hash(line, column);
093 }
094
095}