public override string ToString()
        {
            StringBuilder compliantBlocksSB = new StringBuilder();

            compliantBlocksSB.Append("\nBlocks satisfying the specified storage policy:");
            compliantBlocksSB.Append("\nStorage Policy                  # of blocks       % of blocks\n"
                                     );
            StringBuilder nonCompliantBlocksSB  = new StringBuilder();
            Formatter     compliantFormatter    = new Formatter(compliantBlocksSB);
            Formatter     nonCompliantFormatter = new Formatter(nonCompliantBlocksSB);
            NumberFormat  percentFormat         = NumberFormat.GetPercentInstance();

            percentFormat.SetMinimumFractionDigits(4);
            percentFormat.SetMaximumFractionDigits(4);
            foreach (KeyValuePair <StoragePolicySummary.StorageTypeAllocation, long> storageComboCount
                     in SortByComparator(storageComboCounts))
            {
                double percent = (double)storageComboCount.Value / (double)totalBlocks;
                StoragePolicySummary.StorageTypeAllocation sta = storageComboCount.Key;
                if (sta.PolicyMatches())
                {
                    compliantFormatter.Format("%-25s %10d  %20s%n", sta.GetStoragePolicyDescriptor(),
                                              storageComboCount.Value, percentFormat.Format(percent));
                }
                else
                {
                    if (nonCompliantBlocksSB.Length == 0)
                    {
                        nonCompliantBlocksSB.Append("\nBlocks NOT satisfying the specified storage policy:"
                                                    );
                        nonCompliantBlocksSB.Append("\nStorage Policy                  ");
                        nonCompliantBlocksSB.Append("Specified Storage Policy      # of blocks       % of blocks\n"
                                                    );
                    }
                    nonCompliantFormatter.Format("%-35s %-20s %10d  %20s%n", sta.GetStoragePolicyDescriptor
                                                     (), sta.GetSpecifiedStoragePolicy().GetName(), storageComboCount.Value, percentFormat
                                                 .Format(percent));
                }
            }
            if (nonCompliantBlocksSB.Length == 0)
            {
                nonCompliantBlocksSB.Append("\nAll blocks satisfy specified storage policy.\n");
            }
            compliantFormatter.Close();
            nonCompliantFormatter.Close();
            return(compliantBlocksSB.ToString() + nonCompliantBlocksSB);
        }
Esempio n. 2
0
        internal NumberFormatInfo(Locale locale)
        {
            _locale = locale;

            _numbers = NumberFormat.GetNumberInstance(locale);

            _symbols = new DecimalFormatSymbols(locale)
            {
                Infinity = "Infinity"
            };

            _decimals = _numbers as DecimalFormat ?? new DecimalFormat();
            _decimals.DecimalFormatSymbols = _symbols;

            _currency = NumberFormat.GetCurrencyInstance(locale) as DecimalFormat ?? _decimals;
            _percent  = NumberFormat.GetPercentInstance(locale) as DecimalFormat ?? _decimals;
        }