Foley.Utilities.Collections
Class LinkedList

A Doubly-Linked List implementation of the Foley.Utilities.Collections.IList2 interface.

The Foley.Utilities.Collections.LinkedList can be used with all objects including null.

This class is not guaranteed to be thread safe.

The System.Collections.IEnumerator.MoveNext method of the System.Collections.IEnumerator that is returned from Foley.Utilities.Collections.LinkedList.GetEnumerator is fail-fast. That is, if the Foley.Utilities.Collections.LinkedList is modified after the enumerator is created it will throw a System.SystemException This behavior cannot be guaranteed, and should not be depended on.

Field Summary
int count
        Backer for property Foley.Utilities.Collections.LinkedList.Count
Foley.Utilities.Collections.LinkedList.Node headerNode
int modifications

Constructor Summary
LinkedList()
         Initializes a new instance of the LinkedList class that is empty.
LinkedList(System.Collections.ICollection collection)
         Initializes a new instance of the LinkedList class that contains elements copied from the specified collection.

Property Summary
int Count
         Gets the number of elements contained in the LinkedList.
object Item[int index]
         Gets or sets the System.Object at the specified index. In C#, this property is the indexer for the Foley.Utilities.Collections.LinkedList class.

Properties inherited from class Foley.Utilities.Collections.Collection2Base
IsEmpty, IsFixedSize, IsReadOnly, IsSynchronized, SyncRoot

Method Summary
int Add(object value)
         Adds an System.Object to the end of the Foley.Utilities.Collections.LinkedList.
bool Add(System.Collections.ICollection collection)
         Adds the elements of an System.Collections.ICollection to the end of the Foley.Utilities.Collections.LinkedList.
void Clear()
         Removes all elements from the Foley.Utilities.Collections.LinkedList.
object Clone()
         Creates a shallow copy of the Foley.Utilities.Collections.LinkedList.
Foley.Utilities.Collections.LinkedList Clone(bool attemptDeepCopy)
         Attempts to make a deep copy of the Foley.Utilities.Collections.LinkedList.
bool Contains(object value)
         Determines whether the specified System.Object is in the Foley.Utilities.Collections.LinkedList.
bool Contains(System.Collections.ICollection collection)
         Determines whether all the elements in the specified collection are contained in the Foley.Utilities.Collections.LinkedList contains.
void CopyTo(System.Array array, int index)
         Copies the entire Foley.Utilities.Collections.LinkedList to a compatible one-dimensional System.Array, starting at the specified index of the target array.
Foley.Utilities.Collections.LinkedList.Node FindNodeAt(int index)
         Returns the Foley.Utilities.Collections.LinkedList.Node at the provided index.
System.Collections.IEnumerator GetEnumerator(int index)
         Returns an System.Collections.IEnumerator that can iterate through the Foley.Utilities.Collections.LinkedList that starts at the specified position.
System.Collections.IEnumerator GetEnumerator()
         Returns an System.Collections.IEnumerator for the entire Foley.Utilities.Collections.LinkedList.
int IndexOf(object value)
         Searches for the specified System.Object and returns the zero-based index of the first occurrence within the Foley.Utilities.Collections.LinkedList.
bool Insert(int index, System.Collections.ICollection collection)
         Inserts all the elements of an System.Collections.ICollection starting at a index in the Foley.Utilities.Collections.LinkedList.
bool Insert(int index, object value)
         Inserts an System.Object into the Foley.Utilities.Collections.LinkedList at the specified index.
int LastIndexOf(object value)
         Determines the index of the last occurrence of the specific System.Object in the Foley.Utilities.Collections.LinkedList.
bool Remove(System.Collections.ICollection collection)
         Removes the first occurrence of each element of the specified System.Collections.ICollection from the Foley.Utilities.Collections.LinkedList.
bool Remove(int index, int count)
         Removes the specified number of the elements starting at the position specified in the Foley.Utilities.Collections.LinkedList.
bool Remove(object value)
         Removes the first occurrence of a specific System.Object from the Foley.Utilities.Collections.LinkedList.
bool Remove(Foley.Utilities.Collections.LinkedList.Node value)
         Removes the Foley.Utilities.Collections.LinkedList.Node from the Foley.Utilities.Collections.LinkedList.
bool RemoveAt(int index)
         Removes the elements at the specified position of the Foley.Utilities.Collections.LinkedList.
bool Retain(System.Collections.ICollection collection)
         Retains the first occurrence of each element of the specified System.Collections.ICollection in the Foley.Utilities.Collections.LinkedList.
System.Collections.IList SubList(int index, int count)
         Provides a view of the Foley.Utilities.Collections.LinkedList with the specified number of the elements starting at the position specified.

Methods inherited from class Foley.Utilities.Collections.List2Base
IList.Insert, IList.Remove, IList.RemoveAt

