Skip to content

Commit c389802

Browse files
author
Vladimir Kotal
authored
reduce field visibility in PendingToken (#3822)
* reduce symbol visibility * add copyright * remove the nonpos field * fix position increment
1 parent 379f387 commit c389802

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/PendingToken.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/*
21+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2122
* Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis;
@@ -34,11 +35,6 @@ public class PendingToken {
3435
public final String str;
3536
public final int start;
3637
public final int end;
37-
/**
38-
* When tokenizers allow overlapping tokens, the following field is set to
39-
* {@code true} for tokens that should not increment the position attribute.
40-
*/
41-
public boolean nonpos;
4238

4339
/**
4440
* Initializes an instance with immutable fields for the specified
@@ -86,7 +82,6 @@ public int hashCode() {
8682
*/
8783
@Override
8884
public String toString() {
89-
return "PendingToken{" + str + "<<< start=" + start + ",end=" + end +
90-
",nonpos=" + nonpos + '}';
85+
return "PendingToken{" + str + "<<< start=" + start + ",end=" + end + '}';
9186
}
9287
}

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/plain/DefinitionsTokenStream.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/*
21+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2122
* Copyright (c) 2018, 2020, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis.plain;
@@ -104,7 +105,7 @@ public final boolean incrementToken() throws IOException {
104105
private void setAttribs(PendingToken tok) {
105106
clearAttributes();
106107

107-
this.posIncrAtt.setPositionIncrement(tok.nonpos ? 0 : 1);
108+
this.posIncrAtt.setPositionIncrement(1);
108109
this.termAtt.setEmpty();
109110
this.termAtt.append(tok.str);
110111
this.offsetAtt.setOffset(tok.start, tok.end);

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/PendingTokenTest.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/*
21+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2122
* Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis;
@@ -32,91 +33,80 @@
3233
/**
3334
* Represents a container for tests of {@link PendingToken}.
3435
*/
35-
public class PendingTokenTest {
36+
class PendingTokenTest {
3637

3738
@Test
38-
public void testEquals1() {
39+
void testEquals1() {
3940
PendingToken instance = new PendingToken("", 0, 0);
4041
boolean result = instance.equals(instance);
4142
assertTrue(result, "PendingToken instance equals itself");
4243
}
4344

4445
@Test
45-
public void testEquals2() {
46+
void testEquals2() {
4647
PendingToken instance1 = new PendingToken("a", 0, 1);
47-
assertFalse(instance1.nonpos, "PendingToken default nonpos");
48-
4948
PendingToken instance2 = new PendingToken("a", 0, 1);
50-
instance2.nonpos = true;
5149
boolean result = instance1.equals(instance2);
52-
assertTrue(result, "PendingToken instance equivalence ignores nonpos");
50+
assertTrue(result, "PendingToken instance equivalence false");
5351
}
5452

5553
@Test
56-
public void testNotEquals1() {
54+
void testNotEquals1() {
5755
PendingToken instance1 = new PendingToken("", 0, 0);
5856
PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok
5957
boolean result = instance1.equals(instance2);
6058
assertFalse(result, "PendingToken equals() only 2 immutables match");
6159
}
6260

6361
@Test
64-
public void testNotEquals2() {
62+
void testNotEquals2() {
6563
PendingToken instance1 = new PendingToken("", 0, 0);
6664
PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok
6765
boolean result = instance1.equals(instance2);
6866
assertFalse(result, "PendingToken equals() only 2 immutables match");
6967
}
7068

7169
@Test
72-
public void testNotEquals3() {
70+
void testNotEquals3() {
7371
PendingToken instance1 = new PendingToken("", 0, 0);
7472
PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok
7573
boolean result = instance1.equals(instance2);
7674
assertFalse(result, "PendingToken equals() only 2 immutables match");
7775
}
7876

7977
@Test
80-
public void testSameHashCodes() {
78+
void testSameHashCodes() {
8179
PendingToken instance1 = new PendingToken("a", 0, 1);
82-
assertFalse(instance1.nonpos, "PendingToken default nonpos");
83-
8480
PendingToken instance2 = new PendingToken("a", 0, 1);
85-
instance2.nonpos = true;
86-
assertEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken instance HashCode ignores nonpos");
81+
assertEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken instance HashCode differs");
8782
}
8883

8984
@Test
90-
public void testDifferentHashCodes1() {
85+
void testDifferentHashCodes1() {
9186
PendingToken instance1 = new PendingToken("", 0, 0);
9287
PendingToken instance2 = new PendingToken("", 0, 1); // nonsense but ok
9388
assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match");
9489
}
9590

9691
@Test
97-
public void testDifferentHashCodes2() {
92+
void testDifferentHashCodes2() {
9893
PendingToken instance1 = new PendingToken("", 0, 0);
9994
PendingToken instance2 = new PendingToken("", 1, 0); // nonsense but ok
10095
assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match");
10196
}
10297

10398
@Test
104-
public void testDifferentHashCodes3() {
99+
void testDifferentHashCodes3() {
105100
PendingToken instance1 = new PendingToken("", 0, 0);
106101
PendingToken instance2 = new PendingToken("a", 0, 0); // nonsense but ok
107102
assertNotEquals(instance1.hashCode(), instance2.hashCode(), "PendingToken hashCode() only 2 immutables match");
108103
}
109104

110105
@Test
111-
public void testToString() {
106+
void testToString() {
112107
PendingToken instance = new PendingToken("abc", 0, 4);
113-
String expResult = "PendingToken{abc<<< start=0,end=4,nonpos=false}";
108+
String expResult = "PendingToken{abc<<< start=0,end=4}";
114109
String result = instance.toString();
115110
assertEquals(expResult, result, "PendingToken toString()");
116-
117-
instance.nonpos = true;
118-
expResult = "PendingToken{abc<<< start=0,end=4,nonpos=true}";
119-
result = instance.toString();
120-
assertEquals(expResult, result, "PendingToken toString()");
121111
}
122112
}

0 commit comments

Comments
 (0)