added Misc class
[org.ibex.util.git] / src / org / ibex / util / Misc.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.util;
6
7 import java.io.*;
8 import java.util.*;
9
10 public final class Misc {
11
12     public static class ArrayEnumeration implements Enumeration {
13         private final Object[] o;
14         private int i = 0;
15         public ArrayEnumeration(Object[] o) { this.o = o; }
16         public boolean hasMoreElements() { return o != null && i < o.length; }
17         public Object nextElement() { return hasMoreElements() ? o[i++] : null; }
18     }
19
20     public static class JoinEnumeration implements Enumeration {
21         private final Enumeration e1;
22         private final Enumeration e2;
23         public JoinEnumeration(Enumeration e1, Enumeration e2) { this.e1 = e1; this.e2 = e2; }
24         public boolean hasMoreElements() { return e1.hasMoreElements() || e2.hasMoreElements(); }
25         public Object nextElement() { return e1.hasMoreElements() ? e1.nextElement() : e2.nextElement(); }
26     }
27
28 }
29