Skip to content

Commit 66929f3

Browse files
committed
imagej-mesh2: fix IntelliJ warnings
* Use try-with-resources where appropriate. * Remove unused exceptions from throws declarations.
1 parent 6ba88a9 commit 66929f3

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎imagej/imagej-mesh2/src/test/java/net/imagej/mesh2/AbstractMeshTest.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public abstract class AbstractMeshTest {
5151
public abstract Mesh createMesh();
5252

5353
@Test
54-
public void testMesh() throws Exception {
54+
public void testMesh() {
5555
// Initialize the mesh.
5656
final Mesh mesh = createMesh();
5757
assertSame(mesh, mesh.vertices().mesh());
@@ -145,8 +145,7 @@ public void testMesh() throws Exception {
145145
}
146146

147147
@Test
148-
public void testTriangleNormal() throws URISyntaxException, IOException {
149-
148+
public void testTriangleNormal() {
150149
Mesh inputMesh = new NaiveDoubleMesh();
151150
inputMesh.vertices().add(1, 1, 1);
152151
inputMesh.vertices().add(1, -1, 1);

‎imagej/imagej-mesh2/src/test/java/net/imagej/mesh2/MeshesTest.java‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ private static Mesh createMeshWithNoise() {
160160
}
161161

162162
private static Img<FloatType> getTestImage3D() {
163-
try {
164-
final InputStream is = MeshesTest.class.getResourceAsStream("/3d_geometric_features_testlabel.bin");
163+
try (final InputStream is = MeshesTest.class.getResourceAsStream("/3d_geometric_features_testlabel.bin")) {
165164
return ArrayImgs.floats(ArrayIO.floats(is), 13, 12, 10);
166165
} catch (IOException e) {
167166
throw new RuntimeException(e);
@@ -173,18 +172,18 @@ private static Mesh getMesh() {
173172
// To prevent duplicates, map each (x, y, z) triple to its own index.
174173
final Map<Vector3D, Long> indexMap = new HashMap<>();
175174
final LongArray indices = new LongArray();
176-
try {
177-
Files.lines(Paths.get(MeshesTest.class.getResource("/3d_geometric_features_mesh.txt").toURI()))
178-
.forEach(l -> {
179-
String[] coord = l.split(" ");
180-
final double x = Double.parseDouble(coord[0]);
181-
final double y = Double.parseDouble(coord[1]);
182-
final double z = Double.parseDouble(coord[2]);
183-
final Vector3D vertex = new Vector3D(x, y, z);
184-
final long vIndex = indexMap.computeIfAbsent(vertex, //
185-
v -> m.vertices().add(x, y, z));
186-
indices.add(vIndex);
187-
});
175+
final URL url = MeshesTest.class.getResource("/3d_geometric_features_mesh.txt");
176+
try (Stream<String> lines = Files.lines(Paths.get(url.toURI()))) {
177+
lines.forEach(l -> {
178+
String[] coord = l.split(" ");
179+
final double x = Double.parseDouble(coord[0]);
180+
final double y = Double.parseDouble(coord[1]);
181+
final double z = Double.parseDouble(coord[2]);
182+
final Vector3D vertex = new Vector3D(x, y, z);
183+
final long vIndex = indexMap.computeIfAbsent(vertex, //
184+
v -> m.vertices().add(x, y, z));
185+
indices.add(vIndex);
186+
});
188187
} catch (IOException | URISyntaxException exc) {
189188
exc.printStackTrace();
190189
}

0 commit comments

Comments
 (0)