KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > util > Parameter


1 package org.apache.lucene.util;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.ObjectStreamException JavaDoc;
20 import java.io.Serializable JavaDoc;
21 import java.io.StreamCorruptedException JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * A serializable Enum class.
27  */

28 public abstract class Parameter implements Serializable JavaDoc
29 {
30   static Map JavaDoc allParameters = new HashMap JavaDoc();
31   
32   private String JavaDoc name;
33   
34   private Parameter() {
35     // typesafe enum pattern, no public constructor
36
}
37   
38   protected Parameter(String JavaDoc name) {
39     // typesafe enum pattern, no public constructor
40
this.name = name;
41     String JavaDoc key = makeKey(name);
42     
43     if(allParameters.containsKey(key))
44       throw new IllegalArgumentException JavaDoc("Parameter name " + key + " already used!");
45     
46     allParameters.put(key, this);
47   }
48   
49   private String JavaDoc makeKey(String JavaDoc name){
50     return getClass() + " " + name;
51   }
52   
53   public String JavaDoc toString() {
54     return name;
55   }
56   
57   /**
58    * Resolves the deserialized instance to the local reference for accurate
59    * equals() and == comparisons.
60    *
61    * @return a reference to Parameter as resolved in the local VM
62    * @throws ObjectStreamException
63    */

64   protected Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
65     Object JavaDoc par = allParameters.get(makeKey(name));
66     
67     if(par == null)
68       throw new StreamCorruptedException JavaDoc("Unknown parameter value: " + name);
69       
70     return par;
71   }
72   
73  }
74
Popular Tags