lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r833616 - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/Analysis/CharArraySet.cs Lucene.Net/Analysis/StopAnalyzer.cs Test/Analysis/TestASCIIFoldingFilter.cs Test/Analysis/TestCharArraySet.cs
Date Sat, 07 Nov 2009 00:31:20 GMT
Author: aroush
Date: Sat Nov  7 00:31:20 2009
New Revision: 833616

URL: http://svn.apache.org/viewvc?rev=833616&view=rev
Log:
Fixed JUnit test-cases for: TestCharArraySet.cs

Modified:
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/CharArraySet.cs
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/StopAnalyzer.cs
    incubator/lucene.net/trunk/C#/src/Test/Analysis/TestASCIIFoldingFilter.cs
    incubator/lucene.net/trunk/C#/src/Test/Analysis/TestCharArraySet.cs

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/CharArraySet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Analysis/CharArraySet.cs?rev=833616&r1=833615&r2=833616&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/CharArraySet.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/CharArraySet.cs Sat Nov  7 00:31:20
2009
@@ -81,7 +81,12 @@
 			return entries[GetSlot(text, off, len)] != null;
 		}
 		
-		/// <summary>Returns true if the String is in the set </summary>
+		/// <summary>true if the <code>System.String</code> is in the set </summary>
+		public virtual bool Contains(System.String cs)
+		{
+			return entries[GetSlot(cs)] != null;
+		}
+		
 		private int GetSlot(char[] text, int off, int len)
 		{
 			int code = GetHashCode(text, off, len);
@@ -101,6 +106,26 @@
 			return pos;
 		}
 		
+		/// <summary>Returns true if the String is in the set </summary>
+		private int GetSlot(System.String text)
+		{
+			int code = GetHashCode(text);
+			int pos = code & (entries.Length - 1);
+			char[] text2 = entries[pos];
+			if (text2 != null && !Equals(text, text2))
+			{
+				int inc = ((code >> 8) + code) | 1;
+				do 
+				{
+					code += inc;
+					pos = code & (entries.Length - 1);
+					text2 = entries[pos];
+				}
+				while (text2 != null && !Equals(text, text2));
+			}
+			return pos;
+		}
+		
 		/// <summary>Add this String into the set </summary>
 		public virtual bool Add(System.String text)
 		{
@@ -153,6 +178,30 @@
 			return true;
 		}
 		
+		private bool Equals(System.String text1, char[] text2)
+		{
+			int len = text1.Length;
+			if (len != text2.Length)
+				return false;
+			if (ignoreCase)
+			{
+				for (int i = 0; i < len; i++)
+				{
+					if (System.Char.ToLower(text1[i]) != text2[i])
+						return false;
+				}
+			}
+			else
+			{
+				for (int i = 0; i < len; i++)
+				{
+					if (text1[i] != text2[i])
+						return false;
+				}
+			}
+			return true;
+		}
+		
 		private void  Rehash()
 		{
 			int newSize = 2 * entries.Length;
@@ -169,8 +218,8 @@
 				}
 			}
 		}
-		
-		private int GetHashCode(char[] text, int offset, int len)
+
+        private int GetHashCode(char[] text, int offset, int len)
 		{
 			int code = 0;
 			int stop = offset + len;
@@ -191,6 +240,27 @@
 			return code;
 		}
 		
+		private int GetHashCode(System.String text)
+		{
+			int code = 0;
+			int len = text.Length;
+			if (ignoreCase)
+			{
+				for (int i = 0; i < len; i++)
+				{
+					code = code * 31 + System.Char.ToLower(text[i]);
+				}
+			}
+			else
+			{
+				for (int i = 0; i < len; i++)
+				{
+					code = code * 31 + text[i];
+				}
+			}
+			return code;
+		}
+		
 		public virtual int Size()
 		{
 			return count;
@@ -350,5 +420,37 @@
 				throw new System.NotSupportedException();
 			}
 		}
-	}
+
+        /// <summary>Adds all of the elements in the specified collection to this collection
</summary>
+        public virtual bool AddAll(System.Collections.ICollection items)
+        {
+            bool added = false;
+            System.Collections.IEnumerator iter = items.GetEnumerator();
+            System.Object item;
+            while (iter.MoveNext())
+            {
+                item = iter.Current;
+                added = Add(item);
+            }
+            return added;
+        }
+
+        /// <summary>Removes all elements from the set </summary>
+        public virtual bool Clear()
+        {
+            throw new System.NotSupportedException();
+        }
+
+        /// <summary>Removes from this set all of its elements that are contained in
the specified collection </summary>
+        public virtual bool RemoveAll(System.Collections.ICollection items)
+        {
+            throw new System.NotSupportedException();
+        }
+
+        /// <summary>Retains only the elements in this set that are contained in the
specified collection </summary>
+        public bool RetainAll(System.Collections.ICollection coll)
+        {
+            throw new System.NotSupportedException();
+        }
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/StopAnalyzer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Analysis/StopAnalyzer.cs?rev=833616&r1=833615&r2=833616&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/StopAnalyzer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Analysis/StopAnalyzer.cs Sat Nov  7 00:31:20
2009
@@ -232,11 +232,7 @@
 			{
 				System.String[] stopWords = new System.String[]{"a", "an", "and", "are", "as", "at",
"be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such",
"that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"};
 				CharArraySet stopSet = new CharArraySet(stopWords.Length, false);
-				//stopSet.AddAll(new System.Collections.ArrayList(stopWords));
-                for (int i = 0; i < stopWords.Length; i++)
-                {
-                    stopSet.Add(stopWords[i]);
-                }
+				stopSet.AddAll(new System.Collections.ArrayList(stopWords));
 				ENGLISH_STOP_WORDS_SET = CharArraySet.UnmodifiableSet(stopSet);
 			}
 		}

