From b93f8b21fa0e6ecfc809476a79babf17813e8d55 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Wed, 5 Jun 2024 12:09:33 +0200 Subject: [PATCH] Make TreeUtils.getMinTimepoint() return 0 in case of an empty model. * It was before Integer.MAX_VALUE, which was confusing to be a min time point * Update javadocs and unit test accordingly --- src/main/java/org/mastodon/util/TreeUtils.java | 6 +++++- src/test/java/org/mastodon/util/TreeUtilsTest.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mastodon/util/TreeUtils.java b/src/main/java/org/mastodon/util/TreeUtils.java index b1c6ae44b..14149a5ac 100644 --- a/src/main/java/org/mastodon/util/TreeUtils.java +++ b/src/main/java/org/mastodon/util/TreeUtils.java @@ -232,12 +232,16 @@ private static < V extends Vertex, E extends Edge< V > > RefSet< V > filterRo } /** - * Gets the minimum timepoint in the given {@link Model} at which at least one {@link Spot} exists in the Model. + * Gets the minimum time point in the given {@link Model} at which at least one {@link Spot} exists in the Model. + *
+ * If the model is empty, returns 0. * @param model the {@link Model} * @return the timepoint */ public static int getMinTimepoint( final Model model ) { + if ( model.getGraph().vertices().isEmpty() ) + return 0; int minTimepoint = Integer.MAX_VALUE; for ( final Spot spot : model.getGraph().vertices() ) minTimepoint = Math.min( minTimepoint, spot.getTimepoint() ); diff --git a/src/test/java/org/mastodon/util/TreeUtilsTest.java b/src/test/java/org/mastodon/util/TreeUtilsTest.java index fbaf9df3c..aefbdec85 100644 --- a/src/test/java/org/mastodon/util/TreeUtilsTest.java +++ b/src/test/java/org/mastodon/util/TreeUtilsTest.java @@ -41,6 +41,7 @@ import org.mastodon.collection.RefSet; import org.mastodon.mamut.feature.branch.exampleGraph.ExampleGraph1; import org.mastodon.mamut.feature.branch.exampleGraph.ExampleGraph2; +import org.mastodon.mamut.model.Model; import org.mastodon.mamut.model.ModelGraph; import org.mastodon.mamut.model.Spot; @@ -182,7 +183,7 @@ public void testGetMinTimepoint() { assertEquals( 0, TreeUtils.getMinTimepoint( new ExampleGraph1().getModel() ) ); assertEquals( 0, TreeUtils.getMinTimepoint( new ExampleGraph2().getModel() ) ); - + assertEquals( 0, TreeUtils.getMinTimepoint( new Model() ) ); } @Test