KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > terracotta > session > util > StringArrayEnumeration


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.terracotta.session.util;
5
6 import java.util.Enumeration JavaDoc;
7 import java.util.NoSuchElementException JavaDoc;
8
9 public class StringArrayEnumeration implements Enumeration JavaDoc {
10
11   private static final String JavaDoc[] EMPTY_ARRAY = new String JavaDoc[0];
12   private final String JavaDoc[] strings;
13   private int currIndex = 0;
14
15   public StringArrayEnumeration(String JavaDoc[] strings) {
16     this.strings = (strings == null) ? EMPTY_ARRAY : strings;
17   }
18
19   public boolean hasMoreElements() {
20     return currIndex < strings.length;
21   }
22
23   public Object JavaDoc nextElement() {
24     if (currIndex >= strings.length) throw new NoSuchElementException JavaDoc();
25     String JavaDoc rv = strings[currIndex];
26     currIndex++;
27     return rv;
28   }
29
30 }
31
Popular Tags