示例#1
0
文件: LinkedList.cs 项目: JvPost/AD
        public void RemoveAtIndex(int index)
        {
            if (index > Length - 1)
            {
                throw new IndexOutOfRangeException();
            }
            else if (index == Length - 1)
            {
                Pop();
            }
            else if (index == 0)
            {
                RemoveFirst();
            }
            else
            {
                LinkedListIterator <T> iter = this.Iterator();
                while (iter.CurrentIndex < index)
                {
                    iter.Next();
                }

                iter.Remove();

                Length--;
            }
        }
示例#2
0
文件: LinkedList.cs 项目: JvPost/AD
        public void Remove(T item)
        {
            LinkedListIterator <T> iter = this.Iterator();

            while (iter.HasNext())
            {
                if (iter.Next().Equals(item))
                {
                    iter.Remove();
                    Length--;
                }
            }
        }
示例#3
0
 private Event PeekEvent()
 {
     return(locker.Synchronized(() =>
     {
         LinkedListIterator <Event> i = iterator++;
         Event message = i.Value;
         LinkedListNode <Event> node = i.Node;
         if (node != null)
         {
             events.Remove(node);
             iterator.Remove(node);
         }
         return message;
     }));
 }
示例#4
0
 internal bool Stop(Timer timer)
 {
     lock (this)
     {
         if (_disposed)
         {
             return(false);
         }
         if (timer == null)
         {
             return(false);
         }
         LinkedListNode <Timer> n;
         if (!_m.TryGetValue(timer, out n))
         {
             return(false);
         }
         _s.Remove(n);
         _m.Remove(timer);
         _i.Remove(n);
         return(true);
     }
 }
示例#5
0
        private void handleFileSwap(LinkedListIterator<FileSystemEventArgs> renameIterator, LinkedListIterator<FileSystemEventArgs> deleteIterator)
        {
            FileSystemEventArgs delete = deleteIterator.Current;
            Utils.LinkedListIterator<FileSystemEventArgs> innerIterator = renameIterator.Clone();
            while (innerIterator.hasNext())
            {
                FileSystemEventArgs nextChange = innerIterator.Next();
                if(nextChange == delete) {
                    return;
                }
                RenamedEventArgs erlierRename = renameIterator.Current as RenamedEventArgs;
                RenamedEventArgs rename = nextChange as RenamedEventArgs;
                if (rename != null && Object.Equals(erlierRename.OldFullPath, rename.FullPath))
                {
                    //this is a file swap!
                    renameIterator.Remove();
                    innerIterator.Remove();
                    deleteIterator.Current = new FileSystemEventArgs(
                        WatcherChangeTypes.Changed,
                        Path.GetDirectoryName(erlierRename.OldFullPath),
                        Path.GetFileName(erlierRename.OldFullPath));

                    //remove any events related to temporary swap file (rename.OldFullPath)
                    string tmpFileFullPath = rename.OldFullPath;
                    Utils.LinkedListIterator<FileSystemEventArgs> tmpIterator = renameIterator.Clone();
                    while (tmpIterator.HasPrevious())
                    {
                        FileSystemEventArgs e = tmpIterator.Previous();
                        if(Object.Equals(e.FullPath, tmpFileFullPath))
                        {
                            if(e.ChangeType == WatcherChangeTypes.Renamed){
                                handleRenamed(tmpIterator);
                                if (tmpIterator.Current != null && tmpIterator.Current.ChangeType == WatcherChangeTypes.Renamed)
                                {
                                    tmpFileFullPath = ((RenamedEventArgs)tmpIterator.Current).OldFullPath;
                                }
                            }
                            if (tmpIterator.Current != null)
                            {
                                tmpIterator.Remove();
                            }
                        }
                    }
                }
            }
        }