Modified: incubator/lucene.net/trunk/C#/src/Test/Analysis/TestASCIIFoldingFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Analysis/TestASCIIFoldingFilter.cs?rev=833616&r1=833615&r2=833616&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Analysis/TestASCIIFoldingFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Analysis/TestASCIIFoldingFilter.cs Sat Nov  7 00:31:20
2009
@@ -1,4 +1,4 @@
-/* 
+/* 
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -30,7 +30,7 @@
 		
 		// testLain1Accents() is a copy of TestLatin1AccentFilter.testU().
         [Test]
-		public virtual void  testLatin1Accents()
+		public virtual void  TestLatin1Accents()
 		{
 			TokenStream stream = new WhitespaceTokenizer(new System.IO.StringReader("Des mot clés
À LA CHAÎNE À �? Â Ã Ä Å
Æ Ç È É Ê Ë Ì �? Î
�? IJ �? Ñ" + " Ò Ó Ô Õ
Ö Ø Œ Þ Ù Ú Û Ü �?
Ÿ à á â ã ä å æ ç è
é ê ë ì í î ï ij" + " ð ñ
ò ó ô õ ö ø œ ß þ ù
ú û ü ý ÿ �? fl"));
 			ASCIIFoldingFilter filter = new ASCIIFoldingFilter(stream);
@@ -164,7 +164,7 @@
 		//    ============== end get.test.cases.pl ==============
 		//
         [Test]
-		public virtual void  testAllFoldings()
+		public virtual void  TestAllFoldings()
 		{
 			// Alternating strings of:
 			//   1. All non-ASCII characters to be folded, concatenated together as a

Modified: incubator/lucene.net/trunk/C#/src/Test/Analysis/TestCharArraySet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Analysis/TestCharArraySet.cs?rev=833616&r1=833615&r2=833616&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Analysis/TestCharArraySet.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Analysis/TestCharArraySet.cs Sat Nov  7 00:31:20
2009
@@ -93,8 +93,9 @@
         [Test]
 		public virtual void  TestModifyOnUnmodifiable()
 		{
-			CharArraySet set_Renamed = new CharArraySet(10, true);
-			for (int i = 0; i < TEST_STOP_WORDS.Length; i++) { set_Renamed.Add(TEST_STOP_WORDS[i]);
}
+            //System.Diagnostics.Debugger.Break();
+            CharArraySet set_Renamed = new CharArraySet(10, true);
+			set_Renamed.AddAll(TEST_STOP_WORDS);
 			int size = set_Renamed.Count;
 			set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
 			Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
@@ -161,11 +162,7 @@
 			}
 			try
 			{
-                for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
-                {
-                    if (set_Renamed.Contains(TEST_STOP_WORDS[i]))
-                        set_Renamed.Remove(TEST_STOP_WORDS[i]); // {{Aroush-2.9}} this should
throw
-                }
+				set_Renamed.RemoveAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
 				Assert.Fail("Modified unmodifiable set");
 			}
 			catch (System.NotSupportedException e)
@@ -176,11 +173,7 @@
 			
 			try
 			{
-                for (int i = 0; i < NOT_IN_SET.Length; i++)
-                {
-                    if (!set_Renamed.Contains(NOT_IN_SET[i]))
-                        set_Renamed.Remove(NOT_IN_SET[i]); // {{Aroush-2.9}} this should
throw
-                }
+                set_Renamed.RetainAll(new System.Collections.ArrayList(new System.String[]
{ NOT_IN_SET }));
 				Assert.Fail("Modified unmodifiable set");
 			}
 			catch (System.NotSupportedException e)
@@ -191,11 +184,7 @@
 			
 			try
 			{
-                for (int i = 0; i < NOT_IN_SET.Length; i++)
-                {
-                    if (!set_Renamed.Contains(NOT_IN_SET[i]))
-                        set_Renamed.Add(NOT_IN_SET[i]); // {{Aroush-2.9}} this should throw
-                }
+				set_Renamed.AddAll(new System.Collections.ArrayList(new System.String[] { NOT_IN_SET
}));
 				Assert.Fail("Modified unmodifiable set");
 			}
 			catch (System.NotSupportedException e)
@@ -214,9 +203,7 @@
 		public virtual void  TestUnmodifiableSet()
 		{
 			CharArraySet set_Renamed = new CharArraySet(10, true);
-            for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
-                if (!set_Renamed.Contains(TEST_STOP_WORDS[i]))
-                    set_Renamed.Add(TEST_STOP_WORDS[i]);
+			set_Renamed.AddAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
 			int size = set_Renamed.Count;
 			set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
 			Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");



Mime
View raw message