Methods inherited from class Foley.Utilities.Collections.Collection2Base
IsContainedIn

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Field Detail

count

private int count

Backer for property Foley.Utilities.Collections.LinkedList.Count


headerNode

private Foley.Utilities.Collections.LinkedList.Node headerNode


modifications

private int modifications

Constructor Detail

LinkedList

public LinkedList()

Initializes a new instance of the LinkedList class that is empty.


LinkedList

public LinkedList(System.Collections.ICollection collection)

Initializes a new instance of the LinkedList class that contains elements copied from the specified collection.

Parameters:
collection - The ICollection whose elements are copied to the new list.
Property Detail

Count

public int Count

Gets the number of elements contained in the LinkedList.

Value:
The number of elements actually contained in the LinkedList.

Item

public object this[int index]

Gets or sets the System.Object at the specified index. In C#, this property is the indexer for the Foley.Utilities.Collections.LinkedList class.

Parameters:
index - The zero-based index of the element to get or set.
Value:
The element at the specified index.
Method Detail

Add

public int Add(object value)

Adds an System.Object to the end of the Foley.Utilities.Collections.LinkedList.

Parameters:
value - The System.Object to be added to the end of the Foley.Utilities.Collections.LinkedList
Returns:
The zero-based index at which the value was added.

Add

public bool Add(System.Collections.ICollection collection)

Adds the elements of an System.Collections.ICollection to the end of the Foley.Utilities.Collections.LinkedList.

Parameters:
collection - The System.Collections.ICollection whose elements are added to the end of the Foley.Utilities.Collections.LinkedList.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.
Throws:
System.NullReferenceException - The collection is a null reference (Nothing in Visual Basic).

Clear

public void Clear()

Removes all elements from the Foley.Utilities.Collections.LinkedList.


Clone

public object Clone()

Creates a shallow copy of the Foley.Utilities.Collections.LinkedList.

If you need a deep copy to be attempted use the Foley.Utilities.Collections.LinkedList.Clone(System.Boolean) method.

Returns:
A shallow copy of the Foley.Utilities.Collections.LinkedList.

Clone

public Foley.Utilities.Collections.LinkedList Clone(bool attemptDeepCopy)

Attempts to make a deep copy of the Foley.Utilities.Collections.LinkedList.

Attempts to make a deep copy if attemptDeepCopy is true. It will attempt this by checking if an System.Object is an System.ICloneable, and then defer the process to its Clone method.

If a true deep copy is important, please check the API documentation for the elements that are contained in the list to verify how their Clone method is implemented.

Parameters:
attemptDeepCopy - If true will attempt to make a deep copy, if false it will just return a shallow copy
Returns:
A cloned Foley.Utilities.Collections.LinkedList.
Throws:
System.SystemException - If and System.Object in the list is not an System.ICloneable.
System.SystemException - At the first System.Object that is not an System.ICloneable when attemptDeepCopy is true.

Contains

public bool Contains(object value)

Determines whether the specified System.Object is in the Foley.Utilities.Collections.LinkedList.

This method determines equality by calling System.Object.Equals(System.Object).

Parameters:
value - The System.Object to locate in the Foley.Utilities.Collections.LinkedList. The System.Object to locate can be a null reference (Nothing in Visual Basic).
Returns:
true if value is found in the Foley.Utilities.Collections.LinkedList; otherwise, false.

Contains

public bool Contains(System.Collections.ICollection collection)

Determines whether all the elements in the specified collection are contained in the Foley.Utilities.Collections.LinkedList contains.

Parameters:
collection - The System.Collections.ICollection whose elements are to be checked if all of its elements are contained in the list.
Returns:
true if all the elements of the System.Collections.ICollection are found in the Foley.Utilities.Collections.LinkedList; otherwise, false.
Throws:
System.NullReferenceException - The collection is a null reference (Nothing in Visual Basic).

CopyTo

public void CopyTo(System.Array array,
                   int index)

Copies the entire Foley.Utilities.Collections.LinkedList to a compatible one-dimensional System.Array, starting at the specified index of the target array.

Parameters:
array - The one-dimensional System.Array that is the destination of the elements copied from the Foley.Utilities.Collections.LinkedList. The System.Array must have zero-based indexing.
index - The zero-based index in array at which copying begins.
Throws:
System.ArgumentNullException - The array is a null reference (Nothing in Visual Basic).
System.ArgumentOutOfRangeException - The index is less than zero.
System.ArgumentException - The array is multidimensional. -or- The index is equal to or greater than the length of array. -or-The number of elements in the Foley.Utilities.Collections.LinkedList is greater than the available space from index to the end of the destination array.

FindNodeAt

private Foley.Utilities.Collections.LinkedList.Node FindNodeAt(int index)

Returns the Foley.Utilities.Collections.LinkedList.Node at the provided index.

