lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [lucenenet] 30/35: BREAKING: Lucene.Net.Util.NumberFormat, Lucene.Net.QueryParsers.Flexible.Standard.Config.NumberDateFormat: Changed protected locale field to private, made property named Culture, and changed constructors and methods to use "culture" rather than "locale" for parameter names
Date Sun, 09 Feb 2020 06:16:22 GMT
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 4452aa4b8bef6399c8c379e4317cb80da07c7d50
Author: Shad Storhaug <shad@shadstorhaug.com>
AuthorDate: Sat Feb 8 21:03:16 2020 +0700

    BREAKING: Lucene.Net.Util.NumberFormat, Lucene.Net.QueryParsers.Flexible.Standard.Config.NumberDateFormat:
Changed protected locale field to private, made property named Culture, and changed constructors
and methods to use "culture" rather than "locale" for parameter names
---
 .../Flexible/Standard/Config/NumberDateFormat.cs   | 34 +++++++++++-----------
 src/Lucene.Net/Support/Util/NumberFormat.cs        | 28 +++++++++---------
 2 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
index 60a592c..5e969bb 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
@@ -64,10 +64,10 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
 
         /// <summary>
         /// Constructs a <see cref="NumberDateFormat"/> object using the given <paramref
name="dateStyle"/>,
-        /// <paramref name="timeStyle"/>, and <paramref name="locale"/>.
+        /// <paramref name="timeStyle"/>, and <paramref name="culture"/>.
         /// </summary>
