/// <summary> /// Adds all the elements in the specified collection to the SerializableList if they are not already present. /// </summary> /// <param name="c">A collection of objects to add to the SerializableList.</param> /// <returns><c>true</c> is the SerializableList changed as a result of this operation, <c>false</c> if not.</returns> public bool AddAll(SerializableList <T> c) { bool changed = false; foreach (T item in c) { changed |= this.Add_AndGetResult(item); } return(changed); }
/// <summary> /// Performs a "union" of the two SerializableLists, where all the elements /// in both SerializableLists are present. That is, the element is included if it is in either <c>a</c> or <c>b</c>. /// Neither this SerializableList nor the input SerializableList are modified during the operation. The return value /// is a <c>Clone()</c> of this SerializableList with the extra elements added in. /// </summary> /// <param name="a">A collection of elements.</param> /// <returns>A new <c>SerializableList</c> containing the union of this <c>SerializableList</c> with the specified collection. /// Neither of the input objects is modified by the union.</returns> public virtual SerializableList <T> Union(SerializableList <T> a) { SerializableList <T> resultSerializableList = (SerializableList <T>) this.Clone(); if (a != null) { resultSerializableList.AddAll(a); } return(resultSerializableList); }
/// <summary> /// Remove all the specified elements from this SerializableList, if they exist in this SerializableList. /// </summary> /// <param name="c">A collection of elements to remove.</param> /// <returns><c>true</c> if the SerializableList was modified as a result of this operation.</returns> public bool RemoveAll(SerializableList <T> Values) { bool changed = false; foreach (T o in Values) { changed |= this.Remove(o); } return(changed); }
/// <summary> /// Cretes a SerializableList of another type and convert all elements in this type. /// </summary> /// <typeparam name="U">Convert into this Type </typeparam> /// <param name="converter">Converter from T to U</param> /// <returns>the converted SerializableList</returns> public SerializableList <U> ConvertAll <U>(Converter <T, U> converter) { SerializableList <U> result = new SerializableList <U>(); foreach (T element in this) { result.Add(converter(element)); } return(result); }
/// <summary> /// Performs a "minus" of SerializableList <c>b</c> from SerializableList <c>a</c>. This returns a SerializableList of all /// the elements in SerializableList <c>a</c>, removing the elements that are also in SerializableList <c>b</c>. /// The original SerializableLists are not modified during this operation. The result SerializableList is a <c>Clone()</c> /// of this <c>SerializableList</c> containing the elements from the operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <returns>A SerializableList containing the elements from this SerializableList with the elements in <c>a</c> removed.</returns> public virtual SerializableList <T> Minus(SerializableList <T> a) { SerializableList <T> resultSerializableList = (SerializableList <T>) this.Clone(); if (a != null) { resultSerializableList.RemoveAll(a); } return(resultSerializableList); }
/// <summary> /// Returns <c>true</c> if the SerializableList contains all the elements in the specified collection. /// </summary> /// <param name="c">A collection of objects.</param> /// <returns><c>true</c> if the SerializableList contains all the elements in the specified collection, <c>false</c> otherwise.</returns> public bool ContainsAll(SerializableList <T> c) { foreach (T value in c) { if (!this.Contains(value)) { return(false); } } return(true); }
/// <summary> /// Performs a "minus" of SerializableList <c>b</c> from SerializableList <c>a</c>. This returns a SerializableList of all /// the elements in SerializableList <c>a</c>, removing the elements that are also in SerializableList <c>b</c>. /// The original SerializableLists are not modified during this operation. The result SerializableList is a <c>Clone()</c> /// of SerializableList <c>a</c> containing the elements from the operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <param name="b">A SerializableList of elements.</param> /// <returns>A SerializableList containing <c>A - B</c> elements. <c>null</c> if <c>a</c> is <c>null</c>.</returns> public static SerializableList <T> Minus(SerializableList <T> a, SerializableList <T> b) { if (a == null) { return(null); } else { return(a.Minus(b)); } }
/// <summary> /// Filter the SerializableList, applying the predicate to all elements. /// </summary> /// <param name="predicate"></param> /// <returns>Filtered SerializableList</returns> public SerializableList <T> FindAll(Predicate <T> predicate) { SerializableList <T> result = new SerializableList <T>(); foreach (T element in this) { if (predicate(element)) { result.Add(element); } } return(result); }
/// <summary> /// Performs an "intersection" of the two SerializableLists, where only the elements /// that are present in both SerializableLists remain. That is, the element is included if it exists in /// both SerializableLists. The <c>Intersect()</c> operation does not modify the input SerializableLists. It returns /// a <c>Clone()</c> of this SerializableList with the appropriate elements removed. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <returns>The intersection of this SerializableList with <c>a</c>.</returns> public virtual SerializableList <T> Intersect(SerializableList <T> a) { SerializableList <T> resultSerializableList = (SerializableList <T>) this.Clone(); if (a != null) { resultSerializableList.RetainAll(a); } else { resultSerializableList.Clear(); } return(resultSerializableList); }
/// <summary> /// Performs an "intersection" of the two SerializableLists, where only the elements /// that are present in both SerializableLists remain. That is, the element is included only if it exists in /// both <c>a</c> and <c>b</c>. Neither input object is modified by the operation. /// The result object is a <c>Clone()</c> of one of the input objects (<c>a</c> if it is not <c>null</c>) containing the /// elements from the intersect operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <param name="b">A SerializableList of elements.</param> /// <returns>The intersection of the two input SerializableLists. <c>null</c> if both SerializableLists are <c>null</c>.</returns> public static SerializableList <T> Intersect(SerializableList <T> a, SerializableList <T> b) { if (a == null && b == null) { return(null); } else if (a == null) { return(b.Intersect(a)); } else { return(a.Intersect(b)); } }
/// <summary> /// Performs an "exclusive-or" of the two SerializableLists, keeping only the elements that /// are in one of the SerializableLists, but not in both. The original SerializableLists are not modified /// during this operation. The result SerializableList is a <c>Clone()</c> of this SerializableList containing /// the elements from the exclusive-or operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <returns>A SerializableList containing the result of <c>a ^ b</c>.</returns> public virtual SerializableList <T> ExclusiveOr(SerializableList <T> a) { SerializableList <T> resultSerializableList = (SerializableList <T>) this.Clone(); foreach (T element in a) { if (resultSerializableList.Contains(element)) { resultSerializableList.Remove(element); } else { resultSerializableList.Add(element); } } return(resultSerializableList); }
/// <summary> /// Performs an "exclusive-or" of the two SerializableLists, keeping only the elements that /// are in one of the SerializableLists, but not in both. The original SerializableLists are not modified /// during this operation. The result SerializableList is a <c>Clone()</c> of one of the SerializableLists /// (<c>a</c> if it is not <c>null</c>) containing /// the elements from the exclusive-or operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <param name="b">A SerializableList of elements.</param> /// <returns>A SerializableList containing the result of <c>a ^ b</c>. <c>null</c> if both SerializableLists are <c>null</c>.</returns> public static SerializableList <T> ExclusiveOr(SerializableList <T> a, SerializableList <T> b) { if (a == null && b == null) { return(null); } else if (a == null) { return((SerializableList <T>)b.Clone()); } else if (b == null) { return((SerializableList <T>)a.Clone()); } else { return(a.ExclusiveOr(b)); } }
/// <summary> /// Performs a "union" of two SerializableLists, where all the elements /// in both are present. That is, the element is included if it is in either <c>a</c> or <c>b</c>. /// The return value is a <c>Clone()</c> of one of the SerializableLists (<c>a</c> if it is not <c>null</c>) with elements of the other SerializableList /// added in. Neither of the input SerializableLists is modified by the operation. /// </summary> /// <param name="a">A SerializableList of elements.</param> /// <param name="b">A SerializableList of elements.</param> /// <returns>A SerializableList containing the union of the input SerializableLists. <c>null</c> if both SerializableLists are <c>null</c>.</returns> public static SerializableList <T> Union(SerializableList <T> a, SerializableList <T> b) { if (a == null && b == null) { return(null); } else if (a == null) { return((SerializableList <T>)b.Clone()); } else if (b == null) { return((SerializableList <T>)a.Clone()); } else { return(a.Union(b)); } }
/// <summary> /// Retains only the elements in this SerializableList that are contained in the specified collection. /// </summary> /// <param name="c">Collection that defines the SerializableList of elements to be retained.</param> /// <returns><c>true</c> if this SerializableList changed as a result of this operation.</returns> public bool RetainAll(SerializableList <T> c) { //Put data from C into a SerializableList so we can use the Contains() method. SerializableList <T> cSerializableList = new SerializableList <T>(c); //We are going to build a SerializableList of elements to remove. SerializableList <T> removeSerializableList = new SerializableList <T>(); foreach (T o in this) { //If C does not contain O, then we need to remove O from our //SerializableList. We can't do this while iterating through our SerializableList, so //we put it into RemoveSerializableList for later. if (!cSerializableList.Contains(o)) { removeSerializableList.Add(o); } } return(this.RemoveAll(removeSerializableList)); }
/// <summary> /// copie ctor /// </summary> /// <param name="source"></param> public SerializableList(SerializableList <T> source) { this.InternalHashtable = (Hashtable)source.InternalHashtable.Clone(); }