1 5 package org.h2.value; 6 7 import org.h2.engine.Constants; 8 import org.h2.util.StringCache; 9 10 public class ValueStringIgnoreCase extends ValueStringBase { 11 12 private static final ValueStringIgnoreCase EMPTY = new ValueStringIgnoreCase(""); 13 private int hash; 14 15 protected ValueStringIgnoreCase(String value) { 16 super(value); 17 } 18 19 public int getType() { 20 return Value.STRING_IGNORECASE; 21 } 22 23 protected int compareSecure(Value o, CompareMode mode) { 24 ValueStringIgnoreCase v = (ValueStringIgnoreCase) o; 25 return mode.compareString(value, v.value, true); 26 } 27 28 protected boolean isEqual(Value v) { 29 return v instanceof ValueStringBase && value.equalsIgnoreCase(((ValueStringBase)v).value); 30 } 31 32 public int hashCode() { 33 if (hash == 0) { 34 hash = value.toUpperCase().hashCode(); 36 } 37 return hash; 38 } 39 40 public static ValueStringIgnoreCase get(String s) { 41 if (s.length() == 0) { 42 return EMPTY; 43 } 44 ValueStringIgnoreCase obj = new ValueStringIgnoreCase(StringCache.get(s)); 45 if (s.length() > Constants.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) { 46 return obj; 47 } 48 ValueStringIgnoreCase cache = (ValueStringIgnoreCase) Value.cache(obj); 49 if(cache.value.equals(s)) { 51 return cache; 52 } else { 53 return obj; 54 } 55 } 56 57 } 58 | Popular Tags |