blob: 94f310518bd2e06fe99b080812bfa9da0e54041b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package cuchaz.enigma.gui.util;
import com.google.common.collect.Queues;
import java.util.Deque;
public class History<T> {
private final Deque<T> previous = Queues.newArrayDeque();
private final Deque<T> next = Queues.newArrayDeque();
private T current;
public History(T initial) {
current = initial;
}
public T getCurrent() {
return current;
}
public void push(T value) {
previous.addLast(current);
current = value;
next.clear();
}
public void replace(T value) {
current = value;
}
public boolean canGoBack() {
return !previous.isEmpty();
}
public T goBack() {
next.addFirst(current);
current = previous.removeLast();
return current;
}
public boolean canGoForward() {
return !next.isEmpty();
}
public T goForward() {
previous.addLast(current);
current = next.removeFirst();
return current;
}
}
|