Class CollectionUtils
This class provides the functionality not found in the .NET Collections classes.
Inherited Members
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
public abstract class CollectionUtils
Methods
AcquireReadLock(ICollection)
Acquire a read-lock on the supplied collection, if possible. While held, A read-lock prevents the given collection from being modified.
Declaration
public static void AcquireReadLock(ICollection col)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | The collection. |
Add(ICollection, object)
Adds a new element to the specified collection.
Declaration
public static bool Add(ICollection target, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | target | Collection where the new element will be added. |
| object | obj | Object to add. |
Returns
| Type | Description |
|---|---|
| bool | true if the element was added, false otherwise. |
Remarks
This method allows us to add element to any collection type from the System.Collections namespace in a uniform manner, thus hiding differences in the API between IList implementations and classes such as Queue and Stack. When collection is IDictionary object should be DictionaryEntry.
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | If |
Add(ICollection, object, bool)
Adds a new element to the specified collection.
Declaration
public static bool Add(ICollection target, object obj, bool isUnique)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | target | Collection where the new element will be added. |
| object | obj | Object to add. |
| bool | isUnique | true if the value should be unique in the target collection; false otherwise. |
Returns
| Type | Description |
|---|---|
| bool | true if the element was added, false otherwise. |
Remarks
This method allows us to add element to any collection type from the System.Collections namespace in a uniform manner, thus hiding differences in the API between IList implementations and classes such as Queue and Stack. When collection is IDictionary object should be DictionaryEntry.
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | If |
AddAll(ICollection, ICollection)
Adds all of the elements of the "source" collection to the "target" collection.
Declaration
public static bool AddAll(ICollection target, ICollection source)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | target | Collection where the new elements will be added. |
| ICollection | source | Collection whose elements will be added. |
Returns
| Type | Description |
|---|---|
| bool | true if at least one element was added, false otherwise. |
Remarks
This method allows us to add elements to any collection type from the System.Collections namespace in a uniform manner, thus hiding differences in the API between IList implementations and classes such as Queue and Stack.
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | If |
Clear(ICollection)
Clears specified collection.
Declaration
public static void Clear(ICollection col)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | Collection to clear. |
Remarks
This method allows us to clear any collection type from the System.Collections namespace in a uniform manner, thus hiding differences in the API between IList implementations and classes such as Queue and Stack.
Contains(ICollection, object)
Determines whether an element is in the collection.
Declaration
public static bool Contains(ICollection col, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | Collection where element is searched for. |
| object | obj | The object to locate in the collection. |
Returns
| Type | Description |
|---|---|
| bool | true if the element is found in the collection, false otherwise. |
Remarks
This method allows us to determine if an element is in any collection type from the System.Collections namespace since ICollection does not have method "Contains" defined in its interface. When collection is IDictionary object should be DictionaryEntry.
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | If |
ContainsAll(ICollection, ICollection)
Determines whether all elements from the source collection are contained in the target collection.
Declaration
public static bool ContainsAll(ICollection target, ICollection source)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | target | Collection where elements are searched for. |
| ICollection | source | Collection with objects to locate in the collection. |
Returns
| Type | Description |
|---|---|
| bool | true if all the elements are found in the collection, false otherwise. |
Remarks
When target collection is IDictionary, source collection elements should be DictionaryEntrys.
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | If |
See Also
EqualsArray<T>(T[], T[], IEqualityComparer)
Returns true if the two specified arrays are equal to one another. Two arrays are considered equal if both arrays contain the same number of elements, and all corresponding pairs of elements in the two arrays are equal. In other words, two arrays are equal if they contain the same elements in the same order. Also, two array references are considered equal if both are null
Declaration
public static bool EqualsArray<T>(T[] array1, T[] array2, IEqualityComparer comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array1 | One array to be tested for equality. |
| T[] | array2 | The other array to be tested for equality. |
| IEqualityComparer | comparer | Comparer to use when comparing elements. |
Returns
| Type | Description |
|---|---|
| bool | true if the two arrays are equal; otherwise false. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the array element. |
EqualsDeep(object, object)
Examines whether two parameters are two equal array objects.
Declaration
public static bool EqualsDeep(object obj1, object obj2)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj1 | Object to compare. |
| object | obj2 | Object to compare to. |
Returns
| Type | Description |
|---|---|
| bool | true if two objects are arrays and are of the same array type; otherwise false. |
GetBit(BitArray, int)
Get the value of the specified bit.
Declaration
public static bool GetBit(BitArray bits, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| BitArray | bits | The BitArray to get the bit from. |
| int | index | The bit index to get. |
Returns
| Type | Description |
|---|---|
| bool | The value of the bit or false if the index exceeds the length of the bits. |
HeadList(IDictionary, object)
Returns a portion of the list whose keys are less than the limit object parameter.
Declaration
public static SortedList HeadList(IDictionary dict, object limit)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary | dict | The list where the portion will be extracted. |
| object | limit | The end element of the portion to extract. |
Returns
| Type | Description |
|---|---|
| SortedList | The portion of the collection whose elements are less than the limit object parameter. |
Randomize(IList)
Randomize the order of the elements within the passed list.
Declaration
public static IList Randomize(IList list)
Parameters
| Type | Name | Description |
|---|---|---|
| IList | list | The list to randomize; the passed list is not altered. |
Returns
| Type | Description |
|---|---|
| IList | A new and immutable List whose contents are identical to those of the passed list except for the order in which they appear. |
Randomize<T>(IList<T>)
Randomize the order of the elements within the passed list.
Declaration
public static IList<T> Randomize<T>(IList<T> list)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<T> | list | The list to randomize; the passed list is not altered. |
Returns
| Type | Description |
|---|---|
| IList<T> | A new and immutable List whose contents are identical to those of the passed list except for the order in which they appear. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the element. |
Randomize<T>(T[])
Reorder elements of a type T array in a random way.
Declaration
public static T[] Randomize<T>(T[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | array | The array of type T objects to randomize. |
Returns
| Type | Description |
|---|---|
| T[] | The array of elements ordered in a random manner. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the element. |
ReleaseReadLock(ICollection)
Release a read-lock on the supplied collection.
Declaration
public static void ReleaseReadLock(ICollection col)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | The collection. |
Remove(ICollection, object)
Removes an element from the specified collection.
Declaration
public static bool Remove(ICollection col, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | Collection from which the element should be removed. |
| object | obj | Object to remove. |
Returns
| Type | Description |
|---|---|
| bool | true if the element was removed, false otherwise. |
Remarks
This method allows us to remove element from any collection type from the System.Collections namespace in a uniform manner, thus hiding differences in the API between IList implementations and classes such as Queue and Stack. When collection is IDictionary object should be DictionaryEntry.
RemoveAll(ICollection, ICollection)
Removes all elements contained in the source collection from the target collection.
Declaration
public static bool RemoveAll(ICollection target, ICollection source)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | target | Collection from which the elements should be removed. |
| ICollection | source | Collection of elements to remove. |
Returns
| Type | Description |
|---|---|
| bool | true if at least one element was removed, false otherwise. |
Remarks
When collection is IDictionary objects in source collection should be DictionaryEntrys.
RetainAll(ICollection, ICollection)
Removes all elements from the target collection that are not contained in the source collection.
Declaration
public static bool RetainAll(ICollection target, ICollection source)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | target | Collection from which the elements should be removed. |
| ICollection | source | Collection of elements not to remove. |
Returns
| Type | Description |
|---|---|
| bool | true if at least one element was removed, false otherwise. |
Remarks
When collection is IDictionary objects in source collection should be DictionaryEntrys.
SetBit(BitArray, int, bool)
Set the specified bit to the specified value.
Declaration
public static void SetBit(BitArray bits, int index, bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| BitArray | bits | The BitArray to modify. |
| int | index | The bit index to set. |
| bool | value | The value to set the bit to. |
TailList(IDictionary, object)
Returns a portion of the list whose keys are greater than the limit object parameter.
Declaration
public static SortedList TailList(IDictionary dict, object limit)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary | dict | The list where the portion will be extracted. |
| object | limit | The start element of the portion to extract. |
Returns
| Type | Description |
|---|---|
| SortedList | The portion of the collection whose elements are greater than the limit object parameter. |
ToArray(ICollection)
Returns an array containing all of the elements from the specified collection.
Declaration
public static object[] ToArray(ICollection col)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | Collection whose elements are copied to an array. |
Returns
| Type | Description |
|---|---|
| object[] | An array containing the elements of the collection. |
ToByteArray(sbyte[])
Convert an array of sbyte values to an array of corresponding byte values.
Declaration
public static byte[] ToByteArray(sbyte[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| sbyte[] | array | A sbyte array. |
Returns
| Type | Description |
|---|---|
| byte[] | A byte array. |
ToByteArrayUnchecked(sbyte[])
Convert an array of sbyte values to an array of corresponding byte values.
Declaration
public static byte[] ToByteArrayUnchecked(sbyte[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| sbyte[] | array | A sbyte array. |
Returns
| Type | Description |
|---|---|
| byte[] | A byte array. |
Remarks
Conversion of bytes is being executed as unchecked.
ToDelimitedString(ICollection, string)
Format the content of the passed Object array as a delimited string.
Declaration
public static string ToDelimitedString(ICollection col, string delim)
Parameters
| Type | Name | Description |
|---|---|---|
| ICollection | col | The array. |
| string | delim | The delimiter. |
Returns
| Type | Description |
|---|---|
| string | The formated string. |
ToSByteArray(byte[])
Convert an array of byte values to an array of corresponding sbyte values.
Declaration
public static sbyte[] ToSByteArray(byte[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | array | A byte array. |
Returns
| Type | Description |
|---|---|
| sbyte[] | A sbyte array. |
ToSByteArrayUnchecked(byte[])
Convert an array of byte values to an array of corresponding sbyte values.
Declaration
public static sbyte[] ToSByteArrayUnchecked(byte[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | array | A byte array. |
Returns
| Type | Description |
|---|---|
| sbyte[] | A sbyte array. |
Remarks
Conversion of bytes is being executed as unchecked.
TrimLeftZeroBytes(byte[])
Trim zero bytes from the beggining of the array.
Declaration
public static byte[] TrimLeftZeroBytes(byte[] array)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | array | Array to trim. |
Returns
| Type | Description |
|---|---|
| byte[] | Left trimmed array. |