001 /* 002 * LAPIS lightweight structured text processing system 003 * 004 * Copyright (C) 1998-2002 Carnegie Mellon University, 005 * Copyright (C) 2003 Massachusetts Institute of Technology. 006 * All rights reserved. 007 * 008 * This library is free software; you can redistribute it 009 * and/or modify it under the terms of the GNU General 010 * Public License as published by the Free Software 011 * Foundation, version 2. 012 * 013 * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/ 014 */ 015 016 017 package lapisx.enum; 018 import java.util.Enumeration; 019 import java.util.NoSuchElementException; 020 021 /** 022 * Enumeration which transforms the elements of another enumeration. 023 */ 024 public class ConcatEnumeration implements Enumeration { 025 Enumeration[] e; 026 int i = 0; // current enumeration in e 027 028 public ConcatEnumeration (Enumeration e1, Enumeration e2) { 029 this.e = new Enumeration[] { e1, e2 }; 030 } 031 032 public ConcatEnumeration (Enumeration[] e) { 033 this.e = e; 034 } 035 036 public boolean hasMoreElements () { 037 while (i < e.length) { 038 if (e[i].hasMoreElements ()) 039 return true; 040 else 041 ++i; 042 } 043 return false; 044 } 045 046 public Object nextElement () { 047 while (i < e.length) { 048 try { 049 return e[i].nextElement (); 050 } catch (NoSuchElementException e) { 051 ++i; 052 } 053 } 054 055 throw new NoSuchElementException (); 056 } 057 }