1 /*
2 * Copyright 2006-2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.springframework.osgi.mock;
17
18 import java.util.Enumeration;
19 import java.util.NoSuchElementException;
20
21 /**
22 * Simple enumeration mock backed by an array of objects.
23 *
24 */
25 public class ArrayEnumerator implements Enumeration {
26
27 private final Object[] source;
28
29 private int index = 0;
30
31 public ArrayEnumerator(Object[] source) {
32 this.source = source;
33 }
34
35 public boolean hasMoreElements() {
36 return source.length > index;
37 }
38
39 public Object nextElement() {
40 if (hasMoreElements())
41 return (source[index++]);
42 else
43 throw new NoSuchElementException();
44 }
45 }