1 package mir.storage.store;
4 * Title: StoreContainerType
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.
11 * Copyright: Copyright (c) 2002
18 import java.util.HashMap;
19 import mir.misc.Logfile;
21 public class StoreContainerType {
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;
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;
32 private StoreContainerType() {}
34 private StoreContainerType(Class stocClass, int stocType) {
35 this.stocClass=stocClass;
36 this.stocType=stocType;
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;
44 // inner class for hashlookup
46 int storeType; Class storeClass;
47 public boolean equals(Object o) {
48 if ( o instanceof StoreKey &&
49 ((StoreKey)o).storeType==storeType &&
50 ((StoreKey)o).storeClass==storeClass )
56 StoreKey key = new StoreKey();
57 key.storeClass = stoc_class; key.storeType = stoc_type;
58 if ( uniqueTypes.containsKey(key) )
59 returnStocType=(StoreContainerType)uniqueTypes.get(key);
61 returnStocType=new StoreContainerType(stoc_class,stoc_type);
62 uniqueTypes.put(key,returnStocType);
64 return returnStocType;
67 public String toString() {
68 StringBuffer sb = new StringBuffer("StoreContainerType: ");
69 sb.append(this.stocClass.toString()).append("@");
70 sb.append(stringForStoreType(stocType));
74 private static String stringForStoreType(int stocType) {
76 case STOC_TYPE_ENTITY: return "ENTITY";
77 case STOC_TYPE_ENTITYLIST: return "ENTITYLIST";
78 default: return "UNKNOWN";