提交 946cca91 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Merge CaseInsensitiveConcurrentMap into NullableKeyConcurrentMap

上级 1b87114e
......@@ -73,7 +73,6 @@ import org.h2.util.SourceCompiler;
import org.h2.util.StringUtils;
import org.h2.util.TempFileDeleter;
import org.h2.util.Utils;
import org.h2.value.CaseInsensitiveConcurrentMap;
import org.h2.value.CaseInsensitiveMap;
import org.h2.value.CompareMode;
import org.h2.value.NullableKeyConcurrentMap;
......@@ -2860,9 +2859,7 @@ public class Database implements DataHandler {
* @return the hash map
*/
public <V> ConcurrentHashMap<String, V> newConcurrentStringMap() {
return dbSettings.databaseToUpper ?
new NullableKeyConcurrentMap<V>() :
new CaseInsensitiveConcurrentMap<V>();
return new NullableKeyConcurrentMap<>(!dbSettings.databaseToUpper);
}
/**
......
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.value;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.util.StringUtils;
/**
* A concurrent hash map with a case-insensitive string key, that also allows
* NULL as a key.
*
* @param <V> the value type
*/
public class CaseInsensitiveConcurrentMap<V> extends ConcurrentHashMap<String, V> {
private static final long serialVersionUID = 1L;
private static final String NULL = new String(new byte[0]);
@Override
public V get(Object key) {
return super.get(toUpper(key));
}
@Override
public V put(String key, V value) {
return super.put(toUpper(key), value);
}
@Override
public boolean containsKey(Object key) {
return super.containsKey(toUpper(key));
}
@Override
public V remove(Object key) {
return super.remove(toUpper(key));
}
private static String toUpper(Object key) {
return key == null ? NULL : StringUtils.toUpperEnglish(key.toString());
}
}
......@@ -7,15 +7,29 @@ package org.h2.value;
import java.util.concurrent.ConcurrentHashMap;
import org.h2.util.StringUtils;
/**
* A concurrent hash map that allows null keys
* A concurrent hash map with string keys that allows null keys.
*
* @param <V> the value type
*/
public class NullableKeyConcurrentMap<V> extends ConcurrentHashMap<String, V> {
private static final long serialVersionUID = 1L;
private static final String NULL = new String(new byte[0]);
private static final String NULL = new String();
private final boolean toUpper;
/**
* Create new instance of map.
*
* @param toUpper
* whether keys should be converted to upper case
*/
public NullableKeyConcurrentMap(boolean toUpper) {
this.toUpper = toUpper;
}
@Override
public V get(Object key) {
......@@ -37,8 +51,12 @@ public class NullableKeyConcurrentMap<V> extends ConcurrentHashMap<String, V> {
return super.remove(toUpper(key));
}
private static String toUpper(Object key) {
return key == null ? NULL : key.toString();
private String toUpper(Object key) {
if (key == null) {
return NULL;
}
String s = key.toString();
return toUpper ? StringUtils.toUpperEnglish(s) : s;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论