From f2e7cb58abcb646b85f7cec62d00ce86d08345e4 Mon Sep 17 00:00:00 2001 From: Kevin Ruland 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. --- 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 f72f22a97..5a0b692c9 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);