1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2011-2026 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 * @since 0.16
12 */
13 public final class LineRange {
14
15 /**
16 * The first (alpha) line number in the range.
17 */
18 private final int alpha;
19
20 /**
21 * The last (omega) line number in the range.
22 */
23 private final int omega;
24
25 /**
26 * Default constructor.
27 * @param first The alpha line number
28 * @param last The omega line number
29 */
30 public LineRange(final int first, final int last) {
31 this.alpha = first;
32 this.omega = last;
33 }
34
35 /**
36 * Is the given line number within range.
37 * @param line The given line number to check
38 * @return True if the given line number is within this range
39 */
40 public boolean within(final int line) {
41 return line >= this.first() && line <= this.last();
42 }
43
44 /**
45 * Is the given range entirely within the LineRange. Example, given a
46 * LineRange of [10, 50], the given range of [12,48] should be within
47 * side that. And the method should return true.
48 * @param range The given LineRange to check
49 * @return True if the given is entirely within this LineRange
50 */
51 public boolean within(final LineRange range) {
52 return range.first() >= this.first()
53 && range.last() <= this.last();
54 }
55
56 /**
57 * Get the alpha line number.
58 * @return The alpha line number
59 */
60 public int first() {
61 return this.alpha;
62 }
63
64 /**
65 * Get the omega line number.
66 * @return The omega line number
67 */
68 public int last() {
69 return this.omega;
70 }
71 }