@@ -0,0 +1,1588 @@
+package org.concord.data.state;%0A%0A/**%0A * UnitValueEvaluator%0A * Class name and description%0A *%0A * Date created: Jun 17, 2007%0A *%0A * @author Shengyao Wang%3Cp%3E%0A */%0A/*%0A * Last modification information:%0A * $Revision: 1.1 $%0A * $Date: 2007-06-17 11:56:12 $%0A * $Author: swang $%0A *%0A * Licence Information%0A * Copyright 2004 The Concord Consortium %0A */%0A%0Apublic class UnitValueEvaluator %7B%0A%09private float value;%0A%09private String unit;%0A%09private String unitValue;%0A%09boolean isValidUnitValue = false;%0A%09%0A%09private String unitValueFormat = %22%5C%5Cd+(%5C%5C.?%5C%5Cd*)%7B0,1%7D(%5C%5Cs+%5C%5CD(%5C%5Cw*%5B/%5E-%5D*%5C%5Cw*)*)%7B0,1%7D%22;%0A%09%0A%09public UnitValueEvaluator(String unitValue) %7B%0A%09%09if(unitValue == null %7C%7C unitValue.trim().length() == 0) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09this.unitValue = unitValue.trim();%0A%09%09evaluate();%0A%09%7D%0A%09%0A%09private void evaluate() %7B%0A%09%09if(unitValue.matches(unitValueFormat)) %7B%0A%09%09%09isValidUnitValue = true;%0A%0A%09%09%09int index = unitValue.indexOf(' ');%0A%09%09%09if(index == -1) %7B%0A%09%09%09%09value = Float.parseFloat(unitValue);%0A%09%09%09%09unit = %22%22;%0A%09%09%09%7D else %7B%0A%09%09%09%09String flt = unitValue.substring(0, index);%0A%09%09%09%09unit = unitValue.substring(unitValue.lastIndexOf(' ')+1);%0A%09%09%09%09value = (Float.parseFloat(flt));%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A%09public boolean isValidUnitValue() %7B%0A%09%09return isValidUnitValue;%0A%09%7D%0A%09%0A%09public float getValue() %7B%0A%09%09if(!isValidUnitValue) throw new NumberFormatException();%0A%09%09return value;%0A%09%7D%0A%09%0A%09public String getUnit() %7B%0A%09%09if(!isValidUnitValue) throw new NumberFormatException();%0A%09%09return unit;%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09UnitValueEvaluator uve = new UnitValueEvaluator(%22122ee  %22);%0A%09%09System.out.println(uve.getValue() + %22:%22 + uve.getUnit());%0A%09%7D%0A%7D%0A

Validate input for OTUnitValue