public void FilledList_NavigateForwardAndRemoval() { var list = new LinkedList<int>(); list.AddLast(1); list.AddLast(2); list.AddLast(3); var iter = new LinkedListIterator<int>(list); Assert.AreEqual(3, list.Count); Assert.IsTrue(iter.hasNext()); Assert.AreEqual(1, iter.next()); iter.remove(); Assert.IsTrue(iter.hasNext()); Assert.AreEqual(2, iter.next()); Assert.IsTrue(iter.hasNext()); Assert.AreEqual(3, iter.next()); Assert.AreEqual(2, list.Count); AssertEndOfListHasBeenReached(iter); }
public void FilledList_NavigateForwardAndRemoval() { var list = new LinkedList <int>(); list.AddLast(1); list.AddLast(2); list.AddLast(3); var iter = new LinkedListIterator <int>(list); Assert.AreEqual(3, list.Count); Assert.IsTrue(iter.hasNext()); Assert.AreEqual(1, iter.next()); iter.remove(); Assert.IsTrue(iter.hasNext()); Assert.AreEqual(2, iter.next()); Assert.IsTrue(iter.hasNext()); Assert.AreEqual(3, iter.next()); Assert.AreEqual(2, list.Count); AssertEndOfListHasBeenReached(iter); }
private bool DownloadPackedObject(ProgressMonitor monitor, AnyObjectId id) { // Search for the object in a remote pack whose index we have, // but whose pack we do not yet have. // var iter = new LinkedListIterator <RemotePack>(_unfetchedPacks); while (iter.hasNext() && !monitor.IsCancelled) { RemotePack pack = iter.next(); try { pack.OpenIndex(monitor); } catch (IOException err) { // If the index won't open its either not found or // its a format we don't recognize. In either case // we may still be able to obtain the object from // another source, so don't consider it a failure. // RecordError(id, err); iter.remove(); continue; } if (monitor.IsCancelled) { // If we were cancelled while the index was opening // the open may have aborted. We can't search an // unopen index. // return(false); } if (!pack.Index.HasObject(id)) { // Not in this pack? Try another. // continue; } // It should be in the associated pack. Download that // and attach it to the local repository so we can use // all of the contained objects. // try { pack.DownloadPack(monitor); } catch (IOException err) { // If the pack failed to download, index correctly, // or open in the local repository we may still be // able to obtain this object from another pack or // an alternate. // RecordError(id, err); continue; } finally { // If the pack was good its in the local repository // and Repository.hasObject(id) will succeed in the // future, so we do not need this data anymore. If // it failed the index and pack are unusable and we // shouldn't consult them again. // pack.TmpIdx.DeleteFile(); iter.remove(); } if (!_local.HasObject(id)) { // What the hell? This pack claimed to have // the object, but after indexing we didn't // actually find it in the pack. // RecordError(id, new FileNotFoundException("Object " + id.Name + " not found in " + pack.PackName + ".")); continue; } // Complete any other objects that we can. // IIterator <ObjectId> pending = SwapFetchQueue(); while (pending.hasNext()) { ObjectId p = pending.next(); if (pack.Index.HasObject(p)) { pending.remove(); Process(p); } else { _workQueue.AddLast(p); } } return(true); } return(false); }
public override void Close() { IOException err = null; for (var i = new LinkedListIterator<Stream>(_streams); i.hasNext(); ) { try { i.next().Dispose(); } catch (IOException closeError) { err = closeError; } i.remove(); } if (err != null) throw err; }
private bool DownloadPackedObject(ProgressMonitor monitor, AnyObjectId id) { // Search for the object in a remote pack whose index we have, // but whose pack we do not yet have. // var iter = new LinkedListIterator<RemotePack>(_unfetchedPacks); while (iter.hasNext() && !monitor.IsCancelled) { RemotePack pack = iter.next(); try { pack.OpenIndex(monitor); } catch (IOException err) { // If the index won't open its either not found or // its a format we don't recognize. In either case // we may still be able to obtain the object from // another source, so don't consider it a failure. // RecordError(id, err); iter.remove(); continue; } if (monitor.IsCancelled) { // If we were cancelled while the index was opening // the open may have aborted. We can't search an // unopen index. // return false; } if (!pack.Index.HasObject(id)) { // Not in this pack? Try another. // continue; } // It should be in the associated pack. Download that // and attach it to the local repository so we can use // all of the contained objects. // try { pack.DownloadPack(monitor); } catch (IOException err) { // If the pack failed to download, index correctly, // or open in the local repository we may still be // able to obtain this object from another pack or // an alternate. // RecordError(id, err); continue; } finally { // If the pack was good its in the local repository // and Repository.hasObject(id) will succeed in the // future, so we do not need this data anymore. If // it failed the index and pack are unusable and we // shouldn't consult them again. // pack.TmpIdx.DeleteFile(); iter.remove(); } if (!_local.HasObject(id)) { // What the hell? This pack claimed to have // the object, but after indexing we didn't // actually find it in the pack. // RecordError(id, new FileNotFoundException("Object " + id.Name + " not found in " + pack.PackName + ".")); continue; } // Complete any other objects that we can. // IIterator<ObjectId> pending = SwapFetchQueue(); while (pending.hasNext()) { ObjectId p = pending.next(); if (pack.Index.HasObject(p)) { pending.remove(); Process(p); } else _workQueue.AddLast(p); } return true; } return false; }