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: ListOrderedMapCI.java 1331187 2012-04-27 02:30:47Z tfischer $ 31 */ 32 public class ListOrderedMapCI extends ListOrderedMap 33 { 34 /** Version id for serializing. */ 35 private static final long serialVersionUID = -4349246328751938554L; 36 37 /** 38 * Constructs a new empty ListOrderedMap. 39 */ 40 public ListOrderedMapCI() 41 { 42 super(); 43 } 44 45 /** 46 * Get the object associated with this key. 47 * 48 * @param key A case insensitive String. 49 * @return The value for this key 50 */ 51 public Object get(String key) 52 { 53 return super.get(key.toLowerCase()); 54 } 55 56 /** 57 * Adds a value to the end of the list with the specified key. 58 * 59 * @param key A case insensitive String. 60 * @param value The value to add 61 * @return The value for previously mapped to this key 62 */ 63 public Object put(String key, Object value) 64 { 65 return super.put(key.toLowerCase(), value); 66 } 67 68 /** 69 * Puts a key-value mapping into the map at the specified index. 70 * 71 * @param index The index at which the mapping should be inserted. 72 * @param key A case insensitive String. 73 * @param value The value. 74 * 75 * @return The value for previously mapped to this key 76 */ 77 public Object put(int index, String key, Object value) 78 { 79 return super.put(index, key.toLowerCase(), value); 80 } 81 /** 82 * Gets the index of the specified key. 83 * 84 * @param key A case insensitive String. 85 * @return the index, or -1 if not found 86 */ 87 public int indexOf(String key) 88 { 89 return super.indexOf(key.toLowerCase()); 90 } 91 /** 92 * Removes the mapping for the specified key. 93 * @param key A case insensitive String. 94 * @return the removed value, or null if none existed 95 */ 96 public Object remove (String key) 97 { 98 return super.remove(key.toLowerCase()); 99 } 100 /** 101 * Test if the key exists in the mapping. 102 * 103 * @param key The case insensitive key to test for. 104 * @return True if the key exists. 105 */ 106 public boolean containsKey(String key) 107 { 108 return super.containsKey(key.toLowerCase()); 109 } 110 }