| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
package org.h2.value; |
| 7 |
|
| 8 |
import java.util.HashMap; |
| 9 |
import org.h2.util.StringUtils; |
| 10 |
|
| 11 |
/** |
| 12 |
* A hash map with a case-insensitive string key. |
| 13 |
* |
| 14 |
* @param <V> the value type |
| 15 |
*/ |
| 16 |
public class CaseInsensitiveMap<V> extends HashMap<String, V> { |
| 17 |
|
| 18 |
private static final long serialVersionUID = 1L; |
| 19 |
|
| 20 |
/** |
| 21 |
* Creates new instance of case-insensitive map. |
| 22 |
*/ |
| 23 |
public CaseInsensitiveMap() { |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Creates new instance of case-insensitive map with specified initial |
| 28 |
* capacity. |
| 29 |
* |
| 30 |
* @param initialCapacity the initial capacity |
| 31 |
*/ |
| 32 |
public CaseInsensitiveMap(int initialCapacity) { |
| 33 |
super(initialCapacity); |
| 34 |
} |
| 35 |
|
| 36 |
@Override |
| 37 |
public V get(Object key) { |
| 38 |
return super.get(StringUtils.toUpperEnglish((String) key)); |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public V put(String key, V value) { |
| 43 |
return super.put(StringUtils.toUpperEnglish(key), value); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public V putIfAbsent(String key, V value) { |
| 48 |
return super.putIfAbsent(StringUtils.toUpperEnglish(key), value); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public boolean containsKey(Object key) { |
| 53 |
return super.containsKey(StringUtils.toUpperEnglish((String) key)); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public V remove(Object key) { |
| 58 |
return super.remove(StringUtils.toUpperEnglish((String) key)); |
| 59 |
} |
| 60 |
|
| 61 |
} |