Print

Print


Commit in GeomConverter/src/org/lcsim/units/clhep on MAIN
Constants.java+87added 1.1
SystemOfUnitsMap.java-371.2 removed
+87-37
1 added + 1 removed, total 2 files


GeomConverter/src/org/lcsim/units/clhep
Constants.java added at 1.1
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
SystemOfUnitsMap.java removed after 1.2
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
CVSspam 0.2.8