/*
 * Copyright (c) 2009 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 *
 */

package com.jscape.util.collections;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * @author Alex Usun
 */
public class EnumerationIterator<T>
        implements Iterator<T> {

    private final Enumeration<T> base;

    @SuppressWarnings("unchecked")
    public static <T> Iterator<T> iterator(Enumeration<T> data) {
        return new EnumerationIterator<T>(data);
    }

    @SuppressWarnings("unchecked")
    public static <T> Iterable<T> iterable(final Enumeration data) {
        return new Iterable<T>() {
            @Override
            public Iterator<T> iterator() {
                return EnumerationIterator.iterator(data);
            }
        };
    }

    public EnumerationIterator(Enumeration<T> base) {
        this.base = base;
    }

    @Override
    public boolean hasNext() {
        return this.base.hasMoreElements();
    }

    @Override
    public T next() {
        return this.base.nextElement();
    }

    @Override
    public void remove() {
        throw new UnsupportedOperationException("Remove operation not supported.");
    }
}
