default Iterator<Entry> reverseIterator(int index) { return new Iterator<Entry>() { private final ListIterator<Entry> it = iterator(index + 1); @Override public boolean hasNext() { return it.hasPrevious(); } @Override public Entry next() { return it.previous(); } }; }
public int first() { return history.iterator().next().index() + 1; }
public int first() { return history.iterator().next().index() + 1; }
default ListIterator<Entry> iterator() { return iterator(first()); }
public int searchBackwards(String searchTerm, int startIndex, boolean startsWith) { boolean caseInsensitive = isSet(Option.CASE_INSENSITIVE_SEARCH); if (caseInsensitive) { searchTerm = searchTerm.toLowerCase(); } ListIterator<History.Entry> it = history.iterator(startIndex); while (it.hasPrevious()) { History.Entry e = it.previous(); String line = e.line(); if (caseInsensitive) { line = line.toLowerCase(); } int idx = line.indexOf(searchTerm); if ((startsWith && idx == 0) || (!startsWith && idx >= 0)) { return e.index(); } } return -1; }
protected int searchBackwards(History history, String searchTerm, int startIndex, boolean startsWith) { ListIterator<Entry> it = history.iterator(startIndex); while (it.hasPrevious()) { History.Entry e = it.previous(); if (startsWith) { if (e.line().startsWith(searchTerm)) { return e.index(); } } else { if (e.line().contains(searchTerm)) { return e.index(); } } } return -1; } }
public int searchForwards(String searchTerm, int startIndex, boolean startsWith) { boolean caseInsensitive = isSet(Option.CASE_INSENSITIVE_SEARCH); if (caseInsensitive) { searchTerm = searchTerm.toLowerCase(); } if (startIndex > history.last()) { startIndex = history.last(); } ListIterator<History.Entry> it = history.iterator(startIndex); if (searchIndex != -1 && it.hasNext()) { it.next(); } while (it.hasNext()) { History.Entry e = it.next(); String line = e.line(); if (caseInsensitive) { line = line.toLowerCase(); } int idx = line.indexOf(searchTerm); if ((startsWith && idx == 0) || (!startsWith && idx >= 0)) { return e.index(); } } return -1; }
private String calculateCommand(int currentOffset, Set<Integer> offsets) { if (!offsets.add(currentOffset)) { throw new IllegalArgumentException( "Cycled rerun of commands from history " + offsets); } History history = sqlLine.getLineReader().getHistory(); Iterator<History.Entry> iterator = currentOffset > 0 ? history.iterator(currentOffset - 1) : history.reverseIterator(history.size() - 1 + currentOffset); String command = iterator.next().line(); if (command.trim().startsWith("!/") || command.startsWith("!rerun")) { String[] cmd = sqlLine.split(command); if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) { return command; } int offset = cmd.length == 1 ? -1 : Integer.parseInt(cmd[1]); if (history.size() < offset || history.size() - 1 < -offset) { return command; } return calculateCommand(offset, offsets); } return command; }
private String calculateCommand(int currentOffset, Set<Integer> offsets) { if (!offsets.add(currentOffset)) { throw new IllegalArgumentException( "Cycled rerun of commands from history " + offsets); } History history = sqlLine.getLineReader().getHistory(); Iterator<History.Entry> iterator = currentOffset > 0 ? history.iterator(currentOffset - 1) : history.reverseIterator(history.size() - 1 + currentOffset); String command = iterator.next().line(); if (command.trim().startsWith("!/") || command.startsWith("!rerun")) { String[] cmd = sqlLine.split(command); if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) { return command; } int offset = cmd.length == 1 ? -1 : Integer.parseInt(cmd[1]); if (history.size() < offset || history.size() - 1 < -offset) { return command; } return calculateCommand(offset, offsets); } return command; }
if (pair == null) { pair = StreamSupport.stream( Spliterators.spliteratorUnknownSize(history.iterator((searchIndex < 0 ? history.last() : searchIndex) + 1), Spliterator.ORDERED), false) .flatMap(e -> matches(pat, e.line(), e.index()).stream()) .findFirst()