View Javadoc

1   /**
2    * Copyright 2008 Bryan Ray
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 uk.org.bryanray.testtoys.generator.sequencegenerators;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.apache.commons.collections.iterators.LoopingIterator;
23  
24  
25  /**
26   * <DL>
27   *   <DT><B>Project:</B></DT>
28   *   <DD>TestDataLoader</DD>
29   *   <DT><B>Filename:</B></DT>
30   *   <DD>EnumerationSequenceGenerator.java</DD>
31   *   <DT><B>Creation Date:</B></DT>
32   *   <DD>25 May 2008</DD>
33   * </DL>
34   * 
35   * A sequence generator that serves up a list of values in the order specified.
36   * 
37   * @author Bryan Ray
38   */
39  public class EnumerationSequenceGenerator implements SequenceGenerator {
40  	
41  	private Iterator<String> iterator;
42  	
43  	private String currentValue;
44  	
45  	/**
46  	 * @param enumeration A list of values to use as the enumeration.
47  	 * */
48  	@SuppressWarnings("unchecked")
49  	public EnumerationSequenceGenerator(List<String> enumeration) {
50  		if(0 < enumeration.size()) {
51  			List<String> list = new ArrayList<String>(enumeration);
52  			iterator = new LoopingIterator(list);
53  			currentValue = iterator.next();
54  		}
55  		else {
56  			throw new IllegalArgumentException("At least one enumeration value must be supplied.");
57  		}
58  	}
59  	
60  	/**
61  	 * {@inheritDoc}
62  	 * */
63  	public void next() {
64  		currentValue = iterator.next();
65  	}
66  
67  	/**
68  	 * {@inheritDoc}
69  	 * */
70  	public String value() {
71  		return currentValue;
72  	}
73  
74  }