PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/ooc/frontend/model/tokens/ListReader.java

http://github.com/nddrylliog/ooc
Java | 65 lines | 49 code | 16 blank | 0 comment | 1 complexity | 180a6bacb8400ec627425605cd08884b MD5 | raw file
 1package org.ooc.frontend.model.tokens;
 2
 3import java.util.List;
 4
 5public class ListReader<T> {
 6
 7	List<T> list;
 8	int index;
 9	int length;
10	int mark;
11
12	public ListReader(List<T> list) {
13		this.list = list;
14		this.index = 0;
15		this.length = list.size();
16		this.mark = 0;
17	}
18
19	public boolean hasNext() {
20		return index < length;
21	}
22	
23	public T read() {
24		return list.get(index++);
25	}
26	
27	public T peek() {
28		return list.get(index);
29	}
30	
31	public T prev() {
32		if(index < 1) return list.get(index);
33		return list.get(index - 1);
34	}
35	
36	public T prev(int offset) {
37		return list.get(index - offset);
38	}
39	
40	public int mark() {
41		mark = index;
42		return mark;
43	}
44	
45	public void reset() {
46		index = mark;
47	}
48	
49	public void reset(int index) {
50		this.index = index;
51	}
52	
53	public void rewind() {
54		index--;
55	}
56	
57	public void skip() {
58		index++;
59	}
60	
61	public void skip(int offset) {
62		index += offset;
63	}
64	
65}