You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/02/09 06:16:19 UTC
[lucenenet] 27/35: BREAKING: Lucene.Net.Support.NumberFormat: Moved
to Lucene.Net.Util namespace
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit f062c04891b997f392dd79e24cdcd91b5b0e1677
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Feb 8 17:20:59 2020 +0700
BREAKING: Lucene.Net.Support.NumberFormat: Moved to Lucene.Net.Util namespace
---
Lucene.Net.sln | 22 +--------
.../Flexible/Standard/Config/NumberDateFormat.cs | 2 +-
.../Flexible/Standard/Config/NumericConfig.cs | 34 +++++--------
.../Flexible/Standard/Nodes/NumericQueryNode.cs | 8 ++--
.../Processors/NumericQueryNodeProcessor.cs | 2 +-
.../Processors/NumericRangeQueryNodeProcessor.cs | 2 +-
src/Lucene.Net/Support/{ => Util}/NumberFormat.cs | 55 +++++++++++++---------
7 files changed, 54 insertions(+), 71 deletions(-)
diff --git a/Lucene.Net.sln b/Lucene.Net.sln
index 54a2aa5..b19c811 100644
--- a/Lucene.Net.sln
+++ b/Lucene.Net.sln
@@ -1,24 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-
-# 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. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-VisualStudioVersion = 15.0.26730.8
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 15.0.26730.8
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "azure-templates", "azure-templates", "{05CE3A39-40D4-452D-AFE0-E57E536A08C6}"
ProjectSection(SolutionItems) = preProject
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
index 149102e..60a592c 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Support;
+using Lucene.Net.Util;
using System;
using System.Globalization;
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
index 13d5938..67d842c 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
@@ -1,6 +1,6 @@
-using Lucene.Net.Support;
+using Lucene.Net.Documents;
+using Lucene.Net.Util;
using System;
-using Lucene.Net.Documents;
namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
{
@@ -26,13 +26,11 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
/// <see cref="Search.NumericRangeQuery"/>s.
/// </summary>
/// <seealso cref="Search.NumericRangeQuery"/>
- /// <seealso cref="Support.NumberFormat"/>
+ /// <seealso cref="Util.NumberFormat"/>
public class NumericConfig
{
private int precisionStep;
-
private NumberFormat format;
-
private NumericType type;
/// <summary>
@@ -58,26 +56,18 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
/// <seealso cref="Search.NumericRangeQuery{T}.PrecisionStep"/>
public virtual int PrecisionStep
{
- get { return precisionStep; }
- set { precisionStep = value; }
+ get => precisionStep;
+ set => precisionStep = value;
}
/// <summary>
- /// Gets or Sets the <seealso cref="Support.NumberFormat"/> used to parse a <see cref="string"/> to
+ /// Gets or Sets the <seealso cref="Util.NumberFormat"/> used to parse a <see cref="string"/> to
/// <see cref="object"/> representing a .NET numeric type, cannot be <c>null</c>
/// </summary>
public virtual NumberFormat NumberFormat
{
- get { return format; }
- set
- {
- if (value == null)
- {
- throw new ArgumentException("format cannot be null!");
- }
-
- this.format = value;
- }
+ get => format;
+ set => format = value ?? throw new ArgumentException("format cannot be null!");
}
/// <summary>
@@ -85,18 +75,16 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
/// </summary>
public virtual NumericType Type
{
- get { return type; }
- set { type = value; }
+ get => type;
+ set => type = value;
}
public override bool Equals(object obj)
{
if (obj == this) return true;
- if (obj is NumericConfig)
+ if (obj is NumericConfig other)
{
- NumericConfig other = (NumericConfig)obj;
-
if (this.precisionStep == other.precisionStep
&& this.type == other.type
&& (this.format == other.format || (this.format.Equals(other.format))))
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
index 4bcb813..e1165ed 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
@@ -1,6 +1,6 @@
using Lucene.Net.QueryParsers.Flexible.Core.Nodes;
using Lucene.Net.QueryParsers.Flexible.Core.Parser;
-using Lucene.Net.Support;
+using Lucene.Net.Util;
using System.Globalization;
namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
@@ -38,12 +38,12 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
/// <summary>
/// Creates a <see cref="NumericQueryNode"/> object using the given field,
- /// <see cref="object"/> (representing a .NET numeric type) value and <see cref="Support.NumberFormat"/> used to convert the value to
+ /// <see cref="object"/> (representing a .NET numeric type) value and <see cref="Util.NumberFormat"/> used to convert the value to
/// <see cref="string"/>.
/// </summary>
/// <param name="field">the field associated with this query node</param>
/// <param name="value">the value hold by this node</param>
- /// <param name="numberFormat">the <see cref="Support.NumberFormat"/> used to convert the value to <see cref="string"/></param>
+ /// <param name="numberFormat">the <see cref="Util.NumberFormat"/> used to convert the value to <see cref="string"/></param>
public NumericQueryNode(string field, /*Number*/ object value,
NumberFormat numberFormat)
: base()
@@ -88,7 +88,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
}
/// <summary>
- /// Gets or Sets the <see cref="Support.NumberFormat"/> used to convert the value to <see cref="string"/>.
+ /// Gets or Sets the <see cref="Util.NumberFormat"/> used to convert the value to <see cref="string"/>.
/// </summary>
public virtual NumberFormat NumberFormat
{
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
index 1179035..d3bd06a 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
@@ -7,7 +7,7 @@ using Lucene.Net.QueryParsers.Flexible.Core.Processors;
using Lucene.Net.QueryParsers.Flexible.Messages;
using Lucene.Net.QueryParsers.Flexible.Standard.Config;
using Lucene.Net.QueryParsers.Flexible.Standard.Nodes;
-using Lucene.Net.Support;
+using Lucene.Net.Util;
using System;
using System.Collections.Generic;
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
index ebd53a8..154ef4e 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
@@ -8,7 +8,7 @@ using Lucene.Net.QueryParsers.Flexible.Core.Util;
using Lucene.Net.QueryParsers.Flexible.Messages;
using Lucene.Net.QueryParsers.Flexible.Standard.Config;
using Lucene.Net.QueryParsers.Flexible.Standard.Nodes;
-using Lucene.Net.Support;
+using Lucene.Net.Util;
using System;
using System.Collections.Generic;
diff --git a/src/Lucene.Net/Support/NumberFormat.cs b/src/Lucene.Net/Support/Util/NumberFormat.cs
similarity index 66%
rename from src/Lucene.Net/Support/NumberFormat.cs
rename to src/Lucene.Net/Support/Util/NumberFormat.cs
index 9c9ec64..92b2e31 100644
--- a/src/Lucene.Net/Support/NumberFormat.cs
+++ b/src/Lucene.Net/Support/Util/NumberFormat.cs
@@ -1,29 +1,36 @@
using System;
-using System.Collections.Generic;
using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-namespace Lucene.Net.Support
+namespace Lucene.Net.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.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
+ * 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.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// A LUCENENET specific class that represents a numeric format. This class
+ /// mimicks the design of Java's NumberFormat class, which unlike the
+ /// <see cref="NumberFormatInfo"/> class in .NET, can be subclassed.
+ /// </summary>
+ // LUCENENET NOTE: Ideally, the design of Lucene.NET would be changed to accept a
+ // NumberFormatInfo object instead of using this, or better yet be changed to use IFormatProvider
+ // and/or ICustomFormatter, but since Lucene is using inheritance
+ // and passing this class around to different methods, that would require some major refactoring.
+ // We should probably look into doing that in vNext. We should also look into supporting all of .NET's numeric
+ // types instead of just the ones that Java supports, as well.
public class NumberFormat
{
protected readonly CultureInfo locale;
@@ -82,6 +89,12 @@ namespace Lucene.Net.Support
return number.ToString(format, locale);
}
+ /// <summary>
+ /// When overridden in a subclass, provides the numeric format as a <see cref="string"/>.
+ /// Generally, this is the same format that is passed into the <see cref="M:string.Format(IFormatProvider, string, object)"/>
+ /// method.
+ /// </summary>
+ /// <returns>A numeric format string.</returns>
protected virtual string GetNumberFormat()
{
return null;