001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 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//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.api; 020 021/** 022 * Immutable line and column numbers. 023 * 024 * @author Martin von Gagern 025 */ 026public class LineColumn implements Comparable<LineColumn> 027{ 028 029 /** The one-based line number */ 030 private final int line; 031 032 /** The zero-based column number */ 033 private final int col; 034 035 /** 036 * Constructs a new pair of line and column numbers. 037 * @param line the one-based line number 038 * @param col the zero-based column number 039 */ 040 public LineColumn(int line, int col) 041 { 042 this.line = line; 043 this.col = col; 044 } 045 046 /** @return the one-based line number */ 047 public int getLine() 048 { 049 return line; 050 } 051 052 /** @return the zero-based column number */ 053 public int getColumn() 054 { 055 return col; 056 } 057 058 /** {@inheritDoc} */ 059 @Override 060 public int compareTo(LineColumn lineColumn) 061 { 062 return (this.getLine() != lineColumn.getLine()) 063 ? this.getLine() - lineColumn.getLine() 064 : this.getColumn() - lineColumn.getColumn(); 065 } 066}