basic test run working, next step incorporating into db-layer
[mir.git] / source / mir / storage / store / StoreContainerType.java
index 841c16f..3cb3383 100755 (executable)
@@ -20,15 +20,22 @@ import mir.misc.Logfile;
 
 public class StoreContainerType {
 
-       public final static int    STOC_TYPE_UNKNOWN=0;
-       public final static int    STOC_TYPE_ENTITY=1;
-       public final static int    STOC_TYPE_ENTITYLIST=2;
+       public final static int     STOC_TYPE_UNKNOWN=-1;
+       public final static int     STOC_TYPE_ENTITY=0;
+       public final static int     STOC_TYPE_ENTITYLIST=1;
+  public final static int     STOC_TYPE_MAX=STOC_TYPE_ENTITYLIST;
 
-       private static HashMap      uniqueTypes = new HashMap(); // StoreKey / StoreContainerType
+       private static HashMap[]    uniqueTypes=new HashMap[STOC_TYPE_MAX+1];
        private static Logfile      storeLog;
        private Class               stocClass=null;
        private int                 stocType=STOC_TYPE_UNKNOWN;
 
+  static {
+    uniqueTypes[STOC_TYPE_ENTITY]= new HashMap();
+    uniqueTypes[STOC_TYPE_ENTITYLIST]=new HashMap();
+
+  }
+
        private StoreContainerType() {}
 
        private StoreContainerType(Class stocClass, int stocType) {
@@ -37,31 +44,25 @@ public class StoreContainerType {
        }
 
        public static StoreContainerType valueOf(Class stoc_class, int stoc_type) {
-               /** @todo factory, only gives out types once to make them comparable via ==
-                       *   check if class is StorableObject */
                StoreContainerType returnStocType=null;
-
-                       // inner class for hashlookup
-                        class StoreKey {
-                               int   storeType;
-                               Class storeClass;
-                       }
-
-               StoreKey key = new StoreKey();
-               key.storeClass = stoc_class; key.storeType = stoc_type;
-               if (uniqueTypes.containsKey(key))
-                       returnStocType=(StoreContainerType)uniqueTypes.get(key);
-               else {
-                       returnStocType=new StoreContainerType(stoc_class,stoc_type);
-                       uniqueTypes.put(key,returnStocType);
-               }
+    if (stoc_type>=0 && stoc_type <= STOC_TYPE_MAX) {
+      HashMap current = uniqueTypes[stoc_type];
+      if ( current.containsKey(stoc_class) )
+                         returnStocType=(StoreContainerType)current.get(stoc_class);
+                 else {
+                         returnStocType=new StoreContainerType(stoc_class,stoc_type);
+                         current.put(stoc_class,returnStocType);
+                 }
+    }
                return returnStocType;
        }
 
+  public int getStocType() { return stocType; }
+  public Class getStocClass() { return stocClass; }
+
        public String toString() {
-               StringBuffer sb = new StringBuffer("StoreContainerType: ");
-               sb.append(this.stocClass.toString()).append("@");
-               sb.append(stringForStoreType(stocType)).append("\n");
+               StringBuffer sb = new StringBuffer(this.stocClass.toString());
+               sb.append("@").append(stringForStoreType(stocType));
                return sb.toString();
        }