Ultimate.Utilities.Docs
Ultimate.Utilities.CollectionUtils Class Reference

Utility methods for collections. More...

Static Public Member Functions

static bool AddAll< T > (ICollection< T > collection, IEnumerable< T > elements)
 Adds all elements in the enumeration to the given collection. More...
 
static bool AddAllIgnoreNull< T > (ICollection< T > collection, ICollection< T > elements)
 Adds all non null elements in the enumeration to the given collection. More...
 
static bool AddAllAtIndex< T > (IList< T > collection, IList< T > elements, int index, bool includeNulls=true)
 Adds all elements to the given collection from a specified index More...
 
static bool AddIgnoreNull< T > (ICollection< T > collection, T element)
 Adds an element to the collection unless the element is null. More...
 
static IList< T > Collate< T > (IEnumerable< T > a, IEnumerable< T > b, bool includeDuplicates=true)
 Combines two lists and sorts them by default More...
 
static IList< T > Collate< T > (IEnumerable< T > a, IEnumerable< T > b, IComparer< T > comparer, bool includeDuplicates=true)
 Combines two lists and sorts them using the given comparer More...
 
static ICollection< TOutput > CollectFromParent< TInput, TOutput > (IEnumerable< TInput > inputCollection, ICollection< TOutput > outputCollection=null)
 Transforms all elements from input collection to the output collection of the given type. More...
 
static ICollection< TOutput > CollectFromChild< TInput, TOutput > (IEnumerable< TInput > inputCollection, ICollection< TOutput > outputCollection=null)
 Transforms all elements from input collection to the output collection of the given type. Input collection type must extend output collection type More...
 
static bool ContainsAll< T > (ICollection< T > coll1, ICollection< T > coll2)
 Returns true iff all elements of coll2 are also contained in coll1. More...
 
static bool ContainsAny< T > (ICollection< T > coll1, ICollection< T > coll2)
 Returns true iff at least one element is in both collections. More...
 
static ICollection< T > Disjunction< T > (ICollection< T > coll1, ICollection< T > coll2)
 Returns a Collection containing the exclusive disjunction (symmetric difference) of the given collections. More...
 
static ICollection< T > EmptyCollection< T > ()
 Returns the immutable EMPTY_COLLECTION with generic type safety. More...
 
static ICollection< T > EmptyIfNull< T > (ICollection< T > collection)
 Returns an immutable empty collection if the argument is null, or the argument itself otherwise. More...
 
static ICollection< T > DefaultIfNull< T > (ICollection< T > collection, ICollection< T > defaultCollection)
 Returns the default collection if the argument is null, or the argument itself otherwise. More...
 
static bool IsEmpty< T > (IEnumerable< T > coll)
 Null-safe check if the specified collection is empty. Null returns true. More...
 
static bool IsNotEmpty< T > (IEnumerable< T > coll)
 Null-safe check if the specified collection is not empty. Null returns false. More...
 
static IDictionary< T, int > GetCardinalityMap< T > (IEnumerable< T > coll)
 Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurrences of that element in the Collection. Only those elements present in the collection will appear as keys in the map. More...
 
static bool IsSubCollection< T > (ICollection< T > a, ICollection< T > b)
 Returns true iff a is a sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a. More...
 
static bool IsProperSubCollection< T > (ICollection< T > a, ICollection< T > b)
 Returns true iff a is a proper sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a, and there is at least one element f such that the cardinality of f in b is strictly greater than the cardinality of f in a. More...
 
static bool IsEqualCollection< T > (ICollection< T > a, ICollection< T > b)
 Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities. i.e.,, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b. More...
 
static bool IsEqualCollection< T > (ICollection< T > a, ICollection< T > b, Predicate< T > predicate)
 Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities. i.e.,, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b. More...
 
static IList< T > Clone< T > (IList< T > collection)
 Creates and returns a new collection by cloning the existing collection More...
 
static ICollection< T > RemoveAll< T > (IList< T > collection, IList< T > remove)
 Removes the elements in remove from collection. That is, this method returns a collection containing all the elements in c that are not in remove This method is useful if you do not wish to modify the collection itself and thus cannot call collection.RemoveAll();. More...
 
static ICollection< string > FindWithRegEx (IEnumerable< string > collection, string regEx, RegexOptions options=RegexOptions.None)
 Finds and returns the elements matching the given regular expression More...
 
static int GetLength (this IEnumerable< object > collection)
 Gets the length of a collection. Null Safe More...
 

Properties

static string[] EmptyStringArray [get]
 Empty String Array More...
 

Detailed Description

Utility methods for collections.

Member Function Documentation

static bool Ultimate.Utilities.CollectionUtils.AddAll< T > ( ICollection< T >  collection,
IEnumerable< T >  elements 
)
static

Adds all elements in the enumeration to the given collection.

CollectionUtils.AddAll({ "Satish", "Kumar" }, { "Roronoa", "Zoro" })= { "Satish", "Kumar", "Roronoa", "Zoro" }

