Skip to content

Commit

Permalink
removes lint warnings (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
uklimaschewski authored May 19, 2024
1 parent f6b1b85 commit 6848d45
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 53 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/ezylang/evalex/BaseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
/** Base exception class used in EvalEx. */
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@ToString
@Getter
public class BaseException extends Exception {

@Getter @EqualsAndHashCode.Include private final int startPosition;
@Getter @EqualsAndHashCode.Include private final int endPosition;
@Getter @EqualsAndHashCode.Include private final String tokenString;
@Getter @EqualsAndHashCode.Include private final String message;
@EqualsAndHashCode.Include private final int startPosition;
@EqualsAndHashCode.Include private final int endPosition;
@EqualsAndHashCode.Include private final String tokenString;
@EqualsAndHashCode.Include private final String message;

public BaseException(int startPosition, int endPosition, String tokenString, String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
* </pre>
*/
@Builder(toBuilder = true)
@Getter
public class ExpressionConfiguration {

/** The standard set constants for EvalEx. */
Expand Down Expand Up @@ -95,7 +96,6 @@ public class ExpressionConfiguration {

/** The operator dictionary holds all operators that will be allowed in an expression. */
@Builder.Default
@Getter
@SuppressWarnings("unchecked")
private final OperatorDictionaryIfc operatorDictionary =
MapBasedOperatorDictionary.ofOperators(
Expand Down Expand Up @@ -123,7 +123,6 @@ public class ExpressionConfiguration {

/** The function dictionary holds all functions that will be allowed in an expression. */
@Builder.Default
@Getter
@SuppressWarnings("unchecked")
private final FunctionDictionaryIfc functionDictionary =
MapBasedFunctionDictionary.ofFunctions(
Expand Down Expand Up @@ -200,51 +199,49 @@ public class ExpressionConfiguration {
Map.entry("DT_TODAY", new DateTimeTodayFunction()));

/** The math context to use. */
@Builder.Default @Getter private final MathContext mathContext = DEFAULT_MATH_CONTEXT;
@Builder.Default private final MathContext mathContext = DEFAULT_MATH_CONTEXT;

/**
* The data accessor is responsible for accessing variable and constant values in an expression.
* The supplier will be called once for each new expression, the default is to create a new {@link
* MapBasedDataAccessor} instance for each expression, providing a new storage for each
* expression.
*/
@Builder.Default @Getter
@Builder.Default
private final Supplier<DataAccessorIfc> dataAccessorSupplier = MapBasedDataAccessor::new;

/**
* Default constants will be added automatically to each expression and can be used in expression
* evaluation.
*/
@Builder.Default @Getter
@Builder.Default
private final Map<String, EvaluationValue> defaultConstants = getStandardConstants();

/** Support for arrays in expressions are allowed or not. */
@Builder.Default @Getter private final boolean arraysAllowed = true;
@Builder.Default private final boolean arraysAllowed = true;

/** Support for structures in expressions are allowed or not. */
@Builder.Default @Getter private final boolean structuresAllowed = true;
@Builder.Default private final boolean structuresAllowed = true;

/** Support for implicit multiplication, like in (a+b)(b+c) are allowed or not. */
@Builder.Default @Getter private final boolean implicitMultiplicationAllowed = true;
@Builder.Default private final boolean implicitMultiplicationAllowed = true;

/** Support for single quote string literals, like in 'Hello World' are allowed or not. */
@Builder.Default @Getter private final boolean singleQuoteStringLiteralsAllowed = false;
@Builder.Default private final boolean singleQuoteStringLiteralsAllowed = false;

/**
* The power of operator precedence, can be set higher {@link
* OperatorIfc#OPERATOR_PRECEDENCE_POWER_HIGHER} or to a custom value.
*/
@Builder.Default @Getter
private final int powerOfPrecedence = OperatorIfc.OPERATOR_PRECEDENCE_POWER;
@Builder.Default private final int powerOfPrecedence = OperatorIfc.OPERATOR_PRECEDENCE_POWER;

/**
* If specified, only the final result of the evaluation will be rounded to the specified number
* of decimal digits, using the MathContexts rounding mode.
*
* <p>The default value of _DECIMAL_PLACES_ROUNDING_UNLIMITED_ will disable rounding.
*/
@Builder.Default @Getter
private final int decimalPlacesResult = DECIMAL_PLACES_ROUNDING_UNLIMITED;
@Builder.Default private final int decimalPlacesResult = DECIMAL_PLACES_ROUNDING_UNLIMITED;

/**
* If specified, all results from operations and functions will be rounded to the specified number
Expand All @@ -255,37 +252,36 @@ public class ExpressionConfiguration {
* specified number of decimal digits, using the current rounding mode. Using a value of
* _DECIMAL_PLACES_ROUNDING_UNLIMITED_ will disable automatic rounding.
*/
@Builder.Default @Getter
private final int decimalPlacesRounding = DECIMAL_PLACES_ROUNDING_UNLIMITED;
@Builder.Default private final int decimalPlacesRounding = DECIMAL_PLACES_ROUNDING_UNLIMITED;

/**
* If set to true (default), then the trailing decimal zeros in a number result will be stripped.
*/
@Builder.Default @Getter private final boolean stripTrailingZeros = true;
@Builder.Default private final boolean stripTrailingZeros = true;

/**
* If set to true (default), then variables can be set that have the name of a constant. In that
* case, the constant value will be removed and a variable value will be set.
*/
@Builder.Default @Getter private final boolean allowOverwriteConstants = true;
@Builder.Default private final boolean allowOverwriteConstants = true;

/** The time zone id. By default, the system default zone ID is used. */
@Builder.Default @Getter private final ZoneId zoneId = ZoneId.systemDefault();
@Builder.Default private final ZoneId zoneId = ZoneId.systemDefault();

/** The locale. By default, the system default locale is used. */
@Builder.Default @Getter private final Locale locale = Locale.getDefault();
@Builder.Default private final Locale locale = Locale.getDefault();

/**
* The date-time formatters. When parsing, each format will be tried and the first matching will
* be used. For formatting, only the first will be used.
*
* <p>By default, the {@link ExpressionConfiguration#DEFAULT_DATE_TIME_FORMATTERS} are used.
*/
@Builder.Default @Getter
@Builder.Default
private final List<DateTimeFormatter> dateTimeFormatters = DEFAULT_DATE_TIME_FORMATTERS;

/** The converter to use when converting different data types to an {@link EvaluationValue}. */
@Builder.Default @Getter
@Builder.Default
private final EvaluationValueConverterIfc evaluationValueConverter =
new DefaultEvaluationValueConverter();

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/ezylang/evalex/data/EvaluationValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* corresponding object type.
*/
@Value
public final class EvaluationValue implements Comparable<EvaluationValue> {
public class EvaluationValue implements Comparable<EvaluationValue> {

/** A pre-built, immutable, null value. */
public static final EvaluationValue NULL_VALUE = new EvaluationValue(null, DataType.NULL);
Expand Down Expand Up @@ -143,7 +143,7 @@ public static EvaluationValue of(Object value, ExpressionConfiguration configura
}

/**
* Returns a null value (immutable).
* Returns an immutable null value.
*
* @return A null value.
*/
Expand Down Expand Up @@ -178,7 +178,7 @@ public static EvaluationValue stringValue(String value) {
* @return the new boolean value.
*/
public static EvaluationValue booleanValue(Boolean value) {
return value != null && value.booleanValue() ? TRUE : FALSE;
return value != null && value ? TRUE : FALSE;
}

/**
Expand Down Expand Up @@ -288,6 +288,7 @@ public boolean isDateTimeValue() {
public boolean isDurationValue() {
return getDataType() == DataType.DURATION;
}

/**
* Checks if the value is of type {@link DataType#ARRAY}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*/
public class DefaultEvaluationValueConverter implements EvaluationValueConverterIfc {

static List<ConverterIfc> converters =
static final List<ConverterIfc> converters =
Arrays.asList(
new NumberConverter(),
new StringConverter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.ezylang.evalex.functions.datetime;

import com.ezylang.evalex.EvaluationException;
import com.ezylang.evalex.Expression;
import com.ezylang.evalex.data.EvaluationValue;
import com.ezylang.evalex.functions.AbstractFunction;
Expand All @@ -33,8 +32,7 @@
public class DurationNewFunction extends AbstractFunction {
@Override
public EvaluationValue evaluate(
Expression expression, Token functionToken, EvaluationValue... parameterValues)
throws EvaluationException {
Expression expression, Token functionToken, EvaluationValue... parameterValues) {

int parameterLength = parameterValues.length;

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/ezylang/evalex/parser/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,10 @@ private Token parseHexNumberLiteral() {
// hexadecimal number, consume "0x"
tokenValue.append((char) currentChar);
consumeChar();
tokenValue.append((char) currentChar);
consumeChar();
while (currentChar != -1 && isAtHexChar()) {
do {
tokenValue.append((char) currentChar);
consumeChar();
}
} while (currentChar != -1 && isAtHexChar());
return new Token(tokenStartIndex, tokenValue.toString(), TokenType.NUMBER_LITERAL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testThreadLocal() throws InterruptedException {
}
}
} catch (EvaluationException | ParseException e) {
e.printStackTrace();
System.err.printf("Exception adding decimals: %s%n", e.getMessage());
errorCount.getAndIncrement();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public class TestConfigurationProvider {
Map.entry("?", new PostfixQuestionOperator()))
.withAdditionalFunctions(Map.entry("TEST", new DummyFunction()));

public static ExpressionConfiguration GermanConfiguration =
public static final ExpressionConfiguration GermanConfiguration =
ExpressionConfiguration.builder()
.zoneId(ZoneId.of("Europe/Berlin"))
.locale(Locale.GERMAN)
.build();
public static ExpressionConfiguration ChicagoConfiguration =
public static final ExpressionConfiguration ChicagoConfiguration =
ExpressionConfiguration.builder()
.zoneId(ZoneId.of("America/Chicago"))
.locale(Locale.ENGLISH)
Expand Down
24 changes: 10 additions & 14 deletions src/test/java/com/ezylang/evalex/data/EvaluationValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -548,24 +548,20 @@ void testNullValueSameInstance() {
}

@Test
void nestedEvaluationValue() {
try {
EvaluationValue value1 = EvaluationValue.of("Hello", defaultConfiguration());
EvaluationValue value2 = EvaluationValue.of("World", defaultConfiguration());
void nestedEvaluationValue() throws EvaluationException, ParseException {
EvaluationValue value1 = EvaluationValue.of("Hello", defaultConfiguration());
EvaluationValue value2 = EvaluationValue.of("World", defaultConfiguration());

Map<String, EvaluationValue> structure = new HashMap<>();
structure.put("a", value1);
structure.put("b", value2);
Map<String, EvaluationValue> structure = new HashMap<>();
structure.put("a", value1);
structure.put("b", value2);

EvaluationValue structureMap = EvaluationValue.of(structure, defaultConfiguration());
EvaluationValue structureMap = EvaluationValue.of(structure, defaultConfiguration());

Expression exp = new Expression("value.a == \"Hello\"").with("value", structureMap);
Expression exp = new Expression("value.a == \"Hello\"").with("value", structureMap);

EvaluationValue result = exp.evaluate();
assertThat(result.getBooleanValue()).isTrue();
} catch (EvaluationException | ParseException e) {
e.printStackTrace();
}
EvaluationValue result = exp.evaluate();
assertThat(result.getBooleanValue()).isTrue();
}

@Test
Expand Down

0 comments on commit 6848d45

Please sign in to comment.