You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
8 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace SharpCifs.Util.Sharpen
|
||
|
{
|
||
|
internal class EnumeratorWrapper<T> : Iterator<T>
|
||
7 years ago
|
{
|
||
|
object _collection;
|
||
|
IEnumerator<T> _e;
|
||
|
T _lastVal;
|
||
|
bool _more;
|
||
|
bool _copied;
|
||
8 years ago
|
|
||
7 years ago
|
public EnumeratorWrapper (object collection, IEnumerator<T> e)
|
||
|
{
|
||
|
this._e = e;
|
||
|
this._collection = collection;
|
||
|
_more = e.MoveNext ();
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public override bool HasNext ()
|
||
|
{
|
||
|
return _more;
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public override T Next ()
|
||
|
{
|
||
|
if (!_more)
|
||
|
throw new NoSuchElementException ();
|
||
|
_lastVal = _e.Current;
|
||
|
_more = _e.MoveNext ();
|
||
|
return _lastVal;
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
public override void Remove ()
|
||
|
{
|
||
|
ICollection<T> col = _collection as ICollection<T>;
|
||
|
if (col == null) {
|
||
|
throw new NotSupportedException ();
|
||
|
}
|
||
|
if (_more && !_copied) {
|
||
|
// Read the remaining elements, since the current enumerator
|
||
|
// will be invalid after removing the element
|
||
|
List<T> remaining = new List<T> ();
|
||
|
do {
|
||
|
remaining.Add (_e.Current);
|
||
|
} while (_e.MoveNext ());
|
||
|
_e = remaining.GetEnumerator ();
|
||
|
_e.MoveNext ();
|
||
|
_copied = true;
|
||
|
}
|
||
|
col.Remove (_lastVal);
|
||
|
}
|
||
|
}
|
||
8 years ago
|
}
|