lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mhern...@apache.org
Subject [3/4] git commit: matching exceptions to expectations for ParseInt. adding doc comments.
Date Fri, 01 Aug 2014 17:35:30 GMT
matching exceptions to expectations for ParseInt. adding doc comments.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/0fbb29ed
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/0fbb29ed
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/0fbb29ed

Branch: refs/heads/pcl
Commit: 0fbb29ed5cddacbb3ddb12472b6fe49ca71d4936
Parents: 90a5211
Author: Michael Herndon <mherndon@michaelherndon.com>
Authored: Thu Jul 24 16:43:32 2014 -0400
Committer: Michael Herndon <mherndon@michaelherndon.com>
Committed: Thu Jul 24 16:43:32 2014 -0400

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/ArrayUtil.cs           | 60 +++++++++++++++++---
 .../Lucene.Net.Core.Tests/Util/TestArrayUtil.cs | 11 ++--
 2 files changed, 59 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0fbb29ed/src/Lucene.Net.Core/Util/ArrayUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/ArrayUtil.cs b/src/Lucene.Net.Core/Util/ArrayUtil.cs
index ee734a6..9cde720 100644
--- a/src/Lucene.Net.Core/Util/ArrayUtil.cs
+++ b/src/Lucene.Net.Core/Util/ArrayUtil.cs
@@ -6,23 +6,68 @@ namespace Lucene.Net
     using System.Collections.Generic;
 
     /// <summary>
-    /// Summary description for ArrayUtil
+    /// Utility methods for manipulating arrays.
     /// </summary>
     public static class ArrayUtil
     {
 
-        public static int ParseInt(this char[] chars, int offset = 0, int limit = -1, int
radix = 10)
+
+        /// <summary>
+        /// Parses the string argument as if it was an int value and returns the result.
+        /// </summary>
+        /// <param name="chars">A string representation of an int quantity. </param>
+        /// <param name="offset">The position in the <paramref name="chars"/>
array to start parsing.</param>
+        /// <param name="limit">The number of characters to parse after the <paramref
name="offset"/>.</param>
+        /// <param name="radix"> The base to use for conversion. </param>
+        /// <returns> int the value represented by the argument </returns>
+        /// <exception cref="ArgumentNullException">Throws when <paramref name="chars"/>
is null.</exception>
+        /// <exception cref="ArgumentException">Throws when <paramref name="chars"/>
is empty.</exception>
+        /// <exception cref="ArgumentOutOfRangeException">
+        ///     <list>
+        ///         <item>Throws when <paramref name="offset"/> is less than
zero or greater than <paramref name="chars"/>.Length.</item>
+        ///         <item>Throws when <paramref name="limit"/> is greater than
<paramref name="chars"/>.Length.</item>
+        ///         <item>Throws when <paramref name="radix"/> is less than 2
or greater than 36.</item>
+        ///     </list>
+        /// </exception>
+        /// <exception cref="FormatException">Throws when a character cannot be translated
into a integer.</exception>
+        public static int ParseInt(this string chars, int offset = 0, int limit = -1, int
radix = 10)
         {
             Check.NotNull("chars", chars);
+
+            return ParseInt(chars.ToCharArray(), offset, limit, radix);
+        }
+
+        /// <summary>
+        /// Parses the string argument as if it was an int value and returns the result.
+        /// </summary>
+        /// <param name="chars">A string representation of an int quantity. </param>
+        /// <param name="offset">The position in the <paramref name="chars"/>
array to start parsing.</param>
+        /// <param name="limit">The number of characters to parse after the <paramref
name="offset"/>.</param>
+        /// <param name="radix"> The base to use for conversion. </param>
+        /// <returns>The integer value that was parsed from <pararef name="chars"
/>.</returns>
+        /// <exception cref="ArgumentNullException">Throws when <paramref name="chars"/>
is null.</exception>
+        /// <exception cref="ArgumentException">Throws when <paramref name="chars"/>
is empty.</exception>
+        /// <exception cref="ArgumentOutOfRangeException">
+        ///     <list>
+        ///         <item>Throws when <paramref name="offset"/> is less than
zero or greater than <paramref name="chars"/>.Length.</item>
+        ///         <item>Throws when <paramref name="limit"/> is greater than
<paramref name="chars"/>.Length.</item>
+        ///         <item>Throws when <paramref name="radix"/> is less than 2
or greater than 36.</item>
+        ///     </list>
+        /// </exception>
+        /// <exception cref="FormatException">Throws when a character cannot be translated
into a integer.</exception>
+        public static int ParseInt(this char[] chars, int offset = 0, int limit = -1, int
radix = 10)
+        {
+            Check.NotNull("chars", chars, false);
             Check.Condition(chars.Length == 0, "chars", "The parameter, chars, must not be
an empty array.");
-            Check.Condition(offset < 0 || offset > chars.Length, "offset", 
+            Check.Condition<ArgumentOutOfRangeException>(
+                offset < 0 || offset > chars.Length,  
                 "The parameter, offset ({0}), must be greater than -1 and less than parameter,
chars.Length ({1}).", offset, chars.Length);
 
             if (limit < 0)
                 limit = chars.Length;
 
-            Check.Condition(
-                limit > chars.Length, "limit", 
+            Check.Condition<ArgumentOutOfRangeException>(
+                limit > chars.Length,
                 "The parameter, limit ({0}), must be less than or equal to the length of
the parameter, chars ({1}).", 
                  limit, chars.Length);
 
@@ -43,10 +88,11 @@ namespace Lucene.Net
                 limit--;
             }
 
-            return Parse(chars, offset, limit, radix, negative);
+            return ParseInt(chars, offset, limit, radix, negative);
         }
 
-        private static int Parse(char[] chars, int offset, int len, int radix, bool negative)
+        // parse() in Java
+        private static int ParseInt(char[] chars, int offset, int len, int radix, bool negative)
         {
             int max = int.MinValue / radix;
             int result = 0;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/0fbb29ed/test/Lucene.Net.Core.Tests/Util/TestArrayUtil.cs
----------------------------------------------------------------------
diff --git a/test/Lucene.Net.Core.Tests/Util/TestArrayUtil.cs b/test/Lucene.Net.Core.Tests/Util/TestArrayUtil.cs
index 161d24e..451a09d 100644
--- a/test/Lucene.Net.Core.Tests/Util/TestArrayUtil.cs
+++ b/test/Lucene.Net.Core.Tests/Util/TestArrayUtil.cs
@@ -31,7 +31,8 @@ namespace Lucene.Net.Util
             // chars is null
             Throws<ArgumentNullException>(() =>
             {
-                ArrayUtil.ParseInt(null);
+                string value = null;
+                ArrayUtil.ParseInt(value);
             });
 
             // chars is empty
@@ -55,19 +56,19 @@ namespace Lucene.Net.Util
             });
 
             // throws when limit > chars.Length
-            Throws<ArgumentException>(() =>
+            Throws<ArgumentOutOfRangeException>(() =>
             {
                 ArrayUtil.ParseInt("12".ToCharArray(), limit: 20);
             });
 
             // throws when offset > chars.length;
-            Throws<ArgumentException>(() =>
+            Throws<ArgumentOutOfRangeException>(() =>
             {
-                ArrayUtil.ParseInt("12".ToCharArray(), offset: 20);
+                ArrayUtil.ParseInt("12", offset: 20);
             });
 
             // throws when offset < 0.
-            Throws<ArgumentException>(() =>
+            Throws<ArgumentOutOfRangeException>(() =>
             {
                 ArrayUtil.ParseInt("12".ToCharArray(), offset: -1);
             });


Mime
View raw message