lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [2/3] lucenenet git commit: WIP
Date Thu, 12 May 2016 20:57:09 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
index 23ce187..be85546 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/CharArraySet.cs
@@ -1,12 +1,14 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Linq;
 using System.Text;
+using Lucene.Net.Support;
 using Lucene.Net.Util;
 
 namespace Lucene.Net.Analysis.Util
 {
 
-	/*
+    /*
 	 * 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.
@@ -23,110 +25,112 @@ namespace Lucene.Net.Analysis.Util
 	 * limitations under the License.
 	 */
     /// <summary>
-	/// A simple class that stores Strings as char[]'s in a
-	/// hash table.  Note that this is not a general purpose
-	/// class.  For example, it cannot remove items from the
-	/// set, nor does it resize its hash table to be smaller,
-	/// etc.  It is designed to be quick to test if a char[]
-	/// is in the set without the necessity of converting it
-	/// to a String first.
-	/// 
-	/// <a name="version"></a>
-	/// <para>You must specify the required <seealso cref="LuceneVersion"/>
-	/// compatibility when creating <seealso cref="CharArraySet"/>:
-	/// <ul>
-	///   <li> As of 3.1, supplementary characters are
-	///       properly lowercased.</li>
-	/// </ul>
-	/// Before 3.1 supplementary characters could not be
-	/// lowercased correctly due to the lack of Unicode 4
-	/// support in JDK 1.4. To use instances of
-	/// <seealso cref="CharArraySet"/> with the behavior before Lucene
-	/// 3.1 pass a <seealso cref="LuceneVersion"/> < 3.1 to the constructors.
-	/// <P>
-	/// <em>Please note:</em> This class implements <seealso cref="java.util.Set
Set"/> but
-	/// does not behave like it should in all cases. The generic type is
-	/// {@code Set<Object>}, because you can add any object to it,
-	/// that has a string representation. The add methods will use
-	/// <seealso cref="object#toString"/> and store the result using a {@code char[]}
-	/// buffer. The same behavior have the {@code contains()} methods.
-	/// The <seealso cref="#iterator()"/> returns an {@code Iterator<char[]>}.
-	/// </para>
-	/// </summary>
-	public class CharArraySet : ISet<object>
-	{
-	  public static readonly CharArraySet EMPTY_SET = new CharArraySet(CharArrayMap.emptyMap<object>());
-	  private static readonly object PLACEHOLDER = new object();
-
-	  private readonly CharArrayMap<object> map;
-
-	  /// <summary>
-	  /// Create set with enough capacity to hold startSize terms
-	  /// </summary>
-	  /// <param name="matchVersion">
-	  ///          compatibility match version see <a href="#version">Version
-	  ///          note</a> above for details. </param>
-	  /// <param name="startSize">
-	  ///          the initial capacity </param>
-	  /// <param name="ignoreCase">
-	  ///          <code>false</code> if and only if the set should be case sensitive
-	  ///          otherwise <code>true</code>. </param>
-	  public CharArraySet(LuceneVersion matchVersion, int startSize, bool ignoreCase)
-          : this(new CharArrayMap<object>(matchVersion, startSize, ignoreCase))
-	  {
-	  }
-
-	  /// <summary>
-	  /// Creates a set from a Collection of objects. 
-	  /// </summary>
-	  /// <param name="matchVersion">
-	  ///          compatibility match version see <a href="#version">Version
-	  ///          note</a> above for details. </param>
-	  /// <param name="c">
-	  ///          a collection whose elements to be placed into the set </param>
-	  /// <param name="ignoreCase">
-	  ///          <code>false</code> if and only if the set should be case sensitive
-	  ///          otherwise <code>true</code>. </param>
-	  public CharArraySet(LuceneVersion matchVersion, ICollection<T> c, bool ignoreCase)
-          : this(matchVersion, c.Count, ignoreCase)
-	  {
-		AddAll(c);
-	  }
-
-	  /// <summary>
-	  /// Create set from the specified map (internal only), used also by <seealso cref="CharArrayMap#keySet()"/>
</summary>
-	  internal CharArraySet(CharArrayMap<object> map)
-	  {
-		this.map = map;
-	  }
-      
+    /// A simple class that stores Strings as char[]'s in a
+    /// hash table.  Note that this is not a general purpose
+    /// class.  For example, it cannot remove items from the
+    /// set, nor does it resize its hash table to be smaller,
+    /// etc.  It is designed to be quick to test if a char[]
+    /// is in the set without the necessity of converting it
+    /// to a String first.
+    /// 
+    /// <a name="version"></a>
+    /// <p>You must specify the required <seealso cref="LuceneVersion"/>
+    /// compatibility when creating <seealso cref="CharArraySet"/>:
+    /// <ul>
+    ///   <li> As of 3.1, supplementary characters are
+    ///       properly lowercased.</li>
+    /// </ul>
+    /// Before 3.1 supplementary characters could not be
+    /// lowercased correctly due to the lack of Unicode 4
+    /// support in JDK 1.4. To use instances of
+    /// <seealso cref="CharArraySet"/> with the behavior before Lucene
+    /// 3.1 pass a <seealso cref="LuceneVersion"/> to the constructors.
+    /// <p>
+    /// <em>Please note:</em> This class implements <seealso cref="java.util.Set
Set"/> but
+    /// does not behave like it should in all cases. The generic type is
+    /// {@code Set<Object>}, because you can add any object to it,
+    /// that has a string representation. The add methods will use
+    /// <seealso cref="object#toString"/> and store the result using a {@code char[]}
+    /// buffer. The same behavior have the {@code contains()} methods.
+    /// The <seealso cref="#iterator()"/> returns an {@code Iterator<char[]>}.
+    /// </p>
+    /// </summary>
+    public class CharArraySet : ISet<object>
+    {
+        public static readonly CharArraySet EMPTY_SET = new CharArraySet(CharArrayMap<object>.EmptyMap());
+        private static readonly object PLACEHOLDER = new object();
+
+        private readonly CharArrayMap<object> map;
+
+        /// <summary>
+        /// Create set with enough capacity to hold startSize terms
+        /// </summary>
+        /// <param name="matchVersion">
+        ///          compatibility match version see <a href="#version">Version
+        ///          note</a> above for details. </param>
+        /// <param name="startSize">
+        ///          the initial capacity </param>
+        /// <param name="ignoreCase">
+        ///          <code>false</code> if and only if the set should be case
sensitive
+        ///          otherwise <code>true</code>. </param>
+        public CharArraySet(LuceneVersion matchVersion, int startSize, bool ignoreCase)
+            : this(new CharArrayMap<object>(matchVersion, startSize, ignoreCase))
+        {
+        }
+
+        /// <summary>
+        /// Creates a set from a Collection of objects. 
+        /// </summary>
+        /// <param name="matchVersion">
+        ///          compatibility match version see <a href="#version">Version
+        ///          note</a> above for details. </param>
+        /// <param name="c">
+        ///          a collection whose elements to be placed into the set </param>
+        /// <param name="ignoreCase">
+        ///          <code>false</code> if and only if the set should be case
sensitive
+        ///          otherwise <code>true</code>. </param>
+        public CharArraySet(LuceneVersion matchVersion, IEnumerable<object> c, bool
ignoreCase)
+            : this(matchVersion, c.Count(), ignoreCase)
+        {
+            this.AddAll(c);
+        }
+
         /// <summary>
-	  /// Clears all entries in this set. This method is supported for reusing, but not <seealso
cref="Set#remove"/>. </summary>
-	  public void Clear()
-	  {
-		map.Clear();
-	  }
-
-	  /// <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 map.ContainsKey(text, off, len);
-	  }
-
-	  /// <summary>
-	  /// true if the <code>CharSequence</code> is in the set </summary>
-	  public virtual bool Contains(string cs)
-	  {
-		return map.ContainsKey(cs);
-	  }
-
-	  public bool Contains(object o)
-	  {
-		return map.ContainsKey(o);
-	  }
+        /// Create set from the specified map (internal only), used also by <seealso cref="CharArrayMap#KeySet()"/>
+        /// </summary>
+        internal CharArraySet(CharArrayMap<object> map)
+        {
+            this.map = map;
+        }
+
+        /// <summary>
+        /// Clears all entries in this set. This method is supported for reusing, but not
<seealso cref="Set#Remove"/>.
+        /// </summary>
+        public void Clear()
+        {
+            map.Clear();
+        }
+
+        /// <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 map.ContainsKey(text, off, len);
+        }
+
+        /// <summary>
+        /// true if the <code>CharSequence</code> is in the set </summary>
+        public virtual bool Contains(string cs)
+        {
+            return map.ContainsKey(cs);
+        }
+
+        public bool Contains(object o)
+        {
+            return map.ContainsKey(o);
+        }
 
         public void CopyTo(object[] array, int arrayIndex)
         {
@@ -139,26 +143,26 @@ namespace Lucene.Net.Analysis.Util
         }
 
         public virtual bool Add(object o)
-	  {
-		return map.Put(o, PLACEHOLDER) == null;
-	  }
-
-	  /// <summary>
-	  /// Add this String into the set </summary>
-	  public virtual bool Add(string text)
-	  {
-		return map.Put(text, PLACEHOLDER) == null;
-	  }
-
-	  /// <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 bool Add(char[] text)
-	  {
-		return map.Put(text, PLACEHOLDER) == null;
-	  }
+        {
+            return map.Put(o, PLACEHOLDER) == null;
+        }
+
+        /// <summary>
+        /// Add this String into the set </summary>
+        public virtual bool Add(string text)
+        {
+            return map.Put(text, PLACEHOLDER) == null;
+        }
+
+        /// <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 bool Add(char[] text)
+        {
+            return map.Put(text, PLACEHOLDER) == null;
+        }
 
         public int Count
         {
@@ -173,107 +177,109 @@ namespace Lucene.Net.Analysis.Util
         public bool IsReadOnly { get; private set; }
 
         /// <summary>
-	  /// Returns an unmodifiable <seealso cref="CharArraySet"/>. This allows to provide
-	  /// unmodifiable views of internal sets for "read-only" use.
-	  /// </summary>
-	  /// <param name="set">
-	  ///          a set for which the unmodifiable set is returned. </param>
-	  /// <returns> an new unmodifiable <seealso cref="CharArraySet"/>. </returns>
-	  /// <exception cref="NullPointerException">
-	  ///           if the given set is <code>null</code>. </exception>
-	  public static CharArraySet UnmodifiableSet(CharArraySet set)
-	  {
-		if (set == null)
-		{
-		  throw new System.NullReferenceException("Given set is null");
-		}
-		if (set == EMPTY_SET)
-		{
-		  return EMPTY_SET;
-		}
-		if (set.map is CharArrayMap.UnmodifiableCharArrayMap)
-		{
-		  return set;
-		}
-		return new CharArraySet(CharArrayMap.unmodifiableMap(set.map));
-	  }
-
-	  /// <summary>
-	  /// Returns a copy of the given set as a <seealso cref="CharArraySet"/>. If the
given set
-	  /// is a <seealso cref="CharArraySet"/> the ignoreCase property will be preserved.
-	  /// <para>
-	  /// <b>Note:</b> If you intend to create a copy of another <seealso cref="CharArraySet"/>
where
-	  /// the <seealso cref="LuceneVersion"/> of the source set differs from its copy
-	  /// <seealso cref="#CharArraySet(Version, Collection, boolean)"/> should be used
instead.
-	  /// The <seealso cref="#copy(Version, Set)"/> will preserve the <seealso cref="LuceneVersion"/>
of the
-	  /// source set it is an instance of <seealso cref="CharArraySet"/>.
-	  /// </para>
-	  /// </summary>
-	  /// <param name="matchVersion">
-	  ///          compatibility match version see <a href="#version">Version
-	  ///          note</a> above for details. This argument will be ignored if the
-	  ///          given set is a <seealso cref="CharArraySet"/>. </param>
-	  /// <param name="set">
-	  ///          a set to copy </param>
-	  /// <returns> a copy of the given set as a <seealso cref="CharArraySet"/>.
If the given set
-	  ///         is a <seealso cref="CharArraySet"/> the ignoreCase property as well
as the
-	  ///         matchVersion will be of the given set will be preserved. </returns>
-	  public static CharArraySet Copy<T1>(LuceneVersion matchVersion, HashSet<T1>
set)
-	  {
-		if (set == EMPTY_SET)
-		{
-		  return EMPTY_SET;
-		}
-		if (set is CharArraySet)
-		{
-		  CharArraySet source = (CharArraySet) set;
-		  return new CharArraySet(CharArrayMap.copy(source.map.matchVersion, source.map));
-		}
-		return new CharArraySet(matchVersion, set, false);
-	  }
-
-	  /// <summary>
-	  /// Returns an <seealso cref="IEnumerator"/> for {@code char[]} instances in this
set.
-	  /// </summary>
+        /// Returns an unmodifiable <seealso cref="CharArraySet"/>. This allows to
provide
+        /// unmodifiable views of internal sets for "read-only" use.
+        /// </summary>
+        /// <param name="set">
+        ///          a set for which the unmodifiable set is returned. </param>
+        /// <returns> an new unmodifiable <seealso cref="CharArraySet"/>. </returns>
+        /// <exception cref="NullPointerException">
+        ///           if the given set is <code>null</code>. </exception>
+        public static CharArraySet UnmodifiableSet(CharArraySet set)
+        {
+            if (set == null)
+            {
+                throw new System.NullReferenceException("Given set is null");
+            }
+            if (set == EMPTY_SET)
+            {
+                return EMPTY_SET;
+            }
+            if (set.map is CharArrayMap<object>.UnmodifiableCharArrayMap<object>)
+            {
+                return set;
+            }
+            return new CharArraySet(CharArrayMap<object>.UnmodifiableMap(set.map));
+        }
+
+        /// <summary>
+        /// Returns a copy of the given set as a <seealso cref="CharArraySet"/>. If
the given set
+        /// is a <seealso cref="CharArraySet"/> the ignoreCase property will be preserved.
+        /// <para>
+        /// <b>Note:</b> If you intend to create a copy of another <seealso
cref="CharArraySet"/> where
+        /// the <seealso cref="LuceneVersion"/> of the source set differs from its
copy
+        /// <seealso cref="#CharArraySet(Version, Collection, boolean)"/> should be
used instead.
+        /// The <seealso cref="#copy(Version, Set)"/> will preserve the <seealso
cref="LuceneVersion"/> of the
+        /// source set it is an instance of <seealso cref="CharArraySet"/>.
+        /// </para>
+        /// </summary>
+        /// <param name="matchVersion">
+        ///          compatibility match version see <a href="#version">Version
+        ///          note</a> above for details. This argument will be ignored if the
+        ///          given set is a <seealso cref="CharArraySet"/>. </param>
+        /// <param name="set">
+        ///          a set to copy </param>
+        /// <returns> a copy of the given set as a <seealso cref="CharArraySet"/>.
If the given set
+        ///         is a <seealso cref="CharArraySet"/> the ignoreCase property as
well as the
+        ///         matchVersion will be of the given set will be preserved. </returns>
+        public static CharArraySet Copy<T1>(LuceneVersion matchVersion, ISet<T1>
set)
+        {
+            if (set == EMPTY_SET)
+            {
+                return EMPTY_SET;
+            }
+
+            var source = set as CharArraySet;
+            if (source != null)
+            {
+                return new CharArraySet(CharArrayMap<object>.Copy(source.map.matchVersion,
source.map));
+            }
+
+            return new CharArraySet(matchVersion, set.Cast<object>(), false);
+        }
+
+        /// <summary>
+        /// Returns an <seealso cref="IEnumerator"/> for {@code char[]} instances in
this set.
+        /// </summary>
         public IEnumerator GetEnumerator()
         {
             // use the AbstractSet#keySet()'s iterator (to not produce endless recursion)
-            return map.originalKeySet().GetEnumerator();
+            return map.OriginalKeySet().GetEnumerator();
         }
 
         IEnumerator<object> IEnumerable<object>.GetEnumerator()
         {
             // use the AbstractSet#keySet()'s iterator (to not produce endless recursion)
-            return map.originalKeySet().GetEnumerator();
+            return map.OriginalKeySet().GetEnumerator();
         }
 
         public override string ToString()
-	  {
-		var sb = new StringBuilder("[");
-		foreach (object item in this)
-		{
-		  if (sb.Length > 1)
-		  {
-			  sb.Append(", ");
-		  }
-		  if (item is char[])
-		  {
-			sb.Append((char[]) item);
-		  }
-		  else
-		  {
-			sb.Append(item);
-		  }
-		}
-		return sb.Append(']').ToString();
-	  }
+        {
+            var sb = new StringBuilder("[");
+            foreach (object item in this)
+            {
+                if (sb.Length > 1)
+                {
+                    sb.Append(", ");
+                }
+                if (item is char[])
+                {
+                    sb.Append((char[])item);
+                }
+                else
+                {
+                    sb.Append(item);
+                }
+            }
+            return sb.Append(']').ToString();
+        }
 
-        #region Not used by the Java implementation anyway
         void ICollection<object>.Add(object item)
         {
-            throw new System.NotImplementedException();
+            Add(item);
         }
 
+        #region Not used by the Java implementation anyway
         public void UnionWith(IEnumerable<object> other)
         {
             throw new System.NotImplementedException();
@@ -324,5 +330,5 @@ namespace Lucene.Net.Analysis.Util
             throw new System.NotImplementedException();
         }
         #endregion
-	}
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.Analysis.Common/Analysis/Util/RollingCharBuffer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/RollingCharBuffer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/RollingCharBuffer.cs
index bac5fb6..480b3f3 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/RollingCharBuffer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/RollingCharBuffer.cs
@@ -69,7 +69,7 @@ namespace Lucene.Net.Analysis.Util
          * ahead.  Returns -1 if you hit EOF. */
         public int Get(int pos)
         {
-            //System.out.println("    get pos=" + pos + " nextPos=" + nextPos + " count="
+ count);
+            //System.out.println("    Get pos=" + pos + " nextPos=" + nextPos + " count="
+ count);
             if (pos == nextPos)
             {
                 if (end)
@@ -138,7 +138,7 @@ namespace Lucene.Net.Analysis.Util
         {
             Debug.Assert(length > 0);
             Debug.Assert(InBounds(posStart), "posStart=" + posStart + " length=" + length);
-            //System.out.println("    buffer.get posStart=" + posStart + " len=" + length);
+            //System.out.println("    buffer.Get posStart=" + posStart + " len=" + length);
 
             int startIndex = GetIndex(posStart);
             int endIndex = GetIndex(posStart + length);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.Analysis.Common/Lucene.Net.Analysis.Common.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Lucene.Net.Analysis.Common.csproj b/src/Lucene.Net.Analysis.Common/Lucene.Net.Analysis.Common.csproj
index d8516e2..ef12712 100644
--- a/src/Lucene.Net.Analysis.Common/Lucene.Net.Analysis.Common.csproj
+++ b/src/Lucene.Net.Analysis.Common/Lucene.Net.Analysis.Common.csproj
@@ -63,6 +63,9 @@
     <Compile Include="Analysis\Miscellaneous\PrefixAndSuffixAwareTokenFilter.cs" />
     <Compile Include="Analysis\Miscellaneous\PrefixAwareTokenFilter.cs" />
     <Compile Include="Analysis\Reverse\ReverseStringFilter.cs" />
+    <Compile Include="Analysis\Util\CharArrayMap.cs" />
+    <Compile Include="Analysis\Util\CharArraySet.cs" />
+    <Compile Include="Analysis\Util\FilteringTokenFilter.cs" />
     <Compile Include="Analysis\Util\StemmerUtil.cs" />
     <Compile Include="Analysis\Core\UpperCaseFilter.cs" />
     <Compile Include="Analysis\Core\WhitespaceAnalyzer.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
index 279c20c..8421b39 100644
--- a/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
+++ b/src/Lucene.Net.Core/Support/Compatibility/Collections.cs
@@ -37,5 +37,10 @@ namespace Lucene.Net
             builder.AddRange(d);
             return builder.ToImmutable();
         }
+
+        public static IDictionary<T, S> SingletonMap<T, S>(T key, S value)
+        {
+            return new Dictionary<T, S> {{key, value}};
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.Core/Support/SetExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/SetExtensions.cs b/src/Lucene.Net.Core/Support/SetExtensions.cs
index 2f585f1..b8f7c3f 100644
--- a/src/Lucene.Net.Core/Support/SetExtensions.cs
+++ b/src/Lucene.Net.Core/Support/SetExtensions.cs
@@ -1,9 +1,11 @@
 using System.Collections.Generic;
+using System.Diagnostics;
 
 namespace Lucene.Net.Support
 {
     public static class SetExtensions
     {
+        [DebuggerStepThrough]
         public static void RemoveAll<T>(this ICollection<T> theSet, IEnumerable<T>
removeList)
         {
             foreach (var elt in removeList)
@@ -12,6 +14,7 @@ namespace Lucene.Net.Support
             }
         }
 
+        [DebuggerStepThrough]
         public static void AddAll<T>(this ICollection<T> set, IEnumerable<T>
itemsToAdd)
         {
             foreach (var item in itemsToAdd)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
index 9f8c484..62d45d7 100644
--- a/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
@@ -1,4 +1,5 @@
-using System.Collections;
+using System;
+using System.Collections;
 using System.Collections.Generic;
 using NUnit.Framework;
 
@@ -110,6 +111,16 @@ namespace Lucene.Net.Util
             CollectionAssert.AreEqual(a1, a2);
         }
 
+        protected static void assertSame(Object expected, Object actual)
+        {
+            Assert.AreSame(expected, actual);
+        }
+
+        protected static void assertSame(string message, Object expected, Object actual)
+        {
+            Assert.AreSame(expected, actual, message);
+        }
+
         protected static void fail()
         {
             Assert.Fail();

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTypesHelpers.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTypesHelpers.cs b/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTypesHelpers.cs
index 838b432..a2602fc 100644
--- a/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTypesHelpers.cs
+++ b/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTypesHelpers.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Analysis;
+using System.Collections.Generic;
 
 namespace Lucene.Net
 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.TestFramework/JavaCompatibility/SystemTypesHelpers.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/JavaCompatibility/SystemTypesHelpers.cs b/src/Lucene.Net.TestFramework/JavaCompatibility/SystemTypesHelpers.cs
index 9c3fcea..6fb685b 100644
--- a/src/Lucene.Net.TestFramework/JavaCompatibility/SystemTypesHelpers.cs
+++ b/src/Lucene.Net.TestFramework/JavaCompatibility/SystemTypesHelpers.cs
@@ -1,6 +1,9 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization.Formatters;
 using System.Text;
+using Lucene.Net.Support;
 
 namespace Lucene.Net
 {
@@ -38,7 +41,7 @@ namespace Lucene.Net
             return (sbyte[])(Array)Encoding.GetEncoding(encoding).GetBytes(str);
         }
 
-        public static long size<T>(this IList<T> list)
+        public static int size<T>(this ICollection<T> list)
         {
             return list.Count;
         }
@@ -48,6 +51,50 @@ namespace Lucene.Net
             return (T[]) e.Clone();
         }
 
+        public static void add<T>(this ISet<T> s, T item)
+        {
+            s.Add(item);
+        }
+
+        public static void addAll<T>(this ISet<T> s, IEnumerable<T> other)
+        {
+            s.AddAll(other);
+        }
+
+        public static bool contains<T>(this ISet<T> s, T item)
+        {
+            return s.Contains(item);
+        }
+
+        public static bool containsAll<T>(this ISet<T> s, IEnumerable<T>
list)
+        {
+            return list.Any(s.Contains);
+        }
+
+        public static bool remove<T>(this ISet<T> s, T item)
+        {
+            return s.Remove(item);
+        }
+
+        public static bool removeAll<T>(this ISet<T> s, IEnumerable<T>
list)
+        {
+            return s.removeAll(list);
+        }
+
+        public static void clear<T>(this ISet<T> s)
+        {
+            s.Clear();
+        }
+
+        public static void retainAll<T>(this ISet<T> s, ISet<T> other)
+        {
+            foreach (var e in s)
+            {
+                if (!other.Contains(e))
+                    s.Remove(e);
+            }
+        }
+
         public static void printStackTrace(this Exception e)
         {
             Console.WriteLine(e.StackTrace);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/447e2ce1/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArrayMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArrayMap.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArrayMap.cs
index 9202318..4b3cc0e 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArrayMap.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharArrayMap.cs
@@ -1,5 +1,8 @@
-using System.Collections.Generic;
-using System.Text;
+using System.Text;
+using Lucene.Net.Analysis.Util;
+using Lucene.Net.Support;
+using Lucene.Net.Util;
+using NUnit.Framework;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -18,271 +21,269 @@ using System.Text;
  * limitations under the License.
  */
 
-namespace org.apache.lucene.analysis.util
+namespace Lucene.Net.Tests.Analysis.Common.Analysis.Util
 {
+    [TestFixture]
+    public class TestCharArrayMap : LuceneTestCase
+    {
+//        public virtual void doRandom(int iter, bool ignoreCase)
+//        {
+//            CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT,
1, ignoreCase);
+//            Dictionary<string, int?> hmap = new Dictionary<string, int?>();
+//
+//            char[] key;
+//            for (int i = 0; i < iter; i++)
+//            {
+//                int len = Random().Next(5);
+//                key = new char[len];
+//                for (int j = 0; j < key.Length; j++)
+//                {
+//                    key[j] = (char)Random().Next(127);
+//                }
+//                string keyStr = new string(key);
+//                string hmapKey = ignoreCase ? keyStr.ToLower() : keyStr;
+//
+//                int val = Random().Next();
+//
+//                object o1 = map.Put(key, val);
+//                object o2 = hmap[hmapKey].Value = val;
+//                assertEquals(o1, o2);
+//
+//                // add it again with the string method
+//                assertEquals(val, map.Put(keyStr, val));
+//
+//                assertEquals(val, map.Get(key, 0, key.Length));
+//                assertEquals(val, map.Get(key));
+//                assertEquals(val, map.Get(keyStr));
+//
+//                assertEquals(hmap.Count, map.size());
+//            }
+//        }
+//
+//        [Test]
+//        public virtual void testCharArrayMap()
+//        {
+//            int num = 5 * RANDOM_MULTIPLIER;
+//            for (int i = 0; i < num; i++)
+//            { // pump this up for more random testing
+//                doRandom(1000, false);
+//                doRandom(1000, true);
+//            }
+//        }
+//
+//        [Test]
+//        public virtual void TestMethods()
+//        {
+//            CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT,
2, false);
+//            Dictionary<string, int?> hm = new Dictionary<string, int?>();
+//            hm["foo"] = 1;
+//            hm["bar"] = 2;
+//            cm.PutAll(hm);
+//            assertEquals(hm.Count, cm.Count);
+//            hm["baz"] = 3;
+//            cm.PutAll(hm);
+//            assertEquals(hm.Count, cm.Count);
+//
+//            CharArraySet cs = cm.Keys;
+//            int n = 0;
+//            foreach (object o in cs)
+//            {
+//                assertTrue(cm.ContainsKey(o));
+//                char[] co = (char[])o;
+//                assertTrue(cm.ContainsKey(co, 0, co.Length));
+//                n++;
+//            }
+//            assertEquals(hm.Count, n);
+//            assertEquals(hm.Count, cs.Count);
+//            assertEquals(cm.Count, cs.Count);
+//            cs.Clear();
+//            assertEquals(0, cs.Count);
+//            assertEquals(0, cm.Count);
+//            try
+//            {
+//                cs.Add("test");
+//                fail("keySet() allows adding new keys");
+//            }
+//            catch (System.NotSupportedException)
+//            {
+//                // pass
+//            }
+//            cm.PutAll(hm);
+//            assertEquals(hm.Count, cs.Count);
+//            assertEquals(cm.Count, cs.Count);
+//
+//            IEnumerator<KeyValuePair<object, int?>> iter1 = cm.EntrySet().GetEnumerator();
+//            n = 0;
+//            while (iter1.MoveNext())
+//            {
+//                KeyValuePair<object, int?> entry = iter1.Current;
+//                object key = entry.Key;
+//                int? val = entry.Value;
+//                assertEquals(cm.Get(key), val);
+//                entry.Value = val * 100;
+//                assertEquals(val * 100, (int)cm.Get(key));
+//                n++;
+//            }
+//            assertEquals(hm.Count, n);
+//            cm.Clear();
+//            cm.PutAll(hm);
+//            assertEquals(cm.size(), n);
+//
+//            CharArrayMap<int?>.EntryIterator iter2 = cm.EntrySet().GetEnumerator();
+//            n = 0;
+//            while (iter2.hasNext())
+//            {
+//                char[] keyc = iter2.nextKey();
+//                int? val = iter2.currentValue();
+//                assertEquals(hm[new string(keyc)], val);
+//                iter2.Value = val * 100;
+//                assertEquals(val * 100, (int)cm.get(keyc));
+//                n++;
+//            }
+//            assertEquals(hm.Count, n);
+//
+//            cm.EntrySet().clear();
+//            assertEquals(0, cm.size());
+//            assertEquals(0, cm.EntrySet().size());
+//            assertTrue(cm.Count == 0);
+//        }
 
-	using LuceneTestCase = org.apache.lucene.util.LuceneTestCase;
+        [Test]
+        public virtual void TestModifyOnUnmodifiable()
+        {
+            CharArrayMap<int> map = new CharArrayMap<int>(TEST_VERSION_CURRENT,
2, false);
+            map.Put("foo", 1);
+            map.Put("bar", 2);
+            int size = map.Count;
+            assertEquals(2, size);
+            assertTrue(map.ContainsKey("foo"));
+            assertEquals(1, map.Get("foo"));
+            assertTrue(map.ContainsKey("bar"));
+            assertEquals(2, map.Get("bar"));
 
-	public class TestCharArrayMap : LuceneTestCase
-	{
-	  public virtual void doRandom(int iter, bool ignoreCase)
-	  {
-		CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 1, ignoreCase);
-		Dictionary<string, int?> hmap = new Dictionary<string, int?>();
+            map = CharArrayMap<int>.UnmodifiableMap(map);
+            assertEquals("Map size changed due to unmodifiableMap call", size, map.Count);
+            string NOT_IN_MAP = "SirGallahad";
+            assertFalse("Test String already exists in map", map.ContainsKey(NOT_IN_MAP));
+            assertNull("Test String already exists in map", map.Get(NOT_IN_MAP));
 
-		char[] key;
-		for (int i = 0; i < iter; i++)
-		{
-		  int len = random().Next(5);
-		  key = new char[len];
-		  for (int j = 0; j < key.Length; j++)
-		  {
-			key[j] = (char)random().Next(127);
-		  }
-		  string keyStr = new string(key);
-		  string hmapKey = ignoreCase ? keyStr.ToLower(Locale.ROOT) : keyStr;
+            try
+            {
+                map.Put(NOT_IN_MAP.ToCharArray(), 3);
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
+                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
+                assertEquals("Size of unmodifiable map has changed", size, map.Count);
+            }
 
-		  int val = random().Next();
+            try
+            {
+                map.Put(NOT_IN_MAP, 3);
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
+                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
+                assertEquals("Size of unmodifiable map has changed", size, map.Count);
+            }
 
-		  object o1 = map.put(key, val);
-		  object o2 = hmap[hmapKey].Value = val;
-		  assertEquals(o1,o2);
+            try
+            {
+                map.Put(new StringBuilder(NOT_IN_MAP), 3);
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
+                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
+                assertEquals("Size of unmodifiable map has changed", size, map.Count);
+            }
 
-		  // add it again with the string method
-		  assertEquals(val, map.put(keyStr,val).intValue());
+            try
+            {
+                map.Clear();
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertEquals("Size of unmodifiable map has changed", size, map.size());
+            }
 
-		  assertEquals(val, map.get(key,0,key.Length).intValue());
-		  assertEquals(val, map.get(key).intValue());
-		  assertEquals(val, map.get(keyStr).intValue());
+            try
+            {
+                map.EntrySet().Clear();
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertEquals("Size of unmodifiable map has changed", size, map.size());
+            }
 
-		  assertEquals(hmap.Count, map.size());
-		}
-	  }
+            try
+            {
+                map.Keys.Clear();
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertEquals("Size of unmodifiable map has changed", size, map.size());
+            }
 
-	  public virtual void testCharArrayMap()
-	  {
-		int num = 5 * RANDOM_MULTIPLIER;
-		for (int i = 0; i < num; i++)
-		{ // pump this up for more random testing
-		  doRandom(1000,false);
-		  doRandom(1000,true);
-		}
-	  }
-
-	  public virtual void testMethods()
-	  {
-		CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 2, false);
-		Dictionary<string, int?> hm = new Dictionary<string, int?>();
-		hm["foo"] = 1;
-		hm["bar"] = 2;
-		cm.putAll(hm);
-		assertEquals(hm.Count, cm.size());
-		hm["baz"] = 3;
-		cm.putAll(hm);
-		assertEquals(hm.Count, cm.size());
-
-		CharArraySet cs = cm.Keys;
-		int n = 0;
-		foreach (object o in cs)
-		{
-		  assertTrue(cm.containsKey(o));
-		  char[] co = (char[]) o;
-		  assertTrue(cm.containsKey(co, 0, co.Length));
-		  n++;
-		}
-		assertEquals(hm.Count, n);
-		assertEquals(hm.Count, cs.size());
-		assertEquals(cm.size(), cs.size());
-		cs.clear();
-		assertEquals(0, cs.size());
-		assertEquals(0, cm.size());
-		try
-		{
-		  cs.add("test");
-		  fail("keySet() allows adding new keys");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // pass
-		}
-		cm.putAll(hm);
-		assertEquals(hm.Count, cs.size());
-		assertEquals(cm.size(), cs.size());
-
-		IEnumerator<KeyValuePair<object, int?>> iter1 = cm.entrySet().GetEnumerator();
-		n = 0;
-		while (iter1.MoveNext())
-		{
-		  KeyValuePair<object, int?> entry = iter1.Current;
-		  object key = entry.Key;
-		  int? val = entry.Value;
-		  assertEquals(cm.get(key), val);
-		  entry.Value = val * 100;
-		  assertEquals(val * 100, (int)cm.get(key));
-		  n++;
-		}
-		assertEquals(hm.Count, n);
-		cm.clear();
-		cm.putAll(hm);
-		assertEquals(cm.size(), n);
-
-		CharArrayMap<int?>.EntryIterator iter2 = cm.entrySet().GetEnumerator();
-		n = 0;
-		while (iter2.hasNext())
-		{
-		  char[] keyc = iter2.nextKey();
-		  int? val = iter2.currentValue();
-		  assertEquals(hm[new string(keyc)], val);
-		  iter2.Value = val * 100;
-		  assertEquals(val * 100, (int)cm.get(keyc));
-		  n++;
-		}
-		assertEquals(hm.Count, n);
-
-		cm.entrySet().clear();
-		assertEquals(0, cm.size());
-		assertEquals(0, cm.entrySet().size());
-		assertTrue(cm.Empty);
-	  }
-
-	  public virtual void testModifyOnUnmodifiable()
-	  {
-		CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 2, false);
-		map.put("foo",1);
-		map.put("bar",2);
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int size = map.size();
-		int size = map.size();
-		assertEquals(2, size);
-		assertTrue(map.containsKey("foo"));
-		assertEquals(1, map.get("foo").intValue());
-		assertTrue(map.containsKey("bar"));
-		assertEquals(2, map.get("bar").intValue());
-
-		map = CharArrayMap.unmodifiableMap(map);
-		assertEquals("Map size changed due to unmodifiableMap call", size, map.size());
-		string NOT_IN_MAP = "SirGallahad";
-		assertFalse("Test String already exists in map", map.containsKey(NOT_IN_MAP));
-		assertNull("Test String already exists in map", map.get(NOT_IN_MAP));
-
-		try
-		{
-		  map.put(NOT_IN_MAP.ToCharArray(), 3);
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
-		  assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.put(NOT_IN_MAP, 3);
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
-		  assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.put(new StringBuilder(NOT_IN_MAP), 3);
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
-		  assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.clear();
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.entrySet().clear();
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.Keys.Clear();
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.put((object) NOT_IN_MAP, 3);
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
-		  assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		try
-		{
-		  map.putAll(Collections.singletonMap(NOT_IN_MAP, 3));
-		  fail("Modified unmodifiable map");
-		}
-		catch (System.NotSupportedException)
-		{
-		  // expected
-		  assertFalse("Test String has been added to unmodifiable map", map.containsKey(NOT_IN_MAP));
-		  assertNull("Test String has been added to unmodifiable map", map.get(NOT_IN_MAP));
-		  assertEquals("Size of unmodifiable map has changed", size, map.size());
-		}
-
-		assertTrue(map.containsKey("foo"));
-		assertEquals(1, map.get("foo").intValue());
-		assertTrue(map.containsKey("bar"));
-		assertEquals(2, map.get("bar").intValue());
-	  }
-
-	  public virtual void testToString()
-	  {
-		CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT, Collections.singletonMap("test",1),
false);
-		assertEquals("[test]",cm.Keys.ToString());
-		assertEquals("[1]",cm.values().ToString());
-		assertEquals("[test=1]",cm.entrySet().ToString());
-		assertEquals("{test=1}",cm.ToString());
-		cm.put("test2", 2);
-		assertTrue(cm.Keys.ToString().Contains(", "));
-		assertTrue(cm.values().ToString().Contains(", "));
-		assertTrue(cm.entrySet().ToString().Contains(", "));
-		assertTrue(cm.ToString().Contains(", "));
-	  }
-	}
+            try
+            {
+                map.Put((object)NOT_IN_MAP, 3);
+                fail("Modified unmodifiable map");
+            }
+            catch (System.NotSupportedException)
+            {
+                // expected
+                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
+                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
+                assertEquals("Size of unmodifiable map has changed", size, map.size());
+            }
 
+//            try
+//            {
+//                map.PutAll<string, int>(Collections.SingletonMap(NOT_IN_MAP, 3));
+//                fail("Modified unmodifiable map");
+//            }
+//            catch (System.NotSupportedException)
+//            {
+//                // expected
+//                assertFalse("Test String has been added to unmodifiable map", map.ContainsKey(NOT_IN_MAP));
+//                assertNull("Test String has been added to unmodifiable map", map.Get(NOT_IN_MAP));
+//                assertEquals("Size of unmodifiable map has changed", size, map.size());
+//            }
+//
+//            assertTrue(map.ContainsKey("foo"));
+//            assertEquals(1, map.Get("foo"));
+//            assertTrue(map.ContainsKey("bar"));
+//            assertEquals(2, map.Get("bar"));
+        }
 
+        [Test]
+        public virtual void TestToString()
+        {
+            CharArrayMap<int?> cm = new CharArrayMap<int?>(TEST_VERSION_CURRENT,
Collections.SingletonMap<object, int?>("test", 1), false);
+            assertEquals("[test]", cm.Keys.ToString());
+            assertEquals("[1]", cm.Values.ToString());
+            assertEquals("[test=1]", cm.EntrySet().ToString());
+            assertEquals("{test=1}", cm.ToString());
+            cm.Put("test2", 2);
+            assertTrue(cm.Keys.ToString().Contains(", "));
+            assertTrue(cm.Values.ToString().Contains(", "));
+            assertTrue(cm.EntrySet().ToString().Contains(", "));
+            assertTrue(cm.ToString().Contains(", "));
+        }
+    }
 }
\ No newline at end of file


Mime
View raw message