Parameters:
index - The zero-based index of the Foley.Utilities.Collections.LinkedList.Node.
Returns:
The Foley.Utilities.Collections.LinkedList.Node at the provided index.
Throws:
System.IndexOutOfRangeException - If the index is invalid.

GetEnumerator

public System.Collections.IEnumerator GetEnumerator(int index)

Returns an System.Collections.IEnumerator that can iterate through the Foley.Utilities.Collections.LinkedList that starts at the specified position.

Parameters:
index - Starting index in the list for the begining of the System.Collections.IEnumerator.
Returns:
An System.Collections.IEnumerator that can be used to iterate through the Foley.Utilities.Collections.LinkedList.

GetEnumerator

public System.Collections.IEnumerator GetEnumerator()

Returns an System.Collections.IEnumerator for the entire Foley.Utilities.Collections.LinkedList.

Returns:
An System.Collections.IEnumerator for the entire Foley.Utilities.Collections.LinkedList.

IndexOf

public int IndexOf(object value)

Searches for the specified System.Object and returns the zero-based index of the first occurrence within the Foley.Utilities.Collections.LinkedList.

Parameters:
value - The System.Object to locate in the Foley.Utilities.Collections.LinkedList.
Returns:
The zero-based index of the first occurrence of value within the Foley.Utilities.Collections.LinkedList, if found; otherwise, -1.

Insert

public bool Insert(int index,
                   System.Collections.ICollection collection)

Inserts all the elements of an System.Collections.ICollection starting at a index in the Foley.Utilities.Collections.LinkedList.

Parameters:
index - The index in the Foley.Utilities.Collections.LinkedList to starting inserting the elements of the provided System.Collections.ICollection.
collection - The System.Collections.ICollection whose elements should be inserted to the Foley.Utilities.Collections.LinkedList.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.
Throws:
System.NullReferenceException - The collection is a null reference (Nothing in Visual Basic).
System.ArgumentOutOfRangeException - The index is less than zero.

Insert

public bool Insert(int index,
                   object value)

Inserts an System.Object into the Foley.Utilities.Collections.LinkedList at the specified index.

Parameters:
index - The zero-based index at which value should be inserted.
value - The System.Object to insert.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.

LastIndexOf

public int LastIndexOf(object value)

Determines the index of the last occurrence of the specific System.Object in the Foley.Utilities.Collections.LinkedList.

Parameters:
value - The System.Object to locate in the Foley.Utilities.Collections.LinkedList.
Returns:
The index of the last occurrence of the value if found in the Foley.Utilities.Collections.LinkedList; otherwise, -1.

Remove

public bool Remove(System.Collections.ICollection collection)

Removes the first occurrence of each element of the specified System.Collections.ICollection from the Foley.Utilities.Collections.LinkedList.

Parameters:
collection - The System.Collections.ICollection used to determine what elements to remove from the Foley.Utilities.Collections.LinkedList.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.

Remove

public bool Remove(int index,
                   int count)

Removes the specified number of the elements starting at the position specified in the Foley.Utilities.Collections.LinkedList.

Parameters:
index - Starting position for removing elements from the Foley.Utilities.Collections.LinkedList.
count - The number of elements to remove from the Foley.Utilities.Collections.LinkedList.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.

Remove

public bool Remove(object value)

Removes the first occurrence of a specific System.Object from the Foley.Utilities.Collections.LinkedList.

Parameters:
value - The System.Object to remove from the Foley.Utilities.Collections.LinkedList.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.

Remove

private bool Remove(Foley.Utilities.Collections.LinkedList.Node value)

Removes the Foley.Utilities.Collections.LinkedList.Node from the Foley.Utilities.Collections.LinkedList.

This removal adjusts the remaining Foley.Utilities.Collections.LinkedList.Node accordingly.

Parameters:
value -

RemoveAt

public bool RemoveAt(int index)

Removes the elements at the specified position of the Foley.Utilities.Collections.LinkedList.

Parameters:
index - The zero-based index of the elements to remove.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.

Retain

public bool Retain(System.Collections.ICollection collection)

Retains the first occurrence of each element of the specified System.Collections.ICollection in the Foley.Utilities.Collections.LinkedList.

Parameters:
collection - The System.Collections.ICollection used to determine what elements to be retained in the Foley.Utilities.Collections.LinkedList.
Returns:
true if the Foley.Utilities.Collections.LinkedList is modified; otherwise false.

SubList

public System.Collections.IList SubList(int index,
                                        int count)

Provides a view of the Foley.Utilities.Collections.LinkedList with the specified number of the elements starting at the position specified.

Parameters:
index - Starting position for the view of elements from the Foley.Utilities.Collections.LinkedList.
count - The number of elements to include in the view of the Foley.Utilities.Collections.LinkedList.
Returns:
A view of Foley.Utilities.Collections.LinkedList.