Added convience method UnitGroup.getUnit( String ) which returns the Unit corresponding to the abbreviation. Throws IllegalArgumentException if the requested unit does not exist.

This commit is contained in:
Kevin Ruland 2012-04-26 18:20:10 +00:00
parent b990a5acb2
commit f2e7cb58ab

View File

@ -419,6 +419,14 @@ public class UnitGroup {
throw new IllegalArgumentException("name=" + name);
}
public Unit getUnit( String name ) throws IllegalArgumentException {
for (int i = 0; i < units.size(); i++) {
if (units.get(i).getUnit().equals(name)) {
return units.get(i);
}
}
throw new IllegalArgumentException("name=" + name);
}
public Unit getUnit(int n) {
return units.get(n);