View Javadoc
1   package de.fhdw.wtf.common.stream;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   /**
7    * ScannerInput that relies on a String as sorted source of characters.
8    * 
9    */
10  public class SimpleScannerInput implements ScannerInputStream {
11  	
12  	/**
13  	 * Splitted list of characters showing the stream.
14  	 */
15  	private final List<Character> data = new ArrayList<>();
16  	
17  	/**
18  	 * Constructor using a single String as input source.
19  	 * 
20  	 * @param input
21  	 *            characters in this stream
22  	 */
23  	public SimpleScannerInput(final String input) {
24  		for (int i = 0; i < input.length(); i++) {
25  			this.data.add(input.charAt(i));
26  		}
27  	}
28  	
29  	@Override
30  	public char next() {
31  		final char next = this.data.get(0);
32  		this.data.remove(0);
33  		return next;
34  	}
35  	
36  	@Override
37  	public boolean hasNext() {
38  		return !this.data.isEmpty();
39  	}
40  	
41  }