2 * Copyright 2005 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 namespace Lucene
.Net
.Util
20 /// <summary> A serializable Enum class.</summary>
22 public abstract class Parameter
24 internal static System
.Collections
.IDictionary allParameters
= new System
.Collections
.Hashtable();
26 private System
.String name
;
30 // typesafe enum pattern, no public constructor
33 protected internal Parameter(System
.String name
)
35 // typesafe enum pattern, no public constructor
37 System
.String key
= MakeKey(name
);
39 if (allParameters
.Contains(key
))
40 throw new System
.ArgumentException("Parameter name " + key
+ " already used!");
42 allParameters
[key
] = this;
45 private System
.String
MakeKey(System
.String name
)
47 return GetType() + " " + name
;
50 public override System
.String
ToString()
55 /// <summary> Resolves the deserialized instance to the local reference for accurate
56 /// equals() and == comparisons.
59 /// <returns> a reference to Parameter as resolved in the local VM
61 /// <throws> ObjectStreamException </throws>
62 protected internal virtual System
.Object
ReadResolve()
64 System
.Object par
= allParameters
[MakeKey(name
)];
67 throw new System
.IO
.IOException("Unknown parameter value: " + name
);