Exemple #1
0
        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);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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());
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 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;
 }
Exemple #6
0
        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++;
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
                }
            }
        }
Exemple #10
0
        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);
        }
Exemple #11
0
 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;
     }
 }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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;
            }
        }
Exemple #15
0
 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));
     }
 }
Exemple #16
0
 public void StopNext()
 {
     _next_tmp   = null;
     _next_count = 0;
 }
Exemple #17
0
 public ArrayNode()
 {
     this.next     = null;
     this.previous = null;
     this.data     = default(T);
 }
Exemple #18
0
 public void Dispose()
 {
     _close  = true;
     _length = 0;
     _items  = null;
 }