Skip to content

Commit 264e57a

Browse files
authored
Merge pull request #379 from Serrof/issue-378
use Java 8 features instead of <=7
2 parents b45c756 + 2ca8127 commit 264e57a

File tree

88 files changed

+450
-520
lines changed

Some content is hidden

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

88 files changed

+450
-520
lines changed

hipparchus-clustering/src/main/java/org/hipparchus/clustering/FuzzyKMeansClusterer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public List<CentroidCluster<T>> cluster(final Collection<T> dataPoints)
300300
// there is at least one point
301301
final int pointDimension = points.get(0).getPoint().length;
302302
for (int i = 0; i < k; i++) {
303-
clusters.add(new CentroidCluster<T>(new DoublePoint(new double[pointDimension])));
303+
clusters.add(new CentroidCluster<>(new DoublePoint(new double[pointDimension])));
304304
}
305305

306306
int iteration = 0;
@@ -338,7 +338,7 @@ private void updateClusterCenters() {
338338
i++;
339339
}
340340
MathArrays.scaleInPlace(1.0 / sum, arr);
341-
newClusters.add(new CentroidCluster<T>(new DoublePoint(arr)));
341+
newClusters.add(new CentroidCluster<>(new DoublePoint(arr)));
342342
j++;
343343
}
344344
clusters.clear();

