Skip to content

Commit 9bf9c10

Browse files
committed
refactor field names
1 parent 2942838 commit 9bf9c10

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

  • section-04-behavioral-design-patterns/13-memento/src/main/java/com/luv2code/designpatterns/behavioral/memento

section-04-behavioral-design-patterns/13-memento/src/main/java/com/luv2code/designpatterns/behavioral/memento/CatalogQueryHistory.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,52 @@ public class CatalogQueryHistory {
1414

1515
private static final int MAX_HISTORY = 20;
1616

17-
private Deque<CatalogQueryState.QuerySnapshot> undoCollection = new ArrayDeque<>();
17+
private Deque<CatalogQueryState.QuerySnapshot> undoStack =
18+
new ArrayDeque<>();
1819

19-
private Deque<CatalogQueryState.QuerySnapshot> redoCollection = new ArrayDeque<>();
20+
private Deque<CatalogQueryState.QuerySnapshot> redoStack =
21+
new ArrayDeque<>();
2022

21-
private void pushBounded(Deque<CatalogQueryState.QuerySnapshot> theCollection,
22-
CatalogQueryState.QuerySnapshot snapshot) {
23-
24-
if (theCollection.size() == MAX_HISTORY) {
25-
theCollection.removeLast();
26-
}
27-
28-
theCollection.push(snapshot);
29-
}
3023

3124
public void saveBeforeChange(CatalogQueryState originator) {
3225

33-
redoCollection.clear();
34-
pushBounded(undoCollection, originator.createSnapshot());
26+
redoStack.clear();
27+
pushBounded(undoStack, originator.createSnapshot());
3528
}
3629

3730
public boolean undo(CatalogQueryState originator) {
3831

39-
if (undoCollection.isEmpty()) {
32+
if (undoStack.isEmpty()) {
4033
return false;
4134
}
4235

43-
pushBounded(redoCollection, originator.createSnapshot());
44-
originator.restore(undoCollection.pop());
36+
pushBounded(redoStack, originator.createSnapshot());
37+
originator.restore(undoStack.pop());
4538

4639
return true;
4740
}
4841

4942
public boolean redo(CatalogQueryState originator) {
5043

51-
if (redoCollection.isEmpty()) {
44+
if (redoStack.isEmpty()) {
5245
return false;
5346
}
5447

55-
pushBounded(undoCollection, originator.createSnapshot());
56-
originator.restore(redoCollection.pop());
48+
pushBounded(undoStack, originator.createSnapshot());
49+
originator.restore(redoStack.pop());
5750

5851
return true;
5952
}
6053

54+
private void pushBounded(Deque<CatalogQueryState.QuerySnapshot> stack,
55+
CatalogQueryState.QuerySnapshot snapshot) {
56+
57+
if (stack.size() == MAX_HISTORY) {
58+
stack.removeLast();
59+
}
60+
61+
stack.push(snapshot);
62+
}
6163
}
6264

6365

@@ -69,4 +71,14 @@ public boolean redo(CatalogQueryState originator) {
6971

7072

7173

74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
7284

0 commit comments

Comments
 (0)