From: kruland2607 Date: Thu, 26 Apr 2012 18:20:10 +0000 (+0000) Subject: Added convience method UnitGroup.getUnit( String ) which returns the Unit correspondi... X-Git-Tag: upstream/12.09^2~317 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=278c13848f4367324fed16d2ec713e3c7cce840e;hp=9f60dfb3054c910b90c11ac625a2eb70f8e443bf;p=debian%2Fopenrocket Added convience method UnitGroup.getUnit( String ) which returns the Unit corresponding to the abbreviation. Throws IllegalArgumentException if the requested unit does not exist. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@619 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/src/net/sf/openrocket/unit/UnitGroup.java b/core/src/net/sf/openrocket/unit/UnitGroup.java index f72f22a9..5a0b692c 100644 --- a/core/src/net/sf/openrocket/unit/UnitGroup.java +++ b/core/src/net/sf/openrocket/unit/UnitGroup.java @@ -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);