001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2026 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 * @noinspection ClassCanBeRecord 028 * @noinspectionreason Public API class – converting to record would break binary compatibility. 029 */ 030public class LineColumn implements Comparable<LineColumn> { 031 032 /** The one-based line number. */ 033 private final int line; 034 035 /** The zero-based column number. */ 036 private final int column; 037 038 /** 039 * Constructs a new pair of line and column numbers. 040 * 041 * @param line the one-based line number 042 * @param column the zero-based column number 043 */ 044 public LineColumn(int line, int column) { 045 this.line = line; 046 this.column = column; 047 } 048 049 /** 050 * Gets the one-based line number. 051 * 052 * @return the one-based line number 053 */ 054 public int getLine() { 055 return line; 056 } 057 058 /** 059 * Gets the zero-based column number. 060 * 061 * @return the zero-based column number 062 */ 063 public int getColumn() { 064 return column; 065 } 066 067 @Override 068 public int compareTo(LineColumn lineColumn) { 069 final int result; 070 if (line == lineColumn.line) { 071 result = Integer.compare(column, lineColumn.column); 072 } 073 else { 074 result = Integer.compare(line, lineColumn.line); 075 } 076 return result; 077 } 078 079 @Override 080 public boolean equals(Object other) { 081 if (this == other) { 082 return true; 083 } 084 if (other == null || getClass() != other.getClass()) { 085 return false; 086 } 087 final LineColumn lineColumn = (LineColumn) other; 088 return Objects.equals(line, lineColumn.line) 089 && Objects.equals(column, lineColumn.column); 090 } 091 092 @Override 093 public int hashCode() { 094 return Objects.hash(line, column); 095 } 096 097}