1 /* 2 * SPDX-FileCopyrightText: Copyright (c) 2011-2025 Yegor Bugayenko 3 * SPDX-License-Identifier: MIT 4 */ 5 package com.qulice.checkstyle; 6 7 /** 8 * Represent a line range. For example, a Java method can be described by an 9 * instance of this class. The alpha line could be the method definition and 10 * the omega line could be the end closing bracket. 11 * 12 * @since 0.16 13 */ 14 public final class LineRange { 15 16 /** 17 * The first (alpha) line number in the range. 18 */ 19 private final int alpha; 20 21 /** 22 * The last (omega) line number in the range. 23 */ 24 private final int omega; 25 26 /** 27 * Default constructor. 28 * @param first The alpha line number. 29 * @param last The omega line number. 30 */ 31 public LineRange(final int first, final int last) { 32 this.alpha = first; 33 this.omega = last; 34 } 35 36 /** 37 * Is the given line number within range. 38 * @param line The given line number to check. 39 * @return True if the given line number is within this range. 40 */ 41 public boolean within(final int line) { 42 return line >= this.first() && line <= this.last(); 43 } 44 45 /** 46 * Is the given range entirely within the LineRange. Example, given a 47 * LineRange of [10, 50], the given range of [12,48] should be within 48 * side that. And the method should return true. 49 * @param range The given LineRange to check. 50 * @return True if the given is entirely within this LineRange. 51 */ 52 public boolean within(final LineRange range) { 53 return range.first() >= this.first() 54 && range.last() <= this.last(); 55 } 56 57 /** 58 * Get the alpha line number. 59 * @return The alpha line number. 60 */ 61 public int first() { 62 return this.alpha; 63 } 64 65 /** 66 * Get the omega line number. 67 * @return The omega line number. 68 */ 69 public int last() { 70 return this.omega; 71 } 72 }