public override bool Equals(object obj) { if (obj == null) // check if its null { return(false); } if (this.GetType() != obj.GetType()) // check if the type is the same { return(false); } KeyGeneralization generalization = (KeyGeneralization)obj; if (generalization == null) // check if it can be casted { return(false); } if (generalization.LastValue == this.LastValue) { return(true); } else { return(false); } }
public static Generalization[] Merge(Generalization[] prev_gens, Generalization[] new_gens) { List <Generalization> gens = new List <Generalization>(); if (prev_gens.Length > 0 && prev_gens.Length == new_gens.Length && prev_gens[0].Type == new_gens[0].Type) { for (int i = 0; i < prev_gens.Length; i++) { KeyGeneralization prev_gen = (KeyGeneralization)prev_gens[i]; KeyGeneralization new_gen = (KeyGeneralization)new_gens[i]; if (prev_gen.LastValue == new_gen.LastValue) // if both have the same value, everything is OK { gens.Add(new KeyGeneralization(new_gen.LastValue, new_gen.Time, prev_gen.Occurrences + 1)); } else // if not, then there is no merging { return(new Generalization[0]); } } } return(gens.ToArray()); }