Skip to content

Commit

Permalink
Merge pull request #375 from Serrof/issue-374
Browse files Browse the repository at this point in the history
Removed some code smells
  • Loading branch information
Serrof authored Feb 8, 2025
2 parents 24df8ab + 8afcfb6 commit 6142c30
Show file tree
Hide file tree
Showing 35 changed files with 45 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public FieldHermiteInterpolator() {
*/
@SafeVarargs
public final void addSamplePoint(final T x, final T[] ... value)
throws MathIllegalArgumentException, MathRuntimeException,
throws MathRuntimeException,
NullArgumentException {

MathUtils.checkNotNull(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public HermiteInterpolator() {
* than 20, which prevents computation of a factorial
*/
public void addSamplePoint(final double x, final double[] ... value)
throws MathIllegalArgumentException, MathRuntimeException {
throws MathRuntimeException {

for (int i = 0; i < value.length; ++i) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public enum AllowedSolution {
* acceptable as solutions for root-finding. So, if a function f(x) has
* a root at x = x0, then the root-finding result s must satisfy f(s) &gt;= 0.
*/
ABOVE_SIDE;
ABOVE_SIDE

}
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ protected enum Method {
ILLINOIS,

/** The {@link PegasusSolver <em>Pegasus</em>} method. */
PEGASUS;
PEGASUS

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ public Complex[] solveAll(Complex[] coefficients, Complex initial)
}
// Coefficients for deflated polynomial.
final Complex[] c = new Complex[n + 1];
for (int i = 0; i <= n; i++) {
c[i] = coefficients[i];
}
System.arraycopy(coefficients, 0, c, 0, n + 1);

// Solve individual roots successively.
final Complex[] root = new Complex[n];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public ComplexFormat(String imaginaryCharacter,
if (imaginaryCharacter == null) {
throw new NullArgumentException();
}
if (imaginaryCharacter.length() == 0) {
if (imaginaryCharacter.isEmpty()) {
throw new MathIllegalArgumentException(LocalizedCoreFormats.NO_DATA);
}
MathUtils.checkNotNull(imaginaryFormat, LocalizedCoreFormats.IMAGINARY_FORMAT);
Expand Down Expand Up @@ -376,7 +376,7 @@ public Complex parse(String source, ParsePosition pos) {
// parse sign
int startIndex = pos.getIndex();
char c = CompositeFormat.parseNextCharacter(source, pos);
int sign = 0;
int sign;
switch (c) {
case 0 :
// no sign
Expand Down
6 changes: 2 additions & 4 deletions hipparchus-core/src/main/java/org/hipparchus/dfp/Dfp.java
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ public Dfp subtract(final Dfp x) {
* @return the IEEE flag if an exception occurred
*/
protected int round(int n) {
boolean inc = false;
boolean inc;
switch (field.getRoundingMode()) {
case ROUND_DOWN:
inc = false;
Expand Down Expand Up @@ -2032,9 +2032,7 @@ public Dfp divide(Dfp divisor) {

/* move the remainder into the dividend while left shifting */
dividend[0] = 0;
for (int i = 0; i < mant.length; i++) {
dividend[i + 1] = remainder[i];
}
System.arraycopy(remainder, 0, dividend, 1, mant.length);
}

/* Find the most sig digit */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum RoundingMode {
ROUND_CEIL,

/** Rounds towards negative infinity. */
ROUND_FLOOR;
ROUND_FLOOR

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v)
/** {@inheritDoc} */
@Override
public FieldVector<T> ebeDivide(FieldVector<T> v)
throws MathIllegalArgumentException, MathRuntimeException {
throws MathRuntimeException {
if (v instanceof ArrayFieldVector) {
return ebeDivide((ArrayFieldVector<T>) v);
} else {
Expand Down Expand Up @@ -684,7 +684,7 @@ public T dotProduct(ArrayFieldVector<T> v)
/** {@inheritDoc} */
@Override
public FieldVector<T> projection(FieldVector<T> v)
throws MathIllegalArgumentException, MathRuntimeException {
throws MathRuntimeException {
return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ public RealMatrix getH() {
}

// copy upper triangular part of the matrix
for (int j = i; j < m; ++j) {
h[i][j] = householderVectors[i][j];
}
System.arraycopy(householderVectors[i], i, h[i], i, m - i);
}
cachedH = MatrixUtils.createRealMatrix(h);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public RealMatrix parse(String source, ParsePosition pos) {
if (!rowComponents.isEmpty()) {
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (!CompositeFormat.parseFixedstring(source, trimmedColumnSeparator, pos)) {
if (trimmedRowSuffix.length() != 0 &&
if (!trimmedRowSuffix.isEmpty() &&
!CompositeFormat.parseFixedstring(source, trimmedRowSuffix, pos)) {
return null;
} else {
Expand All @@ -345,7 +345,7 @@ public RealMatrix parse(String source, ParsePosition pos) {
}
} else {
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
if (trimmedRowPrefix.length() != 0 &&
if (!trimmedRowPrefix.isEmpty() &&
!CompositeFormat.parseFixedstring(source, trimmedRowPrefix, pos)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ public double dotProduct(RealVector w)
/** {@inheritDoc} */
@Override
public double cosine(RealVector w)
throws MathIllegalArgumentException, MathRuntimeException {
throws MathRuntimeException {
return v.cosine(w);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public T dotProduct(FieldVector<T> v) throws MathIllegalArgumentException {
/** {@inheritDoc} */
@Override
public FieldVector<T> ebeDivide(FieldVector<T> v)
throws MathIllegalArgumentException, MathRuntimeException {
throws MathRuntimeException {
checkVectorDimensions(v.getDimension());
SparseFieldVector<T> res = new SparseFieldVector<>(this);
OpenIntToFieldHashMap<T>.Iterator iter = res.entries.iterator();
Expand Down Expand Up @@ -425,7 +425,7 @@ public FieldMatrix<T> outerProduct(FieldVector<T> v) {
/** {@inheritDoc} */
@Override
public FieldVector<T> projection(FieldVector<T> v)
throws MathIllegalArgumentException, MathRuntimeException {
throws MathRuntimeException {
checkVectorDimensions(v.getDimension());
return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
}
Expand Down
12 changes: 6 additions & 6 deletions hipparchus-core/src/main/java/org/hipparchus/linear/SymmLQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ public final boolean shouldCheck() {
@Override
public RealVector solve(final RealLinearOperator a,
final RealLinearOperator m, final RealVector b) throws
MathIllegalArgumentException, NullArgumentException, MathIllegalStateException, MathIllegalArgumentException {
NullArgumentException, MathIllegalStateException, MathIllegalArgumentException {
MathUtils.checkNotNull(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension());
return solveInPlace(a, m, b, x, false, 0.);
Expand Down Expand Up @@ -947,7 +947,7 @@ public RealVector solve(final RealLinearOperator a, final RealLinearOperator m,
@Override
public RealVector solve(final RealLinearOperator a,
final RealLinearOperator m, final RealVector b, final RealVector x)
throws MathIllegalArgumentException, NullArgumentException,
throws NullArgumentException,
MathIllegalArgumentException,
MathIllegalStateException {
MathUtils.checkNotNull(x);
Expand All @@ -963,7 +963,7 @@ public RealVector solve(final RealLinearOperator a,
*/
@Override
public RealVector solve(final RealLinearOperator a, final RealVector b)
throws MathIllegalArgumentException, NullArgumentException,
throws NullArgumentException,
MathIllegalArgumentException, MathIllegalStateException {
MathUtils.checkNotNull(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension());
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public RealVector solve(final RealLinearOperator a, final RealVector b,
*/
@Override
public RealVector solve(final RealLinearOperator a, final RealVector b,
final RealVector x) throws MathIllegalArgumentException, NullArgumentException, MathIllegalArgumentException,
final RealVector x) throws NullArgumentException, MathIllegalArgumentException,
MathIllegalStateException {
MathUtils.checkNotNull(x);
return solveInPlace(a, null, b, x.copy(), false, 0.);
Expand All @@ -1045,7 +1045,7 @@ public RealVector solve(final RealLinearOperator a, final RealVector b,
@Override
public RealVector solveInPlace(final RealLinearOperator a,
final RealLinearOperator m, final RealVector b, final RealVector x)
throws MathIllegalArgumentException, NullArgumentException,
throws NullArgumentException,
MathIllegalArgumentException,
MathIllegalStateException {
return solveInPlace(a, m, b, x, false, 0.);
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public RealVector solveInPlace(final RealLinearOperator a,
*/
@Override
public RealVector solveInPlace(final RealLinearOperator a,
final RealVector b, final RealVector x) throws MathIllegalArgumentException, NullArgumentException, MathIllegalArgumentException,
final RealVector b, final RealVector x) throws NullArgumentException, MathIllegalArgumentException,
MathIllegalStateException {
return solveInPlace(a, null, b, x, false, 0.);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ public enum DctNormalization {
* </ul>
* which makes the transform orthogonal. N is the size of the data sample.
*/
ORTHOGONAL_DCT_I;
ORTHOGONAL_DCT_I
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ public enum DftNormalization {
* </ul>
* which makes the transform unitary. N is the size of the data sample.
*/
UNITARY;
UNITARY
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public enum TransformType {
FORWARD,

/** The type to be specified for inverse transforms. */
INVERSE;
INVERSE
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public enum RotationConvention {
* rotation angle. This is how things were done up to version 3.5.
* </p>
*/
FRAME_TRANSFORM;
FRAME_TRANSFORM

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public enum Side {
BOTH,

/** Code for the hyperplane itself. */
HYPER;
HYPER

}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ protected FieldODEStateAndDerivative<T> acceptStep(final AbstractFieldODEStateIn
}

// set end of step
stepEndEventsStates.stream().forEach(s -> s.setStepEnd(currentState.getTime()));
stepEndEventsStates.forEach(s -> s.setStepEnd(currentState.getTime()));

// search for next events that may occur during the step
final int orderingSign = interpolator.isForward() ? +1 : -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.hipparchus.exception.MathIllegalArgumentException;
Expand All @@ -36,9 +37,7 @@ public abstract class AbstractParameterizable implements Parameterizable {
*/
protected AbstractParameterizable(final String ... names) {
parametersNames = new ArrayList<>();
for (final String name : names) {
parametersNames.add(name);
}
Collections.addAll(parametersNames, names);
}

/** Simple constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ public void append(final DenseOutputModel model)

}

for (ODEStateInterpolator interpolator : model.steps) {
steps.add(interpolator);
}
steps.addAll(model.steps);

index = steps.size() - 1;
finalTime = (steps.get(index)).getCurrentState().getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ public void append(final FieldDenseOutputModel<T> model)

}

for (FieldODEStateInterpolator<T> interpolator : model.steps) {
steps.add(interpolator);
}
steps.addAll(model.steps);

index = steps.size() - 1;
finalTime = (steps.get(index)).getCurrentState().getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public enum Action {
* the {@link ODEEventDetector#g(org.hipparchus.ode.ODEStateAndDerivative)}
* function of another event handler.
*/
RESET_EVENTS;
RESET_EVENTS

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.hipparchus.exception.MathIllegalArgumentException;
import org.hipparchus.exception.MathIllegalStateException;
import org.hipparchus.ode.AbstractFieldIntegrator;
import org.hipparchus.ode.FieldEquationsMapper;
import org.hipparchus.ode.FieldODEState;
import org.hipparchus.ode.FieldODEStateAndDerivative;
import org.hipparchus.util.FastMath;
Expand Down Expand Up @@ -195,14 +194,12 @@ protected void sanityChecks(final FieldODEState<T> initialState, final T t)
* @param order order of the method
* @param scale scaling vector for the state vector (can be shorter than state vector)
* @param state0 state at integration start time
* @param mapper mapper for all the equations
* @return first integration step
* @exception MathIllegalStateException if the number of functions evaluations is exceeded
* @exception MathIllegalArgumentException if arrays dimensions do not match equations settings
*/
public double initializeStep(final boolean forward, final int order, final T[] scale,
final FieldODEStateAndDerivative<T> state0,
final FieldEquationsMapper<T> mapper)
final FieldODEStateAndDerivative<T> state0)
throws MathIllegalArgumentException, MathIllegalStateException {

if (stepsizeHelper.getInitialStep() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public FieldODEStateAndDerivative<T> integrate(final FieldExpandableODE<T> equat
for (int i = 0; i < scale.length; ++i) {
scale[i] = helper.getTolerance(i, y[i].abs());
}
hNew = getField().getZero().add(initializeStep(forward, getOrder(), scale, getStepStart(), equations.getMapper()));
hNew = getField().getZero().add(initializeStep(forward, getOrder(), scale, getStepStart()));
firstTime = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ public enum StepNormalizerMode {
* @see StepNormalizer
* @see StepNormalizerBounds
*/
MULTIPLES;
MULTIPLES
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public class LinearConstraintSet implements OptimizationData {
*/
public LinearConstraintSet(LinearConstraint... constraints) {
linearConstraints = new LinkedHashSet<>();
for (LinearConstraint c : constraints) {
linearConstraints.add(c);
}
Collections.addAll(linearConstraints, constraints);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ private double[] altmov(int knew, double adelt) {

final double bigstp = adelt + adelt;
int iflag = 0;
double cauchy = Double.NaN;
double cauchy;
double csave = ZERO;
while (true) {
double wfixsq = ZERO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,7 @@ public Optimum optimize(final LeastSquaresProblem problem) {

//residuals already have weights applied
double[] weightedResidual = currentResiduals;
for (int i = 0; i < nR; i++) {
qtf[i] = weightedResidual[i];
}
System.arraycopy(weightedResidual, 0, qtf, 0, nR);

// compute Qt.res
qTy(qtf, internalData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public Display() {
c.gridy = 0;
c.insets = new Insets(2, 2, 2, 2);

JComponent comp = null;
JComponent comp;

comp = createComponent("Binomial", 0, 40,
new String[] { "p=0.5,n=20", "p=0.7,n=20", "p=0.5,n=40" },
Expand Down
Loading

0 comments on commit 6142c30

Please sign in to comment.