![]() |
Ultimate.Utilities.Docs
|
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... | |
Utility methods for collections.
|
static |
Adds all elements in the enumeration to the given collection.
CollectionUtils.AddAll({ "Satish", "Kumar" }, { "Roronoa", "Zoro" })= { "Satish", "Kumar", "Roronoa", "Zoro" }
T |
collection | The collection to add to, must not be null |
elements | The enumeration of elements to add, must not be null |
|
static |
Adds all elements to the given collection from a specified index
T |
collection | The collection to add to, must not be null |
elements | The list of elements to be added |
index | index from where the elements has to be inserted |
includeNulls | flag to add the null values also (default true) |
|
static |
Adds all non null elements in the enumeration to the given collection.
CollectionUtils.AddAllIgnoreNull({ "Satish", "Kumar" }, { "Roronoa", "Zoro",null })= { "Satish", "Kumar", "Roronoa", "Zoro" }
T |
collection | The collection to add to, must not be null |
elements | The enumeration of elements to add, must not be null |
|
static |
Adds an element to the collection unless the element is null.
T | the type of object the Collection contains |
collection | the collection to add to, must not be null |
element | the object to add, if null it will not be added |
|
static |
Creates and returns a new collection by cloning the existing collection
T |
collection | collection to clone |
|
static |
Combines two lists and sorts them by default
a | a - the first collection, must not be null |
b | b - the second collection, must not be null |
includeDuplicates | must be false if the duplicates should be removed (default true) |
T |
NullReferenceException |
|
static |
Combines two lists and sorts them using the given comparer
a | a - the first collection, must not be null |
b | b - the second collection, must not be null |
comparer | comparer that must be used to sort the result |
includeDuplicates | must be false if the duplicates should be removed (default true) |
T |
NullReferenceException |
|
static |
Transforms all elements from input collection to the output collection of the given type. Input collection type must extend output collection type
TInput | input type |
TOutput | output type |
inputCollection | The Input Collection to be converted |
outputCollection | The Output Collection |
TInput | : | TOutput |
|
static |
Transforms all elements from input collection to the output collection of the given type.
TInput | input type |
TOutput | output type |
inputCollection | The Collection to be converted |
outputCollection | The output collection which is optional |
TOutput | : | TInput |
|
static |
Returns true iff all elements of coll2 are also contained in coll1.
T |
coll1 | coll1 - the first collection, must not be null |
coll2 | coll2 - the second collection, must not be null |
|
static |
Returns true iff at least one element is in both collections.
T |
coll1 | coll1 - the first collection, must not be null |
coll2 | coll2 - the second collection, must not be null |
|
static |
Returns the default collection if the argument is null, or the argument itself otherwise.
T |
collection | collection - the collection, possibly null |
///
defaultCollection | defaukt collection to be returned |
|
static |
Returns a Collection containing the exclusive disjunction (symmetric difference) of the given collections.
T |
coll1 | coll1 - the first collection, must not be null |
coll2 | coll2 - the second collection, must not be null |
|
static |
Returns the immutable EMPTY_COLLECTION with generic type safety.
T | T - the element type |
|
static |
Returns an immutable empty collection if the argument is null, or the argument itself otherwise.
T | T - the element type |
collection | collection - the collection, possibly null |
|
static |
Finds and returns the elements matching the given regular expression
collection | the input collection,must not be null |
regEx | the regular expression |
options | options for the regular expression, defualt no options applied |
|
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.
T | T - the type of object in the returned Map. This is a super type of . |
coll | coll - the collection to get the cardinality map for, must not be null |
|
static |
Gets the length of a collection. Null Safe
collection | input collection |
|
static |
Null-safe check if the specified collection is empty. Null returns true.
T |
coll | coll - the collection to check, may be null |
|
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.
T |
a | a - the first collection, must not be null |
b | b - the second collection, must not be null |
|
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.
T |
a | a - the first collection, must not be null |
b | b - the second collection, must not be null |
predicate | the 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))) |
|
static |
Null-safe check if the specified collection is not empty. Null returns false.
T |
coll | coll - the collection to check, may be null |
|
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.
T |
a | a - the first (sub?) collection, must not be null |
b | b - the second (super?) collection, must not be null |
|
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.
T |
a | a - the first (sub?) collection, must not be null |
b | b - the second (super?) collection, must not be null |
|
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();.
T |
collection | collection - the collection from which items are removed (in the returned collection) |
remove | remove - the items to be removed from the returned collection |
|
staticget |
Empty String Array