hipparchus-clustering/src/main/java/org/hipparchus/clustering/KMeansPlusPlusClusterer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public List<CentroidCluster<T>> cluster(final Collection<T> points)
241241
} else {
242242
newCenter = centroidOf(cluster.getPoints(), cluster.getCenter().getPoint().length);
243243
}
244-
newClusters.add(new CentroidCluster<T>(newCenter));
244+
newClusters.add(new CentroidCluster<>(newCenter));
245245
}
246246
int changes = assignPointsToClusters(newClusters, points, assignments);
247247
clusters = newClusters;
@@ -292,7 +292,7 @@ private List<CentroidCluster<T>> chooseInitialCenters(final Collection<T> points
292292

293293
// Convert to list for indexed access. Make it unmodifiable, since removal of items
294294
// would screw up the logic of this method.
295-
final List<T> pointList = Collections.unmodifiableList(new ArrayList<T> (points));
295+
final List<T> pointList = Collections.unmodifiableList(new ArrayList<>(points));
296296

297297
// The number of points in the list.
298298
final int numPoints = pointList.size();
@@ -309,7 +309,7 @@ private List<CentroidCluster<T>> chooseInitialCenters(final Collection<T> points
309309

310310
final T firstPoint = pointList.get(firstPointIndex);
311311

312-
resultSet.add(new CentroidCluster<T>(firstPoint));
312+
resultSet.add(new CentroidCluster<>(firstPoint));
313313

314314
// Must mark it as taken
315315
taken[firstPointIndex] = true;
@@ -376,7 +376,7 @@ private List<CentroidCluster<T>> chooseInitialCenters(final Collection<T> points
376376

377377
final T p = pointList.get(nextPointIndex);
378378

379-
resultSet.add(new CentroidCluster<T> (p));
379+
resultSet.add(new CentroidCluster<>(p));
380380

381381
// Mark it as taken.
382382
taken[nextPointIndex] = true;

hipparchus-clustering/src/main/java/org/hipparchus/clustering/MultiKMeansPlusPlusClusterer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class MultiKMeansPlusPlusClusterer<T extends Clusterable> extends Cluster
5252
*/
5353
public MultiKMeansPlusPlusClusterer(final KMeansPlusPlusClusterer<T> clusterer,
5454
final int numTrials) {
55-
this(clusterer, numTrials, new SumOfClusterVariances<T>(clusterer.getDistanceMeasure()));
55+
this(clusterer, numTrials, new SumOfClusterVariances<>(clusterer.getDistanceMeasure()));
5656
}
5757

5858
/** Build a clusterer.

hipparchus-core/src/main/java/org/hipparchus/analysis/FunctionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static double[] sample(UnivariateFunction f, double min, double max, int
327327
if (n <= 0) {
328328
throw new MathIllegalArgumentException(
329329
LocalizedCoreFormats.NOT_POSITIVE_NUMBER_OF_SAMPLES,
330-
Integer.valueOf(n));
330+
n);
331331
}
332332
if (min >= max) {
333333
throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,

hipparchus-core/src/main/java/org/hipparchus/analysis/differentiation/SparseGradient.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,7 @@ public SparseGradient add(final SparseGradient a) {
160160
final SparseGradient out = new SparseGradient(value + a.value, derivatives);
161161
for (Map.Entry<Integer, Double> entry : a.derivatives.entrySet()) {
162162
final int id = entry.getKey();
163-
final Double old = out.derivatives.get(id);
164-
if (old == null) {
165-
out.derivatives.put(id, entry.getValue());
166-
} else {
167-
out.derivatives.put(id, old + entry.getValue());
168-
}
163+
out.derivatives.merge(id, entry.getValue(), Double::sum);
169164
}
170165

171166
return out;
@@ -187,12 +182,7 @@ public void addInPlace(final SparseGradient a) {
187182
value += a.value;
188183
for (final Map.Entry<Integer, Double> entry : a.derivatives.entrySet()) {
189184
final int id = entry.getKey();
190-
final Double old = derivatives.get(id);
191-
if (old == null) {
192-
derivatives.put(id, entry.getValue());
193-
} else {
194-
derivatives.put(id, old + entry.getValue());
195-
}
185+
derivatives.merge(id, entry.getValue(), Double::sum);
196186
}
197187
}
198188

@@ -224,12 +214,7 @@ public SparseGradient multiply(final SparseGradient a) {
224214
}
225215
for (Map.Entry<Integer, Double> entry : a.derivatives.entrySet()) {
226216
final int id = entry.getKey();
227-
final Double old = out.derivatives.get(id);
228-
if (old == null) {
229-
out.derivatives.put(id, value * entry.getValue());
230-
} else {
231-
out.derivatives.put(id, old + value * entry.getValue());
232-
}
217+
out.derivatives.merge(id, value * entry.getValue(), Double::sum);
233218
}
234219
return out;
235220
}
@@ -248,17 +233,10 @@ public SparseGradient multiply(final SparseGradient a) {
248233
*/
249234
public void multiplyInPlace(final SparseGradient a) {
250235
// Derivatives.
251-
for (Map.Entry<Integer, Double> entry : derivatives.entrySet()) {
252-
derivatives.put(entry.getKey(), a.value * entry.getValue());
253-
}
236+
derivatives.replaceAll((k, v) -> a.value * v);
254237
for (Map.Entry<Integer, Double> entry : a.derivatives.entrySet()) {
255238
final int id = entry.getKey();
256-
final Double old = derivatives.get(id);
257-
if (old == null) {
258-
derivatives.put(id, value * entry.getValue());
259-
} else {
260-
derivatives.put(id, old + value * entry.getValue());
261-
}
239+
derivatives.merge(id, value * entry.getValue(), Double::sum);
262240
}
263241
value *= a.value;
264242
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ private static double tricube(final double x) {
451451
* if one of the values is not a finite real number.
452452
*/
453453
private static void checkAllFiniteReal(final double[] values) {
454-
for (int i = 0; i < values.length; i++) {
455-
MathUtils.checkFinite(values[i]);
454+
for (double value : values) {
455+
MathUtils.checkFinite(value);
456456
}
457457
}
458458
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ private double laguerre(double lo, double hi) {
158158
double r = Double.NaN;
159159
// Solve all roots and select the one we are seeking.
160160
Complex[] root = complexSolver.solveAll(c, initial);
161-
for (int i = 0; i < root.length; i++) {
162-
if (complexSolver.isRoot(lo, hi, root[i])) {
163-
r = root[i].getReal();
161+
for (Complex complex : root) {
162+
if (complexSolver.isRoot(lo, hi, complex)) {
163+
r = complex.getReal();
164164
break;
165165
}
166166
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public double getReal(int k)
167167
if ((k < 0) || (k >= omegaCount)) {
168168
throw new MathIllegalArgumentException(
169169
LocalizedCoreFormats.OUT_OF_RANGE_ROOT_OF_UNITY_INDEX,
170-
Integer.valueOf(k),
171-
Integer.valueOf(0),
172-
Integer.valueOf(omegaCount - 1));
170+
k,
171+
0,
172+
omegaCount - 1);
173173
}
174174

175175
return omegaReal[k];
@@ -195,9 +195,9 @@ public double getImaginary(int k)
195195
if ((k < 0) || (k >= omegaCount)) {
196196
throw new MathIllegalArgumentException(
197197
LocalizedCoreFormats.OUT_OF_RANGE_ROOT_OF_UNITY_INDEX,
198-
Integer.valueOf(k),
199-
Integer.valueOf(0),
200-
Integer.valueOf(omegaCount - 1));
198+
k,
199+
0,
200+
omegaCount - 1);
201201
}
202202

203203
return isCounterClockWise ? omegaImaginaryCounterClockwise[k] :

hipparchus-core/src/main/java/org/hipparchus/distribution/continuous/EnumeratedRealDistribution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public EnumeratedRealDistribution(final double[] data) {
7777
int index = 0;
7878
for (Entry<Double, Integer> entry : dataMap.entrySet()) {
7979
values[index] = entry.getKey();
80-
probabilities[index] = entry.getValue().intValue() / denom;
80+
probabilities[index] = entry.getValue() / denom;
8181
index++;
8282
}
8383
innerDistribution =

hipparchus-core/src/main/java/org/hipparchus/distribution/discrete/EnumeratedIntegerDistribution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public EnumeratedIntegerDistribution(final int[] data) {
9191
int index = 0;
9292
for (Entry<Integer, Integer> entry : dataMap.entrySet()) {
9393
values[index] = entry.getKey();
94-
probabilities[index] = entry.getValue().intValue() / denom;
94+
probabilities[index] = entry.getValue() / denom;
9595
index++;
9696
}
9797
innerDistribution =

0 commit comments

Comments
 (0)