1 19 20 package org.netbeans.editor; 21 22 import java.util.Map ; 23 import java.util.HashMap ; 24 25 31 32 public class StringMap extends java.util.HashMap { 33 34 char[] testChars; 35 36 int testOffset; 37 38 int testLen; 39 40 static final long serialVersionUID =967608225972123714L; 41 public StringMap() { 42 super(); 43 } 44 45 public StringMap(int initialCapacity) { 46 super(initialCapacity); 47 } 48 49 public StringMap(int initialCapacity, float loadFactor) { 50 super(initialCapacity, loadFactor); 51 } 52 53 public StringMap(Map t) { 54 super(t); 55 } 56 57 public Object get(char[] chars, int offset, int len) { 58 testChars = chars; 59 testOffset = offset; 60 testLen = len; 61 Object o = get(this); 62 testChars = null; return o; 64 } 65 66 public boolean containsKey(char[] chars, int offset, int len) { 67 testChars = chars; 68 testOffset = offset; 69 testLen = len; 70 boolean b = containsKey(this); 71 testChars = null; return b; 73 } 74 75 public Object remove(char[] chars, int offset, int len) { 76 testChars = chars; 77 testOffset = offset; 78 testLen = len; 79 Object o = remove(this); 80 testChars = null; 81 return o; 82 } 83 84 public boolean equals(Object o) { 85 if (this == o) { 86 return true; 87 } 88 89 if (o instanceof String ) { 90 String s = (String )o; 91 if (testLen == s.length()) { 92 for (int i = testLen - 1; i >= 0; i--) { 93 if (testChars[testOffset + i] != s.charAt(i)) { 94 return false; 95 } 96 } 97 return true; 98 } 99 return false; 100 } 101 102 if (o instanceof char[]) { 103 char[] chars = (char[])o; 104 if (testLen == chars.length) { 105 for (int i = testLen - 1; i >= 0; i--) { 106 if (testChars[testOffset + i] != chars[i]) { 107 return false; 108 } 109 } 110 return true; 111 } 112 return false; 113 } 114 115 return false; 116 } 117 118 public int hashCode() { 119 int h = 0; 120 char[] chars = testChars; 121 int off = testOffset; 122 123 for (int i = testLen; i > 0; i--) { 124 h = 31 * h + chars[off++]; 125 } 126 127 return h; 128 } 129 130 } 131 | Popular Tags |