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