Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/puppycrawl/tools/checkstyle/checks/indentation/LineSet.java


1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2003  Oliver Burn
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library 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 GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  package com.puppycrawl.tools.checkstyle.checks.indentation;
20  
21  import java.util.SortedMap;
22  import java.util.TreeMap;
23  
24  /**
25   * Represents a set of lines.
26   *
27   * @author jrichard
28   */
29  public class LineSet
30  {
31      /**
32       * Maps line numbers to their start column.
33       */
34      private SortedMap mLines = new TreeMap();
35  
36      /**
37       * Get the starting column for a given line number.
38       *
39       * @param aLineNum   the specified line number
40       *
41       * @return the starting column for the given line number
42       */
43      public Integer getStartColumn(Integer aLineNum)
44      {
45          Integer colNum = (Integer) mLines.get(aLineNum);
46          return colNum;
47      }
48  
49      /**
50       * Get the starting column for the first line.
51       *
52       * @return the starting column for the first line.
53       */
54      public int firstLineCol()
55      {
56          Object firstLineKey = mLines.firstKey();
57          return ((Integer) mLines.get(firstLineKey)).intValue();
58      }
59  
60      /**
61       * Get the line number of the first line.
62       *
63       * @return the line number of the first line
64       */
65      public int firstLine()
66      {
67          return ((Integer) mLines.firstKey()).intValue();
68      }
69  
70      /**
71       * Get the line number of the last line.
72       *
73       * @return the line number of the last line
74       */
75      public int lastLine()
76      {
77          return ((Integer) mLines.lastKey()).intValue();
78      }
79  
80      /**
81       * Add a line to this set of lines.
82       *
83       * @param aLineNum   the line to add
84       * @param aCol       the starting column of the new line
85       */
86      public void addLineAndCol(Integer aLineNum, int aCol)
87      {
88          mLines.put(aLineNum, new Integer(aCol));
89      }
90  
91      /**
92       * Determines if this set of lines is empty.
93       *
94       * @return true if it is empty, false otherwise
95       */
96      public boolean isEmpty()
97      {
98          return mLines.isEmpty();
99      }
100 
101     /**
102      * @return string representation
103      */
104     public String toString()
105     {
106         return "LineSet[ start=" + firstLine() + ", last=" + lastLine() + "]";
107     }
108 }