Open ctrueden opened 9 years ago
@joshmoore This is how I ended up dealing with the units after my questions in devteam last night. Probably I'm being silly, but it gets the job done in the short term. Suggestions for a better approach are welcome.
@joshmoore Please let me know whether OMERO has methods like this now, or if this utility class continues to be needed.
Hi @ctrueden. I think you're just looking for lookupSymbol
:
$ git diff
diff --git a/components/blitz/test/ome/formats/utests/UnitsTest.java b/components/blitz/test/ome/formats/utests/UnitsTest.java
index 633e382f4f..29f8eb0db5 100644
--- a/components/blitz/test/ome/formats/utests/UnitsTest.java
+++ b/components/blitz/test/ome/formats/utests/UnitsTest.java
@@ -24,6 +24,7 @@ import omero.model.LengthI;
import omero.model.enums.UnitsLength;
import org.testng.annotations.Test;
+import org.testng.Assert;
public class UnitsTest {
@@ -90,4 +91,15 @@ public class UnitsTest {
public void testLengthMappingFromCentimeterToMeter() throws BigResult {
new LengthI(mm(1, UnitsLength.CENTIMETER), UnitsLength.METER);
}
+
+ // see imagej-omero's OMEROUtils.unit (line 49)
+ @Test
+ public void testOMEROtoModel() throws BigResult {
+ UnitsLength unit = UnitsLength.KILOMETER;
+ String u = ome.model.enums.UnitsLength.valueOf(
+ unit.toString()).getSymbol();
+ Assert.assertEquals(u, "km");
+ Assert.assertEquals(LengthI.lookupSymbol(unit), "km");
+ }
+
}
The ImageJ-OMERO code needs to convert between
ome.units.quantity
andomero.model
units. I wrote a utility class to do it—it's a couple of giant switch statements. Is there a better way?