You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by di...@apache.org on 2011/05/14 19:30:17 UTC
[Lucene.Net] svn commit: r1103167 - in /incubator/lucene.net/branches/Lucene.Net_2_9_4g:
src/core/Analysis/ src/core/Analysis/Standard/ src/core/Search/
src/core/Support/ test/core/Analysis/
Author: digy
Date: Sat May 14 17:30:17 2011
New Revision: 1103167
URL: http://svn.apache.org/viewvc?rev=1103167&view=rev
Log:
[LUCENENET-412] [LUCENENET-414] Another implementation of CharArraySet (to make Lucene.Net users happy:) )
Modified:
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/CharArraySet.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Standard/StandardAnalyzer.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopAnalyzer.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopFilter.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/PhraseQuery.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/Set.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestCharArraySet.cs
incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestStopFilter.cs
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/CharArraySet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/CharArraySet.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/CharArraySet.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/CharArraySet.cs Sat May 14 17:30:17 2011
@@ -16,6 +16,7 @@
*/
using System;
+using System.Linq;
using System.Collections.Generic;
namespace Lucene.Net.Analysis
@@ -30,129 +31,383 @@ namespace Lucene.Net.Analysis
/// is in the set without the necessity of converting it
/// to a String first.
/// </summary>
-
- public class CharArraySet : Support.Set<string>
- {
- private const int INIT_SIZE = 8;
- private bool ignoreCase;
-
- /// <summary>Create set with enough capacity to hold startSize
- /// terms
- /// </summary>
- public CharArraySet(int startSize, bool ignoreCase)
- {
- this.ignoreCase = ignoreCase;
- int size = INIT_SIZE;
- while (startSize + (startSize >> 2) > size)
- size <<= 1;
- base.Capacity = size;
- }
-
- /// <summary>Create set from a Collection of char[] or String </summary>
- public CharArraySet(IList<string> c, bool ignoreCase):this(c.Count, ignoreCase)
- {
+
+ public class CharArraySet : ICollection<string>
+ {
+
+ bool _ReadOnly = false;
+ const int INIT_SIZE = 8;
+ char[][] _Entries;
+ int _Count;
+ bool _IgnoreCase;
+
+ #region Constructors
+ /// <summary>Create set with enough capacity to hold startSize
+ /// terms
+ /// </summary>
+ public CharArraySet(int startSize, bool ignoreCase)
+ {
+ this._IgnoreCase = ignoreCase;
+ int size = INIT_SIZE;
+ while (startSize + (startSize >> 2) > size)
+ size <<= 1;
+ _Entries = new char[size][];
+ }
+
+
+ /// <summary>Create set from a Collection of char[] or String </summary>
+ public CharArraySet(IEnumerable<string> c, bool ignoreCase) : this(c.Count(), ignoreCase)
+ {
foreach (string s in c)
{
- if(ignoreCase)
- base.Add(s.ToLower());
- else
- base.Add(c);
+ Add(s);
}
-
- }
-
+ }
- public bool Contains(object o)
+ /// <summary>Create set from entries </summary>
+ private CharArraySet(char[][] entries, bool ignoreCase, int count)
{
- if (o is char[])
- {
- char[] text = (char[])o;
- return Contains(text, 0, text.Length);
- }
- return Contains(o.ToString());
+ this._Entries = entries;
+ this._IgnoreCase = ignoreCase;
+ this._Count = count;
}
+ #endregion
+
+
+ #region public members
public virtual bool Contains(char[] text)
{
return Contains(text, 0, text.Length);
}
- /// <summary>true if the <code>len</code> chars of <code>text</code> starting at <code>off</code>
- /// are in the set
- /// </summary>
- public virtual bool Contains(char[] text, int off, int len)
- {
- if(ignoreCase)
- return base.Contains(new string(text, off, len).ToLower());
- else
- return base.Contains(new string(text, off, len));
- }
+ /// <summary>true if the <code>len</code> chars of <code>text</code> starting at <code>off</code>
+ /// are in the set
+ /// </summary>
+ public virtual bool Contains(char[] text, int off, int len)
+ {
+ return _Entries[GetSlot(text, off, len)] != null;
+ }
- public new bool Contains(string s)
+ /// <summary>Add this char[] directly to the set.
+ /// If ignoreCase is true for this Set, the text array will be directly modified.
+ /// The user should never modify this text array after calling this method.
+ /// </summary>
+ public void Add(char[] text)
{
- if(ignoreCase)
- return base.Contains(s.ToLower());
- else
- return base.Contains(s);
+ if (_ReadOnly) throw new NotSupportedException();
+
+ if (_IgnoreCase)
+ for (int i = 0; i < text.Length; i++)
+ text[i] = System.Char.ToLower(text[i]);
+ int slot = GetSlot(text, 0, text.Length);
+ if (_Entries[slot] != null)
+ return;
+ _Entries[slot] = text;
+ _Count++;
+
+ if (_Count + (_Count >> 2) > _Entries.Length)
+ {
+ Rehash();
+ }
+ }
+
+ /// <summary>Adds all of the elements in the specified collection to this collection </summary>
+ public void Add(IEnumerable<string> coll)
+ {
+ if (_ReadOnly) throw new NotSupportedException();
+
+ foreach (string s in coll)
+ {
+ Add(s);
+ }
+ }
+
+ public static CharArraySet UnmodifiableSet(ICollection<string> items)
+ {
+ CharArraySet set = new CharArraySet(items.Count,true);
+ set.Add(items);
+ set.IsReadOnly = true;
+ return set;
+
+ }
+ #endregion
+
+
+ #region ICollection<string>
+ public void Add(string text)
+ {
+ if (_ReadOnly) throw new NotSupportedException();
+ Add(text.ToCharArray());
+ }
+
+ public void Clear()
+ {
+ if (_ReadOnly) throw new NotSupportedException();
+ _Entries = null;
+ _Count = 0;
+ }
+
+ public bool Contains(string item)
+ {
+ return _Entries[GetSlot(item)] != null;
+ }
+
+ public void CopyTo(string[] array, int arrayIndex)
+ {
+ throw new NotSupportedException();
+ }
+
+ public int Count
+ {
+ get { return _Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return _ReadOnly; }
+ private set { _ReadOnly = value; }
+ }
+
+
+
+ public bool Remove(string item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public IEnumerator<string> GetEnumerator()
+ {
+ return new CharArraySetEnumerator(this);
+ }
+
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
+ {
+ throw new NotImplementedException();
+ }
+ #endregion
+
+
+ #region Private Methods
+
+ private int GetSlot(char[] text, int off, int len)
+ {
+ int code = GetHashCode(text, off, len);
+ int pos = code & (_Entries.Length - 1);
+ char[] text2 = _Entries[pos];
+ if (text2 != null && !Equals(text, off, len, text2))
+ {
+ int inc = ((code >> 8) + code) | 1;
+ do
+ {
+ code += inc;
+ pos = code & (_Entries.Length - 1);
+ text2 = _Entries[pos];
+ }
+ while (text2 != null && !Equals(text, off, len, text2));
+ }
+ return pos;
}
-
-
- /// <summary>Add this char[] directly to the set.
- /// If ignoreCase is true for this Set, the text array will be directly modified.
- /// The user should never modify this text array after calling this method.
- /// </summary>
- public virtual void Add(char[] text)
- {
- if (ignoreCase)
- base.Add(text.ToString().ToLower());
- else
- base.Add(text.ToString());
- }
- public override void Add(string s)
+ /// <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;
+ }
- if (ignoreCase)
- base.Add(s.ToLower());
+ private bool Equals(char[] text1, int off, int len, char[] text2)
+ {
+ if (len != text2.Length)
+ return false;
+ if (_IgnoreCase)
+ {
+ for (int i = 0; i < len; i++)
+ {
+ if (System.Char.ToLower(text1[off + i]) != text2[i])
+ return false;
+ }
+ }
else
- base.Add(s);
+ {
+ for (int i = 0; i < len; i++)
+ {
+ if (text1[off + i] != text2[i])
+ return false;
+ }
+ }
+ return true;
}
- public void AddAll(List<string> c)
+ private bool Equals(System.String text1, char[] text2)
{
- foreach (string s in c)
+ int len = text1.Length;
+ if (len != text2.Length)
+ return false;
+ if (_IgnoreCase)
{
- Add(s);
+ 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;
}
- public void AddAll(string[] c)
+ private void Rehash()
{
- foreach (string s in c)
+ int newSize = 2 * _Entries.Length;
+ char[][] oldEntries = _Entries;
+ _Entries = new char[newSize][];
+
+ for (int i = 0; i < oldEntries.Length; i++)
{
- Add(s);
+ char[] text = oldEntries[i];
+ if (text != null)
+ {
+ // todo: could be faster... no need to compare strings on collision
+ _Entries[GetSlot(text, 0, text.Length)] = text;
+ }
}
}
-
private int GetHashCode(char[] text, int offset, int len)
- {
+ {
+ int code = 0;
+ int stop = offset + len;
+ if (_IgnoreCase)
+ {
+ for (int i = offset; i < stop; i++)
+ {
+ code = code * 31 + System.Char.ToLower(text[i]);
+ }
+ }
+ else
+ {
+ for (int i = offset; i < stop; i++)
+ {
+ code = code * 31 + text[i];
+ }
+ }
+ return code;
+ }
- return new string(text, offset, len).GetHashCode();
- }
-
- private int GetHashCode(System.String text)
- {
- return text.GetHashCode();
- }
+ 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;
+ }
+ #endregion
+
+ #region Unneeded methods(used only in test case)
+ public void RemoveAll(ICollection<string> c)
+ {
+ throw new NotSupportedException();
+ }
+
+ public void RetainAll(ICollection<string> c)
+ {
+ throw new NotSupportedException();
+ }
+ #endregion
+
+
+
+ class CharArraySetEnumerator : IEnumerator<string>
+ {
+ CharArraySet _Creator;
+ int pos = -1;
+ char[] next;
+
+ public CharArraySetEnumerator(CharArraySet creator)
+ {
+ _Creator = creator;
+ GoNext();
+ }
+
+ public string Current
+ {
+ get { return new string(NextCharArray()); }
+ }
+
+ public void Dispose()
+ {
+ }
+
+ object System.Collections.IEnumerator.Current
+ {
+ get { return new string(NextCharArray()); }
+ }
+
+ public bool MoveNext()
+ {
+ return next != null;
+ }
+
+ public void Reset()
+ {
+ throw new NotImplementedException();
+ }
+
+ #region Private Methods
+
+ private void GoNext()
+ {
+ next = null;
+ pos++;
+ while (pos < _Creator._Entries.Length && (next = _Creator._Entries[pos]) == null)
+ pos++;
+ }
+
+ /// <summary>do not modify the returned char[] </summary>
+ char[] NextCharArray()
+ {
+ char[] ret = next;
+ GoNext();
+ return ret;
+ }
+
+ #endregion
+ }
+
+ }
-
- public static CharArraySet UnmodifiableSet(CharArraySet set_Renamed)
- {
- CharArraySet set = new CharArraySet(set_Renamed, true);
- set.ReadOnly = true;
- return set;
- }
}
-
-}
\ No newline at end of file
+
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Standard/StandardAnalyzer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Standard/StandardAnalyzer.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Standard/StandardAnalyzer.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/Standard/StandardAnalyzer.cs Sat May 14 17:30:17 2011
@@ -43,7 +43,7 @@ namespace Lucene.Net.Analysis.Standard
/// </version>
public class StandardAnalyzer : Analyzer
{
- private List<string> stopSet;
+ private ICollection<string> stopSet;
/// <summary> Specifies whether deprecated acronyms should be replaced with HOST type.
/// This is false by default to support backward compatibility.
@@ -108,7 +108,7 @@ namespace Lucene.Net.Analysis.Standard
/// <summary>An unmodifiable set containing some common English words that are usually not
/// useful for searching.
/// </summary>
- public static readonly List<string> STOP_WORDS_SET;
+ public static readonly ICollection<string> STOP_WORDS_SET;
/// <summary>Builds an analyzer with the default stop words ({@link
/// #STOP_WORDS_SET}).
@@ -135,7 +135,7 @@ namespace Lucene.Net.Analysis.Standard
/// instead
/// </deprecated>
[Obsolete("Use StandardAnalyzer(Version, Set) instead")]
- public StandardAnalyzer(List<string> stopWords):this(Version.LUCENE_24, stopWords)
+ public StandardAnalyzer(ICollection<string> stopWords):this(Version.LUCENE_24, stopWords)
{
}
@@ -145,7 +145,7 @@ namespace Lucene.Net.Analysis.Standard
/// </param>
/// <param name="stopWords">stop words
/// </param>
- public StandardAnalyzer(Version matchVersion, List<string> stopWords)
+ public StandardAnalyzer(Version matchVersion, ICollection<string> stopWords)
{
stopSet = stopWords;
Init(matchVersion);
@@ -155,7 +155,7 @@ namespace Lucene.Net.Analysis.Standard
/// <deprecated> Use {@link #StandardAnalyzer(Version, Set)} instead
/// </deprecated>
[Obsolete("Use StandardAnalyzer(Version, Set) instead")]
- public StandardAnalyzer(System.String[] stopWords):this(Version.LUCENE_24, StopFilter.MakeStopSet(stopWords))
+ public StandardAnalyzer(string[] stopWords):this(Version.LUCENE_24, StopFilter.MakeStopSet(stopWords))
{
}
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopAnalyzer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopAnalyzer.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopAnalyzer.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopAnalyzer.cs Sat May 14 17:30:17 2011
@@ -37,7 +37,7 @@ namespace Lucene.Net.Analysis
public sealed class StopAnalyzer:Analyzer
{
- private List<string> stopWords;
+ private ICollection<string> stopWords;
// @deprecated
[Obsolete]
private bool useDefaultStopPositionIncrement;
@@ -54,7 +54,7 @@ namespace Lucene.Net.Analysis
/// <summary>An unmodifiable set containing some common English words that are not usually useful
/// for searching.
/// </summary>
- public static List<string> ENGLISH_STOP_WORDS_SET;
+ public static ICollection<string> ENGLISH_STOP_WORDS_SET;
/// <summary>Builds an analyzer which removes words in
/// ENGLISH_STOP_WORDS.
@@ -312,8 +312,8 @@ namespace Lucene.Net.Analysis
{
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(stopWords);
- ENGLISH_STOP_WORDS_SET = CharArraySet.UnmodifiableSet(stopSet);
+ stopSet.Add(stopWords);
+ ENGLISH_STOP_WORDS_SET = CharArraySet.UnmodifiableSet((ICollection<string>)stopSet);
}
}
}
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopFilter.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Analysis/StopFilter.cs Sat May 14 17:30:17 2011
@@ -58,7 +58,7 @@ namespace Lucene.Net.Analysis
/// </param>
/// <deprecated> Use {@link #StopFilter(boolean, TokenStream, Set)} instead.
/// </deprecated>
- [Obsolete("Use StopFilter(bool, TokenStream, List<string>) instead.")]
+ [Obsolete("Use StopFilter(bool, TokenStream, ICollection<string>) instead.")]
public StopFilter(bool enablePositionIncrements, TokenStream input, System.String[] stopWords):this(enablePositionIncrements, input, stopWords, false)
{
}
@@ -86,8 +86,8 @@ namespace Lucene.Net.Analysis
/// </param>
/// <deprecated> Use {@link #StopFilter(boolean, TokenStream, Set, boolean)} instead.
/// </deprecated>
- [Obsolete("Use StopFilter(bool, TokenStream, List<string>, bool) instead.")]
- public StopFilter(bool enablePositionIncrements, TokenStream in_Renamed, System.String[] stopWords, bool ignoreCase):base(in_Renamed)
+ [Obsolete("Use StopFilter(bool, TokenStream, ICollection<string>, bool) instead.")]
+ public StopFilter(bool enablePositionIncrements, TokenStream in_Renamed, string[] stopWords, bool ignoreCase):base(in_Renamed)
{
this.stopWords = (CharArraySet) MakeStopSet(stopWords, ignoreCase);
this.enablePositionIncrements = enablePositionIncrements;
@@ -115,7 +115,7 @@ namespace Lucene.Net.Analysis
/// <deprecated> Use {@link #StopFilter(boolean, TokenStream, Set, boolean)} instead
/// </deprecated>
[Obsolete("Use StopFilter(bool, TokenStream, Set, bool) instead")]
- public StopFilter(TokenStream input, List<string> stopWords, bool ignoreCase):this(ENABLE_POSITION_INCREMENTS_DEFAULT, input, stopWords, ignoreCase)
+ public StopFilter(TokenStream input, ICollection<string> stopWords, bool ignoreCase) : this(ENABLE_POSITION_INCREMENTS_DEFAULT, input, stopWords, ignoreCase)
{
}
@@ -138,7 +138,7 @@ namespace Lucene.Net.Analysis
/// </param>
/// <param name="ignoreCase">-Ignore case when stopping.
/// </param>
- public StopFilter(bool enablePositionIncrements, TokenStream input, List<string> stopWords, bool ignoreCase) : base(input)
+ public StopFilter(bool enablePositionIncrements, TokenStream input, ICollection<string> stopWords, bool ignoreCase) : base(input)
{
if (stopWords is CharArraySet)
{
@@ -161,8 +161,8 @@ namespace Lucene.Net.Analysis
/// </seealso>
/// <deprecated> Use {@link #StopFilter(boolean, TokenStream, Set)} instead
/// </deprecated>
- [Obsolete("Use StopFilter(bool, TokenStream, List<string>) instead")]
- public StopFilter(TokenStream in_Renamed, List<string> stopWords) : this(ENABLE_POSITION_INCREMENTS_DEFAULT, in_Renamed, stopWords, false)
+ [Obsolete("Use StopFilter(bool, TokenStream, ICollection<string>) instead")]
+ public StopFilter(TokenStream in_Renamed, ICollection<string> stopWords) : this(ENABLE_POSITION_INCREMENTS_DEFAULT, in_Renamed, stopWords, false)
{
}
@@ -178,7 +178,7 @@ namespace Lucene.Net.Analysis
/// </param>
/// <seealso cref="MakeStopSet(java.lang.String[])">
/// </seealso>
- public StopFilter(bool enablePositionIncrements, TokenStream in_Renamed, List<string> stopWords) : this(enablePositionIncrements, in_Renamed, stopWords, false)
+ public StopFilter(bool enablePositionIncrements, TokenStream in_Renamed, ICollection<string> stopWords) : this(enablePositionIncrements, in_Renamed, stopWords, false)
{
}
@@ -196,10 +196,11 @@ namespace Lucene.Net.Analysis
/// </summary>
/// <seealso cref="MakeStopSet(java.lang.String[], boolean)"> passing false to ignoreCase
/// </seealso>
- public static List<string> MakeStopSet(System.String[] stopWords)
- {
- return MakeStopSet(stopWords, false);
- }
+ /// DIGY needed?
+ //public static ICollection<string> MakeStopSet(string[] stopWords)
+ //{
+ // return MakeStopSet(stopWords, false);
+ //}
/// <summary> Builds a Set from an array of stop words,
/// appropriate for passing into the StopFilter constructor.
@@ -209,7 +210,7 @@ namespace Lucene.Net.Analysis
/// </summary>
/// <seealso cref="MakeStopSet(java.lang.String[], boolean)"> passing false to ignoreCase
/// </seealso>
- public static List<string> MakeStopSet(List<string> stopWords)
+ public static ICollection<string> MakeStopSet(ICollection<string> stopWords)
{
return MakeStopSet(stopWords, false);
}
@@ -221,10 +222,10 @@ namespace Lucene.Net.Analysis
/// </param>
/// <returns> a Set containing the words
/// </returns>
- public static List<string> MakeStopSet(System.String[] stopWords, bool ignoreCase)
+ public static ICollection<string> MakeStopSet(string[] stopWords, bool ignoreCase)
{
CharArraySet stopSet = new CharArraySet(stopWords.Length, ignoreCase);
- stopSet.AddAll(stopWords);
+ stopSet.Add(stopWords);
return stopSet;
}
@@ -235,10 +236,10 @@ namespace Lucene.Net.Analysis
/// </param>
/// <returns> A Set containing the words
/// </returns>
- public static List<string> MakeStopSet(List<string> stopWords, bool ignoreCase)
+ public static ICollection<string> MakeStopSet(ICollection<string> stopWords, bool ignoreCase)
{
CharArraySet stopSet = new CharArraySet(stopWords.Count, ignoreCase);
- stopSet.AddAll(stopWords.ToArray());
+ stopSet.Add(stopWords);
return stopSet;
}
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/PhraseQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/PhraseQuery.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/PhraseQuery.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Search/PhraseQuery.cs Sat May 14 17:30:17 2011
@@ -108,7 +108,7 @@ namespace Lucene.Net.Search
/// <summary>Returns the set of terms in this phrase. </summary>
public virtual Term[] GetTerms()
{
- return (Term[])terms.ToArray();
+ return terms.ToArray();
}
/// <summary> Returns the relative positions of terms in this phrase.</summary>
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/Set.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/Set.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/Set.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/src/core/Support/Set.cs Sat May 14 17:30:17 2011
@@ -23,32 +23,13 @@ namespace Lucene.Net.Support
public class Set<T> : System.Collections.Generic.List<T>
{
System.Collections.Generic.HashSet<T> _Set = new System.Collections.Generic.HashSet<T>();
- bool _ReadOnly = false;
public Set()
{
}
-
- public Set(bool readOnly)
- {
- this._ReadOnly = readOnly;
- }
-
- public bool ReadOnly
- {
- set
- {
- _ReadOnly = value;
- }
- get
- {
- return _ReadOnly;
- }
- }
-
+
public new virtual void Add(T item)
{
- if (_ReadOnly) throw new NotSupportedException();
if (_Set.Contains(item)) return;
_Set.Add(item);
base.Add(item);
@@ -56,7 +37,6 @@ namespace Lucene.Net.Support
public void Add(Support.Set<T> items)
{
- if (_ReadOnly) throw new NotSupportedException();
foreach(T item in items)
{
if(_Set.Contains(item)) continue;
@@ -67,7 +47,6 @@ namespace Lucene.Net.Support
public void Add(System.Collections.Generic.IList<T> items)
{
- if (_ReadOnly) throw new NotSupportedException();
foreach (T item in items)
{
if (_Set.Contains(item)) continue;
@@ -83,36 +62,14 @@ namespace Lucene.Net.Support
public new void Clear()
{
- if (_ReadOnly) throw new NotSupportedException();
_Set.Clear();
base.Clear();
}
public new void Remove(T item)
{
- if (_ReadOnly) throw new NotSupportedException();
_Set.Remove(item);
base.Remove(item);
}
-
- public void RemoveAll(System.Collections.Generic.IList<T> list)
- {
- if (_ReadOnly) throw new NotSupportedException();
- }
-
- public void RetainAll(System.Collections.Generic.IList<T> list)
- {
- if (_ReadOnly) throw new NotSupportedException();
- }
-
- public void RemoveAll(System.Collections.ArrayList list)
- {
- if (_ReadOnly) throw new NotSupportedException();
- }
-
- public void RetainAll(System.Collections.ArrayList list)
- {
- if (_ReadOnly) throw new NotSupportedException();
- }
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestCharArraySet.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestCharArraySet.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestCharArraySet.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestCharArraySet.cs Sat May 14 17:30:17 2011
@@ -97,7 +97,7 @@ namespace Lucene.Net.Analysis
{
//System.Diagnostics.Debugger.Break();
CharArraySet set_Renamed = new CharArraySet(10, true);
- set_Renamed.AddAll(TEST_STOP_WORDS);
+ set_Renamed.Add(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");
@@ -164,7 +164,7 @@ namespace Lucene.Net.Analysis
}
try
{
- set_Renamed.RemoveAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
+ set_Renamed.RemoveAll(TEST_STOP_WORDS);
Assert.Fail("Modified unmodifiable set");
}
catch (System.NotSupportedException e)
@@ -175,7 +175,7 @@ namespace Lucene.Net.Analysis
try
{
- set_Renamed.RetainAll(new System.Collections.ArrayList(new System.String[] { NOT_IN_SET }));
+ set_Renamed.RetainAll(new System.String[] { NOT_IN_SET });
Assert.Fail("Modified unmodifiable set");
}
catch (System.NotSupportedException e)
@@ -186,7 +186,7 @@ namespace Lucene.Net.Analysis
try
{
- set_Renamed.AddAll(new System.String[] { NOT_IN_SET });
+ set_Renamed.Add(new System.String[] { NOT_IN_SET });
Assert.Fail("Modified unmodifiable set");
}
catch (System.NotSupportedException e)
@@ -205,7 +205,7 @@ namespace Lucene.Net.Analysis
public virtual void TestUnmodifiableSet()
{
CharArraySet set_Renamed = new CharArraySet(10, true);
- set_Renamed.AddAll(TEST_STOP_WORDS);
+ set_Renamed.Add(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");
Modified: incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestStopFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestStopFilter.cs?rev=1103167&r1=1103166&r2=1103167&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestStopFilter.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_2_9_4g/test/core/Analysis/TestStopFilter.cs Sat May 14 17:30:17 2011
@@ -67,7 +67,7 @@ namespace Lucene.Net.Analysis
{
System.IO.StringReader reader = new System.IO.StringReader("Now is The Time");
System.String[] stopWords = new System.String[]{"is", "the", "Time"};
- List<string> stopSet = StopFilter.MakeStopSet(stopWords);
+ ICollection<string> stopSet = StopFilter.MakeStopSet(stopWords);
TokenStream stream = new StopFilter(false, new WhitespaceTokenizer(reader), stopSet);
TermAttribute termAtt = (TermAttribute) stream.GetAttribute(typeof(TermAttribute));
Assert.IsTrue(stream.IncrementToken());
@@ -94,7 +94,7 @@ namespace Lucene.Net.Analysis
System.String[] stopWords = (System.String[]) a.ToArray();
for (int i = 0; i < a.Count; i++)
Log("Stop: " + stopWords[i]);
- List<string> stopSet = StopFilter.MakeStopSet(stopWords);
+ ICollection<string> stopSet = StopFilter.MakeStopSet(stopWords);
// with increments
System.IO.StringReader reader = new System.IO.StringReader(sb.ToString());
StopFilter stpf = new StopFilter(false, new WhitespaceTokenizer(reader), stopSet);
@@ -123,8 +123,8 @@ namespace Lucene.Net.Analysis
System.String[] stopWords1 = (System.String[]) a1.ToArray();
for (int i = 0; i < a1.Count; i++)
Log("Stop1: " + stopWords1[i]);
- List<string> stopSet0 = StopFilter.MakeStopSet(stopWords0);
- List<string> stopSet1 = StopFilter.MakeStopSet(stopWords1);
+ ICollection<string> stopSet0 = StopFilter.MakeStopSet(stopWords0);
+ ICollection<string> stopSet1 = StopFilter.MakeStopSet(stopWords1);
reader = new System.IO.StringReader(sb.ToString());
StopFilter stpf0 = new StopFilter(false, new WhitespaceTokenizer(reader), stopSet0); // first part of the set
stpf0.SetEnablePositionIncrements(true);