GeomConverter/src/org/lcsim/units/clhep
diff -N Constants.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Constants.java 9 Apr 2007 19:31:57 -0000 1.1
@@ -0,0 +1,87 @@
+package org.lcsim.units.clhep;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+/**
+ * Statically accessible version of CLHEP units and
+ * physical constants. Two methods are forwarded
+ * from Map.
+ *
+ * @see #get(String)
+ * @see #entrySet()
+ *
+ * The method
+ *
+ * @see #getInstance()
+ *
+ * should be used to retrieve a static reference
+ * to this class.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ *
+ */
+public class Constants
+{
+ Map<String, Double> constantsMap = new HashMap<String, Double>();
+
+ private static Constants instance = new Constants();
+
+ public double get(String key)
+ {
+ return constantsMap.get(key);
+ }
+
+ public Set<Entry<String,Double>> entrySet()
+ {
+ return constantsMap.entrySet();
+ }
+
+ public static Constants getInstance()
+ {
+ return instance;
+ }
+
+ private Constants()
+ {
+ setupSystemOfUnits();
+ setupPhysicalConstants();
+ }
+
+ private void setupSystemOfUnits()
+ {
+ SystemOfUnits units = new SystemOfUnits();
+ Class<SystemOfUnits> klass = SystemOfUnits.class;
+ Field[] fields = klass.getFields();
+ for (Field f : fields)
+ {
+ try {
+ constantsMap.put(f.getName(), f.getDouble(units));
+ }
+ catch ( IllegalAccessException x )
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ }
+
+ private void setupPhysicalConstants()
+ {
+ PhysicalConstants units = new PhysicalConstants();
+ Class<SystemOfUnits> klass = SystemOfUnits.class;
+ Field[] fields = klass.getFields();
+ for (Field f : fields)
+ {
+ try {
+ constantsMap.put(f.getName(), f.getDouble(units));
+ }
+ catch ( IllegalAccessException x )
+ {
+ throw new RuntimeException(x);
+ }
+ }
+ }
+}
\ No newline at end of file
GeomConverter/src/org/lcsim/units/clhep
diff -N SystemOfUnitsMap.java
--- SystemOfUnitsMap.java 9 Apr 2007 19:21:01 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,37 +0,0 @@
-package org.lcsim.units.clhep;
-
-import java.lang.reflect.Field;
-import java.util.HashMap;
-
-public class SystemOfUnitsMap
-extends HashMap<String,Double>
-{
- private static final SystemOfUnitsMap instance = new SystemOfUnitsMap();
-
- public static SystemOfUnitsMap getInstance()
- {
- return instance;
- }
-
- public SystemOfUnitsMap()
- {
- create();
- }
-
- private void create()
- {
- SystemOfUnits units = new SystemOfUnits();
- Class<SystemOfUnits> klass = SystemOfUnits.class;
- Field[] fields = klass.getFields();
- for (Field f : fields)
- {
- try {
- this.put(f.getName(), f.getDouble(units));
- }
- catch ( IllegalAccessException x )
- {
- throw new RuntimeException(x);
- }
- }
- }
-}
\ No newline at end of file