Пример #1
0
        /**
         * Initializes the {@link DateEncoder.Builder} specified
         * @param b         the builder on which to set the mapping.
         * @param m         the map containing the values
         * @param key       the key to be set.
         */
        private static void SetDateFieldBits(DateEncoder.Builder b, Map <string, object> m, string key)
        {
            Tuple t = (Tuple)m[key];

            switch (key)
            {
            case "season":
            {
                if (t.Count > 1 && (TypeConverter.Convert <double>(t.Get(1))) > 0.0)
                {
                    b.Season((int)t.Get(0), TypeConverter.Convert <double>(t.Get(1)));
                }
                else
                {
                    b.Season((int)t.Get(0));
                }
                break;
            }

            case "dayOfWeek":
            {
                if (t.Count > 1 && (TypeConverter.Convert <double>(t.Get(1)) > 0.0))
                {
                    b.DayOfWeek((int)t.Get(0), TypeConverter.Convert <double>(t.Get(1)));
                }
                else
                {
                    b.DayOfWeek((int)t.Get(0));
                }
                break;
            }

            case "weekend":
            {
                if (t.Count > 1 && (TypeConverter.Convert <double>(t.Get(1))) > 0.0)
                {
                    b.Weekend((int)t.Get(0), TypeConverter.Convert <double>(t.Get(1)));
                }
                else
                {
                    b.Weekend((int)t.Get(0));
                }
                break;
            }

            case "holiday":
            {
                if (t.Count > 1 && (TypeConverter.Convert <double>(t.Get(1))) > 0.0)
                {
                    b.Holiday((int)t.Get(0), TypeConverter.Convert <double>(t.Get(1)));
                }
                else
                {
                    b.Holiday((int)t.Get(0));
                }
                break;
            }

            case "timeOfDay":
            {
                if (t.Count > 1 && (TypeConverter.Convert <double>(t.Get(1))) > 0.0)
                {
                    b.TimeOfDay((int)t.Get(0), TypeConverter.Convert <double>(t.Get(1)));
                }
                else
                {
                    b.TimeOfDay((int)t.Get(0));
                }
                break;
            }

            case "customDays":
            {
                if (t.Count > 1 && (TypeConverter.Convert <double>(t.Get(1))) > 0.0)
                {
                    b.CustomDays((int)t.Get(0), (List <string>)t.Get(1));
                }
                else
                {
                    b.CustomDays((int)t.Get(0));
                }
                break;
            }

            default: break;
            }
        }
Пример #2
0
        /**
         * Do special configuration for DateEncoder
         * @param encoderSettings
         */
        private static void ConfigureDateBuilder(MultiEncoder multiEncoder, string fieldName, Map <string, Map <string, object> > encoderSettings, DateEncoder.Builder b)
        {
            Map <string, object> dateEncoderSettings = GetEncoderMap(fieldName, encoderSettings, "DateEncoder");

            if (dateEncoderSettings == null)
            {
                throw new InvalidOperationException("Input requires missing DateEncoder settings mapping.");
            }

            foreach (string key in dateEncoderSettings.Keys)
            {
                if (!key.Equals("fieldname", StringComparison.InvariantCultureIgnoreCase) && !key.Equals("encoderType") && !key.Equals("type") &&
                    !key.Equals("fieldType") && !key.Equals("fieldEncodings"))
                {
                    if (!key.Equals("season") && !key.Equals("dayOfWeek") &&
                        !key.Equals("weekend") && !key.Equals("holiday") &&
                        !key.Equals("timeOfDay") &&
                        !key.Equals("customDays") &&
                        !key.Equals("formatPattern") && !key.Equals("dateFormatter"))
                    {
                        multiEncoder.SetValue(b, key, dateEncoderSettings[key]);
                    }
                    else
                    {
                        if (key.Equals("formatPattern"))
                        {
                            b.FormatPattern((string)dateEncoderSettings[key]);
                        }
                        else if (key.Equals("dateFormatter"))
                        {
                            b.Formatter((DateTimeFormatInfo)dateEncoderSettings[key]);
                        }
                        else
                        {
                            SetDateFieldBits(b, dateEncoderSettings, key);
                        }
                    }
                }
            }
        }