-        public NumberDateFormat(DateFormat dateStyle, DateFormat timeStyle, CultureInfo locale)
-            : base(locale)
+        public NumberDateFormat(DateFormat dateStyle, DateFormat timeStyle, CultureInfo culture)
+            : base(culture)
         {
             this.dateStyle = dateStyle;
             this.timeStyle = timeStyle;
@@ -81,26 +81,26 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
 
         public override string Format(double number)
         {
-            return new DateTime(EPOCH).AddMilliseconds(number).ToString(GetDateFormat(),
this.locale);
+            return new DateTime(EPOCH).AddMilliseconds(number).ToString(GetDateFormat(),
Culture);
         }
 
         public override string Format(long number)
         {
-            return new DateTime(EPOCH).AddMilliseconds(number).ToString(GetDateFormat(),
this.locale);
+            return new DateTime(EPOCH).AddMilliseconds(number).ToString(GetDateFormat(),
Culture);
         }
 
         public override object Parse(string source)
         {
             // Try exact format first, if it fails, do a loose DateTime.Parse
             DateTime d;
-            d = DateTime.ParseExact(source, GetDateFormat(), this.locale, DateTimeStyles.None);
+            d = DateTime.ParseExact(source, GetDateFormat(), Culture, DateTimeStyles.None);
 
             return (d - new DateTime(EPOCH)).TotalMilliseconds;
         }
 
         public override string Format(object number)
         {
-            return new DateTime(EPOCH).AddMilliseconds(Convert.ToInt64(number, CultureInfo.InvariantCulture)).ToString(GetDateFormat(),
this.locale);
+            return new DateTime(EPOCH).AddMilliseconds(Convert.ToInt64(number, CultureInfo.InvariantCulture)).ToString(GetDateFormat(),
Culture);
         }
 
         public void SetDateFormat(string dateFormat)
@@ -117,45 +117,45 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
         {
             if (dateFormat != null) return dateFormat;
 
-            return GetDateFormat(this.dateStyle, this.timeStyle, this.locale);
+            return GetDateFormat(this.dateStyle, this.timeStyle, Culture);
         }
 
-        public static string GetDateFormat(DateFormat dateStyle, DateFormat timeStyle, CultureInfo
locale)
+        public static string GetDateFormat(DateFormat dateStyle, DateFormat timeStyle, CultureInfo
culture)
         {
             string datePattern = "", timePattern = "";
 
             switch (dateStyle)
             {
                 case DateFormat.SHORT:
-                    datePattern = locale.DateTimeFormat.ShortDatePattern;
+                    datePattern = culture.DateTimeFormat.ShortDatePattern;
                     break;
                 case DateFormat.MEDIUM:
-                    datePattern = locale.DateTimeFormat.LongDatePattern
+                    datePattern = culture.DateTimeFormat.LongDatePattern
                         .Replace("dddd,", "").Replace(", dddd", "") // Remove the day of
the week
                         .Replace("MMMM", "MMM"); // Replace month with abbreviated month
                     break;
                 case DateFormat.LONG:
-                    datePattern = locale.DateTimeFormat.LongDatePattern
+                    datePattern = culture.DateTimeFormat.LongDatePattern
                         .Replace("dddd,", "").Replace(", dddd", ""); // Remove the day of
the week
                     break;
                 case DateFormat.FULL:
-                    datePattern = locale.DateTimeFormat.LongDatePattern;
+                    datePattern = culture.DateTimeFormat.LongDatePattern;
                     break;
             }
 
             switch (timeStyle)
             {
                 case DateFormat.SHORT:
-                    timePattern = locale.DateTimeFormat.ShortTimePattern;
+                    timePattern = culture.DateTimeFormat.ShortTimePattern;
                     break;
                 case DateFormat.MEDIUM:
-                    timePattern = locale.DateTimeFormat.LongTimePattern;
+                    timePattern = culture.DateTimeFormat.LongTimePattern;
                     break;
                 case DateFormat.LONG:
-                    timePattern = locale.DateTimeFormat.LongTimePattern.Replace("z", "").Trim()
+ " z";
+                    timePattern = culture.DateTimeFormat.LongTimePattern.Replace("z", "").Trim()
+ " z";
                     break;
                 case DateFormat.FULL:
-                    timePattern = locale.DateTimeFormat.LongTimePattern.Replace("z", "").Trim()
+ " z"; // LUCENENET TODO: Time zone info not being added to match behavior of Java, but Java
doc is unclear on what the difference is between this and LONG
+                    timePattern = culture.DateTimeFormat.LongTimePattern.Replace("z", "").Trim()
+ " z"; // LUCENENET TODO: Time zone info not being added to match behavior of Java, but Java
doc is unclear on what the difference is between this and LONG
                     break;
             }
 
diff --git a/src/Lucene.Net/Support/Util/NumberFormat.cs b/src/Lucene.Net/Support/Util/NumberFormat.cs
index 92b2e31..311d096 100644
--- a/src/Lucene.Net/Support/Util/NumberFormat.cs
+++ b/src/Lucene.Net/Support/Util/NumberFormat.cs
@@ -33,45 +33,47 @@ namespace Lucene.Net.Util
     // types instead of just the ones that Java supports, as well.
     public class NumberFormat
     {
-        protected readonly CultureInfo locale;
+        private readonly CultureInfo culture;
 
         //private int maximumIntegerDigits;
         //private int minimumIntegerDigits;
         //private int maximumFractionDigits;
         //private int minimumFractionDigits;
 
-        public NumberFormat(CultureInfo locale)
+        public NumberFormat(CultureInfo culture)
         {
-            this.locale = locale;
+            this.culture = culture;
         }
 
+        protected CultureInfo Culture => culture;
+
         public virtual string Format(object number)
         {
             string format = GetNumberFormat();
 
             if (number is int)
             {
-                return ((int)number).ToString(format, locale);
+                return ((int)number).ToString(format, culture);
             }
             else if (number is long)
             {
-                return ((long)number).ToString(format, locale);
+                return ((long)number).ToString(format, culture);
             }
             else if (number is short)
             {
-                return ((short)number).ToString(format, locale);
+                return ((short)number).ToString(format, culture);
             }
             else if (number is float)
             {
-                return ((float)number).ToString(format, locale);
+                return ((float)number).ToString(format, culture);
             }
             else if (number is double)
             {
-                return ((double)number).ToString(format, locale);
+                return ((double)number).ToString(format, culture);
             }
             else if (number is decimal)
             {
-                return ((decimal)number).ToString(format, locale);
+                return ((decimal)number).ToString(format, culture);
             }
 
             throw new ArgumentException("Cannot format given object as a Number");
@@ -80,13 +82,13 @@ namespace Lucene.Net.Util
         public virtual string Format(double number)
         {
             string format = GetNumberFormat();
-            return number.ToString(format, locale);
+            return number.ToString(format, culture);
         }
 
         public virtual string Format(long number)
         {
             string format = GetNumberFormat();
-            return number.ToString(format, locale);
+            return number.ToString(format, culture);
         }
 
         /// <summary>
@@ -102,12 +104,12 @@ namespace Lucene.Net.Util
 
         public virtual /*Number*/ object Parse(string source)
         {
-            return decimal.Parse(source, locale);
+            return decimal.Parse(source, culture);
         }
 
         public override string ToString()
         {
-            return base.ToString() + " - " + GetNumberFormat() + " - " + locale.ToString();
+            return base.ToString() + " - " + GetNumberFormat() + " - " + culture.ToString();
         }
 
         // LUCENENET TODO: Add additional functionality to edit the NumberFormatInfo


Mime
View raw message