2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * $Id: Attributes.java 464373 2006-10-16 04:21:54Z rahul $
20   */
21  package org.apache.shale.clay.config.beans;
22  
23  import java.util.TreeMap;
24  
25  /***
26   * <p>Normalize the case of a String key to lower case making
27   * the collection case insensitive.</p>
28   */
29  public class Attributes extends TreeMap {
30  
31      /***
32       * <p>Unique serial id.</p>
33       */
34      private static final long serialVersionUID = 3905244515647173938L;
35  
36      /***
37       * <p>Make the key case insensitive.</p>
38       *
39       * @param key attribute key
40       * @return <code>true</code> if key is contained
41       */
42      public boolean containsKey(Object key) {
43          Object normKey = null;
44  
45          if (key != null && key instanceof String) {
46             normKey = ((String) key).toLowerCase();
47          } else {
48             normKey = key;
49          }
50  
51          return super.containsKey(normKey);
52      }
53  
54      /***
55       * <p>Make the key case insensitive.</p>
56       *
57       * @param key attribute name
58       * @return value
59       */
60      public Object get(Object key) {
61          Object normKey = null;
62          if (key != null && key instanceof String) {
63              normKey = ((String) key).toLowerCase();
64          } else {
65              normKey = key;
66          }
67  
68          return super.get(normKey);
69      }
70  
71      /***
72       * <p>Make the key case insensitive.</p>
73       *
74       * @param key attribute name
75       * @param value attribute value
76       *
77       * @return original value
78       */
79      public Object put(Object key, Object value) {
80          Object normKey = null;
81          if (key != null && key instanceof String) {
82              normKey = ((String) key).toLowerCase();
83          } else {
84              normKey = key;
85          }
86  
87          return super.put(normKey, value);
88      }
89  
90  }