Skip to content

Commit

Permalink
Use enum LabelOptions directly in ExportLabelImageView
Browse files Browse the repository at this point in the history
* LabelOptions.getByName() method is no longer needed
  • Loading branch information
stefanhahmann committed Nov 23, 2023
1 parent 37b7251 commit 84c0994
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
*/
package org.mastodon.mamut.io.exporter.labelimage.config;

import java.util.NoSuchElementException;


public enum LabelOptions
{
Expand All @@ -46,15 +44,8 @@ public enum LabelOptions
this.name = name;
}

public static LabelOptions getByName( final String name )
{
for ( final LabelOptions options : values() )
if ( options.getName().equals( name ) )
return options;
throw new NoSuchElementException();
}

public String getName()
@Override
public String toString()
{
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class ExportLabelImageView implements Command
+ "</html>\n";

@SuppressWarnings("all")
@Parameter(label = "Label Id", choices = { "Spot track Id", "Branch spot ID", "Spot ID" })
private String option = LabelOptions.BRANCH_SPOT_ID.getName();
@Parameter(label = "Label Id")
private LabelOptions option = LabelOptions.BRANCH_SPOT_ID;

@SuppressWarnings("all")
@Parameter(label = "Frame rate reduction", description = "Only export every n-th. 1 means no reduction. Value must be >= 1.", min = "1")
Expand All @@ -83,7 +83,6 @@ public class ExportLabelImageView implements Command
public void run()
{
ExportLabelImageController controller = new ExportLabelImageController( projectModel, context );
LabelOptions selectedOption = LabelOptions.getByName( option );
controller.saveLabelImageToFile( selectedOption, saveTo, showResult, frameRateReduction );
controller.saveLabelImageToFile( option, saveTo, showResult, frameRateReduction );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,9 @@

public class LabelOptionsTest
{

@Test
public void getByName()
{
assertEquals( LabelOptions.SPOT_ID, LabelOptions.getByName( "Spot ID" ) );
assertEquals( LabelOptions.BRANCH_SPOT_ID, LabelOptions.getByName( "Branch spot ID" ) );
assertEquals( LabelOptions.TRACK_ID, LabelOptions.getByName( "Spot track Id" ) );
assertThrows( NoSuchElementException.class, () -> LabelOptions.getByName( "Foo" ) );
}

@Test
public void getName()
public void testToString()
{
assertEquals( "Spot ID", LabelOptions.SPOT_ID.getName() );
assertEquals( "Branch spot ID", LabelOptions.BRANCH_SPOT_ID.getName() );
assertEquals( "Spot track Id", LabelOptions.TRACK_ID.getName() );
assertEquals( "Spot ID", LabelOptions.SPOT_ID.toString() );
}
}

0 comments on commit 84c0994

Please sign in to comment.