예제 #1
0
        public virtual void doubleArray()
        {
            FormatSettingsProvider    settingsProvider = FormatSettingsProvider.INSTANCE;
            FormatSettings <object>   defaultSettings  = FormatSettings.of(FormatCategory.TEXT, ValueFormatters.UNSUPPORTED);
            FormatSettings <double[]> settings         = settingsProvider.settings(typeof(double[]), defaultSettings);
            ValueFormatter <double[]> formatter        = settings.Formatter;

            double[] array = new double[] { 1, 2, 3 };

            assertThat(formatter.formatForDisplay(array)).isEqualTo("[1.0, 2.0, 3.0]");
            assertThat(formatter.formatForCsv(array)).isEqualTo("[1.0 2.0 3.0]");
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Obtains the format settings for a given type.
        /// </summary>
        /// @param <T>  the type of the value </param>
        /// <param name="clazz">  the type to format </param>
        /// <param name="defaultSettings">  the default settings, used if no settings are found for the type </param>
        /// <returns> the format settings </returns>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public <T> FormatSettings<T> settings(Class clazz, FormatSettings<Object> defaultSettings)
        public virtual FormatSettings <T> settings <T>(Type clazz, FormatSettings <object> defaultSettings)
        {
            FormatSettings <T> settings = (FormatSettings <T>)settingsCache[clazz];

            if (settings == null)
            {
                settings = (FormatSettings <T>)TYPE_SETTINGS[clazz];
                if (settings == null)
                {
                    settings = (FormatSettings <T>)defaultSettings;
                }
                settingsCache[clazz] = settings;
            }
            return(settings);
        }
예제 #3
0
        //-----------------------------------------------------------------------
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj != null && obj.GetType() == this.GetType())
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: FormatSettings<?> other = (FormatSettings<?>) obj;
                FormatSettings <object> other = (FormatSettings <object>)obj;
                return(JodaBeanUtils.equal(category, other.category) && JodaBeanUtils.equal(formatter, other.formatter));
            }
            return(false);
        }
        //-------------------------------------------------------------------------
        /// <summary>
        /// Formats a value into a string.
        /// </summary>
        /// <param name="value">  the value </param>
        /// <param name="format">  the format that controls how the value is formatted </param>
        /// <returns> the formatted value </returns>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") protected String formatValue(Object value, ReportOutputFormat format)
        protected internal virtual string formatValue(object value, ReportOutputFormat format)
        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: Object formatValue = value instanceof java.util.Optional ? ((java.util.Optional<?>) value).orElse(null) : value;
            object formatValue = value is Optional ? ((Optional <object>)value).orElse(null) : value;

            if (formatValue == null)
            {
                return("");
            }
            FormatSettings <object> formatSettings = formatSettingsProvider.settings(formatValue.GetType(), defaultSettings);
            ValueFormatter <object> formatter      = formatSettings.Formatter;

            return(format == ReportOutputFormat.CSV ? formatter.formatForCsv(formatValue) : formatter.formatForDisplay(formatValue));
        }
 /// <summary>
 /// Creates a new formatter with a set of default format settings.
 /// </summary>
 /// <param name="defaultSettings">  default format settings, used if there are no settings for a data type. </param>
 protected internal ReportFormatter(FormatSettings <object> defaultSettings)
 {
     this.defaultSettings = defaultSettings;
 }