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=-1;
24 public final static int STOC_TYPE_ENTITY=0;
25 public final static int STOC_TYPE_ENTITYLIST=1;
26 public final static int STOC_TYPE_MAX=STOC_TYPE_ENTITYLIST;
28 private static HashMap[] uniqueTypes=new HashMap[STOC_TYPE_MAX+1];
29 private static Logfile storeLog;
30 private Class stocClass=null;
31 private int stocType=STOC_TYPE_UNKNOWN;
34 uniqueTypes[STOC_TYPE_ENTITY]= new HashMap();
35 uniqueTypes[STOC_TYPE_ENTITYLIST]=new HashMap();
39 private StoreContainerType() {}
41 private StoreContainerType(Class stocClass, int stocType) {
42 this.stocClass=stocClass;
43 this.stocType=stocType;
46 public static StoreContainerType valueOf(Class stoc_class, int stoc_type) {
47 StoreContainerType returnStocType=null;
48 if (stoc_type>=0 && stoc_type <= STOC_TYPE_MAX) {
49 HashMap current = uniqueTypes[stoc_type];
50 if ( current.containsKey(stoc_class) )
51 returnStocType=(StoreContainerType)current.get(stoc_class);
53 returnStocType=new StoreContainerType(stoc_class,stoc_type);
54 current.put(stoc_class,returnStocType);
57 return returnStocType;
60 public int getStocType() { return stocType; }
61 public Class getStocClass() { return stocClass; }
63 public String toString() {
64 StringBuffer sb = new StringBuffer(this.stocClass.toString());
65 sb.append("@").append(stringForStoreType(stocType));
69 private static String stringForStoreType(int stocType) {
71 case STOC_TYPE_ENTITY: return "ENTITY";
72 case STOC_TYPE_ENTITYLIST: return "ENTITYLIST";
73 default: return "UNKNOWN";