MATH-1572: Simplify conditional expressions
* Simplify bitwise * Simplify boolean expression * Simplify conditional expression * Redundant 'if' statement
This commit is contained in:
parent
14d5d0c2d1
commit
1c8d8da63a
|
@ -617,7 +617,7 @@ public final class MathArrays {
|
||||||
*/
|
*/
|
||||||
public static boolean equals(float[] x, float[] y) {
|
public static boolean equals(float[] x, float[] y) {
|
||||||
if (x == null || y == null) {
|
if (x == null || y == null) {
|
||||||
return !((x == null) ^ (y == null));
|
return (x == null) == (y == null);
|
||||||
}
|
}
|
||||||
if (x.length != y.length) {
|
if (x.length != y.length) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -643,7 +643,7 @@ public final class MathArrays {
|
||||||
*/
|
*/
|
||||||
public static boolean equalsIncludingNaN(float[] x, float[] y) {
|
public static boolean equalsIncludingNaN(float[] x, float[] y) {
|
||||||
if (x == null || y == null) {
|
if (x == null || y == null) {
|
||||||
return !((x == null) ^ (y == null));
|
return (x == null) == (y == null);
|
||||||
}
|
}
|
||||||
if (x.length != y.length) {
|
if (x.length != y.length) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -668,7 +668,7 @@ public final class MathArrays {
|
||||||
*/
|
*/
|
||||||
public static boolean equals(double[] x, double[] y) {
|
public static boolean equals(double[] x, double[] y) {
|
||||||
if (x == null || y == null) {
|
if (x == null || y == null) {
|
||||||
return !((x == null) ^ (y == null));
|
return (x == null) == (y == null);
|
||||||
}
|
}
|
||||||
if (x.length != y.length) {
|
if (x.length != y.length) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -694,7 +694,7 @@ public final class MathArrays {
|
||||||
*/
|
*/
|
||||||
public static boolean equalsIncludingNaN(double[] x, double[] y) {
|
public static boolean equalsIncludingNaN(double[] x, double[] y) {
|
||||||
if (x == null || y == null) {
|
if (x == null || y == null) {
|
||||||
return !((x == null) ^ (y == null));
|
return (x == null) == (y == null);
|
||||||
}
|
}
|
||||||
if (x.length != y.length) {
|
if (x.length != y.length) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2351,10 +2351,7 @@ public class Dfp implements RealFieldElement<Dfp> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is greater than x
|
// if this is greater than x
|
||||||
boolean up = false;
|
boolean up = this.lessThan(x);
|
||||||
if (this.lessThan(x)) {
|
|
||||||
up = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compare(this, x) == 0) {
|
if (compare(this, x) == 0) {
|
||||||
return newInstance(x);
|
return newInstance(x);
|
||||||
|
|
|
@ -941,11 +941,7 @@ public final class DfpMath {
|
||||||
*/
|
*/
|
||||||
public static Dfp acos(Dfp a) {
|
public static Dfp acos(Dfp a) {
|
||||||
Dfp result;
|
Dfp result;
|
||||||
boolean negative = false;
|
boolean negative = a.lessThan(a.getZero());
|
||||||
|
|
||||||
if (a.lessThan(a.getZero())) {
|
|
||||||
negative = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
a = Dfp.copySign(a, a.getOne()); // absolute value
|
a = Dfp.copySign(a, a.getOne()); // absolute value
|
||||||
|
|
||||||
|
|
|
@ -371,10 +371,7 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Ser
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PolynomialFunction other = (PolynomialFunction) obj;
|
PolynomialFunction other = (PolynomialFunction) obj;
|
||||||
if (!Arrays.equals(coefficients, other.coefficients)) {
|
return Arrays.equals(coefficients, other.coefficients);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -186,11 +186,7 @@ public class SimpleCurveFitter extends AbstractCurveFitter {
|
||||||
if (comp != 0) {
|
if (comp != 0) {
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
comp = Double.compare(p1.getWeight(), p2.getWeight());
|
return Double.compare(p1.getWeight(), p2.getWeight());
|
||||||
if (comp != 0) {
|
|
||||||
return comp;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,7 @@ public class EventState {
|
||||||
// force the sign to its value "just after the event"
|
// force the sign to its value "just after the event"
|
||||||
previousEventTime = t;
|
previousEventTime = t;
|
||||||
g0Positive = increasing;
|
g0Positive = increasing;
|
||||||
nextAction = handler.eventOccurred(t, y, !(increasing ^ forward));
|
nextAction = handler.eventOccurred(t, y, increasing == forward);
|
||||||
} else {
|
} else {
|
||||||
g0Positive = g0 >= 0;
|
g0Positive = g0 >= 0;
|
||||||
nextAction = EventHandler.Action.CONTINUE;
|
nextAction = EventHandler.Action.CONTINUE;
|
||||||
|
|
|
@ -301,7 +301,7 @@ public class FieldEventState<T extends RealFieldElement<T>> {
|
||||||
// force the sign to its value "just after the event"
|
// force the sign to its value "just after the event"
|
||||||
previousEventTime = state.getTime();
|
previousEventTime = state.getTime();
|
||||||
g0Positive = increasing;
|
g0Positive = increasing;
|
||||||
nextAction = handler.eventOccurred(state, !(increasing ^ forward));
|
nextAction = handler.eventOccurred(state, increasing == forward);
|
||||||
} else {
|
} else {
|
||||||
g0Positive = g0.getReal() >= 0;
|
g0Positive = g0.getReal() >= 0;
|
||||||
nextAction = Action.CONTINUE;
|
nextAction = Action.CONTINUE;
|
||||||
|
|
|
@ -57,6 +57,6 @@ public class SolutionCallback implements OptimizationData {
|
||||||
* @return {@code true} if the solution is optimal, {@code false} otherwise
|
* @return {@code true} if the solution is optimal, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public boolean isSolutionOptimal() {
|
public boolean isSolutionOptimal() {
|
||||||
return tableau != null ? tableau.isOptimal() : false;
|
return tableau != null && tableau.isOptimal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -896,7 +896,7 @@ public class CMAESOptimizer
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
long bits = Double.doubleToLongBits(value);
|
long bits = Double.doubleToLongBits(value);
|
||||||
return (int) ((1438542 ^ (bits >>> 32) ^ bits) & 0xffffffff);
|
return (int) ((1438542 ^ (bits >>> 32) ^ bits));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -376,14 +376,7 @@ public class Frequency<T extends Comparable<T>> implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Frequency<?> other = (Frequency<?>) obj;
|
Frequency<?> other = (Frequency<?>) obj;
|
||||||
if (freqTable == null) {
|
return freqTable.equals(other.freqTable);
|
||||||
if (other.freqTable != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!freqTable.equals(other.freqTable)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,10 +148,7 @@ public class VectorialCovariance implements Serializable {
|
||||||
if (!Arrays.equals(productsSums, other.productsSums)) {
|
if (!Arrays.equals(productsSums, other.productsSums)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!Arrays.equals(sums, other.sums)) {
|
return Arrays.equals(sums, other.sums);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,10 +96,7 @@ public class VectorialMean implements Serializable {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
VectorialMean other = (VectorialMean) obj;
|
VectorialMean other = (VectorialMean) obj;
|
||||||
if (!Arrays.equals(means, other.means)) {
|
return Arrays.equals(means, other.means);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -908,7 +908,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean add(final E e) {
|
public boolean add(final E e) {
|
||||||
return size() < capacity ? super.add(e) : false;
|
return size() < capacity && super.add(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -924,7 +924,7 @@ public class PSquarePercentile extends AbstractStorelessUnivariateStatistic
|
||||||
boolean isCollectionLess =
|
boolean isCollectionLess =
|
||||||
collection != null &&
|
collection != null &&
|
||||||
collection.size() + size() <= capacity;
|
collection.size() + size() <= capacity;
|
||||||
return isCollectionLess ? super.addAll(collection) : false;
|
return isCollectionLess && super.addAll(collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1132,11 +1132,7 @@ public class KolmogorovSmirnovTest {
|
||||||
throw new InsufficientDataException();
|
throw new InsufficientDataException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.length == x.length + y.length) {
|
return values.length != x.length + y.length; // There are no ties.
|
||||||
return false; // There are no ties.
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue