Coverage Report - com.puppycrawl.tools.checkstyle.checks.indentation.LineSet
 
Classes in this File Line Coverage Branch Coverage Complexity
LineSet
100%
11/11
N/A
1
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2018 the original author or authors.
 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  
 
 20  
 package com.puppycrawl.tools.checkstyle.checks.indentation;
 21  
 
 22  
 import java.util.SortedMap;
 23  
 import java.util.TreeMap;
 24  
 
 25  
 /**
 26  
  * Represents a set of lines.
 27  
  *
 28  
  * @author jrichard
 29  
  */
 30  2283
 public class LineSet {
 31  
 
 32  
     /**
 33  
      * Maps line numbers to their start column.
 34  
      */
 35  2283
     private final SortedMap<Integer, Integer> lines = new TreeMap<>();
 36  
 
 37  
     /**
 38  
      * Get the starting column for a given line number.
 39  
      *
 40  
      * @param lineNum   the specified line number
 41  
      *
 42  
      * @return the starting column for the given line number
 43  
      */
 44  
     public Integer getStartColumn(Integer lineNum) {
 45  5519
         return lines.get(lineNum);
 46  
     }
 47  
 
 48  
     /**
 49  
      * Get the starting column for the first line.
 50  
      *
 51  
      * @return the starting column for the first line.
 52  
      */
 53  
     public int firstLineCol() {
 54  2262
         final Integer firstLineKey = lines.firstKey();
 55  2262
         return lines.get(firstLineKey);
 56  
     }
 57  
 
 58  
     /**
 59  
      * Get the line number of the first line.
 60  
      *
 61  
      * @return the line number of the first line
 62  
      */
 63  
     public int firstLine() {
 64  1993
         return lines.firstKey();
 65  
     }
 66  
 
 67  
     /**
 68  
      * Get the line number of the last line.
 69  
      *
 70  
      * @return the line number of the last line
 71  
      */
 72  
     public int lastLine() {
 73  1993
         return lines.lastKey();
 74  
     }
 75  
 
 76  
     /**
 77  
      * Add a line to this set of lines.
 78  
      *
 79  
      * @param lineNum   the line to add
 80  
      * @param col       the starting column of the new line
 81  
      */
 82  
     public void addLineAndCol(int lineNum, int col) {
 83  3030
         lines.put(lineNum, col);
 84  3030
     }
 85  
 
 86  
     /**
 87  
      * Determines if this set of lines is empty.
 88  
      *
 89  
      * @return true if it is empty, false otherwise
 90  
      */
 91  
     public boolean isEmpty() {
 92  2013
         return lines.isEmpty();
 93  
     }
 94  
 
 95  
     @Override
 96  
     public String toString() {
 97  1
         return "LineSet[firstLine=" + lines.firstKey() + ", lastLine=" + lines.lastKey() + "]";
 98  
     }
 99  
 
 100  
 }