/** * Navigates to the next (more recent) command. * <p> * This method wraps around, i.e. it returns {@code null} when there is no * more-recent command in the history. * </p> * * @return the next command */ public String next() { position = entries.next(position); return position < 0 ? currentCommand : entries.get(position); }
/** * Navigates to the next (more recent) command. * <p> * This method wraps around, i.e. it returns {@code null} when there is no * more-recent command in the history. * </p> * * @return the next command */ public String next() { position = entries.next(position); return position < 0 ? currentCommand : entries.get(position); }
@Test public void test() { int count = 3; final LastRecentlyUsed<String> lru = new LastRecentlyUsed<>(count); for (int i = 1; i <= count; i++) { lru.add("" + i); } int position = -1; for (int i = 1; i <= count; i++) { position = lru.next(position); assertEquals("" + i, lru.get(position)); } position = lru.next(position); assertEquals(-1, position); for (int i = count; i >= 1; i--) { position = lru.previous(position); assertEquals("" + i, lru.get(position)); } position = lru.previous(position); assertEquals(-1, position); }