LUCENE-1502: a few small cleanups to CharArraySet

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@732141 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2009-01-06 22:01:35 +00:00
parent 43609e891d
commit d666ae5eda
2 changed files with 17 additions and 23 deletions

View File

@ -191,22 +191,15 @@ public class CharArraySet extends AbstractSet {
}
private int getHashCode(CharSequence text) {
int code;
int code = 0;
int len = text.length();
if (ignoreCase) {
code = 0;
int len = text.length();
for (int i=0; i<len; i++) {
code = code*31 + Character.toLowerCase(text.charAt(i));
}
} else {
if (false && text instanceof String) {
code = text.hashCode();
} else {
code = 0;
int len = text.length();
for (int i=0; i<len; i++) {
code = code*31 + text.charAt(i);
}
for (int i=0; i<len; i++) {
code = code*31 + text.charAt(i);
}
}
return code;
@ -225,22 +218,15 @@ public class CharArraySet extends AbstractSet {
if (o instanceof char[]) {
char[] text = (char[])o;
return contains(text, 0, text.length);
} else if (o instanceof CharSequence) {
return contains((CharSequence)o);
}
return false;
}
return contains(o.toString());
}
public boolean add(Object o) {
if (o instanceof char[]) {
return add((char[])o);
} else if (o instanceof String) {
return add((String)o);
} else if (o instanceof CharSequence) {
return add((CharSequence)o);
} else {
return add(o.toString());
}
return add(o.toString());
}
/** The Iterator<String> for this set. Strings are constructed on the fly, so

View File

@ -21,8 +21,8 @@ import java.util.Arrays;
import org.apache.lucene.util.LuceneTestCase;
public class TestCharArraySet extends LuceneTestCase
{
public class TestCharArraySet extends LuceneTestCase {
public void testRehash() throws Exception {
CharArraySet cas = new CharArraySet(0, true);
for(int i=0;i<StopAnalyzer.ENGLISH_STOP_WORDS.length;i++)
@ -40,4 +40,12 @@ public class TestCharArraySet extends LuceneTestCase
assertTrue(set.contains(findme, 1, 4));
assertTrue(set.contains(new String(findme,1,4)));
}
public void testObjectContains() {
CharArraySet set = new CharArraySet(10, true);
Integer val = new Integer(1);
set.add(val);
assertTrue(set.contains(val));
assertTrue(set.contains(new Integer(1)));
}
}