예제 #1
0
 static EventLogger()
 {
     TIME_FORMAT = NumberFormat.GetInstance(Locale.Us);
     TIME_FORMAT.MinimumFractionDigits = 2;
     TIME_FORMAT.MaximumFractionDigits = 2;
     TIME_FORMAT.GroupingUsed          = false;
 }
예제 #2
0
 private string getPictureResolution(Context context, string imagePath)
 {
     BitmapFactory.Options bitMapOption = new BitmapFactory.Options();
     bitMapOption.InJustDecodeBounds = true;
     BitmapFactory.DecodeFile(imagePath, bitMapOption);
     return(NumberFormat.GetInstance(context.Resources.Configuration.Locale).Format(bitMapOption.OutWidth) + " x " +
            NumberFormat.GetInstance(context.Resources.Configuration.Locale).Format(bitMapOption.OutHeight));
 }
예제 #3
0
        public void Test_setNumberFormatLjava_text_NumberFormat()
        {
            DateFormat   format = DateFormat.GetInstance();
            NumberFormat f1     = NumberFormat.GetInstance();

            format.SetNumberFormat(f1);
            NUnit.Framework.Assert.IsTrue(f1 == format.GetNumberFormat(), "Not identical NumberFormat");
        }
예제 #4
0
 /*
  * Initializes the <code>PluralRules</code> object.
  * Postcondition:<br/>
  *   <code>ulocale</code>    :  is <code>locale</code><br/>
  *   <code>pluralRules</code>:  if <code>rules</code> != <code>null</code>
  *                              it's set to rules, otherwise it is the
  *                              predefined plural rule set for the locale
  *                              <code>ulocale</code>.<br/>
  *   <code>parsedValues</code>: is <code>null</code><br/>
  *   <code>pattern</code>:      is <code>null</code><br/>
  *   <code>numberFormat</code>: a <code>NumberFormat</code> for the locale
  *                              <code>ulocale</code>.
  */
 private void Init(PluralRules rules, PluralType type, ULocale locale, NumberFormat numberFormat)
 {
     ulocale     = locale;
     pluralRules = (rules == null) ? PluralRules.ForLocale(ulocale, type)
                                   : rules;
     pluralRulesWrapper = new PluralSelectorAdapter(pluralRules); // ICU4N: Have to pass a reference to pluralRules in the constructor
     ResetPattern();
     this.numberFormat = (numberFormat == null) ? NumberFormat.GetInstance(ulocale) : numberFormat;
 }
예제 #5
0
 /*
  * Initializes the <code>PluralRules</code> object.
  * Postcondition:<br/>
  *   <code>ulocale</code>    :  is <code>locale</code><br/>
  *   <code>pluralRules</code>:  if <code>rules</code> != <code>null</code>
  *                              it's set to rules, otherwise it is the
  *                              predefined plural rule set for the locale
  *                              <code>ulocale</code>.<br/>
  *   <code>parsedValues</code>: is <code>null</code><br/>
  *   <code>pattern</code>:      is <code>null</code><br/>
  *   <code>numberFormat</code>: a <code>NumberFormat</code> for the locale
  *                              <code>ulocale</code>.
  */
 private void Init(PluralRules rules, PluralType type, UCultureInfo locale, NumberFormat numberFormat)
 {
     ulocale     = locale;
     pluralRules = (rules == null) ? PluralRules.ForLocale(ulocale, type) // ICU4N TODO: Make extension method for UCultureInfo.GetPluralRules(PluralType)..?
                                   : rules;
     pluralRulesWrapper = new PluralSelectorAdapter(pluralRules);         // ICU4N: Have to pass a reference to pluralRules in the constructor
     ResetPattern();
     this.numberFormat = (numberFormat == null) ? NumberFormat.GetInstance(ulocale) : numberFormat;
 }
