diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java index aa2350274a..bbda65d47e 100644 --- a/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java +++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolatingFunction.java @@ -175,14 +175,10 @@ public double value(double x, double y) * @return {@code true} if (x, y) is a valid point. */ public boolean isValidPoint(double x, double y) { - if (x < xval[0] || - x > xval[xval.length - 1] || - y < yval[0] || - y > yval[yval.length - 1]) { - return false; - } else { - return true; - } + return !(x < xval[0]) && + !(x > xval[xval.length - 1]) && + !(y < yval[0]) && + !(y > yval[yval.length - 1]); } /** diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolator.java index 62d16029bf..792b291872 100644 --- a/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolator.java +++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/BicubicInterpolator.java @@ -100,14 +100,10 @@ public BicubicInterpolatingFunction interpolate(final double[] xval, /** {@inheritDoc} */ @Override public boolean isValidPoint(double x, double y) { - if (x < xval[1] || - x > xval[xval.length - 2] || - y < yval[1] || - y > yval[yval.length - 2]) { - return false; - } else { - return true; - } + return !(x < xval[1]) && + !(x > xval[xval.length - 2]) && + !(y < yval[1]) && + !(y > yval[yval.length - 2]); } }; } diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java index f547a1f3b3..2e165d70e8 100644 --- a/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java +++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/PiecewiseBicubicSplineInterpolatingFunction.java @@ -157,14 +157,10 @@ public double value(double x, */ public boolean isValidPoint(double x, double y) { - if (x < xval[0] || - x > xval[xval.length - 1] || - y < yval[0] || - y > yval[yval.length - 1]) { - return false; - } else { - return true; - } + return !(x < xval[0]) && + !(x > xval[xval.length - 1]) && + !(y < yval[0]) && + !(y > yval[yval.length - 1]); } /** diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java index ca1698bedd..587195b633 100644 --- a/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java +++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolatingFunction.java @@ -341,16 +341,12 @@ public double value(double x, double y, double z) * @return {@code true} if (x, y, z) is a valid point. */ public boolean isValidPoint(double x, double y, double z) { - if (x < xval[0] || - x > xval[xval.length - 1] || - y < yval[0] || - y > yval[yval.length - 1] || - z < zval[0] || - z > zval[zval.length - 1]) { - return false; - } else { - return true; - } + return !(x < xval[0]) && + !(x > xval[xval.length - 1]) && + !(y < yval[0]) && + !(y > yval[yval.length - 1]) && + !(z < zval[0]) && + !(z > zval[zval.length - 1]); } /** diff --git a/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolator.java b/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolator.java index bdc7f201b0..60874cfdbb 100644 --- a/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolator.java +++ b/src/main/java/org/apache/commons/math4/analysis/interpolation/TricubicInterpolator.java @@ -128,16 +128,12 @@ public TricubicInterpolatingFunction interpolate(final double[] xval, /** {@inheritDoc} */ @Override public boolean isValidPoint(double x, double y, double z) { - if (x < xval[1] || - x > xval[xval.length - 2] || - y < yval[1] || - y > yval[yval.length - 2] || - z < zval[1] || - z > zval[zval.length - 2]) { - return false; - } else { - return true; - } + return !(x < xval[1]) && + !(x > xval[xval.length - 2]) && + !(y < yval[1]) && + !(y > yval[yval.length - 2]) && + !(z < zval[1]) && + !(z > zval[zval.length - 2]); } }; } diff --git a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java index 9333c1eb3f..56330e3b71 100644 --- a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java +++ b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialFunction.java @@ -372,10 +372,7 @@ public boolean equals(Object obj) { return false; } PolynomialFunction other = (PolynomialFunction) obj; - if (!Arrays.equals(coefficients, other.coefficients)) { - return false; - } - return true; + return Arrays.equals(coefficients, other.coefficients); } /** diff --git a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java index d7263c2fdc..847693af00 100644 --- a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java +++ b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialSplineFunction.java @@ -227,11 +227,7 @@ public double[] getKnots() { * @return {@code true} if {@code x} is a valid point. */ public boolean isValidPoint(double x) { - if (x < knots[0] || - x > knots[n]) { - return false; - } else { - return true; - } + return !(x < knots[0]) && + !(x > knots[n]); } } diff --git a/src/main/java/org/apache/commons/math4/dfp/Dfp.java b/src/main/java/org/apache/commons/math4/dfp/Dfp.java index 841ec2f32b..4ec5c5845d 100644 --- a/src/main/java/org/apache/commons/math4/dfp/Dfp.java +++ b/src/main/java/org/apache/commons/math4/dfp/Dfp.java @@ -2365,10 +2365,7 @@ public Dfp nextAfter(final Dfp x) { } // if this is greater than x - boolean up = false; - if (this.lessThan(x)) { - up = true; - } + boolean up = this.lessThan(x); if (compare(this, x) == 0) { return newInstance(x); diff --git a/src/main/java/org/apache/commons/math4/dfp/DfpMath.java b/src/main/java/org/apache/commons/math4/dfp/DfpMath.java index 734c8faf60..5c6aca209d 100644 --- a/src/main/java/org/apache/commons/math4/dfp/DfpMath.java +++ b/src/main/java/org/apache/commons/math4/dfp/DfpMath.java @@ -945,11 +945,7 @@ public static Dfp asin(final Dfp a) { */ public static Dfp acos(Dfp a) { Dfp result; - boolean negative = false; - - if (a.lessThan(a.getZero())) { - negative = true; - } + boolean negative = a.lessThan(a.getZero()); a = Dfp.copysign(a, a.getOne()); // absolute value diff --git a/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java b/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java index 93d99b657e..55bea82f8e 100644 --- a/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java +++ b/src/main/java/org/apache/commons/math4/fitting/GaussianCurveFitter.java @@ -273,10 +273,7 @@ public int compare(WeightedObservedPoint p1, return comp; } comp = Double.compare(p1.getWeight(), p2.getWeight()); - if (comp != 0) { - return comp; - } - return 0; + return comp; } }; diff --git a/src/main/java/org/apache/commons/math4/ode/events/EventState.java b/src/main/java/org/apache/commons/math4/ode/events/EventState.java index 76ef13d755..cf5310ae43 100644 --- a/src/main/java/org/apache/commons/math4/ode/events/EventState.java +++ b/src/main/java/org/apache/commons/math4/ode/events/EventState.java @@ -365,7 +365,7 @@ public void stepAccepted(final double t, final double[] y) { // force the sign to its value "just after the event" previousEventTime = t; g0Positive = increasing; - nextAction = handler.eventOccurred(t, y, !(increasing ^ forward)); + nextAction = handler.eventOccurred(t, y, increasing == forward); } else { g0Positive = g0 >= 0; nextAction = EventHandler.Action.CONTINUE; diff --git a/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java b/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java index cfbbd4343e..cb0763e7b9 100644 --- a/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java +++ b/src/main/java/org/apache/commons/math4/ode/events/FieldEventState.java @@ -301,7 +301,7 @@ public void stepAccepted(final FieldODEStateAndDerivative state) { // force the sign to its value "just after the event" previousEventTime = state.getTime(); g0Positive = increasing; - nextAction = handler.eventOccurred(state, !(increasing ^ forward)); + nextAction = handler.eventOccurred(state, increasing == forward); } else { g0Positive = g0.getReal() >= 0; nextAction = Action.CONTINUE; diff --git a/src/main/java/org/apache/commons/math4/optim/linear/SolutionCallback.java b/src/main/java/org/apache/commons/math4/optim/linear/SolutionCallback.java index a14409d67f..66b7479316 100644 --- a/src/main/java/org/apache/commons/math4/optim/linear/SolutionCallback.java +++ b/src/main/java/org/apache/commons/math4/optim/linear/SolutionCallback.java @@ -57,6 +57,6 @@ public PointValuePair getSolution() { * @return {@code true} if the solution is optimal, {@code false} otherwise */ public boolean isSolutionOptimal() { - return tableau != null ? tableau.isOptimal() : false; + return tableau != null && tableau.isOptimal(); } } diff --git a/src/main/java/org/apache/commons/math4/stat/Frequency.java b/src/main/java/org/apache/commons/math4/stat/Frequency.java index 66629cec6f..21031a1238 100644 --- a/src/main/java/org/apache/commons/math4/stat/Frequency.java +++ b/src/main/java/org/apache/commons/math4/stat/Frequency.java @@ -378,13 +378,10 @@ public boolean equals(Object obj) { } Frequency other = (Frequency) obj; if (freqTable == null) { - if (other.freqTable != null) { - return false; - } - } else if (!freqTable.equals(other.freqTable)) { - return false; + return other.freqTable == null; + } else { + return freqTable.equals(other.freqTable); } - return true; } } diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialCovariance.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialCovariance.java index cf27522645..7bb4b9eddf 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialCovariance.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialCovariance.java @@ -148,10 +148,7 @@ public boolean equals(Object obj) { if (!Arrays.equals(productsSums, other.productsSums)) { return false; } - if (!Arrays.equals(sums, other.sums)) { - return false; - } - return true; + return Arrays.equals(sums, other.sums); } } diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialMean.java b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialMean.java index cdc5a26a2a..01af0edd61 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialMean.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/moment/VectorialMean.java @@ -96,10 +96,7 @@ public boolean equals(Object obj) { return false; } VectorialMean other = (VectorialMean) obj; - if (!Arrays.equals(means, other.means)) { - return false; - } - return true; + return Arrays.equals(means, other.means); } } diff --git a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java index e0381edf7b..f7130a96fc 100644 --- a/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java +++ b/src/main/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentile.java @@ -908,7 +908,7 @@ private static class FixedCapacityList extends ArrayList implements Serial */ @Override public boolean add(final E e) { - return size() < capacity ? super.add(e) : false; + return size() < capacity && super.add(e); } /** @@ -924,7 +924,7 @@ public boolean addAll(Collection collection) { boolean isCollectionLess = collection != null && collection.size() + size() <= capacity; - return isCollectionLess ? super.addAll(collection) : false; + return isCollectionLess && super.addAll(collection); } } diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java index 4a670cbc10..85e47558cf 100644 --- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java +++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java @@ -1133,11 +1133,7 @@ private static boolean hasTies(double[] x, double[] y) { throw new InsufficientDataException(); } - if (values.length == x.length + y.length) { - return false; // There are no ties. - } - - return true; + return values.length != x.length + y.length; // There are no ties. } /** diff --git a/src/main/java/org/apache/commons/math4/util/MathArrays.java b/src/main/java/org/apache/commons/math4/util/MathArrays.java index 864dbcf4ff..f5f1c23246 100644 --- a/src/main/java/org/apache/commons/math4/util/MathArrays.java +++ b/src/main/java/org/apache/commons/math4/util/MathArrays.java @@ -777,7 +777,7 @@ public int compare(PairDoubleInteger o1, */ public static boolean equals(float[] x, float[] y) { if ((x == null) || (y == null)) { - return !((x == null) ^ (y == null)); + return (x == null) == (y == null); } if (x.length != y.length) { return false; @@ -803,7 +803,7 @@ public static boolean equals(float[] x, float[] y) { */ public static boolean equalsIncludingNaN(float[] x, float[] y) { if ((x == null) || (y == null)) { - return !((x == null) ^ (y == null)); + return (x == null) == (y == null); } if (x.length != y.length) { return false; @@ -828,7 +828,7 @@ public static boolean equalsIncludingNaN(float[] x, float[] y) { */ public static boolean equals(double[] x, double[] y) { if ((x == null) || (y == null)) { - return !((x == null) ^ (y == null)); + return (x == null) == (y == null); } if (x.length != y.length) { return false; @@ -854,7 +854,7 @@ public static boolean equals(double[] x, double[] y) { */ public static boolean equalsIncludingNaN(double[] x, double[] y) { if ((x == null) || (y == null)) { - return !((x == null) ^ (y == null)); + return (x == null) == (y == null); } if (x.length != y.length) { return false; @@ -1117,11 +1117,7 @@ public static boolean verifyValues(final double[] values, final int begin, Integer.valueOf(begin + length), Integer.valueOf(values.length), true); } - if (length == 0 && !allowEmpty) { - return false; - } - - return true; + return length != 0 || allowEmpty; }