updates for 0.9.4
[debian/openrocket] / src / net / sf / openrocket / unit / UnitGroup.java
index 850cb925bf5a37d6147ff51db9b2ddcbd502876a..6b6d4997675052a5ad1ad33bf110f5ce17d6a799 100644 (file)
@@ -316,6 +316,26 @@ public class UnitGroup {
                defaultUnit = n;
        }
        
+       
+       
+       /**
+        * Find a unit by approximate unit name.  Only letters and (ordinary) numbers are
+        * considered in the matching.  This method is mainly means for testing, allowing
+        * a simple means to obtain a particular unit.
+        * 
+        * @param str   the unit name.
+        * @return              the corresponding unit, or <code>null</code> if not found.
+        */
+       public Unit findApproximate(String str) {
+               str = str.replaceAll("\\W", "").trim();
+               for (Unit u: units) {
+                       String name = u.getUnit().replaceAll("\\W", "").trim();
+                       if (str.equalsIgnoreCase(name))
+                               return u;
+               }
+               return null;
+       }
+       
        /**
         * Set the default unit based on the unit name.  Does nothing if the name
         * does not match any of the units.
@@ -393,6 +413,22 @@ public class UnitGroup {
        }
        
        
+
+       
+       
+       /**
+        * Creates a new Value object with the specified value and the default unit of this group.
+        * 
+        * @param value the value to set.
+        * @return              a new Value object.
+        */
+       public Value toValue(double value) {
+               return this.getDefaultUnit().toValue(value);
+       }
+       
+       
+       
+       
        private static final Pattern STRING_PATTERN = Pattern.compile("^\\s*([0-9.,-]+)(.*?)$");
        /**
         * Converts a string into an SI value.  If the string has one of the units in this