xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/PendingToken.java (revision c389802dce0d8fde10e602cd558c2c2fc332bc29)
1b5840353SAdam Hornáček /*
2b5840353SAdam Hornáček  * CDDL HEADER START
3b5840353SAdam Hornáček  *
4b5840353SAdam Hornáček  * The contents of this file are subject to the terms of the
5b5840353SAdam Hornáček  * Common Development and Distribution License (the "License").
6b5840353SAdam Hornáček  * You may not use this file except in compliance with the License.
7b5840353SAdam Hornáček  *
8b5840353SAdam Hornáček  * See LICENSE.txt included in this distribution for the specific
9b5840353SAdam Hornáček  * language governing permissions and limitations under the License.
10b5840353SAdam Hornáček  *
11b5840353SAdam Hornáček  * When distributing Covered Code, include this CDDL HEADER in each
12b5840353SAdam Hornáček  * file and include the License file at LICENSE.txt.
13b5840353SAdam Hornáček  * If applicable, add the following below this CDDL HEADER, with the
14b5840353SAdam Hornáček  * fields enclosed by brackets "[]" replaced with your own identifying
15b5840353SAdam Hornáček  * information: Portions Copyright [yyyy] [name of copyright owner]
16b5840353SAdam Hornáček  *
17b5840353SAdam Hornáček  * CDDL HEADER END
18b5840353SAdam Hornáček  */
19b5840353SAdam Hornáček 
20b5840353SAdam Hornáček /*
21*c389802dSVladimir Kotal  * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
22b5840353SAdam Hornáček  * Copyright (c) 2018, Chris Fraire <cfraire@me.com>.
23b5840353SAdam Hornáček  */
249805b761SAdam Hornáček package org.opengrok.indexer.analysis;
25b5840353SAdam Hornáček 
26b5840353SAdam Hornáček import java.util.Objects;
27b5840353SAdam Hornáček 
28b5840353SAdam Hornáček /**
29b5840353SAdam Hornáček  * Represents an almost-wholly immutable tuple whose field data are used by
30b5840353SAdam Hornáček  * {@link JFlexTokenizer} to set attributes to be read while iterating a
31b5840353SAdam Hornáček  * token stream.
32b5840353SAdam Hornáček  */
33b5840353SAdam Hornáček public class PendingToken {
34b5840353SAdam Hornáček 
35b5840353SAdam Hornáček     public final String str;
36b5840353SAdam Hornáček     public final int start;
37b5840353SAdam Hornáček     public final int end;
38b5840353SAdam Hornáček 
39b5840353SAdam Hornáček     /**
40b5840353SAdam Hornáček      * Initializes an instance with immutable fields for the specified
41b5840353SAdam Hornáček      * arguments.
4281b586e6SVladimir Kotal      * @param str string value
4381b586e6SVladimir Kotal      * @param start start offset
4481b586e6SVladimir Kotal      * @param end end offset
45b5840353SAdam Hornáček      */
PendingToken(String str, int start, int end)46b5840353SAdam Hornáček     public PendingToken(String str, int start, int end) {
47b5840353SAdam Hornáček         this.str = str;
48b5840353SAdam Hornáček         this.start = start;
49b5840353SAdam Hornáček         this.end = end;
50b5840353SAdam Hornáček     }
51b5840353SAdam Hornáček 
52b5840353SAdam Hornáček     /**
53b5840353SAdam Hornáček      * Compares this instance's immutable fields to the other.
5481b586e6SVladimir Kotal      * @param o object
55b5840353SAdam Hornáček      * @return {@code true} if the objects are equal
56b5840353SAdam Hornáček      */
57b5840353SAdam Hornáček     @Override
equals(Object o)58b5840353SAdam Hornáček     public boolean equals(Object o) {
59b5840353SAdam Hornáček         if (o == this) {
60b5840353SAdam Hornáček             return true;
61b5840353SAdam Hornáček         }
62b5840353SAdam Hornáček         if (!(o instanceof PendingToken)) {
63b5840353SAdam Hornáček             return false;
64b5840353SAdam Hornáček         }
65b5840353SAdam Hornáček         PendingToken other = (PendingToken) o;
66b5840353SAdam Hornáček         return start == other.start && end == other.end &&
67b5840353SAdam Hornáček             str.equals(other.str);
68b5840353SAdam Hornáček     }
69b5840353SAdam Hornáček 
70b5840353SAdam Hornáček     /**
71b5840353SAdam Hornáček      * Calculates a hash code from the instance's immutable fields.
72b5840353SAdam Hornáček      * @return a hash value
73b5840353SAdam Hornáček      */
74b5840353SAdam Hornáček     @Override
hashCode()75b5840353SAdam Hornáček     public int hashCode() {
76b5840353SAdam Hornáček         return Objects.hash(str, start, end);
77b5840353SAdam Hornáček     }
78b5840353SAdam Hornáček 
79b5840353SAdam Hornáček     /**
80b5840353SAdam Hornáček      * Gets a readable representation for debugging.
81b5840353SAdam Hornáček      * @return a defined instance
82b5840353SAdam Hornáček      */
83b5840353SAdam Hornáček     @Override
toString()84b5840353SAdam Hornáček     public String toString() {
85*c389802dSVladimir Kotal         return "PendingToken{" + str + "<<< start=" + start + ",end=" + end + '}';
86b5840353SAdam Hornáček     }
87b5840353SAdam Hornáček }
88