Skip to content

Commit 5f52ec1

Browse files
committed
Reformat files
1 parent 46f8ff4 commit 5f52ec1

34 files changed

Lines changed: 165 additions & 161 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
[![GitHub Actions](https://github.com/ref-humbold/AlgoLib_Java/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/ref-humbold/AlgoLib_Java/actions/workflows/build-and-test.yml)
44

5-
![License](https://img.shields.io/github/license/ref-humbold/AlgoLib_Java?style=plastic)
5+
[![License](https://img.shields.io/github/license/ref-humbold/AlgoLib_Java?style=plastic)](./LICENSE)
66

7-
ALGOrithms LIBrary - Java version
7+
**Algo**rithms **Lib**rary - Java version
88

99
Library of various algorithms and data structures.

src/main/java/com/github/refhumbold/algolib/geometry/GeometryObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ protected GeometryObject()
88
{
99
}
1010

11+
public abstract double[] getCoordinates();
12+
1113
protected static boolean areEqual(double d1, double d2)
1214
{
1315
return Math.abs(d1 - d2) < EPSILON;
1416
}
15-
16-
public abstract double[] getCoordinates();
1717
}

src/main/java/com/github/refhumbold/algolib/geometry/dim2/ClosestPoints.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.NoSuchElementException;
66
import java.util.Objects;
77
import java.util.Optional;
8+
import java.util.stream.IntStream;
89
import com.github.refhumbold.algolib.tuples.Pair;
910

1011
/** Algorithm for searching pair of closest points in 2D. */
@@ -34,7 +35,8 @@ public static Pair<Point2D, Point2D> findClosestPoints(List<Point2D> points)
3435
}
3536

3637
// Searches for closest points among three of them.
37-
private static Pair<Point2D, Point2D> searchThree(Point2D point1,
38+
private static Pair<Point2D, Point2D> searchThree(
39+
Point2D point1,
3840
Point2D point2,
3941
Point2D point3)
4042
{
@@ -53,17 +55,18 @@ private static Pair<Point2D, Point2D> searchThree(Point2D point1,
5355

5456
// Searches for closest points inside a belt of given width.
5557
// The resulting distance should not be less than belt width.
56-
private static Optional<Pair<Point2D, Point2D>> checkBelt(List<Point2D> pointsY,
58+
private static Optional<Pair<Point2D, Point2D>> checkBelt(
59+
List<Point2D> pointsY,
5760
double middleX,
5861
double beltWidth)
5962
{
6063
Optional<Pair<Point2D, Point2D>> closestPoints = Optional.empty();
61-
List<Integer> beltPoints = new ArrayList<>();
6264
double minDistance = beltWidth;
63-
64-
for(int i = 0; i < pointsY.size(); ++i)
65-
if(pointsY.get(i).x >= middleX - beltWidth && pointsY.get(i).x <= middleX + beltWidth)
66-
beltPoints.add(i);
65+
List<Integer> beltPoints = IntStream.range(0, pointsY.size())
66+
.filter(i -> pointsY.get(i).x >= middleX - beltWidth
67+
&& pointsY.get(i).x <= middleX + beltWidth)
68+
.boxed()
69+
.toList();
6770

6871
for(int i = 1; i < beltPoints.size(); ++i)
6972
for(int j = i + 1; j < beltPoints.size(); ++j)
@@ -91,7 +94,8 @@ private static Optional<Pair<Point2D, Point2D>> checkBelt(List<Point2D> pointsY,
9194

9295
// Searches for closest points in given sublist of points.
9396
// Points are given sorted by X coordinate and by Y coordinate.
94-
private static Pair<Point2D, Point2D> searchClosest(List<Point2D> pointsX,
97+
private static Pair<Point2D, Point2D> searchClosest(
98+
List<Point2D> pointsX,
9599
List<Point2D> pointsY,
96100
int indexBegin,
97101
int indexEnd)

src/main/java/com/github/refhumbold/algolib/geometry/dim2/ConvexHull.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public static List<Point2D> findConvexHull(List<Point2D> points)
3434
for(Point2D pt : anglePoints)
3535
{
3636
while(hull.size() > 1
37-
&& crossProduct(hull.get(hull.size() - 2), hull.get(hull.size() - 1), pt) >= 0)
38-
hull.remove(hull.size() - 1);
37+
&& crossProduct(hull.get(hull.size() - 2), hull.getLast(), pt) >= 0)
38+
hull.removeLast();
3939

4040
hull.add(pt);
4141
}

src/main/java/com/github/refhumbold/algolib/geometry/dim2/Geometry2D.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.refhumbold.algolib.geometry.dim2;
22

3+
import java.util.Comparator;
34
import java.util.List;
45

56
/** Algorithms for basic geometrical operations in 2D. */
@@ -11,7 +12,7 @@ public final class Geometry2D
1112
*/
1213
public static void sortByX(List<Point2D> points)
1314
{
14-
points.sort((pt1, pt2) -> Double.compare(pt1.x, pt2.x));
15+
points.sort(Comparator.comparingDouble(pt -> pt.x));
1516
}
1617

1718
/**
@@ -20,7 +21,7 @@ public static void sortByX(List<Point2D> points)
2021
*/
2122
public static void sortByY(List<Point2D> points)
2223
{
23-
points.sort((pt1, pt2) -> Double.compare(pt1.y, pt2.y));
24+
points.sort(Comparator.comparingDouble(pt -> pt.y));
2425
}
2526

2627
/**
@@ -30,12 +31,8 @@ public static void sortByY(List<Point2D> points)
3031
*/
3132
public static void sortByAngle(List<Point2D> points)
3233
{
33-
points.sort((pt1, pt2) -> {
34-
if(pt1.angleDeg() == pt2.angleDeg())
35-
return Double.compare(pt1.radius(), pt2.radius());
36-
else
37-
return Double.compare(pt1.angleDeg(), pt2.angleDeg());
38-
});
34+
points.sort((pt1, pt2) -> pt1.angleDeg() == pt2.angleDeg() ? Double.compare(pt1.radius(),
35+
pt2.radius()) : Double.compare(pt1.angleDeg(), pt2.angleDeg()));
3936
}
4037

4138
/**

src/main/java/com/github/refhumbold/algolib/geometry/dim3/Geometry3D.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.refhumbold.algolib.geometry.dim3;
22

3+
import java.util.Comparator;
34
import java.util.List;
45

56
/** Algorithms for basic geometrical operations in 3D. */
@@ -11,7 +12,7 @@ public final class Geometry3D
1112
*/
1213
public static void sortByX(List<Point3D> points)
1314
{
14-
points.sort((pt1, pt2) -> Double.compare(pt1.x, pt2.x));
15+
points.sort(Comparator.comparingDouble(pt -> pt.x));
1516
}
1617

1718
/**
@@ -20,7 +21,7 @@ public static void sortByX(List<Point3D> points)
2021
*/
2122
public static void sortByY(List<Point3D> points)
2223
{
23-
points.sort((pt1, pt2) -> Double.compare(pt1.y, pt2.y));
24+
points.sort(Comparator.comparingDouble(pt -> pt.y));
2425
}
2526

2627
/**
@@ -29,7 +30,7 @@ public static void sortByY(List<Point3D> points)
2930
*/
3031
public static void sortByZ(List<Point3D> points)
3132
{
32-
points.sort((pt1, pt2) -> Double.compare(pt1.z, pt2.z));
33+
points.sort(Comparator.comparingDouble(pt -> pt.z));
3334
}
3435

3536
/**
@@ -42,8 +43,7 @@ public static double distance(Point3D point1, Point3D point2)
4243
{
4344
return Math.sqrt(
4445
(point2.x - point1.x) * (point2.x - point1.x) + (point2.y - point1.y) * (point2.y
45-
- point1.y)
46-
+ (point2.z - point1.z) * (point2.z - point1.z));
46+
- point1.y) + (point2.z - point1.z) * (point2.z - point1.z));
4747
}
4848

4949
/**
@@ -66,6 +66,6 @@ public static Point3D translate(Point3D point, Vector3D vector)
6666
public static Point3D reflect(Point3D point, Point3D centre)
6767
{
6868
return Point3D.of(-point.x + 2 * centre.x, -point.y + 2 * centre.y,
69-
-point.z + 2 * centre.z);
69+
-point.z + 2 * centre.z);
7070
}
7171
}

src/main/java/com/github/refhumbold/algolib/graphs/MultipartiteGraph.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public Vertex<VertexId> addVertex(int groupNumber, Vertex<VertexId> vertex)
171171
* @return the created vertex
172172
* @throws IllegalArgumentException if vertex already exists
173173
*/
174-
public Vertex<VertexId> addVertex(int groupNumber,
174+
public Vertex<VertexId> addVertex(
175+
int groupNumber,
175176
Vertex<VertexId> vertex,
176177
VertexProperty property)
177178
{
@@ -205,7 +206,8 @@ public Edge<VertexId> addEdgeBetween(Vertex<VertexId> source, Vertex<VertexId> d
205206
* @throws IllegalArgumentException if edge already exists
206207
* @throws GraphPartitionException if the vertices belong to the same group
207208
*/
208-
public Edge<VertexId> addEdgeBetween(Vertex<VertexId> source,
209+
public Edge<VertexId> addEdgeBetween(
210+
Vertex<VertexId> source,
209211
Vertex<VertexId> destination,
210212
EdgeProperty property)
211213
{

src/main/java/com/github/refhumbold/algolib/graphs/algorithms/Cutting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void onExit(Vertex<VertexId> vertex)
8484
{
8585
int minimalLowValue = dfsChildren.get(vertex)
8686
.stream()
87-
.mapToInt(child -> lowValues.get(child))
87+
.mapToInt(lowValues::get)
8888
.min()
8989
.orElse(Integer.MAX_VALUE);
9090

src/main/java/com/github/refhumbold/algolib/graphs/algorithms/LowestCommonAncestor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public final class LowestCommonAncestor<VertexId, VertexProperty, EdgeProperty>
1818
private final LcaStrategy<VertexId> strategy = new LcaStrategy<>();
1919
private boolean empty = true;
2020

21-
public LowestCommonAncestor(TreeGraph<VertexId, VertexProperty, EdgeProperty> graph,
21+
public LowestCommonAncestor(
22+
TreeGraph<VertexId, VertexProperty, EdgeProperty> graph,
2223
Vertex<VertexId> root)
2324
{
2425
this.graph = graph;
@@ -55,7 +56,7 @@ private Vertex<VertexId> find(Vertex<VertexId> vertex1, Vertex<VertexId> vertex2
5556
.filter(candidate -> !isOffspring(vertex2,
5657
candidate))
5758
.findFirst()
58-
.orElse(paths.get(vertex1).get(0));
59+
.orElse(paths.get(vertex1).getFirst());
5960

6061
return find(nextVertex, vertex2);
6162
}

src/main/java/com/github/refhumbold/algolib/graphs/algorithms/Matching.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ private void bfs(Map<Vertex<VertexId>, Double> distances)
9191
}
9292
}
9393

94-
private boolean dfs(Vertex<VertexId> vertex,
94+
private boolean dfs(
95+
Vertex<VertexId> vertex,
9596
Set<Vertex<VertexId>> visited,
9697
Map<Vertex<VertexId>, Double> distances)
9798
{

0 commit comments

Comments
 (0)