From 278c13848f4367324fed16d2ec713e3c7cce840e Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Thu, 26 Apr 2012 18:20:10 +0000 Subject: [PATCH] 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 --- core/src/net/sf/openrocket/unit/UnitGroup.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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); -- 2.30.2