org.jline.reader.History.iterator()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.4k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.jline.reader.History.iterator()方法的一些代码示例,展示了History.iterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。History.iterator()方法的具体详情如下:
包路径:org.jline.reader.History
类名称:History
方法名:iterator

History.iterator介绍

暂无

代码示例

代码示例来源:origin: org.jline/jline

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();
    }
  };
}

代码示例来源:origin: apache/karaf

public int first() {
  return history.iterator().next().index() + 1;
}

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.core

public int first() {
  return history.iterator().next().index() + 1;
}

代码示例来源:origin: org.jline/jline

default ListIterator<Entry> iterator() {
  return iterator(first());
}

代码示例来源:origin: org.jline/jline

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;
}

代码示例来源:origin: org.jline/jline

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;
  }
}

代码示例来源:origin: org.jline/jline

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;
}

代码示例来源:origin: julianhyde/sqlline

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;
}

代码示例来源:origin: sqlline/sqlline

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;
}

代码示例来源:origin: org.jline/jline

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()

相关文章