Skip to content

Commit 925f491

Browse files
committed
refactoring
1 parent 5026c4e commit 925f491

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

src/main/java/com/igormaznitsa/prologparser/ParserContext.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,32 @@ public interface ParserContext {
6262

6363
/**
6464
* Check that the context contains an operator starts with some string
65-
* @param source source prolog parser making request, must not be null
65+
*
66+
* @param source source prolog parser making request, must not be null
6667
* @param namePrefix string to be used to look for operator starts with it, must not be null
6768
* @return true if there is such operator, false otherwise
6869
*/
6970
boolean hasOpStartsWith(PrologParser source, String namePrefix);
7071

7172
/**
7273
* Find operators for their name.
74+
*
7375
* @param source source prolog parser making request, must not be null
74-
* @param name name of operators, must not be null
76+
* @param name name of operators, must not be null
7577
* @return operator container if such one is found, null otherwise
7678
*/
7779
OpContainer findOpForName(PrologParser source, String name);
7880

7981
/**
8082
* Find all operators registered in context.
83+
*
8184
* @return map of operators to their names registered in the context, must not be null
8285
*/
8386
Map<String, OpContainer> findAllOperators();
8487

8588
/**
8689
* Get maximum allowed length value for internal parser text buffers.
90+
*
8791
* @return maximum allowed text parser buffers length in chars
8892
*/
8993
default int getMaxTokenizerBufferLength() {
@@ -92,6 +96,7 @@ default int getMaxTokenizerBufferLength() {
9296

9397
/**
9498
* get parser flags for the parser context.
99+
*
95100
* @return flags as bit field
96101
* @see ParserContext#FLAG_NONE
97102
* @see ParserContext#FLAG_VAR_AS_FUNCTOR

src/main/java/com/igormaznitsa/prologparser/PrologParser.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/**
6161
* Abstract base Prolog parser.
6262
*/
63-
public abstract class PrologParser implements Iterator<PrologTerm>, Iterable<PrologTerm>, Closeable {
63+
public abstract class PrologParser implements Iterable<PrologTerm>, Closeable {
6464

6565
public static final PrologTerm[] EMPTY_TERM_ARRAY = new PrologTerm[0];
6666
protected static final Koi7CharOpMap META_OP_MAP;
@@ -184,7 +184,6 @@ public ParserContext getContext() {
184184
return context;
185185
}
186186

187-
@Override
188187
public boolean hasNext() {
189188
if (this.lastFoundTerm == null) {
190189
final PrologTerm found = readBlock(OPERATORS_PHRASE);
@@ -206,7 +205,6 @@ public boolean hasNext() {
206205
return this.lastFoundTerm != null;
207206
}
208207

209-
@Override
210208
public PrologTerm next() {
211209
try {
212210
if (hasNext()) {
@@ -674,7 +672,7 @@ public PrologTerm next() {
674672
public Stream<PrologTerm> stream() {
675673
return StreamSupport.stream(
676674
Spliterators.spliteratorUnknownSize(
677-
this,
675+
this.iterator(),
678676
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL),
679677
false
680678
);

src/main/java/com/igormaznitsa/prologparser/terms/PrologList.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public PrologTerm getTermAt(final int index) {
110110
return result == null ? EMPTY_ANONYMOUS_VAR : result;
111111
}
112112

113+
@Override
113114
public boolean isEmpty() {
114115
return this.elements[0] == null && this.elements[1] == null;
115116
}
@@ -167,6 +168,7 @@ public PrologList addAsNewListToEndOfListChain(final PrologTerm term) {
167168

168169
/**
169170
* Replace last tail element in list chain.
171+
*
170172
* @param newTailElement new element
171173
*/
172174
public void replaceEndListElement(final PrologTerm newTailElement) {

src/main/java/com/igormaznitsa/prologparser/terms/PrologStruct.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ public PrologTerm getTermAt(final int index) {
134134

135135
/**
136136
* Set element for its position.
137+
*
137138
* @param index zero based index
138-
* @param term term to set to position
139+
* @param term term to set to position
139140
* @throws ArrayIndexOutOfBoundsException if wrong index
140141
*/
141142
public void setElementAt(final int index, final PrologTerm term) {

src/main/java/com/igormaznitsa/prologparser/tokenizer/Tokenizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private void skipUntilBlockCommentEnd() throws IOException {
258258
boolean starCharDetected = false;
259259
while (!Thread.currentThread().isInterrupted()) {
260260
final int readChar = this.readChar();
261-
if (readChar < 0 || readChar == '/' && starCharDetected) {
261+
if (readChar < 0 || (readChar == '/' && starCharDetected)) {
262262
break;
263263
} else {
264264
starCharDetected = readChar == '*';

src/test/java/com/igormaznitsa/prologparser/IntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ public void testUnexpectedlyEndedReadStream() {
11161116
new InputStreamReader(
11171117
new PrologSourceKoi7Generator(rnd.nextBoolean(),
11181118
numChars,
1119-
false)), new DefaultParserContext(FLAG_BLOCK_COMMENTS));
1119+
false), StandardCharsets.UTF_8), new DefaultParserContext(FLAG_BLOCK_COMMENTS));
11201120

11211121
while (parser.hasNext()) {
11221122
assertNotNull(parser.next());

0 commit comments

Comments
 (0)