Skip to content

Commit 13d8bb5

Browse files
committed
refactoring
1 parent d25555d commit 13d8bb5

File tree

2 files changed

+111
-112
lines changed

2 files changed

+111
-112
lines changed

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* specific language governing permissions and limitations
1919
* under the License.
2020
*/
21-
2221
package com.igormaznitsa.prologparser.terms;
2322

2423
import com.igormaznitsa.prologparser.exceptions.CriticalUnexpectedError;
@@ -56,9 +55,9 @@ public PrologStruct(final PrologTerm functor, final PrologTerm[] elements) {
5655
}
5756

5857
public PrologStruct(
59-
final PrologTerm functor,
60-
final PrologTerm[] elements,
61-
final int line, final int pos
58+
final PrologTerm functor,
59+
final PrologTerm[] elements,
60+
final int line, final int pos
6261
) {
6362
this(functor, elements);
6463
setPos(pos);
@@ -105,10 +104,8 @@ protected PrologStruct(final PrologTerm functor, final int arity, final int line
105104
}
106105

107106
private static PrologTerm assertFunctor(final PrologTerm functor) {
108-
if (
109-
functor.getType() == SPEC_TERM_OPERATOR_CONTAINER
110-
|| functor.getType() == LIST
111-
) {
107+
if (functor.getType() == SPEC_TERM_OPERATOR_CONTAINER
108+
|| functor.getType() == LIST) {
112109
throw new IllegalArgumentException("Non-allowed functor type: " + functor.getType());
113110
}
114111
if (functor instanceof PrologNumeric) {
@@ -136,7 +133,7 @@ public PrologTerm getTermAt(final int index) {
136133
* Set element for its position.
137134
*
138135
* @param index zero based index
139-
* @param term term to set to position
136+
* @param term term to set to position
140137
* @throws ArrayIndexOutOfBoundsException if wrong index
141138
*/
142139
public void setElementAt(final int index, final PrologTerm term) {
@@ -173,7 +170,7 @@ public PrologStruct copyWithAnotherFunctor(final PrologTerm newFunctor) {
173170
@Override
174171
public boolean isAnyBlock() {
175172
return this.functor == Op.VIRTUAL_OPERATOR_BLOCK
176-
|| this.functor == Op.VIRTUAL_OPERATOR_CURLY_BLOCK;
173+
|| this.functor == Op.VIRTUAL_OPERATOR_CURLY_BLOCK;
177174
}
178175

179176
@Override
@@ -225,14 +222,14 @@ public String toString() {
225222
final PrologTerm arg1 = getTermAt(0);
226223
final String text1 = getTermAt(0).toString();
227224

228-
final PrologTerm arg2 = getArity()>1 ? getTermAt(1) : null;
225+
final PrologTerm arg2 = getArity() > 1 ? getTermAt(1) : null;
229226
final String text2 = arg2 == null ? null : getTermAt(1).toString();
230227

231228
switch (operatorFunctor.getAssoc()) {
232229
case FX: {
233230
builder.append(opName).append(' ');
234231

235-
if (arg1.getPrecedence() >= functorPrecedence) {
232+
if (arg1.isBlock() || arg1.getPrecedence() >= functorPrecedence) {
236233
builder.append('(').append(text1).append(')');
237234
} else {
238235
builder.append(text1);
@@ -243,15 +240,15 @@ public String toString() {
243240
builder.append(opName);
244241
builder.append(' ');
245242

246-
if (arg1.getPrecedence() > functorPrecedence) {
243+
if (arg1.isBlock() || arg1.getPrecedence() > functorPrecedence) {
247244
builder.append('(').append(text1).append(')');
248245
} else {
249246
builder.append(text1);
250247
}
251248
}
252249
break;
253250
case XF: {
254-
if (arg1.getPrecedence() >= functorPrecedence) {
251+
if (arg1.isBlock() || arg1.getPrecedence() >= functorPrecedence) {
255252
builder.append('(').append(text1).append(')');
256253
} else {
257254
builder.append(text1);
@@ -261,7 +258,7 @@ public String toString() {
261258
}
262259
break;
263260
case YF: {
264-
if (arg1.getPrecedence() > functorPrecedence) {
261+
if (arg1.isBlock() || arg1.getPrecedence() > functorPrecedence) {
265262
builder.append('(').append(text1).append(')');
266263
} else {
267264
builder.append(text1);
@@ -361,10 +358,10 @@ public boolean isEmpty() {
361358
@Override
362359
public Stream<PrologTerm> stream() {
363360
return StreamSupport.stream(
364-
Spliterators.spliterator(
365-
this.elements,
366-
Spliterator.ORDERED | Spliterator.NONNULL
367-
), false);
361+
Spliterators.spliterator(
362+
this.elements,
363+
Spliterator.ORDERED | Spliterator.NONNULL
364+
), false);
368365
}
369366

370367
@Override

0 commit comments

Comments
 (0)