/// <summary>
        /// Creates a collection of all possible keys given some tariff attributes.
        /// </summary>
        /// <param name="attributes">The attributes from whose attribute values all possible keys are to be created.</param>
        /// <returns>All possible keys provided by the given tariff attributes.</returns>
        public static IEnumerable <ITariffKey> Combinations(IEnumerable <ITariffAttribute> attributes)
        {
            IEnumerable <ITariffKey> combinations = null;

            foreach (ITariffAttribute attribute in attributes)
            {
                if (combinations == null)
                {
                    combinations = attribute.Select(x => new TariffKey(new List <TariffAttributeValue>()
                    {
                        x
                    }));
                }
                else
                {
                    IList <ITariffKey> tmpCombinations = new List <ITariffKey>();

                    foreach (ITariffKey key in combinations)
                    {
                        foreach (TariffAttributeValue attributeValue in attribute)
                        {
                            ITariffKey tmpKey = new TariffKey(key.TariffAttributeValues.Append(attributeValue));
                            tmpCombinations.Add(tmpKey);
                        }
                    }

                    combinations = tmpCombinations;
                }
            }

            return(combinations);
        }
Beispiel #2
0
        /// <summary>
        /// Constructor of the tariff data.
        /// </summary>
        /// <param name="attributes">Attributes the data is to be modelled with.</param>
        public TariffData(IEnumerable <ITariffAttribute> attributes)
        {
            Attributes = new List <ITariffAttribute>(attributes).AsReadOnly();
            _cells     = new Dictionary <ITariffKey, TariffCell>(TariffKey.CreateTariffKeyComparer());

            foreach (ITariffKey key in TariffKey.Combinations(Attributes))
            {
                _cells.Add(key, new TariffCell(0m, 0));
            }
        }