예제 #6
0
        /// <summary>Helper function to generate a name that is unique for the task.</summary>
        /// <remarks>
        /// Helper function to generate a name that is unique for the task.
        /// <p>The generated name can be used to create custom files from within the
        /// different tasks for the job, the names for different tasks will not collide
        /// with each other.</p>
        /// <p>The given name is postfixed with the task type, 'm' for maps, 'r' for
        /// reduces and the task partition number. For example, give a name 'test'
        /// running on the first map o the job the generated name will be
        /// 'test-m-00000'.</p>
        /// </remarks>
        /// <param name="conf">the configuration for the job.</param>
        /// <param name="name">the name to make unique.</param>
        /// <returns>a unique name accross all tasks of the job.</returns>
        public static string GetUniqueName(JobConf conf, string name)
        {
            int partition = conf.GetInt(JobContext.TaskPartition, -1);

            if (partition == -1)
            {
                throw new ArgumentException("This method can only be called from within a Job");
            }
            string taskType = conf.GetBoolean(JobContext.TaskIsmap, JobContext.DefaultTaskIsmap
                                              ) ? "m" : "r";
            NumberFormat numberFormat = NumberFormat.GetInstance();

            numberFormat.SetMinimumIntegerDigits(5);
            numberFormat.SetGroupingUsed(false);
            return(name + "-" + taskType + "-" + numberFormat.Format(partition));
        }
예제 #7
0
        private static NumberFormat GetFormat(string format)
        {
            if (format == null)
            {
                return(NumberFormat.GetInstance());
            }
            if (format.Length >= 1)
            {
                switch (char.ToUpper(format[0]))
                {
                case 'C':
                {
                    string       javaFormat;
                    NumberFormat nf = NumberFormat.GetCurrencyInstance();
                    if (format.Length == 1)
                    {
                        javaFormat = "0.00";
                    }
                    else
                    {
                        int decimalCount;
                        if (int.TryParse(format.JavaSubstring(1), out decimalCount))
                        {
                            javaFormat = "0." + new string('0', decimalCount);
                            if (0 == decimalCount)
                            {
                                javaFormat = "0";
                            }
                        }
                        else
                        {
                            javaFormat = format;
                        }
                    }

                    if (nf.IsGroupingUsed())
                    {
                        javaFormat = "#,##" + javaFormat;
                    }

                    javaFormat = nf.Currency.GetSymbol() + javaFormat;

                    return(new DecimalFormat(javaFormat));
                }

                case 'D':
                {
                    if (format.Length == 1)
                    {
                        return(new DecimalFormat("0"));
                    }
                    int decimalCount;
                    if (int.TryParse(format.JavaSubstring(1), out decimalCount))
                    {
                        string javaFormat = new string('0', decimalCount);
                        if (0 == decimalCount)
                        {
                            javaFormat = "0";
                        }
                        return(new DecimalFormat(javaFormat));
                    }
                }
                break;

                case 'E':
                {
                    if (format.Length == 1)
                    {
                        return(new ScientificFormat("0.000000E000"));
                    }
                    int decimalCount;
                    if (int.TryParse(format.JavaSubstring(1), out decimalCount))
                    {
                        string javaFormat = "0." + new string('0', decimalCount);
                        if (0 == decimalCount)
                        {
                            javaFormat = "0";
                        }
                        return(new ScientificFormat(javaFormat + "E000"));
                    }
                }
                break;

                case 'F':
                case 'P':
                {
                    string javaFormat;
                    if (format.Length == 1)
                    {
                        javaFormat = "0.00";
                    }
                    else
                    {
                        int decimalCount;
                        if (int.TryParse(format.JavaSubstring(1), out decimalCount))
                        {
                            javaFormat = "0." + new string('0', decimalCount);
                            if (0 == decimalCount)
                            {
                                javaFormat = "0";
                            }
                        }
                        else
                        {
                            javaFormat = format;
                        }
                    }

                    if ('P' == char.ToUpper(format[0]))
                    {
                        return(new DecimalFormat(javaFormat + " %"));
                    }

                    return(new DecimalFormat(javaFormat));
                }

                case 'G':
                case 'R':
                    return(new DecimalFormat("0.################################"));

                case 'N':
                {
                    if (format.Length == 1)
                    {
                        return(new DecimalFormat("#,##0.00"));
                    }
                    int decimalCount;
                    if (int.TryParse(format.JavaSubstring(1), out decimalCount))
                    {
                        string javaFormat = "#,##0." + new string('0', decimalCount);
                        if (0 == decimalCount)
                        {
                            javaFormat = "#,##0";
                        }
                        return(new DecimalFormat(javaFormat));
                    }
                }
                break;

                case 'X':
                    if (format.Length == 1)
                    {
                        return(new HexFormat(8, char.IsUpper(format[0])));
                    }
                    int numDigits;
                    if (int.TryParse(format.JavaSubstring(1), out numDigits))
                    {
                        return(new HexFormat(numDigits, char.IsUpper(format[0])));
                    }
                    break;
                }
            }
            return(new DecimalFormat(format));
        }
