Merge remote-tracking branch 'origin/GT-3222-dragonmacher-dt-history-issue'

This commit is contained in:
Ryan Kurtz 2019-10-28 11:32:17 -04:00
commit 90854a01a6
18 changed files with 1383 additions and 536 deletions

View file

@ -82,6 +82,10 @@ public class HistoryList<T> {
* True signals that this list will allow duplicate entries. False signals to not only not
* allow duplicates, but to also move the position of an item if it is re-added to the
* list.
*
* <p>For correct behavior when not allowing duplicates, ensure you have defined an
* <code>equals</code> method to work as you expect. If two different items are considered
* equal, then this class will only remove the duplicate if the equals method returns true.
*
* <p>The default is false
*
@ -162,7 +166,6 @@ public class HistoryList<T> {
* <p>No action is taken if the current pointer is already at the beginning of the list.
*/
public void goBack() {
if (historyIndex == 0) {
return;
}
@ -172,6 +175,18 @@ public class HistoryList<T> {
broadcast(t);
}
/**
* Performs a {@link #goBack()} until the given item becomes the current item. This is
* useful if you wish to go backward to a specific item in the list.
*
* @param t the item
*/
public void goBackTo(T t) {
while (!getCurrentHistoryItem().equals(t) && hasPrevious()) {
goBack();
}
}
/**
* Moves this history list's current item pointer forward one and then calls the user-provided
* callback to signal the newly selected item.
@ -187,6 +202,18 @@ public class HistoryList<T> {
broadcast(t);
}
/**
* Performs a {@link #goForward()} until the given item becomes the current item. This is
* useful if you wish to go forward to a specific item in the list.
*
* @param t the item
*/
public void goForwardTo(T t) {
while (!getCurrentHistoryItem().equals(t) && hasNext()) {
goForward();
}
}
/**
* Returns the item currently pointed to within the list of items. When an item is
* added, this will be that item. Otherwise, it will be the last item navigated.
@ -217,7 +244,7 @@ public class HistoryList<T> {
/**
* Get all items in the history that come after the current history item. They are
* returned in navigation order, as traversed if {@link #goForward() is called.
* returned in navigation order, as traversed if {@link #goForward()} is called.
*
* @return the items
*/

View file

@ -15,7 +15,7 @@
*/
package util;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.LinkedList;
@ -425,6 +425,32 @@ public class HistoryListTest {
assertNextItems();
}
@Test
public void testBackToItem() {
addHistory(A);
addHistory(B);
addHistory(C);
historyList.goBackTo(A);
assertCurrentItem(A);
}
@Test
public void testForwardToItem() {
addHistory(A);
addHistory(B);
addHistory(C);
goBack();
goBack();
goBack();
assertCurrentItem(A);
historyList.goForwardTo(C);
assertCurrentItem(C);
}
//==================================================================================================
// Private Methods
//==================================================================================================