View Javadoc

1   package org.apache.torque.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.collections.map.ListOrderedMap;
23  
24  /***
25   * A subclass of the Apache Commons ListOrderedMap that has case insensitive
26   * String key methods.  This is done by converting all String keys to 
27   * lower case.
28   *
29   * @author <a href="mailto:greg.monroe@dukece.com">Greg Monroe</a>
30   * @version $Id$
31   */
32  public class ListOrderedMapCI extends ListOrderedMap
33  {
34      private static final long serialVersionUID = -4349246328751938554L;
35  
36      /***
37       * Constructs a new empty ListOrderedMap.
38       */
39      public ListOrderedMapCI() {
40          super();
41      }
42  
43      /***
44       * Get the object associated with this key.
45       * 
46       * @param key A case insensitive String.
47       * @return The value for this key
48       */
49      public Object get( String key ) {
50         return super.get( key.toLowerCase() ); 
51      }
52      /***
53       * Adds a value to the end of the list with the specified key.
54       * 
55       * @param key A case insensitive String.
56       * @param value The value to add
57       * @return The value for previously mapped to this key
58       */
59      public Object put( String key, Object value ) {
60          return super.put( key.toLowerCase(), value ); 
61      }
62      /***
63       * Puts a key-value mapping into the map at the specified index.
64       * 
65       * @param index The index at which the mapping should be inserted.  
66       * @param key A case insensitive String.
67       * @param value The value.
68       * @return The value for previously mapped to this key
69       */
70      public Object put( int index, String key, Object value ) {
71          return super.put(index, key.toLowerCase(), value );
72      }
73      /***
74       * Gets the index of the specified key.
75       * 
76       * @param key A case insensitive String.
77       * @return the index, or -1 if not found
78       */
79      public int indexOf( String key ) {
80          return super.indexOf( key.toLowerCase() );
81      }
82      /***
83       * Removes the mapping for the specified key.
84       * @param key A case insensitive String.
85       * @return the removed value, or null if none existed
86       */
87      public Object remove ( String key ) {
88          return super.remove( key.toLowerCase() );
89      }
90      /***
91       * Test if the key exists in the mapping.
92       * 
93       * @param key The case insensitive key to test for.
94       * @return True if the key exists.
95       */
96      public boolean containsKey( String key ) {
97          return super.containsKey( key.toLowerCase());
98      }
99  }