lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r732141 - in /lucene/java/trunk/src: java/org/apache/lucene/analysis/CharArraySet.java test/org/apache/lucene/analysis/TestCharArraySet.java
Date Tue, 06 Jan 2009 22:01:36 GMT
Author: mikemccand
Date: Tue Jan  6 14:01:35 2009
New Revision: 732141

URL: http://svn.apache.org/viewvc?rev=732141&view=rev
Log:
LUCENE-1502: a few small cleanups to CharArraySet

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java
    lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java?rev=732141&r1=732140&r2=732141&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java Tue Jan  6 14:01:35
2009
@@ -191,22 +191,15 @@
   }
 
   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 @@
     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

Modified: lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java?rev=732141&r1=732140&r2=732141&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java Tue Jan  6
14:01:35 2009
@@ -21,8 +21,8 @@
 
 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 @@
     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)));
+  }
 }



Mime
View raw message