Esempio n. 1
0
        public void IntExtractor_Returns_Integer_For_Timespan()
        {
            var extractor = new IntExtractor();
            var actual    = extractor.GetValue(dataElements, "1002");

            actual.Should().Be(1234);
        }
Esempio n. 2
0
    static Item _GetIntItem(int inItemNameTextID,
                            PlayerPersistentInfoData inPlayerData,
                            List <FriendInfo> inFriendsData,
                            E_Better inBetter,
                            IntExtractor inExtractor)
    {
        IntItem item = new IntItem();

        item.m_NameIndex = inItemNameTextID;

        return(_GetIntItem(item, inPlayerData, inFriendsData, inBetter, inExtractor));
    }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldExtractNegativeInt()
        internal virtual void ShouldExtractNegativeInt()
        {
            // GIVEN
            Extractors extractors = new Extractors(',');
            int        value      = -1234567;

            // WHEN
            char[]       asChars   = value.ToString().ToCharArray();
            IntExtractor extractor = extractors.Int_();

            extractor.Extract(asChars, 0, asChars.Length, false);

            // THEN
            assertEquals(value, extractor.IntValue());
        }
Esempio n. 4
0
        /// <summary>
        /// Why do we have a public constructor here and why isn't this class an enum?
        /// It's because the array extractors can be configured with an array delimiter,
        /// something that would be impossible otherwise. There's an equivalent <seealso cref="valueOf(string)"/>
        /// method to keep the feel of an enum.
        /// </summary>
        public Extractors(char arrayDelimiter, bool emptyStringsAsNull, bool trimStrings, System.Func <ZoneId> defaultTimeZone)
        {
            try
            {
                foreach (System.Reflection.FieldInfo field in this.GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
                {
                    if (isStatic(field.Modifiers))
                    {
                        object value = field.get(null);
                        if (value is Extractor)
                        {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: instances.put(field.getName(), (Extractor<?>) value);
                            _instances[field.Name] = (Extractor <object>)value;
                        }
                    }
                }

                Add(@string        = new StringExtractor(emptyStringsAsNull));
                Add(_long_         = new LongExtractor());
                Add(_int_          = new IntExtractor());
                Add(_char_         = new CharExtractor());
                Add(_short_        = new ShortExtractor());
                Add(_byte_         = new ByteExtractor());
                Add(_boolean_      = new BooleanExtractor());
                Add(_float_        = new FloatExtractor());
                Add(_double_       = new DoubleExtractor());
                Add(_stringArray   = new StringArrayExtractor(arrayDelimiter, trimStrings));
                Add(_booleanArray  = new BooleanArrayExtractor(arrayDelimiter));
                Add(_byteArray     = new ByteArrayExtractor(arrayDelimiter));
                Add(_shortArray    = new ShortArrayExtractor(arrayDelimiter));
                Add(_intArray      = new IntArrayExtractor(arrayDelimiter));
                Add(_longArray     = new LongArrayExtractor(arrayDelimiter));
                Add(_floatArray    = new FloatArrayExtractor(arrayDelimiter));
                Add(_doubleArray   = new DoubleArrayExtractor(arrayDelimiter));
                Add(_point         = new PointExtractor());
                Add(_date          = new DateExtractor());
                Add(_time          = new TimeExtractor(defaultTimeZone));
                Add(_dateTime      = new DateTimeExtractor(defaultTimeZone));
                Add(_localTime     = new LocalTimeExtractor());
                Add(_localDateTime = new LocalDateTimeExtractor());
                Add(_duration      = new DurationExtractor());
            }
            catch (IllegalAccessException)
            {
                throw new Exception("Bug in reflection code gathering all extractors");
            }
        }
Esempio n. 5
0
    static Item _GetIntItem(IntItem inItem,
                            PlayerPersistentInfoData inPlayerData,
                            List <FriendInfo> inFriendsData,
                            E_Better inBetter,
                            IntExtractor inExtractor)
    {
        IntItem item = inItem;

        item.m_PlayerValue = -1;
        item.m_SecondValue = -1;
        return(item);

        /*
         * IntItem item        = inItem;
         * item.m_PlayerValue = inExtractor(inPlayerData);
         * item.m_SecondValue = -1;
         *
         * foreach(FriendInfo fi in inFriendsData)
         * {
         *      int friendValue = inExtractor(fi.m_PPIData);
         *      if(friendValue > item.m_SecondValue)
         *      {
         *              item.m_SecondValue           = friendValue;
         *              item.m_SecondValueFriendName = fi.m_Name;
         *      }
         * }
         *
         * if(inBetter != E_Better.None && inFriendsData.Count > 0)
         * {
         *      item.m_HighlightPlayer = (inBetter == E_Better.Bigger  && item.m_PlayerValue > item.m_SecondValue) ||
         *                                                       (inBetter == E_Better.Smaller && item.m_PlayerValue < item.m_SecondValue);
         *      item.m_HighlightFriend = (inBetter == E_Better.Bigger  && item.m_PlayerValue < item.m_SecondValue) ||
         *                                                       (inBetter == E_Better.Smaller && item.m_PlayerValue > item.m_SecondValue);
         * }
         *
         * return item;
         */
    }
        private object GetValue(List <DataElement> detailData, FieldConfiguration fieldConfiguration)
        {
            object retVal = null;

            try
            {
                switch (fieldConfiguration.Type)
                {
                case ElasticFieldTypes.TypeString:
                    var textExtractor = new TextExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, textExtractor);
                    break;

                case ElasticFieldTypes.TypeTimePeriod:
                    var timePeriodExtractor = new TimePeriodExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, timePeriodExtractor);
                    break;

                case ElasticFieldTypes.TypeDateWithYear:
                    var dateWithYearExtractor = new DateWithYearExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, dateWithYearExtractor);
                    break;

                case ElasticFieldTypes.TypeBase64:
                    var elasticBase64Extractor = new Base64Extractor();
                    retVal = GetValue(detailData, fieldConfiguration, elasticBase64Extractor);
                    break;

                case ElasticFieldTypes.TypeInt + "?":
                case ElasticFieldTypes.TypeInt:
                    var intExtractor = new IntExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, intExtractor);
                    break;

                case ElasticFieldTypes.TypeBool + "?":
                case ElasticFieldTypes.TypeBool:
                    var boolExtractor = new BoolExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, boolExtractor);
                    break;

                case ElasticFieldTypes.TypeFloat + "?":
                case ElasticFieldTypes.TypeFloat:
                    var floatExtractor = new FloatExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, floatExtractor);
                    break;

                case ElasticFieldTypes.TypeHyperlink:
                    var hyperlinkExtractor = new HyperlinkExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, hyperlinkExtractor);
                    break;

                case ElasticFieldTypes.TypeEntityLink:
                    var entityLinkExtractor = new EntityLinkExtractor();
                    retVal = GetValue(detailData, fieldConfiguration, entityLinkExtractor);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                throw;
            }

            return(retVal);
        }