Skip to content

Commit

Permalink
Use API instead of sys prop lookup
Browse files Browse the repository at this point in the history
Remove noisy parens
Use final
Use Integer.valueOf()
USe Float.valueOf()
Use Double.valueOf()
Use Short.valueOf()
Use .valueOf()
Use {} to create arrays
Remove extra ';'
Remove trailing whitespace
Remove unused imports
Remove redundant super() call
Use diamonds
Remove redundant cast
Slightly longer line lengths
  • Loading branch information
garydgregory committed Sep 15, 2023
1 parent 625b35c commit 558fb5d
Show file tree
Hide file tree
Showing 98 changed files with 1,415 additions and 1,434 deletions.
2 changes: 1 addition & 1 deletion src/main/config/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ limitations under the License.
</module>

<module name="LineLength">
<property name="max" value="132"/>
<property name="max" value="160"/>
</module>

<module name="TreeWalker">
Expand Down
66 changes: 33 additions & 33 deletions src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public interface SetBuilder {
* @param extended whether the set is extended or not
* @return the array builder
*/
public SetBuilder setBuilder(final int size, boolean extended) {
public SetBuilder setBuilder(final int size, final boolean extended) {
return new org.apache.commons.jexl3.internal.SetBuilder(size);
}
@Deprecated
Expand Down Expand Up @@ -361,7 +361,7 @@ public interface MapBuilder {
* @param extended whether the map is extended or not
* @return the map builder
*/
public MapBuilder mapBuilder(final int size, boolean extended) {
public MapBuilder mapBuilder(final int size, final boolean extended) {
return new org.apache.commons.jexl3.internal.MapBuilder(size);
}
@Deprecated
Expand All @@ -371,7 +371,7 @@ public MapBuilder mapBuilder(final int size, boolean extended) {
public MapBuilder mapBuilder(final int size) {
return mapBuilder(size, false);
}

/**
* Creates a literal range.
* <p>The default implementation only accepts integers and longs.</p>
Expand All @@ -384,8 +384,8 @@ public MapBuilder mapBuilder(final int size) {
public Iterable<?> createRange(final Object from, final Object to) throws ArithmeticException {
final long lfrom = toLong(from);
final long lto = toLong(to);
if ((lfrom >= Integer.MIN_VALUE && lfrom <= Integer.MAX_VALUE)
&& (lto >= Integer.MIN_VALUE && lto <= Integer.MAX_VALUE)) {
if (lfrom >= Integer.MIN_VALUE && lfrom <= Integer.MAX_VALUE
&& lto >= Integer.MIN_VALUE && lto <= Integer.MAX_VALUE) {
return org.apache.commons.jexl3.internal.IntegerRange.create((int) lfrom, (int) lto);
}
return org.apache.commons.jexl3.internal.LongRange.create(lfrom, lto);
Expand Down Expand Up @@ -456,7 +456,7 @@ protected boolean toBoolean(final boolean strict, final Object val) {
*/
public boolean toBoolean(final Object val) {
if (val instanceof Boolean) {
return ((Boolean) val);
return (Boolean) val;
}
if (val instanceof Number) {
final double number = toDouble(strict, val);
Expand Down Expand Up @@ -512,13 +512,13 @@ public int toInteger(final Object val) {
return parseInteger((String) val);
}
if (val instanceof Boolean) {
return ((Boolean) val) ? 1 : 0;
return (Boolean) val ? 1 : 0;
}
if (val instanceof AtomicBoolean) {
return ((AtomicBoolean) val).get() ? 1 : 0;
}
if (val instanceof Character) {
return ((Character) val);
return (Character) val;
}
if (val == null) {
return controlNullOperand(strict, 0);
Expand Down Expand Up @@ -563,13 +563,13 @@ public long toLong(final Object val) {
return parseLong((String) val);
}
if (val instanceof Boolean) {
return ((Boolean) val) ? 1L : 0L;
return (Boolean) val ? 1L : 0L;
}
if (val instanceof AtomicBoolean) {
return ((AtomicBoolean) val).get() ? 1L : 0L;
}
if (val instanceof Character) {
return ((Character) val);
return (Character) val;
}
if (val == null) {
return controlNullOperand(strict, 0L);
Expand Down Expand Up @@ -620,7 +620,7 @@ public BigInteger toBigInteger(final Object val) {
return BigInteger.valueOf(((Number) val).longValue());
}
if (val instanceof Boolean) {
return BigInteger.valueOf(((Boolean) val) ? 1L : 0L);
return BigInteger.valueOf((Boolean) val ? 1L : 0L);
}
if (val instanceof AtomicBoolean) {
return BigInteger.valueOf(((AtomicBoolean) val).get() ? 1L : 0L);
Expand All @@ -629,7 +629,7 @@ public BigInteger toBigInteger(final Object val) {
return parseBigInteger((String) val);
}
if (val instanceof Character) {
final int i = ((Character) val);
final int i = (Character) val;
return BigInteger.valueOf(i);
}
if (val == null) {
Expand Down Expand Up @@ -668,7 +668,7 @@ public BigDecimal toBigDecimal(final Object val) {
return roundBigDecimal((BigDecimal) val);
}
if (val instanceof Double) {
if (Double.isNaN(((Double) val))) {
if (Double.isNaN((Double) val)) {
return BigDecimal.ZERO;
}
return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
Expand All @@ -677,7 +677,7 @@ public BigDecimal toBigDecimal(final Object val) {
return roundBigDecimal(new BigDecimal(val.toString(), getMathContext()));
}
if (val instanceof Boolean) {
return BigDecimal.valueOf(((Boolean) val) ? 1. : 0.);
return BigDecimal.valueOf((Boolean) val ? 1. : 0.);
}
if (val instanceof AtomicBoolean) {
return BigDecimal.valueOf(((AtomicBoolean) val).get() ? 1L : 0L);
Expand All @@ -690,7 +690,7 @@ public BigDecimal toBigDecimal(final Object val) {
return roundBigDecimal(new BigDecimal(string, getMathContext()));
}
if (val instanceof Character) {
final int i = ((Character) val);
final int i = (Character) val;
return new BigDecimal(i);
}
if (val == null) {
Expand Down Expand Up @@ -726,15 +726,15 @@ protected double toDouble(final boolean strict, final Object val) {
*/
public double toDouble(final Object val) {
if (val instanceof Double) {
return ((Double) val);
return (Double) val;
}
if (val instanceof Number) {
//The below construct is used rather than ((Number)val).doubleValue() to ensure
//equality between comparing new Double( 6.4 / 3 ) and the jexl expression of 6.4 / 3
return Double.parseDouble(String.valueOf(val));
}
if (val instanceof Boolean) {
return ((Boolean) val) ? 1. : 0.;
return (Boolean) val ? 1. : 0.;
}
if (val instanceof AtomicBoolean) {
return ((AtomicBoolean) val).get() ? 1. : 0.;
Expand All @@ -743,7 +743,7 @@ public double toDouble(final Object val) {
return parseDouble((String) val);
}
if (val instanceof Character) {
return ((Character) val);
return (Character) val;
}
if (val == null) {
return controlNullOperand(strict, 0.d);
Expand Down Expand Up @@ -1186,13 +1186,13 @@ protected Object increment(final Object val, final int incr) {
return incr;
}
if (val instanceof Integer) {
return ((Integer) val) + incr;
return (Integer) val + incr;
}
if (val instanceof Double) {
return ((Double) val) + incr;
return (Double) val + incr;
}
if (val instanceof Long) {
return ((Long) val) + incr;
return (Long) val + incr;
}
if (val instanceof BigDecimal) {
final BigDecimal bd = (BigDecimal) val;
Expand All @@ -1203,13 +1203,13 @@ protected Object increment(final Object val, final int incr) {
return bi.add(BigInteger.valueOf(incr));
}
if (val instanceof Float) {
return ((Float) val) + incr;
return (Float) val + incr;
}
if (val instanceof Short) {
return (short) (((Short) val) + incr);
return (short) ((Short) val + incr);
}
if (val instanceof Byte) {
return (byte) (((Byte) val) + incr);
return (byte) ((Byte) val + incr);
}
throw new ArithmeticException("Object "+(incr < 0? "decrement":"increment")+":(" + val + ")");
}
Expand Down Expand Up @@ -1393,9 +1393,9 @@ public Object mod(final Object left, final Object right) {
protected static boolean isMultiplyExact(final long x, final long y, final long r) {
final long ax = Math.abs(x);
final long ay = Math.abs(y);
return !(((ax | ay) >>> (Integer.SIZE - 1) != 0)
&& (((y != 0) && (r / y != x))
|| (x == Long.MIN_VALUE && y == -1)));
return !((ax | ay) >>> Integer.SIZE - 1 != 0
&& (y != 0 && r / y != x
|| x == Long.MIN_VALUE && y == -1));
}

/**
Expand Down Expand Up @@ -1686,7 +1686,7 @@ public Boolean endsWith(final Object left, final Object right) {
return false;
}
if (left instanceof CharSequence) {
return (toString(left)).endsWith(toString(right));
return toString(left).endsWith(toString(right));
}
return null;
}
Expand All @@ -1708,7 +1708,7 @@ public Boolean startsWith(final Object left, final Object right) {
return false;
}
if (left instanceof CharSequence) {
return (toString(left)).startsWith(toString(right));
return toString(left).startsWith(toString(right));
}
return null;
}
Expand Down Expand Up @@ -1928,11 +1928,11 @@ private static boolean computeCompare321(final JexlArithmetic arithmetic) {
Class<?> arithmeticClass = arithmetic.getClass();
while(arithmeticClass != JexlArithmetic.class) {
try {
Method cmp = arithmeticClass.getDeclaredMethod("compare", Object.class, Object.class, String.class);
final Method cmp = arithmeticClass.getDeclaredMethod("compare", Object.class, Object.class, String.class);
if (cmp.getDeclaringClass() != JexlArithmetic.class) {
return true;
}
} catch (NoSuchMethodException xany) {
} catch (final NoSuchMethodException xany) {
arithmeticClass = arithmeticClass.getSuperclass();
}
}
Expand Down Expand Up @@ -2041,7 +2041,7 @@ public boolean equals(final Object left, final Object right) {
* @return the test result
*/
public boolean lessThan(final Object left, final Object right) {
if ((left == right) || (left == null) || (right == null)) {
if (left == right || left == null || right == null) {
return false;
}
return compare(left, right, JexlOperator.LT) < 0;
Expand All @@ -2056,7 +2056,7 @@ public boolean lessThan(final Object left, final Object right) {
* @return the test result
*/
public boolean greaterThan(final Object left, final Object right) {
if ((left == right) || left == null || right == null) {
if (left == right || left == null || right == null) {
return false;
}
return compare(left, right, JexlOperator.GT) > 0;
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/org/apache/commons/jexl3/JexlFeatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,23 @@ public final class JexlFeatures {
* The default features flag mask.
*/
private static final long DEFAULT_FEATURES =
(1L << LOCAL_VAR)
| (1L << SIDE_EFFECT)
| (1L << SIDE_EFFECT_GLOBAL)
| (1L << ARRAY_REF_EXPR)
| (1L << NEW_INSTANCE)
| (1L << LOOP)
| (1L << LAMBDA)
| (1L << METHOD_CALL)
| (1L << STRUCTURED_LITERAL)
| (1L << PRAGMA)
| (1L << ANNOTATION)
| (1L << SCRIPT)
| (1L << THIN_ARROW)
| (1L << NS_PRAGMA)
| (1L << IMPORT_PRAGMA)
| (1L << COMPARATOR_NAMES)
| (1L << PRAGMA_ANYWHERE);
1L << LOCAL_VAR
| 1L << SIDE_EFFECT
| 1L << SIDE_EFFECT_GLOBAL
| 1L << ARRAY_REF_EXPR
| 1L << NEW_INSTANCE
| 1L << LOOP
| 1L << LAMBDA
| 1L << METHOD_CALL
| 1L << STRUCTURED_LITERAL
| 1L << PRAGMA
| 1L << ANNOTATION
| 1L << SCRIPT
| 1L << THIN_ARROW
| 1L << NS_PRAGMA
| 1L << IMPORT_PRAGMA
| 1L << COMPARATOR_NAMES
| 1L << PRAGMA_ANYWHERE;

/**
* Creates an all-features-enabled instance.
Expand All @@ -162,7 +162,7 @@ public JexlFeatures(final JexlFeatures features) {
@Override
public int hashCode() { //CSOFF: MagicNumber
int hash = 3;
hash = 53 * hash + (int) (this.flags ^ (this.flags >>> 32));
hash = 53 * hash + (int) (this.flags ^ this.flags >>> 32);
hash = 53 * hash + (this.reservedNames != null ? this.reservedNames.hashCode() : 0);
return hash;
}
Expand Down Expand Up @@ -252,7 +252,7 @@ public Predicate<String> namespaceTest() {
*/
private void setFeature(final int feature, final boolean flag) {
if (flag) {
flags |= (1L << feature);
flags |= 1L << feature;
} else {
flags &= ~(1L << feature);
}
Expand All @@ -264,7 +264,7 @@ private void setFeature(final int feature, final boolean flag) {
* @return true if on, false if off
*/
private boolean getFeature(final int feature) {
return (flags & (1L << feature)) != 0L;
return (flags & 1L << feature) != 0L;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/commons/jexl3/JexlOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public final class JexlOptions {
* @return the new flags mask value
*/
private static int set(final int ordinal, final int mask, final boolean value) {
return value? mask | (1 << ordinal) : mask & ~(1 << ordinal);
return value? mask | 1 << ordinal : mask & ~(1 << ordinal);
}

/**
Expand Down Expand Up @@ -146,7 +146,7 @@ public static int parseFlags(final int initial, final String... flags) {
for (int f = 0; f < NAMES.length; ++f) {
if (NAMES[f].equals(name)) {
if (b) {
mask |= (1 << f);
mask |= 1 << f;
} else {
mask &= ~(1 << f);
}
Expand Down Expand Up @@ -444,7 +444,7 @@ public JexlOptions copy() {
if (i > 0) {
strb.append(' ');
}
strb.append((flags & (1 << i)) != 0? '+':'-');
strb.append((flags & 1 << i) != 0? '+':'-');
strb.append(NAMES[i]);
}
return strb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Object create(final boolean e) {
return list;
}
// convert untyped array to the common class if not Object.class
if ((commonClass == null) || Object.class.equals(commonClass)) {
if (commonClass == null || Object.class.equals(commonClass)) {
return untyped.clone();
}
final int size = added;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/commons/jexl3/internal/Closure.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected Closure(final Interpreter theCaller, final ASTJexlLambda lambda) {
*/
protected Closure(final Script base, final Object[] args) {
super(base.jexl, base.source, base.script);
final Frame sf = (base instanceof Closure) ? ((Closure) base).frame : null;
final Frame sf = base instanceof Closure ? ((Closure) base).frame : null;
frame = sf == null
? script.createFrame(args)
: sf.assign(args);
Expand Down Expand Up @@ -113,8 +113,8 @@ public String[] getUnboundParameters() {
*/
void captureSelfIfRecursive(final Frame parentFrame, final int symbol) {
if (script instanceof ASTJexlLambda) {
Scope parentScope = parentFrame != null ? parentFrame.getScope() : null;
Scope localScope = frame != null ? frame.getScope() : null;
final Scope parentScope = parentFrame != null ? parentFrame.getScope() : null;
final Scope localScope = frame != null ? frame.getScope() : null;
if (parentScope != null && localScope != null && parentScope == localScope.getParent()) {
final Integer reg = localScope.getCaptured(symbol);
if (reg != null) {
Expand Down
Loading

0 comments on commit 558fb5d

Please sign in to comment.