public override bool Equals(object o) { if (o == (object)this) { return(true); } Array <object> array = (Array <object>)o; int n = _length; if (n != array._length) { return(false); } ArrayNode <T> items1 = this._items; ArrayNode <object> items2 = array._items; for (int i = 0; i < n; i++) { object o1 = items1.next; object o2 = items2.next; if (!((o1 == null) ? o2 == null : o1.Equals(o2))) { return(false); } } return(true); }
public T Get(int idx) { if (_close) { return(default(T)); } int size = _length - 1; if (0 <= idx && idx <= size) { ArrayNode <T> o = this._items.next; int count = 0; for (; count < idx;) { o = o.next; count++; } return(o.data); } else if (idx == size) { return(_items.data); } return(default(T)); }
public string ToString(char split) { if (IsEmpty()) { return("[]"); } ArrayNode <T> o = this._items.next; System.Text.StringBuilder buffer = new System.Text.StringBuilder( CollectionUtils.INITIAL_CAPACITY); buffer.Append('['); int count = 0; for (; o != this._items;) { buffer.Append(o.data); if (count != _length - 1) { buffer.Append(split); } o = o.next; count++; } buffer.Append(']'); return(buffer.ToString()); }
public bool Remove(int idx) { if (_close) { return(false); } int size = _length - 1; if (0 <= idx && idx <= size) { ArrayNode <T> o = this._items.next; int count = 0; for (; count < idx;) { o = o.next; count++; } return(Remove(o.data)); } else if (idx == size) { return(Remove(_items.data)); } return(false); }
public void Clear() { this._close = false; this._length = 0; this.StopNext(); this.StopPrevious(); this._items = null; this._items = new ArrayNode <T>(); this._items.next = this._items; this._items.previous = this._items; }
public void AddFront(T data) { if (_close) { return; } ArrayNode <T> newNode = new ArrayNode <T>(); newNode.data = data; newNode.next = this._items.next; this._items.next.previous = newNode; this._items.next = newNode; newNode.previous = this._items; _length++; }
public bool Remove(T data) { if (_close) { return(false); } ArrayNode <T> toDelete = this.Find(data); if (toDelete != this._items && toDelete != null) { toDelete.previous.next = toDelete.next; toDelete.next.previous = toDelete.previous; _length--; return(true); } return(false); }
public ArrayNode <T> Find(T data) { if (_close) { return(null); } ArrayNode <T> o = this._items.next; for (; o != this._items && !data.Equals(o.data);) { o = o.next; } if (o == this._items) { return(null); } return(o); }
public void Add(T data) { ArrayNode <T> newNode = new ArrayNode <T>(); ArrayNode <T> o = this._items.next; newNode.data = data; if (o == this._items) { this.AddFront(data); } else { for (; o != this._items;) { o = o.next; } if (o == this._items) { this.AddBack(newNode.data); } } }
public bool Contains(T data, bool identity) { if (_close) { return(false); } ArrayNode <T> o = this._items.next; for (; o != this._items;) { if ((identity || data == null) && (object)o.data == (object)data) { return(true); } else if (data.Equals(o.data)) { return(true); } o = o.next; } return(false); }
public void InsertBetween(ArrayNode <T> previous, ArrayNode <T> next, ArrayNode <T> newNode) { if (_close) { return; } if (previous == this._items && next != this._items) { this.AddFront(newNode.data); } else if (previous != this._items && next == this._items) { this.AddBack(newNode.data); } else { newNode.next = next; newNode.previous = previous; previous.next = newNode; next.previous = newNode; } }
public int LastIndexOf(T data, bool identity) { if (_close) { return(-1); } int count = _length - 1; ArrayNode <T> o = this._items.previous; for (; o != this._items && count > 0;) { if ((identity || data == null) && (object)o.data == (object)data) { return(count); } else if (data.Equals(o.data)) { return(count); } o = o.previous; count--; } return(-1); }
public int IndexOf(T data, bool identity) { if (_close) { return(-1); } int count = 0; ArrayNode <T> o = this._items.next; for (; o != this._items && count < _length;) { if ((identity || data == null) && (object)o.data == (object)data) { return(count); } else if (data.Equals(o.data)) { return(count); } o = o.next; count++; } return(-1); }
public void Set(int idx, T v) { if (_close) { return; } int size = _length - 1; if (0 <= idx && idx <= size) { ArrayNode <T> o = this._items.next; int count = 0; for (; count < idx;) { o = o.next; count++; } o.data = v; } else if (idx == size) { _items.data = v; } }
public T Next() { if (IsEmpty()) { return(default(T)); } if (_next_count == 0) { _next_tmp = this._items.next; _next_count++; return(_next_tmp.data); } if (_next_tmp != this._items && _next_count < _length) { _next_tmp = _next_tmp.next; _next_count++; return(_next_tmp.data); } else { StopNext(); return(default(T)); } }
public void StopNext() { _next_tmp = null; _next_count = 0; }
public ArrayNode() { this.next = null; this.previous = null; this.data = default(T); }
public void Dispose() { _close = true; _length = 0; _items = null; }