KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > SerializationUtil


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object;
5
6 import gnu.trove.TObjectIntHashMap;
7 import gnu.trove.TObjectIntIterator;
8
9 /**
10  * Some utility stuff for logical serialization
11  */

12 public class SerializationUtil {
13
14   // NOTE: DO NOT USE VALUE 0. A zero indicates a mapping that does exist
15
public final static int ADD = 1;
16   public final static int ADD_AT = 2;
17   public final static int ADD_LAST = 3;
18   public final static int ADD_FIRST = 4;
19   public final static int PUT = 5;
20   public final static int CLEAR = 6;
21   public final static int REMOVE = 7;
22   public final static int REMOVE_AT = 8;
23   public final static int SET = 9;
24   public final static int SET_ELEMENT = 10;
25   public final static int SET_SIZE = 11;
26   public final static int TRIM_TO_SIZE = 12;
27   public final static int INSERT_AT = 13;
28   public final static int REMOVE_FIRST = 14;
29   public final static int REMOVE_LAST = 15;
30   public final static int REMOVE_RANGE = 16;
31   public final static int SET_TIME = 17;
32   public final static int SET_NANOS = 18;
33   public final static int REMOVE_ALL = 19;
34   public final static int VIEW_SET = 20;
35   public final static int GET = 21;
36   public final static int TAKE = 22;
37   public final static int REMOVE_FIRST_N = 23;
38   public final static int REPLACE = 24;
39   public final static int REPLACE_IF_VALUE_EQUAL = 25;
40   public final static int PUT_IF_ABSENT = 26;
41   public final static int REMOVE_IF_VALUE_EQUAL = 27;
42
43   public final static String JavaDoc PUSH_SIGNATURE = "push(Ljava/lang/Object;)java/lang/Object;";
44   public final static String JavaDoc POP_SIGNATURE = "pop()java/lang/Object;";
45   public final static String JavaDoc ADD_AT_SIGNATURE = "add(ILjava/lang/Object;)V";
46   public final static String JavaDoc INSERT_ELEMENT_AT_SIGNATURE = "insertElementAt(Ljava/lang/Object;I)V";
47   public final static String JavaDoc ADD_ELEMENT_SIGNATURE = "addElement(Ljava/lang/Object;)V";
48   public final static String JavaDoc ADD_ALL_AT_SIGNATURE = "addAll(ILjava/util/Collection;)Z";
49   public final static String JavaDoc ADD_SIGNATURE = "add(Ljava/lang/Object;)Z";
50   public final static String JavaDoc ADD_ALL_SIGNATURE = "addAll(Ljava/util/Collection;)Z";
51   public final static String JavaDoc ADD_LAST_SIGNATURE = "addLast(Ljava/lang/Object;)V";
52   public final static String JavaDoc ADD_FIRST_SIGNATURE = "addFirst(Ljava/lang/Object;)V";
53   public final static String JavaDoc CLEAR_SIGNATURE = "clear()V";
54   public final static String JavaDoc PUT_SIGNATURE = "put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;";
55   public final static String JavaDoc GET_SIGNATURE = "get(Ljava/lang/Object;)Ljava/lang/Object;";
56   public final static String JavaDoc SET_SIGNATURE = "set(ILjava/lang/Object;)Ljava/lang/Object;";
57   public final static String JavaDoc SET_ELEMENT_SIGNATURE = "setElementAt(Ljava/lang/Object;I)V";
58   public final static String JavaDoc TRIM_TO_SIZE_SIGNATURE = "trimToSize()V";
59   public final static String JavaDoc SET_SIZE_SIGNATURE = "setSize(I)V";
60   public final static String JavaDoc REMOVE_AT_SIGNATURE = "remove(I)Ljava/lang/Object;";
61   public final static String JavaDoc REMOVE_SIGNATURE = "remove(Ljava/lang/Object;)Z";
62   public final static String JavaDoc REMOVE_KEY_SIGNATURE = "remove(Ljava/lang/Object;)Ljava/lang/Object;";
63   public final static String JavaDoc REMOVE_ENTRY_FOR_KEY_SIGNATURE = "removeEntryForKey(Ljava/lang/Object;)Ljava/util/HashMap$Entry;";
64   public final static String JavaDoc REMOVE_ELEMENT_SIGNATURE = "removeElement(Ljava/lang/Object;)Z";
65   public final static String JavaDoc REMOVE_ELEMENT_AT_SIGNATURE = "removeElementAt(I)V";
66   public final static String JavaDoc REMOVE_ALL_ELEMENTS_SIGNATURE = "removeAllElements()V";
67   public final static String JavaDoc REMOVE_ALL_SIGNATURE = "removeAll(Ljava/util/Collection;)Z";
68   public final static String JavaDoc ITERATOR_SIGNATURE = "iterator()Ljava/util/Iterator;";
69   public final static String JavaDoc TROVE_REMOVE_AT_SIGNATURE = "removeAt(I)V";
70   public final static String JavaDoc REMOVE_FIRST_SIGNATURE = "removeFirst()Ljava/lang/Object;";
71   public final static String JavaDoc REMOVE_LAST_SIGNATURE = "removeLast()Ljava/lang/Object;";
72   public final static String JavaDoc REMOVE_RANGE_SIGNATURE = "removeRange(II)V";
73   public final static String JavaDoc TO_ARRAY_SIGNATURE = "toArray([Ljava/lang/Object;)[Ljava/lang/Object;";
74   public final static String JavaDoc COPY_INTO_SIGNATURE = "copyInto([Ljava/lang/Object;)V";
75   public final static String JavaDoc SUBSET_SIGNATURE = "subSet(Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/SortedSet;";
76   public final static String JavaDoc HEADSET_SIGNATURE = "headSet(Ljava/lang/Object;)Ljava/util/SortedSet;";
77   public final static String JavaDoc TAILSET_SIGNATURE = "tailSet(Ljava/lang/Object;)Ljava/util/SortedSet;";
78   public final static String JavaDoc EXECUTE_SIGNATURE = "execute(Ljava/lang/Object;)Z";
79   public final static String JavaDoc ENTRY_SET_SIGNATURE = "entrySet()Ljava/util/Set;";
80   public final static String JavaDoc KEY_SET_SIGNATURE = "keySet()Ljava/util/Set;";
81   public final static String JavaDoc VALUES_SIGNATURE = "values()Ljava/util/Collection;";
82   public final static String JavaDoc SET_TIME_SIGNATURE = "setTime(J)V";
83   public final static String JavaDoc SET_YEAR_SIGNATURE = "setYear(I)V";
84   public final static String JavaDoc SET_MONTH_SIGNATURE = "setMonth(I)V";
85   public final static String JavaDoc SET_DATE_SIGNATURE = "setDate(I)V";
86   public final static String JavaDoc SET_HOURS_SIGNATURE = "setHours(I)V";
87   public final static String JavaDoc SET_MINUTES_SIGNATURE = "setMinutes(I)V";
88   public final static String JavaDoc SET_SECONDS_SIGNATURE = "setSeconds(I)V";
89   public final static String JavaDoc SET_NANOS_SIGNATURE = "setNanos(I)V";
90   public final static String JavaDoc ITERATOR_REMOVE_SIGNATURE = "remove()V";
91   public final static String JavaDoc ELEMENTS_SIGNATURE = "elements()Ljava/util/Enumeration;";
92   public final static String JavaDoc QUEUE_PUT_SIGNATURE = "put(Ljava/lang/Object;)V";
93   public final static String JavaDoc OFFER_SIGNATURE = "offer(Ljava/lang/Object;)Z";
94   public final static String JavaDoc OFFER_TIMEOUT_SIGNATURE = "offer(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;)Z";
95   public final static String JavaDoc TAKE_SIGNATURE = "take()Ljava/lang/Object;";
96   public final static String JavaDoc POLL_TIMEOUT_SIGNATURE = "poll(JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;";
97   public final static String JavaDoc POLL_SIGNATURE = "poll()Ljava/lang/Object;";
98   public final static String JavaDoc DRAIN_TO_SIGNATURE = "drainTo(Ljava/util/Collection;)I";
99   public final static String JavaDoc DRAIN_TO_N_SIGNATURE = "drainTo(Ljava/util/Collection;I)I";
100   public final static String JavaDoc REMOVE_FIRST_N_SIGNATURE = "removeFirst(I)V";
101   public final static String JavaDoc PUT_IF_ABSENT_SIGNATURE = "putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;";
102   public final static String JavaDoc REMOVE_IF_VALUE_EQUAL_SIGNATURE = "remove(Ljava/lang/Object;Ljava/lang/Object;)Z";
103   public final static String JavaDoc REPLACE_SIGNATURE = "replace(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;";
104   public final static String JavaDoc REPLACE_IF_VALUE_EQUAL_SIGNATURE = "replace(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z";
105   public final static String JavaDoc SEGMENT_FOR_SIGNATURE = "segmentFor(I)Ljava/util/concurrent/ConcurrentHashMap$Segment;";
106   public final static String JavaDoc CONTAINS_VALUE_SIGNATURE = "containsValue(Ljava/lang/Object;)Z";
107   public final static String JavaDoc SIZE_SIGNATURE = "size()I";
108   public final static String JavaDoc IS_EMPTY_SIGNATURE = "isEmpty()Z";
109   public final static String JavaDoc SIGNAL_SIGNATURE = "signal()V";
110   public final static String JavaDoc SIGNAL_ALL_SIGNATURE = "signalAll()V";
111   public final static String JavaDoc TRANSFORM_VALUES_SIGNATURE = "transformValues(Lgnu/trove/TObjectFunction;)V";
112
113   private final TObjectIntHashMap mappings = new TObjectIntHashMap();
114
115   public SerializationUtil() {
116     mappings.put(SET_ELEMENT_SIGNATURE, SET_ELEMENT);
117     mappings.put(SET_SIZE_SIGNATURE, SET_SIZE);
118     mappings.put(TRIM_TO_SIZE_SIGNATURE, TRIM_TO_SIZE);
119     mappings.put(REMOVE_ALL_ELEMENTS_SIGNATURE, CLEAR);
120     mappings.put(REMOVE_ELEMENT_AT_SIGNATURE, REMOVE_AT);
121     mappings.put(REMOVE_ELEMENT_SIGNATURE, REMOVE);
122     mappings.put(ADD_ELEMENT_SIGNATURE, ADD);
123     mappings.put(INSERT_ELEMENT_AT_SIGNATURE, INSERT_AT);
124     mappings.put(ADD_AT_SIGNATURE, ADD_AT);
125     mappings.put(ADD_ALL_AT_SIGNATURE, ADD_AT);
126     mappings.put(ADD_SIGNATURE, ADD);
127     mappings.put(ADD_ALL_SIGNATURE, ADD);
128     mappings.put(ADD_LAST_SIGNATURE, ADD_LAST);
129     mappings.put(ADD_FIRST_SIGNATURE, ADD_FIRST);
130     mappings.put(CLEAR_SIGNATURE, CLEAR);
131     mappings.put(PUT_SIGNATURE, PUT);
132     mappings.put(GET_SIGNATURE, GET);
133     mappings.put(SET_SIGNATURE, SET);
134     mappings.put(REMOVE_AT_SIGNATURE, REMOVE_AT);
135     mappings.put(REMOVE_SIGNATURE, REMOVE);
136     mappings.put(REMOVE_IF_VALUE_EQUAL_SIGNATURE, REMOVE_IF_VALUE_EQUAL);
137     mappings.put(REMOVE_KEY_SIGNATURE, REMOVE);
138     mappings.put(TROVE_REMOVE_AT_SIGNATURE, REMOVE);
139     mappings.put(REMOVE_ENTRY_FOR_KEY_SIGNATURE, REMOVE);
140     mappings.put(REMOVE_FIRST_SIGNATURE, REMOVE_FIRST);
141     mappings.put(REMOVE_LAST_SIGNATURE, REMOVE_LAST);
142     mappings.put(REMOVE_RANGE_SIGNATURE, REMOVE_RANGE);
143     mappings.put(SET_TIME_SIGNATURE, SET_TIME);
144     mappings.put(SET_NANOS_SIGNATURE, SET_NANOS);
145     mappings.put(REMOVE_ALL_SIGNATURE, REMOVE_ALL);
146     mappings.put(QUEUE_PUT_SIGNATURE, PUT);
147     mappings.put(TAKE_SIGNATURE, TAKE);
148     mappings.put(REMOVE_FIRST_N_SIGNATURE, REMOVE_FIRST_N);
149     mappings.put(PUT_IF_ABSENT_SIGNATURE, PUT_IF_ABSENT);
150     mappings.put(REPLACE_SIGNATURE, REPLACE);
151     mappings.put(REPLACE_IF_VALUE_EQUAL_SIGNATURE, REPLACE_IF_VALUE_EQUAL);
152   }
153
154   public String JavaDoc[] getSignatures() {
155     String JavaDoc[] rv = new String JavaDoc[this.mappings.size()];
156     int index = 0;
157     for (TObjectIntIterator i = mappings.iterator(); i.hasNext(); index++) {
158       i.advance();
159       rv[index] = (String JavaDoc) i.key();
160     }
161     return rv;
162   }
163
164   public int methodToID(String JavaDoc name) {
165     int i = mappings.get(name);
166     if (i == 0) throw new AssertionError JavaDoc("Illegal method name:" + name);
167     return i;
168   }
169
170   public boolean isParent(String JavaDoc fieldName) {
171     return fieldName.matches("^this\\$\\d+$");
172   }
173 }
174
Popular Tags