1: /// <summary>
2: /// Provides an adapter that can convert a Java
3: /// Enumeration class into something that implements
4: /// IEnumerator.
5: /// </summary>
6: public class EnumeratorEnumerationAdapter : IEnumerator
7: {
8: #region Private Fields
9:
10: /// <summary>
11: /// The class being adapted.
12: /// </summary>
13: private Enumeration mEnumeration;
14:
15: /// <summary>
16: /// The current object.
17: /// </summary>
18: private object mCurrent;
19:
20: #endregion
21:
22: #region Implementation of IEnumerator
23:
24: /// <summary>
25: /// Advances the enumerator to the next element of the collection.
26: /// </summary>
27: /// <returns>
28: /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
29: /// </returns>
30: /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception><filterpriority>2</filterpriority>
31: public bool MoveNext()
32: {
33: if (!mEnumeration.hasMoreElements())
34: {
35: return false;
36: }
37:
38: mCurrent = mEnumeration.nextElement();
39: return true;
40: }
41:
42: /// <summary>
43: /// Sets the enumerator to its initial position, which is before the first element in the collection.
44: /// </summary>
45: /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception><filterpriority>2</filterpriority>
46: public void Reset()
47: {
48: throw new NotSupportedException();
49: }
50:
51: /// <summary>
52: /// Gets the current element in the collection.
53: /// </summary>
54: /// <returns>
55: /// The current element in the collection.
56: /// </returns>
57: /// <exception cref="T:System.InvalidOperationException">The enumerator is positioned before the first element of the collection or after the last element.-or- The collection was modified after the enumerator was created.</exception><filterpriority>2</filterpriority>
58: public object Current
59: {
60: get
61: {
62: return mCurrent;
63: }
64: }
65:
66: #endregion
67:
68: #region Public Constructors
69:
70: /// <summary>
71: /// Creates an adapter for the specified enumeration.
72: /// </summary>
73: /// <param name="enumeration"></param>
74: public EnumeratorEnumerationAdapter(Enumeration enumeration)
75: {
76: mEnumeration = enumeration;
77: mCurrent = null;
78: }
79:
80: #endregion
81: }