KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > value > ValueStringIgnoreCase


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

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 JavaDoc 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             // this is locale sensitive
35
hash = value.toUpperCase().hashCode();
36         }
37         return hash;
38     }
39
40     public static ValueStringIgnoreCase get(String JavaDoc 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         // the cached object could have the wrong case (it would still be 'equal', but we don't like to store it)
50
if(cache.value.equals(s)) {
51             return cache;
52         } else {
53             return obj;
54         }
55     }
56
57 }
58
Popular Tags