precompile regex / stringutil
[mir.git] / source / mir / storage / store / StoreContainerType.java
1 package mir.storage.store;
2
3 /**
4  * Title:         StoreContainerType
5  *
6  * Description:   StoreContainerTypes are uniqe Objects and are generated
7  *                via @see valueOf(Class stocClass, int stocType).
8  *                For every combination of stocClass and stocType there is
9  *                only one Object instantiated.
10  *
11  * Copyright:     Copyright (c) 2002
12  * Company:       indy
13  *
14  * @author        rk
15  * @version 1.0
16  */
17
18 import java.util.HashMap;
19 import mir.misc.Logfile;
20
21 public class StoreContainerType {
22
23         public final static int    STOC_TYPE_UNKNOWN=0;
24         public final static int    STOC_TYPE_ENTITY=1;
25         public final static int    STOC_TYPE_ENTITYLIST=2;
26
27         private static HashMap      uniqueTypes = new HashMap(); // StoreKey / StoreContainerType
28         private static Logfile      storeLog;
29         private Class               stocClass=null;
30         private int                 stocType=STOC_TYPE_UNKNOWN;
31
32         private StoreContainerType() {}
33
34         private StoreContainerType(Class stocClass, int stocType) {
35                 this.stocClass=stocClass;
36                 this.stocType=stocType;
37         }
38
39         public static StoreContainerType valueOf(Class stoc_class, int stoc_type) {
40                 /** @todo factory, only gives out types once to make them comparable via ==
41                         *   check if class is StorableObject */
42                 StoreContainerType returnStocType=null;
43
44                         // inner class for hashlookup
45                          class StoreKey {
46                                 int   storeType;
47                                 Class storeClass;
48                         }
49
50                 StoreKey key = new StoreKey();
51                 key.storeClass = stoc_class; key.storeType = stoc_type;
52                 if (uniqueTypes.containsKey(key))
53                         returnStocType=(StoreContainerType)uniqueTypes.get(key);
54                 else {
55                         returnStocType=new StoreContainerType(stoc_class,stoc_type);
56                         uniqueTypes.put(key,returnStocType);
57                 }
58                 return returnStocType;
59         }
60
61         public String toString() {
62                 StringBuffer sb = new StringBuffer("StoreContainerType: ");
63                 sb.append(this.stocClass.toString()).append("@");
64                 sb.append(stringForStoreType(stocType)).append("\n");
65                 return sb.toString();
66         }
67
68         private static String stringForStoreType(int stocType) {
69                 switch(stocType) {
70                         case STOC_TYPE_ENTITY: return "ENTITY";
71                         case STOC_TYPE_ENTITYLIST: return "ENTITYLIST";
72                         default: return "UNKNOWN";
73                 }
74         }
75 }