/* * Copyright (c) 2005 Kazuya Ujihara * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it freely, * subject to the following restrictions: * 1. The origin of this software must not be misrepresented; * you must not claim that you wrote the original software. * If you use this software in a product, an acknowledgment * in the product documentation would be appreciated but is not required. * 2. Altered source versions must be plainly marked as such, * and must not be misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ package jp.ujihara.jsharp.util; import System.Collections.IEnumerator; import System.Collections.IEnumerable; import java.util.Iterator; import java.util.Enumeration; import java.util.ConcurrentModificationException; public class DotNetEnumerator implements IEnumerator { private final static Object NOT_INIT = new Object(); private Enumeration enumeration; private Object current; public DotNetEnumerator(Enumeration enumeration) { if (enumeration == null) throw new System.ArgumentNullException(); this.enumeration = enumeration; current = NOT_INIT; } public DotNetEnumerator(Iterator iterator) { this(new IteratorEnumeration(iterator)); } public boolean MoveNext() throws System.InvalidOperationException { try { boolean r = enumeration.hasMoreElements(); if (r) current = enumeration.nextElement(); return r; } catch (ConcurrentModificationException e) { throw new System.InvalidOperationException(e.getMessage(), e); } } public void Reset() throws System.InvalidOperationException { throw new System.InvalidOperationException(); } /** @property */ public Object get_Current() throws System.InvalidOperationException { if (current == NOT_INIT) throw new System.InvalidOperationException(); return current; } }