예제 #8
0
 internal static string Format(double value, IFormatProvider provider)
 {
     return(NumberFormat.GetInstance().Format(value));
 }
예제 #9
0
        /// <summary>
        /// Parses the pattern to determine new strings and ranges for this
        /// <see cref="ChoiceFormat"/>.
        /// </summary>
        /// <param name="template">The pattern of strings and ranges.</param>
        /// <exception cref="ArgumentException">If an error occurs while parsing the pattern.</exception>
        public void ApplyPattern(string template)
        {
            double[]      limits = new double[5];
            List <string> formats = new List <string>();
            int           length = template.Length, limitCount = 0, index = 0;
            StringBuffer  buffer   = new StringBuffer();
            NumberFormat  format   = NumberFormat.GetInstance(CultureInfo.InvariantCulture);
            ParsePosition position = new ParsePosition(0);

            while (true)
            {
                index = SkipWhitespace(template, index);
                if (index >= length)
                {
                    if (limitCount == limits.Length)
                    {
                        choiceLimits = limits;
                    }
                    else
                    {
                        choiceLimits = new double[limitCount];
                        System.Array.Copy(limits, 0, choiceLimits, 0, limitCount);
                    }
                    choiceFormats = new String[formats.Count];
                    for (int i = 0; i < formats.Count; i++)
                    {
                        choiceFormats[i] = formats[i];
                    }
                    return;
                }
                position.Index = index;
                object value = format.Parse(template, position);

                index = SkipWhitespace(template, position.Index);
                if (position.ErrorIndex != -1 || index >= length)
                {
                    // Fix Harmony 540
                    choiceLimits  = new double[0];
                    choiceFormats = new string[0];
                    return;
                }
                char ch = template[index++];
                if (limitCount == limits.Length)
                {
                    double[] newLimits = new double[limitCount * 2];
                    System.Array.Copy(limits, 0, newLimits, 0, limitCount);
                    limits = newLimits;
                }
                double next;
                switch (ch)
                {
                case '#':
                case '\u2264':
                    next = Convert.ToDouble(value);
                    break;

                case '<':
                    next = NextDouble(Convert.ToDouble(value));
                    break;

                default:
                    throw new ArgumentException();     // ICU4N TODO: Shouldn't this be FormatException in .NET?
                }
                if (limitCount > 0 && next <= limits[limitCount - 1])
                {
                    throw new ArgumentException(); // ICU4N TODO: Shouldn't this be FormatException in .NET?
                }
                buffer.Length  = (0);
                position.Index = (index);
                UpTo(template, position, buffer, '|');
                index = position.Index;
                limits[limitCount++] = next;
                formats.Add(buffer.ToString());
            }
        }
예제 #10
0
 static EventLogger()
 {
     TimeFormat = NumberFormat.GetInstance(Locale.Us);
     TimeFormat.MinimumFractionDigits = 2;
     TimeFormat.MaximumFractionDigits = 2;
 }