Example #1
0
        /// <summary>
        /// Creates a copy of the cube, excluding values whose keys have a matching key part value.
        /// </summary>
        /// <param name="keyPart">The dimension and key value of items to be removed.</param>
        /// <returns>A new cube where the values matching the key part have been removed.</returns>
        public Cube <TValue> Exclude(KeyPart keyPart)
        {
            if (keyPart == null)
            {
                throw new ArgumentNullException("keyPart");
            }
            if (!keyLookup.ContainsKey(keyPart.Dimension))
            {
                throw new ArgumentException("Cannot filter by a dimension that is not in the cube.", "dimension");
            }
            LookupBuilder <TValue> builder = new LookupBuilder <TValue>(keyLookup.Keys);

            foreach (KeyValuePair <Key, TValue> pair in valueLookup)
            {
                if (!keyPart.Equals(pair.Key.GetKeyPart(keyPart.Dimension)))
                {
                    builder.Add(pair.Key, pair.Value);
                }
            }
            return(new Cube <TValue>(builder));
        }
Example #2
0
 /// <summary>
 /// Gets whether the given key is equal.
 /// </summary>
 /// <param name="other">The other key.</param>
 /// <returns>True if obj is a Key and it represents the same key; otherwise, false.</returns>
 public bool Equals(Key other)
 {
     if (other == null)
     {
         return(false);
     }
     foreach (KeyValuePair <Dimension, KeyPart> pair in keyParts)
     {
         Dimension dimension = pair.Key;
         KeyPart   keyPart   = pair.Value;
         if (!other.keyParts.ContainsKey(dimension))
         {
             return(false);
         }
         KeyPart otherKeyPart = other.keyParts[dimension];
         if (!keyPart.Equals(otherKeyPart))
         {
             return(false);
         }
     }
     return(true);
 }