Skip to content

Commit 2e3bf92

Browse files
committed
more elegant use of lambda
1 parent 0ce7dd9 commit 2e3bf92

File tree

144 files changed

+923
-1927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+923
-1927
lines changed

hipparchus-clustering/src/test/java/org/hipparchus/clustering/DBSCANClustererTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,12 @@ void testGetMinPts() {
181181

182182
@Test
183183
void testNegativeEps() {
184-
assertThrows(MathIllegalArgumentException.class, () -> {
185-
new DBSCANClusterer<DoublePoint>(-2.0, 5);
186-
});
184+
assertThrows(MathIllegalArgumentException.class, () -> new DBSCANClusterer<DoublePoint>(-2.0, 5));
187185
}
188186

189187
@Test
190188
void testNegativeMinPts() {
191-
assertThrows(MathIllegalArgumentException.class, () -> {
192-
new DBSCANClusterer<DoublePoint>(2.0, -5);
193-
});
189+
assertThrows(MathIllegalArgumentException.class, () -> new DBSCANClusterer<DoublePoint>(2.0, -5));
194190
}
195191

196192
@Test

hipparchus-clustering/src/test/java/org/hipparchus/clustering/FuzzyKMeansClustererTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ void testCluster() {
8989

9090
@Test
9191
void testTooSmallFuzzynessFactor() {
92-
assertThrows(MathIllegalArgumentException.class, () -> {
93-
new FuzzyKMeansClusterer<DoublePoint>(3, 1.0);
94-
});
92+
assertThrows(MathIllegalArgumentException.class, () -> new FuzzyKMeansClusterer<DoublePoint>(3, 1.0));
9593
}
9694

9795
@Test

hipparchus-core/src/test/java/org/hipparchus/CalculusFieldElementAbstractTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public void testSign() {
594594

595595
@Test
596596
public void testLinearCombinationReference() {
597-
doTestLinearCombinationReference(x -> build(x), 5.0e-16, 1.0);
597+
doTestLinearCombinationReference(this::build, 5.0e-16, 1.0);
598598
}
599599

600600
protected void doTestLinearCombinationReference(final DoubleFunction<T> builder,

hipparchus-core/src/test/java/org/hipparchus/analysis/FieldFunctionsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public <T extends CalculusFieldElement<T>> T value(T x) {
3434
}
3535
};
3636
CalculusFieldUnivariateFunction<Binary64> f1Converted = f1.toCalculusFieldUnivariateFunction(Binary64Field.getInstance());
37-
CalculusFieldUnivariateFunction<Binary64> f2 = x -> x.twice();
37+
CalculusFieldUnivariateFunction<Binary64> f2 = CalculusFieldElement::twice;
3838

3939
for (double x = 0; x < 1; x += 0.01) {
4040
assertEquals(f2.value(new Binary64(x)).getReal(),

hipparchus-core/src/test/java/org/hipparchus/analysis/FunctionUtilsTest.java

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,17 @@ void testFixingArguments() {
226226

227227
@Test
228228
void testSampleWrongBounds(){
229-
assertThrows(MathIllegalArgumentException.class, () -> {
230-
FunctionUtils.sample(new Sin(), FastMath.PI, 0.0, 10);
231-
});
229+
assertThrows(MathIllegalArgumentException.class, () -> FunctionUtils.sample(new Sin(), FastMath.PI, 0.0, 10));
232230
}
233231

234232
@Test
235233
void testSampleNegativeNumberOfPoints(){
236-
assertThrows(MathIllegalArgumentException.class, () -> {
237-
FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, -1);
238-
});
234+
assertThrows(MathIllegalArgumentException.class, () -> FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, -1));
239235
}
240236

241237
@Test
242238
void testSampleNullNumberOfPoints(){
243-
assertThrows(MathIllegalArgumentException.class, () -> {
244-
FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, 0);
245-
});
239+
assertThrows(MathIllegalArgumentException.class, () -> FunctionUtils.sample(new Sin(), 0.0, FastMath.PI, 0));
246240
}
247241

248242
@Test
@@ -260,24 +254,9 @@ void testSample() {
260254
@Test
261255
void testToDifferentiableUnivariate() {
262256

263-
final UnivariateFunction f0 = new UnivariateFunction() {
264-
@Override
265-
public double value(final double x) {
266-
return x * x;
267-
}
268-
};
269-
final UnivariateFunction f1 = new UnivariateFunction() {
270-
@Override
271-
public double value(final double x) {
272-
return 2 * x;
273-
}
274-
};
275-
final UnivariateFunction f2 = new UnivariateFunction() {
276-
@Override
277-
public double value(final double x) {
278-
return 2;
279-
}
280-
};
257+
final UnivariateFunction f0 = x -> x * x;
258+
final UnivariateFunction f1 = x -> 2 * x;
259+
final UnivariateFunction f2 = x -> 2;
281260
final UnivariateDifferentiableFunction f = FunctionUtils.toDifferentiable(f0, f1, f2);
282261

283262
DSFactory factory = new DSFactory(1, 2);
@@ -306,18 +285,8 @@ void testToDifferentiableMultivariate() {
306285

307286
final double a = 1.5;
308287
final double b = 0.5;
309-
final MultivariateFunction f = new MultivariateFunction() {
310-
@Override
311-
public double value(final double[] point) {
312-
return a * point[0] + b * point[1];
313-
}
314-
};
315-
final MultivariateVectorFunction gradient = new MultivariateVectorFunction() {
316-
@Override
317-
public double[] value(final double[] point) {
318-
return new double[] { a, b };
319-
}
320-
};
288+
final MultivariateFunction f = point -> a * point[0] + b * point[1];
289+
final MultivariateVectorFunction gradient = point -> new double[] { a, b };
321290
final MultivariateDifferentiableFunction mdf = FunctionUtils.toDifferentiable(f, gradient);
322291

323292
DSFactory factory11 = new DSFactory(1, 1);
@@ -358,18 +327,8 @@ void testToDifferentiableMultivariateInconsistentGradient() {
358327

359328
final double a = 1.5;
360329
final double b = 0.5;
361-
final MultivariateFunction f = new MultivariateFunction() {
362-
@Override
363-
public double value(final double[] point) {
364-
return a * point[0] + b * point[1];
365-
}
366-
};
367-
final MultivariateVectorFunction gradient = new MultivariateVectorFunction() {
368-
@Override
369-
public double[] value(final double[] point) {
370-
return new double[] { a, b, 0.0 };
371-
}
372-
};
330+
final MultivariateFunction f = point -> a * point[0] + b * point[1];
331+
final MultivariateVectorFunction gradient = point -> new double[] { a, b, 0.0 };
373332
final MultivariateDifferentiableFunction mdf = FunctionUtils.toDifferentiable(f, gradient);
374333

375334
DSFactory factory = new DSFactory(1, 1);

hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DSCompilerTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,12 @@ void testIndices() {
142142

143143
@Test
144144
void testIncompatibleParams() {
145-
assertThrows(MathIllegalArgumentException.class, () -> {
146-
DSCompiler.getCompiler(3, 2).checkCompatibility(DSCompiler.getCompiler(4, 2));
147-
});
145+
assertThrows(MathIllegalArgumentException.class, () -> DSCompiler.getCompiler(3, 2).checkCompatibility(DSCompiler.getCompiler(4, 2)));
148146
}
149147

150148
@Test
151149
void testIncompatibleOrder() {
152-
assertThrows(MathIllegalArgumentException.class, () -> {
153-
DSCompiler.getCompiler(3, 3).checkCompatibility(DSCompiler.getCompiler(3, 2));
154-
});
150+
assertThrows(MathIllegalArgumentException.class, () -> DSCompiler.getCompiler(3, 3).checkCompatibility(DSCompiler.getCompiler(3, 2)));
155151
}
156152

157153
@Test

hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/DerivativeStructureTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,17 @@ protected DerivativeStructure build(final double x) {
6969

7070
@Test
7171
void testWrongVariableIndex() {
72-
assertThrows(MathIllegalArgumentException.class, () -> {
73-
new DSFactory(3, 1).variable(3, 1.0);
74-
});
72+
assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(3, 1).variable(3, 1.0));
7573
}
7674

7775
@Test
7876
void testMissingOrders() {
79-
assertThrows(MathIllegalArgumentException.class, () -> {
80-
new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(0, 1);
81-
});
77+
assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(0, 1));
8278
}
8379

8480
@Test
8581
void testTooLargeOrder() {
86-
assertThrows(MathIllegalArgumentException.class, () -> {
87-
new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(1, 1, 2);
88-
});
82+
assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(3, 1).variable(0, 1.0).getPartialDerivative(1, 1, 2));
8983
}
9084

9185
@Test
@@ -1518,9 +1512,7 @@ void testDegRad() {
15181512

15191513
@Test
15201514
void testComposeMismatchedDimensions() {
1521-
assertThrows(MathIllegalArgumentException.class, () -> {
1522-
new DSFactory(1, 3).variable(0, 1.2).compose(new double[3]);
1523-
});
1515+
assertThrows(MathIllegalArgumentException.class, () -> new DSFactory(1, 3).variable(0, 1.2).compose(new double[3]));
15241516
}
15251517

15261518
@Test

hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureAbstractTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ protected FieldDerivativeStructure<T> build(final double x) {
7878

7979
@Test
8080
public void testWrongFieldVariableIndex() {
81-
assertThrows(MathIllegalArgumentException.class, () -> {
82-
buildFactory(3, 1).variable(3, buildScalar(1.0));
83-
});
81+
assertThrows(MathIllegalArgumentException.class, () -> buildFactory(3, 1).variable(3, buildScalar(1.0)));
8482
}
8583

8684
@Test

hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureComplexTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void testHypotNoOverflow() {
6565
@Override
6666
@Test
6767
public void testLinearCombinationReference() {
68-
doTestLinearCombinationReference(x -> build(x), 4.8e-16, 1.0);
68+
doTestLinearCombinationReference(this::build, 4.8e-16, 1.0);
6969
}
7070

7171
@Override

hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/FieldDerivativeStructureDfpTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void testHypotNoOverflow() {
6060
@Override
6161
@Test
6262
public void testLinearCombinationReference() {
63-
doTestLinearCombinationReference(x -> build(x), 4.15e-9, 4.21e-9);
63+
doTestLinearCombinationReference(this::build, 4.15e-9, 4.21e-9);
6464
}
6565

6666
@Override

0 commit comments

Comments
 (0)