01: package org.apache.solr.util;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.util.*;
21:
22: /** <code>SimpleOrderedMap</code> is a {@link NamedList} where access by key is more
23: * important than maintaining order when it comes to representing the
24: * held data in other forms, as ResponseWriters normally do.
25: * It's normally not a good idea to repeat keys or use null keys, but this
26: * is not enforced. If key uniqueness enforcement is desired, use a regular {@link Map}.
27: * <p>
28: * For example, a JSON response writer may choose to write a SimpleOrderedMap
29: * as {"foo":10,"bar":20} and may choose to write a NamedList as
30: * ["foo",10,"bar",20]. An XML response writer may choose to render both
31: * the same way.
32: * </p>
33: * <p>
34: * This class does not provide efficient lookup by key, it's main purpose is
35: * to hold data to be serialized. It aims to minimize overhead and to be
36: * efficient at adding new elements.
37: * </p>
38: */
39: public class SimpleOrderedMap<T> extends NamedList<T> {
40: /** Creates an empty instance */
41: public SimpleOrderedMap() {
42: super ();
43: }
44:
45: /**
46: * Creates an instance backed by an explicitly specified list of
47: * pairwise names/values.
48: *
49: * @param nameValuePairs underlying List which should be used to implement a SimpleOrderedMap; modifying this List will affect the SimpleOrderedMap.
50: */
51: public SimpleOrderedMap(List nameValuePairs) {
52: super (nameValuePairs);
53: }
54:
55: public SimpleOrderedMap<T> clone() {
56: ArrayList newList = new ArrayList(nvPairs.size());
57: newList.addAll(nvPairs);
58: return new SimpleOrderedMap<T>(newList);
59: }
60: }
|