001 /*
002 * This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 * This file is licensed to You under the Eclipse Public License (EPL);
005 * You may not use this file except in compliance with the License. You
006 * may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 * See the COPYRIGHT.txt file distributed with this work for information
011 * regarding copyright ownership.
012 */
013 package org.jikesrvm.compilers.opt.util;
014
015 import java.util.Enumeration;
016 import java.util.Iterator;
017
018
019 public abstract class GraphNodeEnumerator implements GraphNodeEnumeration {
020
021 public final GraphNode nextElement() { return next(); }
022
023 public static GraphNodeEnumerator create(Enumeration<GraphNode> e) {
024 return new Enum(e);
025 }
026
027 public static GraphNodeEnumerator create(Iterator<GraphNode> i) {
028 return new Iter(i);
029 }
030
031 public static GraphNodeEnumerator create(Iterable<GraphNode> i) {
032 return new Iter(i.iterator());
033 }
034
035 private static final class Enum extends GraphNodeEnumerator {
036 private final Enumeration<GraphNode> e;
037
038 Enum(Enumeration<GraphNode> e) {
039 this.e = e;
040 }
041
042 public boolean hasMoreElements() { return e.hasMoreElements(); }
043
044 public GraphNode next() { return e.nextElement(); }
045 }
046
047 private static final class Iter extends GraphNodeEnumerator {
048 private final Iterator<GraphNode> i;
049
050 Iter(Iterator<GraphNode> i) {
051 this.i = i;
052 }
053
054 public boolean hasMoreElements() { return i.hasNext(); }
055
056 public GraphNode next() { return i.next(); }
057 }
058 }