~kirkland/eucalyptus/label-metadata

« back to all changes in this revision

Viewing changes to clc/modules/core/src/edu/ucsb/eucalyptus/util/CaseInsensitiveMap.java

  • Committer: graziano obertelli
  • Date: 2009-01-07 03:32:35 UTC
  • Revision ID: graziano@cs.ucsb.edu-20090107033235-oxhuexp18v8hg0pw
Tags: 1.4
from CVS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Software License Agreement (BSD License)
 
3
 *
 
4
 * Copyright (c) 2008, Regents of the University of California
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use of this software in source and binary forms, with or
 
8
 * without modification, are permitted provided that the following conditions
 
9
 * are met:
 
10
 *
 
11
 * * Redistributions of source code must retain the above
 
12
 *   copyright notice, this list of conditions and the
 
13
 *   following disclaimer.
 
14
 *
 
15
 * * Redistributions in binary form must reproduce the above
 
16
 *   copyright notice, this list of conditions and the
 
17
 *   following disclaimer in the documentation and/or other
 
18
 *   materials provided with the distribution.
 
19
 *
 
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
21
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
22
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
23
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
24
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
25
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
26
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
27
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
28
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
29
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
30
 * POSSIBILITY OF SUCH DAMAGE.
 
31
 *
 
32
 * Author: Sunil Soman sunils@cs.ucsb.edu
 
33
 */
 
34
package edu.ucsb.eucalyptus.util;
 
35
 
 
36
import java.util.*;
 
37
import java.util.concurrent.ConcurrentHashMap;
 
38
 
 
39
public class CaseInsensitiveMap {
 
40
        private ConcurrentHashMap<String, String> map;
 
41
 
 
42
        public CaseInsensitiveMap() {
 
43
                map = new ConcurrentHashMap<String, String> ();
 
44
        }
 
45
 
 
46
        public CaseInsensitiveMap(Map m) {
 
47
                map = new ConcurrentHashMap<String, String> ();
 
48
                Iterator iterator = m.keySet().iterator();
 
49
                while(iterator.hasNext()) {
 
50
                        Object key = iterator.next();
 
51
                        map.put(key.toString().toLowerCase(), (String) m.get(key));
 
52
                }
 
53
        }
 
54
 
 
55
 
 
56
        public Object get(Object o) {
 
57
                return map.get(o.toString().toLowerCase());
 
58
        }
 
59
 
 
60
        public int size() {
 
61
                return map.size();
 
62
        }
 
63
 
 
64
        public boolean isEmpty() {
 
65
                return map.isEmpty();
 
66
        }
 
67
 
 
68
        public boolean containsKey(Object o) {
 
69
                return map.containsKey(o.toString().toLowerCase());
 
70
        }
 
71
 
 
72
        public boolean containsValue(Object o) {
 
73
                return map.containsValue(o);
 
74
        }
 
75
 
 
76
        public Object put(Object o, Object o1) {
 
77
                return map.put(o.toString().toLowerCase(), (String)o1);
 
78
        }
 
79
 
 
80
        public Object remove(Object o) {
 
81
                return map.remove(o.toString().toLowerCase());
 
82
        }
 
83
 
 
84
        public void putAll(Map map) {
 
85
                map.putAll(map);
 
86
        }
 
87
 
 
88
        public void clear() {
 
89
                map.clear();
 
90
        }
 
91
 
 
92
        public Set keySet() {
 
93
                return map.keySet();
 
94
        }
 
95
 
 
96
        public Collection values() {
 
97
                return map.values();
 
98
        }
 
99
 
 
100
        public Set entrySet() {
 
101
                return map.entrySet();
 
102
        }
 
103
 
 
104
        public TreeMap removeSub(String subString) {
 
105
                TreeMap result = new TreeMap();
 
106
                Iterator iterator = map.keySet().iterator();
 
107
                while(iterator.hasNext()) {
 
108
                        Object key = iterator.next();
 
109
                        if(key.toString().startsWith(subString)) {
 
110
                                result.put(key, map.get(key));
 
111
                        }
 
112
                }
 
113
                return result;
 
114
        }
 
115
}