001: ////////////////////////////////////////////////////////////////////////////////
002: // checkstyle: Checks Java source code for adherence to a set of rules.
003: // Copyright (C) 2001-2007 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: ////////////////////////////////////////////////////////////////////////////////
019: package com.puppycrawl.tools.checkstyle.checks.indentation;
020:
021: import java.util.SortedMap;
022: import java.util.TreeMap;
023:
024: /**
025: * Represents a set of lines.
026: *
027: * @author jrichard
028: */
029: public class LineSet {
030: /**
031: * Maps line numbers to their start column.
032: */
033: private final SortedMap mLines = new TreeMap();
034:
035: /**
036: * Get the starting column for a given line number.
037: *
038: * @param aLineNum the specified line number
039: *
040: * @return the starting column for the given line number
041: */
042: public Integer getStartColumn(Integer aLineNum) {
043: return (Integer) mLines.get(aLineNum);
044: }
045:
046: /**
047: * Get the starting column for the first line.
048: *
049: * @return the starting column for the first line.
050: */
051: public int firstLineCol() {
052: final Object firstLineKey = mLines.firstKey();
053: return ((Integer) mLines.get(firstLineKey)).intValue();
054: }
055:
056: /**
057: * Get the line number of the first line.
058: *
059: * @return the line number of the first line
060: */
061: public int firstLine() {
062: return ((Integer) mLines.firstKey()).intValue();
063: }
064:
065: /**
066: * Get the line number of the last line.
067: *
068: * @return the line number of the last line
069: */
070: public int lastLine() {
071: return ((Integer) mLines.lastKey()).intValue();
072: }
073:
074: /**
075: * Add a line to this set of lines.
076: *
077: * @param aLineNum the line to add
078: * @param aCol the starting column of the new line
079: */
080: public void addLineAndCol(Integer aLineNum, int aCol) {
081: mLines.put(aLineNum, new Integer(aCol));
082: }
083:
084: /**
085: * Determines if this set of lines is empty.
086: *
087: * @return true if it is empty, false otherwise
088: */
089: public boolean isEmpty() {
090: return mLines.isEmpty();
091: }
092:
093: /**
094: * @return string representation
095: */
096: public String toString() {
097: return "LineSet[ start=" + firstLine() + ", last=" + lastLine()
098: + "]";
099: }
100: }
|