Template Parameters
T
Parameters
collectionThe collection to add to, must not be null
elementsThe enumeration of elements to add, must not be null
Returns
static bool Ultimate.Utilities.CollectionUtils.AddAllAtIndex< T > ( IList< T >  collection,
IList< T >  elements,
int  index,
bool  includeNulls = true 
)
static

Adds all elements to the given collection from a specified index

Template Parameters
T
Parameters
collectionThe collection to add to, must not be null
elementsThe list of elements to be added
indexindex from where the elements has to be inserted
includeNullsflag to add the null values also (default true)
Returns
static bool Ultimate.Utilities.CollectionUtils.AddAllIgnoreNull< T > ( ICollection< T >  collection,
ICollection< T >  elements 
)
static

Adds all non null elements in the enumeration to the given collection.

CollectionUtils.AddAllIgnoreNull({ "Satish", "Kumar" }, { "Roronoa", "Zoro",null })= { "Satish", "Kumar", "Roronoa", "Zoro" }

Template Parameters
T
Parameters
collectionThe collection to add to, must not be null
elementsThe enumeration of elements to add, must not be null
Returns
static bool Ultimate.Utilities.CollectionUtils.AddIgnoreNull< T > ( ICollection< T >  collection,
element 
)
static

Adds an element to the collection unless the element is null.

Template Parameters
Tthe type of object the Collection contains
Parameters
collectionthe collection to add to, must not be null
elementthe object to add, if null it will not be added
Returns
static IList<T> Ultimate.Utilities.CollectionUtils.Clone< T > ( IList< T >  collection)
static

Creates and returns a new collection by cloning the existing collection

Template Parameters
T
Parameters
collectioncollection to clone
Returns
a cloned copy of collection
static IList<T> Ultimate.Utilities.CollectionUtils.Collate< T > ( IEnumerable< T >  a,
IEnumerable< T >  b,
bool  includeDuplicates = true 
)
static

Combines two lists and sorts them by default

Parameters
aa - the first collection, must not be null
bb - the second collection, must not be null
includeDuplicatesmust be false if the duplicates should be removed (default true)
Template Parameters
T
Returns
Exceptions
NullReferenceException
static IList<T> Ultimate.Utilities.CollectionUtils.Collate< T > ( IEnumerable< T >  a,
IEnumerable< T >  b,
IComparer< T >  comparer,
bool  includeDuplicates = true 
)
static

Combines two lists and sorts them using the given comparer

Parameters
aa - the first collection, must not be null
bb - the second collection, must not be null
comparercomparer that must be used to sort the result
includeDuplicatesmust be false if the duplicates should be removed (default true)
Template Parameters
T
Returns
Exceptions
NullReferenceException
static ICollection<TOutput> Ultimate.Utilities.CollectionUtils.CollectFromChild< TInput, TOutput > ( IEnumerable< TInput >  inputCollection,
ICollection< TOutput >  outputCollection = null 
)
static

Transforms all elements from input collection to the output collection of the given type. Input collection type must extend output collection type

Template Parameters
TInputinput type
TOutputoutput type
Parameters
inputCollectionThe Input Collection to be converted
outputCollectionThe Output Collection
Type Constraints
TInput :TOutput 
static ICollection<TOutput> Ultimate.Utilities.CollectionUtils.CollectFromParent< TInput, TOutput > ( IEnumerable< TInput >  inputCollection,
ICollection< TOutput >  outputCollection = null 
)
static

Transforms all elements from input collection to the output collection of the given type.

Template Parameters
TInputinput type
TOutputoutput type
Parameters
inputCollectionThe Collection to be converted
outputCollectionThe output collection which is optional
Returns
output collection of given type
Type Constraints
TOutput :TInput 
static bool Ultimate.Utilities.CollectionUtils.ContainsAll< T > ( ICollection< T >  coll1,
ICollection< T >  coll2 
)
static

Returns true iff all elements of coll2 are also contained in coll1.

Template Parameters
T
Parameters
coll1coll1 - the first collection, must not be null
coll2coll2 - the second collection, must not be null
Returns
true iff the intersection of the collections has the same cardinality as the set of unique elements from the second collection
static bool Ultimate.Utilities.CollectionUtils.ContainsAny< T > ( ICollection< T >  coll1,
ICollection< T >  coll2 
)
static

Returns true iff at least one element is in both collections.

Template Parameters
T
Parameters
coll1coll1 - the first collection, must not be null
coll2coll2 - the second collection, must not be null
Returns
true iff the intersection of the collections is non-empty
static ICollection<T> Ultimate.Utilities.CollectionUtils.DefaultIfNull< T > ( ICollection< T >  collection,
ICollection< T >  defaultCollection 
)
static

Returns the default collection if the argument is null, or the argument itself otherwise.

Template Parameters
T
Parameters
collectioncollection - the collection, possibly null

///

Parameters
defaultCollectiondefaukt collection to be returned
Returns
given default collection if the argument is null
static ICollection<T> Ultimate.Utilities.CollectionUtils.Disjunction< T > ( ICollection< T >  coll1,
ICollection< T >  coll2 
)
static

