From 0e4960dc4e1d820b72bd3d301da2cde60351d137 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 24 Jan 2016 21:11:04 +0100 Subject: [PATCH] Avoid getters for final fields --- .../java/jscl/text/BracketedExpression.java | 4 +- .../java/jscl/text/CommaAndExpression.java | 2 +- .../main/java/jscl/text/CommaAndVector.java | 2 +- .../java/jscl/text/CompoundIdentifier.java | 8 ++-- .../main/java/jscl/text/ConstantParser.java | 4 +- jscl/src/main/java/jscl/text/Digits.java | 14 +++---- .../src/main/java/jscl/text/DoubleParser.java | 34 ++++++++--------- .../main/java/jscl/text/ExponentParser.java | 2 +- jscl/src/main/java/jscl/text/Identifier.java | 14 +++---- .../jscl/text/ImplicitFunctionParser.java | 14 +++---- .../main/java/jscl/text/IntegerParser.java | 20 +++++----- .../java/jscl/text/JsclIntegerParser.java | 6 +-- .../src/main/java/jscl/text/MatrixParser.java | 4 +- jscl/src/main/java/jscl/text/MinusParser.java | 8 ++-- .../jscl/text/MultiplyOrDivideFactor.java | 6 +-- .../java/jscl/text/NumeralBaseParser.java | 4 +- .../main/java/jscl/text/OperatorParser.java | 2 +- .../java/jscl/text/ParameterListParser.java | 4 +- jscl/src/main/java/jscl/text/Parser.java | 37 ++++--------------- jscl/src/main/java/jscl/text/ParserUtils.java | 22 +++++------ .../main/java/jscl/text/PlusOrMinusTerm.java | 8 ++-- .../java/jscl/text/PostfixFunctionParser.java | 8 ++-- .../jscl/text/PostfixFunctionsParser.java | 4 +- .../java/jscl/text/PowerExponentParser.java | 6 +-- jscl/src/main/java/jscl/text/PowerParser.java | 12 +++--- .../main/java/jscl/text/PrimeCharacters.java | 10 ++--- jscl/src/main/java/jscl/text/RootParser.java | 2 +- jscl/src/main/java/jscl/text/Subscript.java | 4 +- .../java/jscl/text/UsualFunctionParser.java | 2 +- .../src/main/java/jscl/text/VectorParser.java | 4 +- 30 files changed, 125 insertions(+), 146 deletions(-) diff --git a/jscl/src/main/java/jscl/text/BracketedExpression.java b/jscl/src/main/java/jscl/text/BracketedExpression.java index c7fa511c..205218f3 100644 --- a/jscl/src/main/java/jscl/text/BracketedExpression.java +++ b/jscl/src/main/java/jscl/text/BracketedExpression.java @@ -13,7 +13,7 @@ public class BracketedExpression implements Parser { } public ExpressionVariable parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.tryToParse(p, pos0, '('); @@ -21,7 +21,7 @@ public class BracketedExpression implements Parser { try { result = ExpressionParser.parser.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/CommaAndExpression.java b/jscl/src/main/java/jscl/text/CommaAndExpression.java index 036cf451..92929b23 100644 --- a/jscl/src/main/java/jscl/text/CommaAndExpression.java +++ b/jscl/src/main/java/jscl/text/CommaAndExpression.java @@ -13,7 +13,7 @@ public class CommaAndExpression implements Parser { } public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); diff --git a/jscl/src/main/java/jscl/text/CommaAndVector.java b/jscl/src/main/java/jscl/text/CommaAndVector.java index 009f5d1e..cea793dc 100644 --- a/jscl/src/main/java/jscl/text/CommaAndVector.java +++ b/jscl/src/main/java/jscl/text/CommaAndVector.java @@ -15,7 +15,7 @@ public class CommaAndVector implements Parser { @Nonnull public JsclVector parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); diff --git a/jscl/src/main/java/jscl/text/CompoundIdentifier.java b/jscl/src/main/java/jscl/text/CompoundIdentifier.java index 1a793094..b52665fe 100644 --- a/jscl/src/main/java/jscl/text/CompoundIdentifier.java +++ b/jscl/src/main/java/jscl/text/CompoundIdentifier.java @@ -14,7 +14,7 @@ public class CompoundIdentifier implements Parser { @Nonnull public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); StringBuilder result = new StringBuilder(); @@ -23,7 +23,7 @@ public class CompoundIdentifier implements Parser { String s = Identifier.parser.parse(p, previousSumElement); result.append(s); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } @@ -49,7 +49,7 @@ class DotAndIdentifier implements Parser { } public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.tryToParse(p, pos0, '.'); @@ -57,7 +57,7 @@ class DotAndIdentifier implements Parser { try { result = Identifier.parser.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/ConstantParser.java b/jscl/src/main/java/jscl/text/ConstantParser.java index 06073fb0..4aa0f1a9 100644 --- a/jscl/src/main/java/jscl/text/ConstantParser.java +++ b/jscl/src/main/java/jscl/text/ConstantParser.java @@ -64,7 +64,7 @@ class Superscript implements Parser { } public Integer parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.tryToParse(p, pos0, '{'); @@ -73,7 +73,7 @@ class Superscript implements Parser { try { result = IntegerParser.parser.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/Digits.java b/jscl/src/main/java/jscl/text/Digits.java index d44c9f4d..7d18293d 100644 --- a/jscl/src/main/java/jscl/text/Digits.java +++ b/jscl/src/main/java/jscl/text/Digits.java @@ -18,22 +18,22 @@ public class Digits implements Parser { // returns digit public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final StringBuilder result = new StringBuilder(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { - result.append(p.getExpression().charAt(p.getPosition().intValue())); - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) { + result.append(p.expression.charAt(p.position.intValue())); + p.position.increment(); } else { ParserUtils.throwParseException(p, pos0, Messages.msg_9); } - while (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { - result.append(p.getExpression().charAt(p.getPosition().intValue())); - p.getPosition().increment(); + while (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) { + result.append(p.expression.charAt(p.position.intValue())); + p.position.increment(); } return result.toString(); diff --git a/jscl/src/main/java/jscl/text/DoubleParser.java b/jscl/src/main/java/jscl/text/DoubleParser.java index d6ee5b58..18cff22c 100644 --- a/jscl/src/main/java/jscl/text/DoubleParser.java +++ b/jscl/src/main/java/jscl/text/DoubleParser.java @@ -39,7 +39,7 @@ class Singularity implements Parser { @Nonnull public Double parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); double result = 0d; @@ -64,7 +64,7 @@ class FloatingPointLiteral implements Parser { } public Double parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final NumeralBase nb = NumeralBaseParser.parser.parse(p, previousSumElement); @@ -88,7 +88,7 @@ class FloatingPointLiteral implements Parser { point = true; } catch (ParseException e) { if (!digits) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } } @@ -101,7 +101,7 @@ class FloatingPointLiteral implements Parser { result.append(digitsParser.parse(p, previousSumElement)); } catch (ParseException e) { if (!digits) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } } @@ -111,7 +111,7 @@ class FloatingPointLiteral implements Parser { exponent = true; } catch (ParseException e) { if (!point) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } } @@ -124,7 +124,7 @@ class FloatingPointLiteral implements Parser { try { return nb.toDouble(doubleString); } catch (NumberFormatException e) { - throw new ParseException(Messages.msg_8, p.getPosition().intValue(), p.getExpression(), doubleString); + throw new ParseException(Messages.msg_8, p.position.intValue(), p.expression, doubleString); } } } @@ -138,7 +138,7 @@ class DecimalPoint implements Parser { @Nullable public Void parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); @@ -157,15 +157,15 @@ class ExponentPart implements Parser { @Nonnull public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final StringBuilder result = new StringBuilder(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && (p.getExpression().charAt(p.getPosition().intValue()) == 'e' || p.getExpression().charAt(p.getPosition().intValue()) == 'E')) { - char c = p.getExpression().charAt(p.getPosition().intValue()); - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == 'e' || p.expression.charAt(p.position.intValue()) == 'E')) { + char c = p.expression.charAt(p.position.intValue()); + p.position.increment(); result.append(c); } else { ParserUtils.throwParseException(p, pos0, Messages.msg_10, 'e', 'E'); @@ -174,7 +174,7 @@ class ExponentPart implements Parser { try { result.append(SignedInteger.parser.parse(p, previousSumElement)); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } @@ -191,22 +191,22 @@ class SignedInteger implements Parser { @Nonnull public String parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final StringBuilder result = new StringBuilder(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && (p.getExpression().charAt(p.getPosition().intValue()) == '+' || p.getExpression().charAt(p.getPosition().intValue()) == '-')) { - char c = p.getExpression().charAt(p.getPosition().intValue()); - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == '+' || p.expression.charAt(p.position.intValue()) == '-')) { + char c = p.expression.charAt(p.position.intValue()); + p.position.increment(); result.append(c); } try { result.append(IntegerParser.parser.parse(p, previousSumElement).intValue()); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/ExponentParser.java b/jscl/src/main/java/jscl/text/ExponentParser.java index 2861a7f0..3c99dfa3 100644 --- a/jscl/src/main/java/jscl/text/ExponentParser.java +++ b/jscl/src/main/java/jscl/text/ExponentParser.java @@ -18,7 +18,7 @@ class ExponentParser implements Parser { } public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); boolean sign = MinusParser.parser.parse(p, previousSumElement).isSign(); diff --git a/jscl/src/main/java/jscl/text/Identifier.java b/jscl/src/main/java/jscl/text/Identifier.java index 67992664..5f549759 100644 --- a/jscl/src/main/java/jscl/text/Identifier.java +++ b/jscl/src/main/java/jscl/text/Identifier.java @@ -28,22 +28,22 @@ public class Identifier implements Parser { // returns getVariable/constant getName @Nonnull public String parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final StringBuilder result = new StringBuilder(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && isValidFirstCharacter(p.getExpression().charAt(p.getPosition().intValue()))) { - result.append(p.getExpression().charAt(p.getPosition().intValue())); - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && isValidFirstCharacter(p.expression.charAt(p.position.intValue()))) { + result.append(p.expression.charAt(p.position.intValue())); + p.position.increment(); } else { ParserUtils.throwParseException(p, pos0, Messages.msg_5); } - while (p.getPosition().intValue() < p.getExpression().length() && isValidNotFirstCharacter(p.getExpression(), p.getPosition())) { - result.append(p.getExpression().charAt(p.getPosition().intValue())); - p.getPosition().increment(); + while (p.position.intValue() < p.expression.length() && isValidNotFirstCharacter(p.expression, p.position)) { + result.append(p.expression.charAt(p.position.intValue())); + p.position.increment(); } return result.toString(); diff --git a/jscl/src/main/java/jscl/text/ImplicitFunctionParser.java b/jscl/src/main/java/jscl/text/ImplicitFunctionParser.java index 78c42212..b24868ed 100644 --- a/jscl/src/main/java/jscl/text/ImplicitFunctionParser.java +++ b/jscl/src/main/java/jscl/text/ImplicitFunctionParser.java @@ -19,13 +19,13 @@ public class ImplicitFunctionParser implements Parser { } public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); Generic a[]; final String name = ParserUtils.parseWithRollback(CompoundIdentifier.parser, pos0, previousSumElement, p); if (FunctionsRegistry.getInstance().getNames().contains(name) || OperatorsRegistry.getInstance().getNames().contains(name)) { - p.getPosition().setValue(pos0); - throw new ParseException(Messages.msg_6, p.getPosition().intValue(), p.getExpression(), name); + p.position.setValue(pos0); + throw new ParseException(Messages.msg_6, p.position.intValue(), p.expression, name); } final List subscripts = new ArrayList(); @@ -46,7 +46,7 @@ public class ImplicitFunctionParser implements Parser { try { a = ParameterListParser.parser1.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } @@ -87,7 +87,7 @@ class SuperscriptList implements Parser { } public int[] parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.tryToParse(p, pos0, '{'); @@ -95,7 +95,7 @@ class SuperscriptList implements Parser { try { result.add(IntegerParser.parser.parse(p, previousSumElement)); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } @@ -123,7 +123,7 @@ class CommaAndInteger implements Parser { } public Integer parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); diff --git a/jscl/src/main/java/jscl/text/IntegerParser.java b/jscl/src/main/java/jscl/text/IntegerParser.java index ceff45d6..83622339 100644 --- a/jscl/src/main/java/jscl/text/IntegerParser.java +++ b/jscl/src/main/java/jscl/text/IntegerParser.java @@ -15,7 +15,7 @@ public class IntegerParser implements Parser { } public Integer parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); /*int n; @@ -40,18 +40,18 @@ public class IntegerParser implements Parser { final StringBuilder result = new StringBuilder(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { - char c = p.getExpression().charAt(p.getPosition().intValue()); - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) { + char c = p.expression.charAt(p.position.intValue()); + p.position.increment(); result.append(c); } else { - p.getPosition().setValue(pos0); - throw new ParseException(Messages.msg_7, p.getPosition().intValue(), p.getExpression()); + p.position.setValue(pos0); + throw new ParseException(Messages.msg_7, p.position.intValue(), p.expression); } - while (p.getPosition().intValue() < p.getExpression().length() && nb.getAcceptableCharacters().contains(p.getExpression().charAt(p.getPosition().intValue()))) { - char c = p.getExpression().charAt(p.getPosition().intValue()); - p.getPosition().increment(); + while (p.position.intValue() < p.expression.length() && nb.getAcceptableCharacters().contains(p.expression.charAt(p.position.intValue()))) { + char c = p.expression.charAt(p.position.intValue()); + p.position.increment(); result.append(c); } @@ -59,7 +59,7 @@ public class IntegerParser implements Parser { try { return nb.toInteger(number); } catch (NumberFormatException e) { - throw new ParseException(Messages.msg_8, p.getPosition().intValue(), p.getExpression(), number); + throw new ParseException(Messages.msg_8, p.position.intValue(), p.expression, number); } } } diff --git a/jscl/src/main/java/jscl/text/JsclIntegerParser.java b/jscl/src/main/java/jscl/text/JsclIntegerParser.java index c1f19c42..690aad17 100644 --- a/jscl/src/main/java/jscl/text/JsclIntegerParser.java +++ b/jscl/src/main/java/jscl/text/JsclIntegerParser.java @@ -16,7 +16,7 @@ public class JsclIntegerParser implements Parser { } public JsclInteger parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final NumeralBase nb = NumeralBaseParser.parser.parse(p, previousSumElement); @@ -25,7 +25,7 @@ public class JsclIntegerParser implements Parser { try { result.append(new Digits(nb).parse(p, previousSumElement)); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } @@ -33,7 +33,7 @@ public class JsclIntegerParser implements Parser { try { return nb.toJsclInteger(number); } catch (NumberFormatException e) { - throw new ParseException(Messages.msg_8, p.getPosition().intValue(), p.getExpression(), number); + throw new ParseException(Messages.msg_8, p.position.intValue(), p.expression, number); } } } diff --git a/jscl/src/main/java/jscl/text/MatrixParser.java b/jscl/src/main/java/jscl/text/MatrixParser.java index 5721f594..33671142 100644 --- a/jscl/src/main/java/jscl/text/MatrixParser.java +++ b/jscl/src/main/java/jscl/text/MatrixParser.java @@ -17,7 +17,7 @@ public class MatrixParser implements Parser { } public Matrix parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final List vectors = new ArrayList(); @@ -26,7 +26,7 @@ public class MatrixParser implements Parser { try { vectors.add(VectorParser.parser.parse(p, previousSumElement)); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/MinusParser.java b/jscl/src/main/java/jscl/text/MinusParser.java index e9017e88..1b633a23 100644 --- a/jscl/src/main/java/jscl/text/MinusParser.java +++ b/jscl/src/main/java/jscl/text/MinusParser.java @@ -21,16 +21,16 @@ class MinusParser implements Parser { public Result parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) { final boolean result; - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '-') { + if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '-') { result = true; - p.getPosition().increment(); + p.position.increment(); } else { result = false; - p.getPosition().setValue(pos0); + p.position.setValue(pos0); } return new Result(result); diff --git a/jscl/src/main/java/jscl/text/MultiplyOrDivideFactor.java b/jscl/src/main/java/jscl/text/MultiplyOrDivideFactor.java index 7f69cce7..ba0acc3b 100644 --- a/jscl/src/main/java/jscl/text/MultiplyOrDivideFactor.java +++ b/jscl/src/main/java/jscl/text/MultiplyOrDivideFactor.java @@ -23,11 +23,11 @@ class MultiplyOrDivideFactor implements Parser { } public Generic parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == (multiplication ? '*' : '/')) { - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == (multiplication ? '*' : '/')) { + p.position.increment(); } else { ParserUtils.throwParseException(p, pos0, Messages.msg_10, '*', '/'); } diff --git a/jscl/src/main/java/jscl/text/NumeralBaseParser.java b/jscl/src/main/java/jscl/text/NumeralBaseParser.java index 9a1b5eb3..ba2b4feb 100644 --- a/jscl/src/main/java/jscl/text/NumeralBaseParser.java +++ b/jscl/src/main/java/jscl/text/NumeralBaseParser.java @@ -14,9 +14,9 @@ public class NumeralBaseParser implements Parser { } public NumeralBase parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); - NumeralBase result = p.getMathContext().getNumeralBase(); + NumeralBase result = p.context.getNumeralBase(); ParserUtils.skipWhitespaces(p); diff --git a/jscl/src/main/java/jscl/text/OperatorParser.java b/jscl/src/main/java/jscl/text/OperatorParser.java index d3558e77..1e947735 100644 --- a/jscl/src/main/java/jscl/text/OperatorParser.java +++ b/jscl/src/main/java/jscl/text/OperatorParser.java @@ -21,7 +21,7 @@ public class OperatorParser implements Parser { @Nonnull public Operator parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final String operatorName = Identifier.parser.parse(p, previousSumElement); if (!valid(operatorName)) { diff --git a/jscl/src/main/java/jscl/text/ParameterListParser.java b/jscl/src/main/java/jscl/text/ParameterListParser.java index eca5d07b..c92db0bb 100644 --- a/jscl/src/main/java/jscl/text/ParameterListParser.java +++ b/jscl/src/main/java/jscl/text/ParameterListParser.java @@ -22,7 +22,7 @@ public class ParameterListParser implements Parser { @Nonnull public Generic[] parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final List result = new ArrayList(); @@ -32,7 +32,7 @@ public class ParameterListParser implements Parser { result.add(ExpressionParser.parser.parse(p, previousSumElement)); } catch (ParseException e) { if (minNumberOfParameters > 0) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } } diff --git a/jscl/src/main/java/jscl/text/Parser.java b/jscl/src/main/java/jscl/text/Parser.java index 3ed0ecf5..0b7525ce 100644 --- a/jscl/src/main/java/jscl/text/Parser.java +++ b/jscl/src/main/java/jscl/text/Parser.java @@ -6,7 +6,6 @@ import jscl.math.Generic; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -26,29 +25,29 @@ public interface Parser { */ T parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException; - static class Parameters { + class Parameters { @Nonnull - private final String expression; + public final String expression; @Nonnull - private final MutableInt position; + public final MutableInt position; @Nonnull - private final List exceptions = new ArrayList(); + public final List exceptions = new ArrayList(); @Nonnull - private final MathContext mathContext; + public final MathContext context; /** * @param expression expression to be parsed * @param position current position of expression. Side effect: if parsing is successful this parameter should be increased on the number of parsed letters (incl whitespaces etc) - * @param mathContext math engine to be used in parsing + * @param context math engine to be used in parsing */ - Parameters(@Nonnull String expression, @Nonnull MutableInt position, @Nonnull MathContext mathContext) { + Parameters(@Nonnull String expression, @Nonnull MutableInt position, @Nonnull MathContext context) { this.expression = expression; this.position = position; - this.mathContext = mathContext; + this.context = context; } @Nonnull @@ -56,30 +55,10 @@ public interface Parser { return new Parameters(expression, position, mathEngine); } - @Nonnull - public String getExpression() { - return expression; - } - - @Nonnull - public MutableInt getPosition() { - return position; - } - public void addException(@Nonnull ParseException e) { if (!exceptions.contains(e)) { exceptions.add(e); } } - - @Nonnull - public MathContext getMathContext() { - return mathContext; - } - - @Nonnull - public List getExceptions() { - return Collections.unmodifiableList(exceptions); - } } } diff --git a/jscl/src/main/java/jscl/text/ParserUtils.java b/jscl/src/main/java/jscl/text/ParserUtils.java index c847eb40..dc9baab5 100644 --- a/jscl/src/main/java/jscl/text/ParserUtils.java +++ b/jscl/src/main/java/jscl/text/ParserUtils.java @@ -21,8 +21,8 @@ public class ParserUtils { } public static void skipWhitespaces(@Nonnull Parser.Parameters p) { - final MutableInt position = p.getPosition(); - final String expression = p.getExpression(); + final MutableInt position = p.position; + final String expression = p.expression; while (position.intValue() < expression.length() && Character.isWhitespace(expression.charAt(position.intValue()))) { position.increment(); @@ -34,10 +34,10 @@ public class ParserUtils { char ch) throws ParseException { skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length()) { - char actual = p.getExpression().charAt(p.getPosition().intValue()); + if (p.position.intValue() < p.expression.length()) { + char actual = p.expression.charAt(p.position.intValue()); if (actual == ch) { - p.getPosition().increment(); + p.position.increment(); } else { throwParseException(p, pos0, Messages.msg_12, ch); } @@ -51,9 +51,9 @@ public class ParserUtils { @Nonnull String s) throws ParseException { skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length()) { - if (p.getExpression().startsWith(s, p.getPosition().intValue())) { - p.getPosition().add(s.length()); + if (p.position.intValue() < p.expression.length()) { + if (p.expression.startsWith(s, p.position.intValue())) { + p.position.add(s.length()); } else { throwParseException(p, pos0, Messages.msg_11, s); } @@ -66,8 +66,8 @@ public class ParserUtils { int pos0, @Nonnull String messageId, Object... parameters) throws ParseException { - final MutableInt position = p.getPosition(); - final ParseException parseException = new ParseException(messageId, position.intValue(), p.getExpression(), parameters); + final MutableInt position = p.position; + final ParseException parseException = new ParseException(messageId, position.intValue(), p.expression, parameters); position.setValue(pos0); throw parseException; } @@ -83,7 +83,7 @@ public class ParserUtils { try { result = parser.parse(p, previousSumParser); } catch (ParseException e) { - p.getPosition().setValue(initialPosition); + p.position.setValue(initialPosition); throw e; } diff --git a/jscl/src/main/java/jscl/text/PlusOrMinusTerm.java b/jscl/src/main/java/jscl/text/PlusOrMinusTerm.java index 943c75c1..91e2b587 100644 --- a/jscl/src/main/java/jscl/text/PlusOrMinusTerm.java +++ b/jscl/src/main/java/jscl/text/PlusOrMinusTerm.java @@ -18,14 +18,14 @@ class PlusOrMinusTerm implements Parser { } public Generic parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); boolean sign = false; - if (p.getPosition().intValue() < p.getExpression().length() && (p.getExpression().charAt(p.getPosition().intValue()) == '+' || p.getExpression().charAt(p.getPosition().intValue()) == '-')) { - sign = p.getExpression().charAt(p.getPosition().intValue()) == '-'; - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && (p.expression.charAt(p.position.intValue()) == '+' || p.expression.charAt(p.position.intValue()) == '-')) { + sign = p.expression.charAt(p.position.intValue()) == '-'; + p.position.increment(); } else { ParserUtils.throwParseException(p, pos0, Messages.msg_10, '+', '-'); } diff --git a/jscl/src/main/java/jscl/text/PostfixFunctionParser.java b/jscl/src/main/java/jscl/text/PostfixFunctionParser.java index 30cc8206..1b0c5b30 100644 --- a/jscl/src/main/java/jscl/text/PostfixFunctionParser.java +++ b/jscl/src/main/java/jscl/text/PostfixFunctionParser.java @@ -20,17 +20,17 @@ public class PostfixFunctionParser implements Parser { if (postfixFunction == null) { if (TripleFactorial.NAME.equals(postfixResult.getPostfixFunctionName())) { - throw new ParseException(Messages.msg_18, parseParameters.getPosition().intValue(), parseParameters.getExpression()); + throw new ParseException(Messages.msg_18, parseParameters.position.intValue(), parseParameters.expression); } else { - throw new ParseException(Messages.msg_4, parseParameters.getPosition().intValue(), parseParameters.getExpression(), postfixResult.getPostfixFunctionName()); + throw new ParseException(Messages.msg_4, parseParameters.position.intValue(), parseParameters.expression, postfixResult.getPostfixFunctionName()); } } diff --git a/jscl/src/main/java/jscl/text/PowerExponentParser.java b/jscl/src/main/java/jscl/text/PowerExponentParser.java index e7488cdf..df4ab57d 100644 --- a/jscl/src/main/java/jscl/text/PowerExponentParser.java +++ b/jscl/src/main/java/jscl/text/PowerExponentParser.java @@ -18,12 +18,12 @@ class PowerExponentParser implements Parser { } public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); try { PowerParser.parser.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } @@ -31,7 +31,7 @@ class PowerExponentParser implements Parser { try { result = ExponentParser.parser.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/PowerParser.java b/jscl/src/main/java/jscl/text/PowerParser.java index 960f9afc..164f1f1d 100644 --- a/jscl/src/main/java/jscl/text/PowerParser.java +++ b/jscl/src/main/java/jscl/text/PowerParser.java @@ -20,16 +20,16 @@ class PowerParser implements Parser { @Nullable public Void parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '^') { - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '^') { + p.position.increment(); } else { - if (isDoubleStar(p.getExpression(), p.getPosition())) { - p.getPosition().increment(); - p.getPosition().increment(); + if (isDoubleStar(p.expression, p.position)) { + p.position.increment(); + p.position.increment(); } else { ParserUtils.throwParseException(p, pos0, Messages.msg_10, '^', "**"); } diff --git a/jscl/src/main/java/jscl/text/PrimeCharacters.java b/jscl/src/main/java/jscl/text/PrimeCharacters.java index 6e38a76c..9bd76c36 100644 --- a/jscl/src/main/java/jscl/text/PrimeCharacters.java +++ b/jscl/src/main/java/jscl/text/PrimeCharacters.java @@ -14,21 +14,21 @@ public class PrimeCharacters implements Parser { public Integer parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); int result = 0; ParserUtils.skipWhitespaces(p); - if (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '\'') { - p.getPosition().increment(); + if (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '\'') { + p.position.increment(); result = 1; } else { ParserUtils.throwParseException(p, pos0, Messages.msg_12, '\''); } - while (p.getPosition().intValue() < p.getExpression().length() && p.getExpression().charAt(p.getPosition().intValue()) == '\'') { - p.getPosition().increment(); + while (p.position.intValue() < p.expression.length() && p.expression.charAt(p.position.intValue()) == '\'') { + p.position.increment(); result++; } diff --git a/jscl/src/main/java/jscl/text/RootParser.java b/jscl/src/main/java/jscl/text/RootParser.java index 5c95bd42..125c0379 100644 --- a/jscl/src/main/java/jscl/text/RootParser.java +++ b/jscl/src/main/java/jscl/text/RootParser.java @@ -14,7 +14,7 @@ public class RootParser implements Parser { } public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final String name = Identifier.parser.parse(p, previousSumElement); if (name.compareTo("root") != 0) { diff --git a/jscl/src/main/java/jscl/text/Subscript.java b/jscl/src/main/java/jscl/text/Subscript.java index 9bfd56d6..d4734e1b 100644 --- a/jscl/src/main/java/jscl/text/Subscript.java +++ b/jscl/src/main/java/jscl/text/Subscript.java @@ -13,7 +13,7 @@ public class Subscript implements Parser { } public Generic parse(@Nonnull Parameters p, @Nullable Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.tryToParse(p, pos0, '['); @@ -21,7 +21,7 @@ public class Subscript implements Parser { try { a = ExpressionParser.parser.parse(p, previousSumElement); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; } diff --git a/jscl/src/main/java/jscl/text/UsualFunctionParser.java b/jscl/src/main/java/jscl/text/UsualFunctionParser.java index d0009814..afbcb426 100644 --- a/jscl/src/main/java/jscl/text/UsualFunctionParser.java +++ b/jscl/src/main/java/jscl/text/UsualFunctionParser.java @@ -28,7 +28,7 @@ class UsualFunctionParser implements Parser { } public Function parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); final String name = Identifier.parser.parse(p, previousSumElement); diff --git a/jscl/src/main/java/jscl/text/VectorParser.java b/jscl/src/main/java/jscl/text/VectorParser.java index 0a97fa55..ad98ba50 100644 --- a/jscl/src/main/java/jscl/text/VectorParser.java +++ b/jscl/src/main/java/jscl/text/VectorParser.java @@ -16,7 +16,7 @@ public class VectorParser implements Parser { } public JsclVector parse(@Nonnull Parameters p, Generic previousSumElement) throws ParseException { - int pos0 = p.getPosition().intValue(); + int pos0 = p.position.intValue(); ParserUtils.skipWhitespaces(p); @@ -26,7 +26,7 @@ public class VectorParser implements Parser { try { result.add(ExpressionParser.parser.parse(p, previousSumElement)); } catch (ParseException e) { - p.getPosition().setValue(pos0); + p.position.setValue(pos0); throw e; }