Skip to content

Commit 6142c30

Browse files
authored
Merge pull request #375 from Serrof/issue-374
Removed some code smells
2 parents 24df8ab + 8afcfb6 commit 6142c30

File tree

35 files changed

+45
-71
lines changed

35 files changed

+45
-71
lines changed

hipparchus-core/src/main/java/org/hipparchus/analysis/interpolation/FieldHermiteInterpolator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public FieldHermiteInterpolator() {
9191
*/
9292
@SafeVarargs
9393
public final void addSamplePoint(final T x, final T[] ... value)
94-
throws MathIllegalArgumentException, MathRuntimeException,
94+
throws MathRuntimeException,
9595
NullArgumentException {
9696

9797
MathUtils.checkNotNull(x);

hipparchus-core/src/main/java/org/hipparchus/analysis/interpolation/HermiteInterpolator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public HermiteInterpolator() {
9090
* than 20, which prevents computation of a factorial
9191
*/
9292
public void addSamplePoint(final double x, final double[] ... value)
93-
throws MathIllegalArgumentException, MathRuntimeException {
93+
throws MathRuntimeException {
9494

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

hipparchus-core/src/main/java/org/hipparchus/analysis/solvers/AllowedSolution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ public enum AllowedSolution {
7171
* acceptable as solutions for root-finding. So, if a function f(x) has
7272
* a root at x = x0, then the root-finding result s must satisfy f(s) &gt;= 0.
7373
*/
74-
ABOVE_SIDE;
74+
ABOVE_SIDE
7575

7676
}

hipparchus-core/src/main/java/org/hipparchus/analysis/solvers/BaseSecantSolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ protected enum Method {
265265
ILLINOIS,
266266

267267
/** The {@link PegasusSolver <em>Pegasus</em>} method. */
268-
PEGASUS;
268+
PEGASUS
269269

270270
}
271271
}

hipparchus-core/src/main/java/org/hipparchus/analysis/solvers/LaguerreSolver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ public Complex[] solveAll(Complex[] coefficients, Complex initial)
296296
}
297297
// Coefficients for deflated polynomial.
298298
final Complex[] c = new Complex[n + 1];
299-
for (int i = 0; i <= n; i++) {
300-
c[i] = coefficients[i];
301-
}
299+
System.arraycopy(coefficients, 0, c, 0, n + 1);
302300

303301
// Solve individual roots successively.
304302
final Complex[] root = new Complex[n];

hipparchus-core/src/main/java/org/hipparchus/complex/ComplexFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public ComplexFormat(String imaginaryCharacter,
143143
if (imaginaryCharacter == null) {
144144
throw new NullArgumentException();
145145
}
146-
if (imaginaryCharacter.length() == 0) {
146+
if (imaginaryCharacter.isEmpty()) {
147147
throw new MathIllegalArgumentException(LocalizedCoreFormats.NO_DATA);
148148
}
149149
MathUtils.checkNotNull(imaginaryFormat, LocalizedCoreFormats.IMAGINARY_FORMAT);
@@ -376,7 +376,7 @@ public Complex parse(String source, ParsePosition pos) {
376376
// parse sign
377377
int startIndex = pos.getIndex();
378378
char c = CompositeFormat.parseNextCharacter(source, pos);
379-
int sign = 0;
379+
int sign;
380380
switch (c) {
381381
case 0 :
382382
// no sign

hipparchus-core/src/main/java/org/hipparchus/dfp/Dfp.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ public Dfp subtract(final Dfp x) {
15941594
* @return the IEEE flag if an exception occurred
15951595
*/
15961596
protected int round(int n) {
1597-
boolean inc = false;
1597+
boolean inc;
15981598
switch (field.getRoundingMode()) {
15991599
case ROUND_DOWN:
16001600
inc = false;
@@ -2032,9 +2032,7 @@ public Dfp divide(Dfp divisor) {
20322032

20332033
/* move the remainder into the dividend while left shifting */
20342034
dividend[0] = 0;
2035-
for (int i = 0; i < mant.length; i++) {
2036-
dividend[i + 1] = remainder[i];
2037-
}
2035+
System.arraycopy(remainder, 0, dividend, 1, mant.length);
20382036
}
20392037

20402038
/* Find the most sig digit */

hipparchus-core/src/main/java/org/hipparchus/dfp/DfpField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public enum RoundingMode {
5555
ROUND_CEIL,
5656

5757
/** Rounds towards negative infinity. */
58-
ROUND_FLOOR;
58+
ROUND_FLOOR
5959

6060
}
6161

hipparchus-core/src/main/java/org/hipparchus/linear/ArrayFieldVector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public ArrayFieldVector<T> ebeMultiply(ArrayFieldVector<T> v)
600600
/** {@inheritDoc} */
601601
@Override
602602
public FieldVector<T> ebeDivide(FieldVector<T> v)
603-
throws MathIllegalArgumentException, MathRuntimeException {
603+
throws MathRuntimeException {
604604
if (v instanceof ArrayFieldVector) {
605605
return ebeDivide((ArrayFieldVector<T>) v);
606606
} else {
@@ -684,7 +684,7 @@ public T dotProduct(ArrayFieldVector<T> v)
684684
/** {@inheritDoc} */
685685
@Override
686686
public FieldVector<T> projection(FieldVector<T> v)
687-
throws MathIllegalArgumentException, MathRuntimeException {
687+
throws MathRuntimeException {
688688
return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
689689
}
690690

hipparchus-core/src/main/java/org/hipparchus/linear/HessenbergTransformer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ public RealMatrix getH() {
156156
}
157157

158158
// copy upper triangular part of the matrix
159-
for (int j = i; j < m; ++j) {
160-
h[i][j] = householderVectors[i][j];
161-
}
159+
System.arraycopy(householderVectors[i], i, h[i], i, m - i);
162160
}
163161
cachedH = MatrixUtils.createRealMatrix(h);
164162
}

hipparchus-core/src/main/java/org/hipparchus/linear/RealMatrixFormat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public RealMatrix parse(String source, ParsePosition pos) {
329329
if (!rowComponents.isEmpty()) {
330330
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
331331
if (!CompositeFormat.parseFixedstring(source, trimmedColumnSeparator, pos)) {
332-
if (trimmedRowSuffix.length() != 0 &&
332+
if (!trimmedRowSuffix.isEmpty() &&
333333
!CompositeFormat.parseFixedstring(source, trimmedRowSuffix, pos)) {
334334
return null;
335335
} else {
@@ -345,7 +345,7 @@ public RealMatrix parse(String source, ParsePosition pos) {
345345
}
346346
} else {
347347
CompositeFormat.parseAndIgnoreWhitespace(source, pos);
348-
if (trimmedRowPrefix.length() != 0 &&
348+
if (!trimmedRowPrefix.isEmpty() &&
349349
!CompositeFormat.parseFixedstring(source, trimmedRowPrefix, pos)) {
350350
return null;
351351
}

hipparchus-core/src/main/java/org/hipparchus/linear/RealVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ public double dotProduct(RealVector w)
14251425
/** {@inheritDoc} */
14261426
@Override
14271427
public double cosine(RealVector w)
1428-
throws MathIllegalArgumentException, MathRuntimeException {
1428+
throws MathRuntimeException {
14291429
return v.cosine(w);
14301430
}
14311431

hipparchus-core/src/main/java/org/hipparchus/linear/SparseFieldVector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public T dotProduct(FieldVector<T> v) throws MathIllegalArgumentException {
237237
/** {@inheritDoc} */
238238
@Override
239239
public FieldVector<T> ebeDivide(FieldVector<T> v)
240-
throws MathIllegalArgumentException, MathRuntimeException {
240+
throws MathRuntimeException {
241241
checkVectorDimensions(v.getDimension());
242242
SparseFieldVector<T> res = new SparseFieldVector<>(this);
243243
OpenIntToFieldHashMap<T>.Iterator iter = res.entries.iterator();
@@ -425,7 +425,7 @@ public FieldMatrix<T> outerProduct(FieldVector<T> v) {
425425
/** {@inheritDoc} */
426426
@Override
427427
public FieldVector<T> projection(FieldVector<T> v)
428-
throws MathIllegalArgumentException, MathRuntimeException {
428+
throws MathRuntimeException {
429429
checkVectorDimensions(v.getDimension());
430430
return v.mapMultiply(dotProduct(v).divide(v.dotProduct(v)));
431431
}

hipparchus-core/src/main/java/org/hipparchus/linear/SymmLQ.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ public final boolean shouldCheck() {
879879
@Override
880880
public RealVector solve(final RealLinearOperator a,
881881
final RealLinearOperator m, final RealVector b) throws
882-
MathIllegalArgumentException, NullArgumentException, MathIllegalStateException, MathIllegalArgumentException {
882+
NullArgumentException, MathIllegalStateException, MathIllegalArgumentException {
883883
MathUtils.checkNotNull(a);
884884
final RealVector x = new ArrayRealVector(a.getColumnDimension());
885885
return solveInPlace(a, m, b, x, false, 0.);
@@ -947,7 +947,7 @@ public RealVector solve(final RealLinearOperator a, final RealLinearOperator m,
947947
@Override
948948
public RealVector solve(final RealLinearOperator a,
949949
final RealLinearOperator m, final RealVector b, final RealVector x)
950-
throws MathIllegalArgumentException, NullArgumentException,
950+
throws NullArgumentException,
951951
MathIllegalArgumentException,
952952
MathIllegalStateException {
953953
MathUtils.checkNotNull(x);
@@ -963,7 +963,7 @@ public RealVector solve(final RealLinearOperator a,
963963
*/
964964
@Override
965965
public RealVector solve(final RealLinearOperator a, final RealVector b)
966-
throws MathIllegalArgumentException, NullArgumentException,
966+
throws NullArgumentException,
967967
MathIllegalArgumentException, MathIllegalStateException {
968968
MathUtils.checkNotNull(a);
969969
final RealVector x = new ArrayRealVector(a.getColumnDimension());
@@ -1025,7 +1025,7 @@ public RealVector solve(final RealLinearOperator a, final RealVector b,
10251025
*/
10261026
@Override
10271027
public RealVector solve(final RealLinearOperator a, final RealVector b,
1028-
final RealVector x) throws MathIllegalArgumentException, NullArgumentException, MathIllegalArgumentException,
1028+
final RealVector x) throws NullArgumentException, MathIllegalArgumentException,
10291029
MathIllegalStateException {
10301030
MathUtils.checkNotNull(x);
10311031
return solveInPlace(a, null, b, x.copy(), false, 0.);
@@ -1045,7 +1045,7 @@ public RealVector solve(final RealLinearOperator a, final RealVector b,
10451045
@Override
10461046
public RealVector solveInPlace(final RealLinearOperator a,
10471047
final RealLinearOperator m, final RealVector b, final RealVector x)
1048-
throws MathIllegalArgumentException, NullArgumentException,
1048+
throws NullArgumentException,
10491049
MathIllegalArgumentException,
10501050
MathIllegalStateException {
10511051
return solveInPlace(a, m, b, x, false, 0.);
@@ -1161,7 +1161,7 @@ public RealVector solveInPlace(final RealLinearOperator a,
11611161
*/
11621162
@Override
11631163
public RealVector solveInPlace(final RealLinearOperator a,
1164-
final RealVector b, final RealVector x) throws MathIllegalArgumentException, NullArgumentException, MathIllegalArgumentException,
1164+
final RealVector b, final RealVector x) throws NullArgumentException, MathIllegalArgumentException,
11651165
MathIllegalStateException {
11661166
return solveInPlace(a, null, b, x, false, 0.);
11671167
}

hipparchus-fft/src/main/java/org/hipparchus/transform/DctNormalization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ public enum DctNormalization {
6666
* </ul>
6767
* which makes the transform orthogonal. N is the size of the data sample.
6868
*/
69-
ORTHOGONAL_DCT_I;
69+
ORTHOGONAL_DCT_I
7070
}

hipparchus-fft/src/main/java/org/hipparchus/transform/DftNormalization.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ public enum DftNormalization {
5656
* </ul>
5757
* which makes the transform unitary. N is the size of the data sample.
5858
*/
59-
UNITARY;
59+
UNITARY
6060
}

hipparchus-fft/src/main/java/org/hipparchus/transform/TransformType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public enum TransformType {
3030
FORWARD,
3131

3232
/** The type to be specified for inverse transforms. */
33-
INVERSE;
33+
INVERSE
3434
}

hipparchus-geometry/src/main/java/org/hipparchus/geometry/euclidean/threed/RotationConvention.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ public enum RotationConvention {
7878
* rotation angle. This is how things were done up to version 3.5.
7979
* </p>
8080
*/
81-
FRAME_TRANSFORM;
81+
FRAME_TRANSFORM
8282

8383
}

hipparchus-geometry/src/main/java/org/hipparchus/geometry/partitioning/Side.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public enum Side {
3636
BOTH,
3737

3838
/** Code for the hyperplane itself. */
39-
HYPER;
39+
HYPER
4040

4141
}

hipparchus-ode/src/main/java/org/hipparchus/ode/AbstractFieldIntegrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ protected FieldODEStateAndDerivative<T> acceptStep(final AbstractFieldODEStateIn
320320
}
321321

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

325325
// search for next events that may occur during the step
326326
final int orderingSign = interpolator.isForward() ? +1 : -1;

hipparchus-ode/src/main/java/org/hipparchus/ode/AbstractParameterizable.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Collection;
21+
import java.util.Collections;
2122
import java.util.List;
2223

2324
import org.hipparchus.exception.MathIllegalArgumentException;
@@ -36,9 +37,7 @@ public abstract class AbstractParameterizable implements Parameterizable {
3637
*/
3738
protected AbstractParameterizable(final String ... names) {
3839
parametersNames = new ArrayList<>();
39-
for (final String name : names) {
40-
parametersNames.add(name);
41-
}
40+
Collections.addAll(parametersNames, names);
4241
}
4342

4443
/** Simple constructor.

hipparchus-ode/src/main/java/org/hipparchus/ode/DenseOutputModel.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ public void append(final DenseOutputModel model)
164164

165165
}
166166

167-
for (ODEStateInterpolator interpolator : model.steps) {
168-
steps.add(interpolator);
169-
}
167+
steps.addAll(model.steps);
170168

171169
index = steps.size() - 1;
172170
finalTime = (steps.get(index)).getCurrentState().getTime();

hipparchus-ode/src/main/java/org/hipparchus/ode/FieldDenseOutputModel.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ public void append(final FieldDenseOutputModel<T> model)
157157

158158
}
159159

160-
for (FieldODEStateInterpolator<T> interpolator : model.steps) {
161-
steps.add(interpolator);
162-
}
160+
steps.addAll(model.steps);
163161

164162
index = steps.size() - 1;
165163
finalTime = (steps.get(index)).getCurrentState().getTime();

hipparchus-ode/src/main/java/org/hipparchus/ode/events/Action.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public enum Action {
6767
* the {@link ODEEventDetector#g(org.hipparchus.ode.ODEStateAndDerivative)}
6868
* function of another event handler.
6969
*/
70-
RESET_EVENTS;
70+
RESET_EVENTS
7171

7272
}

hipparchus-ode/src/main/java/org/hipparchus/ode/nonstiff/AdaptiveStepsizeFieldIntegrator.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.hipparchus.exception.MathIllegalArgumentException;
2828
import org.hipparchus.exception.MathIllegalStateException;
2929
import org.hipparchus.ode.AbstractFieldIntegrator;
30-
import org.hipparchus.ode.FieldEquationsMapper;
3130
import org.hipparchus.ode.FieldODEState;
3231
import org.hipparchus.ode.FieldODEStateAndDerivative;
3332
import org.hipparchus.util.FastMath;
@@ -195,14 +194,12 @@ protected void sanityChecks(final FieldODEState<T> initialState, final T t)
195194
* @param order order of the method
196195
* @param scale scaling vector for the state vector (can be shorter than state vector)
197196
* @param state0 state at integration start time
198-
* @param mapper mapper for all the equations
199197
* @return first integration step
200198
* @exception MathIllegalStateException if the number of functions evaluations is exceeded
201199
* @exception MathIllegalArgumentException if arrays dimensions do not match equations settings
202200
*/
203201
public double initializeStep(final boolean forward, final int order, final T[] scale,
204-
final FieldODEStateAndDerivative<T> state0,
205-
final FieldEquationsMapper<T> mapper)
202+
final FieldODEStateAndDerivative<T> state0)
206203
throws MathIllegalArgumentException, MathIllegalStateException {
207204

208205
if (stepsizeHelper.getInitialStep() > 0) {

hipparchus-ode/src/main/java/org/hipparchus/ode/nonstiff/EmbeddedRungeKuttaFieldIntegrator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public FieldODEStateAndDerivative<T> integrate(final FieldExpandableODE<T> equat
279279
for (int i = 0; i < scale.length; ++i) {
280280
scale[i] = helper.getTolerance(i, y[i].abs());
281281
}
282-
hNew = getField().getZero().add(initializeStep(forward, getOrder(), scale, getStepStart(), equations.getMapper()));
282+
hNew = getField().getZero().add(initializeStep(forward, getOrder(), scale, getStepStart()));
283283
firstTime = false;
284284
}
285285

hipparchus-ode/src/main/java/org/hipparchus/ode/sampling/StepNormalizerMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ public enum StepNormalizerMode {
7070
* @see StepNormalizer
7171
* @see StepNormalizerBounds
7272
*/
73-
MULTIPLES;
73+
MULTIPLES
7474
}

hipparchus-optim/src/main/java/org/hipparchus/optim/linear/LinearConstraintSet.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public class LinearConstraintSet implements OptimizationData {
4343
*/
4444
public LinearConstraintSet(LinearConstraint... constraints) {
4545
linearConstraints = new LinkedHashSet<>();
46-
for (LinearConstraint c : constraints) {
47-
linearConstraints.add(c);
48-
}
46+
Collections.addAll(linearConstraints, constraints);
4947
}
5048

5149
/**

hipparchus-optim/src/main/java/org/hipparchus/optim/nonlinear/scalar/noderiv/BOBYQAOptimizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ private double[] altmov(int knew, double adelt) {
14311431

14321432
final double bigstp = adelt + adelt;
14331433
int iflag = 0;
1434-
double cauchy = Double.NaN;
1434+
double cauchy;
14351435
double csave = ZERO;
14361436
while (true) {
14371437
double wfixsq = ZERO;

hipparchus-optim/src/main/java/org/hipparchus/optim/nonlinear/vector/leastsquares/LevenbergMarquardtOptimizer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ public Optimum optimize(final LeastSquaresProblem problem) {
349349

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

356354
// compute Qt.res
357355
qTy(qtf, internalData);

hipparchus-samples/src/main/java/org/hipparchus/samples/IntegerDistributionComparison.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public Display() {
234234
c.gridy = 0;
235235
c.insets = new Insets(2, 2, 2, 2);
236236

237-
JComponent comp = null;
237+
JComponent comp;
238238

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

0 commit comments

Comments
 (0)