Returns a Collection containing the exclusive disjunction (symmetric difference) of the given collections.

Template Parameters
T
Parameters
coll1coll1 - the first collection, must not be null
coll2coll2 - the second collection, must not be null
Returns
the symmetric difference of the two collections
static ICollection<T> Ultimate.Utilities.CollectionUtils.EmptyCollection< T > ( )
static

Returns the immutable EMPTY_COLLECTION with generic type safety.

Template Parameters
TT - the element type
Returns
immutable empty collection
static ICollection<T> Ultimate.Utilities.CollectionUtils.EmptyIfNull< T > ( ICollection< T >  collection)
static

Returns an immutable empty collection if the argument is null, or the argument itself otherwise.

Template Parameters
TT - the element type
Parameters
collectioncollection - the collection, possibly null
Returns
an empty collection if the argument is null
static ICollection<string> Ultimate.Utilities.CollectionUtils.FindWithRegEx ( IEnumerable< string >  collection,
string  regEx,
RegexOptions  options = RegexOptions.None 
)
static

Finds and returns the elements matching the given regular expression

Parameters
collectionthe input collection,must not be null
regExthe regular expression
optionsoptions for the regular expression, defualt no options applied
Returns
returns the collection of elements matching the regular expression
static IDictionary<T, int> Ultimate.Utilities.CollectionUtils.GetCardinalityMap< T > ( IEnumerable< T >  coll)
static

Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurrences of that element in the Collection. Only those elements present in the collection will appear as keys in the map.

Template Parameters
TT - the type of object in the returned Map. This is a super type of .
Parameters
collcoll - the collection to get the cardinality map for, must not be null
Returns
the populated cardinality map
static int Ultimate.Utilities.CollectionUtils.GetLength ( this IEnumerable< object >  collection)
static

Gets the length of a collection. Null Safe

Parameters
collectioninput collection
Returns
collection length or -1 if null
static bool Ultimate.Utilities.CollectionUtils.IsEmpty< T > ( IEnumerable< T >  coll)
static

Null-safe check if the specified collection is empty. Null returns true.

Template Parameters
T
Parameters
collcoll - the collection to check, may be null
Returns
true if empty or null
static bool Ultimate.Utilities.CollectionUtils.IsEqualCollection< T > ( ICollection< T >  a,
ICollection< T >  b 
)
static

Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities. i.e.,, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b.

Template Parameters
T
Parameters
aa - the first collection, must not be null
bb - the second collection, must not be null
Returns
true iff the collections contain the same elements with the same cardinalities.
static bool Ultimate.Utilities.CollectionUtils.IsEqualCollection< T > ( ICollection< T >  a,
ICollection< T >  b,
Predicate< T >  predicate 
)
static

Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities. i.e.,, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b.

Template Parameters
T
Parameters
aa - the first collection, must not be null
bb - the second collection, must not be null
predicatethe predicate passed to calculate the equality.The predicate method must be applied on the collection 'b' and should be expecting collection "a" element as parameter.(ex: (x)=>b.Any(i=>i.equals(x)))
Returns
true iff the collections contain the same elements matching the given predicate
static bool Ultimate.Utilities.CollectionUtils.IsNotEmpty< T > ( IEnumerable< T >  coll)
static

Null-safe check if the specified collection is not empty. Null returns false.

Template Parameters
T
Parameters
collcoll - the collection to check, may be null
Returns
true if non-null and non-empty
static bool Ultimate.Utilities.CollectionUtils.IsProperSubCollection< T > ( ICollection< T >  a,
ICollection< T >  b 
)
static

Returns true iff a is a proper sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a, and there is at least one element f such that the cardinality of f in b is strictly greater than the cardinality of f in a.

Template Parameters
T
Parameters
aa - the first (sub?) collection, must not be null
bb - the second (super?) collection, must not be null
Returns
true iff a is a proper sub-collection of b
static bool Ultimate.Utilities.CollectionUtils.IsSubCollection< T > ( ICollection< T >  a,
ICollection< T >  b 
)
static

Returns true iff a is a sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a.

Template Parameters
T
Parameters
aa - the first (sub?) collection, must not be null
bb - the second (super?) collection, must not be null
Returns
true iff a is a sub-collection of b
static ICollection<T> Ultimate.Utilities.CollectionUtils.RemoveAll< T > ( IList< T >  collection,
IList< T >  remove 
)
static

Removes the elements in remove from collection. That is, this method returns a collection containing all the elements in c that are not in remove This method is useful if you do not wish to modify the collection itself and thus cannot call collection.RemoveAll();.

Template Parameters
T
Parameters
collectioncollection - the collection from which items are removed (in the returned collection)
removeremove - the items to be removed from the returned collection
Returns
a Collection containing all the elements of collection except any elements that also occur in remove.

Property Documentation

string [] Ultimate.Utilities.CollectionUtils.EmptyStringArray
staticget

Empty String Array


The documentation for this class was generated from the following file: