Exemplo n.º 1
0
        public bool TryGetValue(object [] keys, out TValueType cubeValue)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            if (keys.Length != this.AxisSet.Count)
            {
                throw new ArgumentException($"Expected {this.AxisSet.Count} key(s), got given {keys.Length}");
            }

            uint [] mappedKeys = new uint [keys.Length];
            for (int idx = 0; idx < mappedKeys.Length; idx++)
            {
                if (!_valueMapper.TryGetID(keys [idx], out var mappedKey))
                {
                    cubeValue = default(TValueType);
                    return(false);
                }

                mappedKeys [idx] = mappedKey;
            }

            if (this._dictionary.TryGetValue(mappedKeys, out cubeValue))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public IEnumerator <IError> GetMatchingErrors(IDictionary <string, object> errorKeys)
        {
            if (errorKeys == null || errorKeys.Count == 0)
            {
                var enumerator = this.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    yield return(enumerator.Current);
                }

                yield break;
            }

            var convertedKeys = new Dictionary <string, uint?>();

            foreach (var pair in errorKeys)
            {
                uint id;
                if (_valueMapper.TryGetID(pair.Value, out id))
                {
                    convertedKeys [pair.Key] = id;
                }
                else
                {
                    // We know for certain that there were no entries explicitly for the given
                    // value, however, general purpose ones could still match it (think getting errors
                    // for tenor = 3M, but there's a general failure for that trade)
                    //
                    // In order to avoid the non-threadsafety of updating the valuemapper, we need to
                    // inform the underlying dictionary of the desires
                    convertedKeys [pair.Key] = null;
                }
            }

            {
                var enumerator = this._errorsDictionary.GetEnumerator(convertedKeys);
                while (enumerator.MoveNext())
                {
                    yield return(new Error(_valueMapper,
                                           _axisNames,
                                           enumerator.Current.Key,
                                           enumerator.Current.Value));
                }
            }
        }