/// <summary> /// Checks to see if both Chemical Groups that are passed in are valid for a /// set operation. If they are not, then an exception will be thrown. /// </summary> private static void SetCheck(ChemicalGroup a, ChemicalGroup b) { if (a == null || b == null) { throw new ArgumentNullException("Both groups must be filled in."); } if (a.Factory != b.Factory) { throw new ArgumentException("Chemical Groups A and B come from different factories."); } if (a.isDisposed || b.isDisposed) { throw new ArgumentException("Cannot perform set operations on disposed Chemical Groups."); } }
/// <summary> /// Returns a Chemical Group containing the set intersection of 'a' and 'b'. /// </summary> public static ChemicalGroup Inersection(ChemicalGroup a, ChemicalGroup b) { SetCheck(a, b); var atomicNumbers = new HashSet <int>(a.Select(chem => { return(chem.AtomicNumber); })); atomicNumbers.IntersectWith(b.Select(chem => { return(chem.AtomicNumber); })); ChemicalGroup result = new ChemicalGroup(a.Factory); foreach (var atomicNumber in atomicNumbers.ToArray()) { result.AddChemicalElement(atomicNumber); } return(result); }
public void AddChemicalElements(ChemicalGroup group) { if (this.IsLocked) { return; } if (group == null) { throw new ArgumentNullException(); } HashSet <int> currentKeys = new HashSet <int>(m_elements.Select(chem => { return(chem.AtomicNumber); })); HashSet <int> newKeys = new HashSet <int>(group.m_elements.Select(chem => { return(chem.AtomicNumber); })); newKeys.ExceptWith(currentKeys.ToArray()); foreach (var key in newKeys) { AddChemicalElement(key); } }