imagej / imagej-omero

Server- and client-side communication between ImageJ and OMERO
GNU General Public License v2.0
12 stars 10 forks source link

Investigate nicer way to convert between unit data structures #57

Open ctrueden opened 9 years ago

ctrueden commented 9 years ago

The ImageJ-OMERO code needs to convert between ome.units.quantity and omero.model units. I wrote a utility class to do it—it's a couple of giant switch statements. Is there a better way?

ctrueden commented 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.

ctrueden commented 6 years ago

@joshmoore Please let me know whether OMERO has methods like this now, or if this utility class continues to be needed.

joshmoore commented 6 years ago

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");
+    }
+
 }