jline.console.history.History.entries()方法的使用及代码示例

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

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

History.entries介绍

暂无

代码示例

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

public boolean history(String line) {
 Iterator hist = beeLine.getConsoleReader().getHistory().entries();
 String[] tmp;
 while(hist.hasNext()){
  tmp = hist.next().toString().split(":", 2);
  tmp[0] = Integer.toString(Integer.parseInt(tmp[0]) + 1);
  beeLine.output(beeLine.getColorBuffer().pad(tmp[0], 6)
    .append(":" + tmp[1]));
 }
 return true;
}

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

public int searchBackwards(String searchTerm, int startIndex, boolean startsWith) {
  ListIterator<History.Entry> it = history.entries(startIndex);
  while (it.hasPrevious()) {
    History.Entry e = it.previous();
    if (startsWith) {
      if (e.value().toString().startsWith(searchTerm)) {
        return e.index();
      }
    } else {
      if (e.value().toString().contains(searchTerm)) {
        return e.index();
      }
    }
  }
  return -1;
}

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

public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
  if (startIndex >= history.size()) {
    startIndex = history.size() - 1;
  }
  ListIterator<History.Entry> it = history.entries(startIndex);
  if (searchIndex != -1 && it.hasNext()) {
    it.next();
  }
  while (it.hasNext()) {
    History.Entry e = it.next();
    if (startsWith) {
      if (e.value().toString().startsWith(searchTerm)) {
        return e.index();
      }
    } else {
      if (e.value().toString().contains(searchTerm)) {
        return e.index();
      }
    }
  }
  return -1;
}

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

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
  throws IOException {
 if (cl.hasOption(clearHist.getOpt())) {
  shellState.getReader().getHistory().clear();
 } else {
  Iterator<Entry> source = shellState.getReader().getHistory().entries();
  Iterator<String> historyIterator = Iterators.transform(source,
    input -> String.format("%d: %s", input.index() + 1, input.value()));
  shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
 }
 return 0;
}

代码示例来源:origin: com.netflix.eureka2/eureka-testkit

private void saveHistory() {
  if (HISTORY_FILE != null) {
    if (HISTORY_FILE.exists()) {
      boolean deleted = HISTORY_FILE.delete();
      if (!deleted) {
        System.err.println("Failed to delete the history file.");
      }
    }
    try {
      ListIterator<Entry> iterator = consoleReader.getHistory().entries();
      try (FileWriter writer = new FileWriter(HISTORY_FILE)) {
        while (iterator.hasNext()) {
          writer.write(iterator.next().value().toString());
          writer.write('\n');
        }
      }
    } catch (IOException ignored) {
      System.err.println("ERROR: could not save history file into ~/.eureka_history");
    }
  }
}

代码示例来源:origin: com.netflix.eureka/eureka2-testkit

private void saveHistory() {
  if (HISTORY_FILE != null) {
    if (HISTORY_FILE.exists()) {
      boolean deleted = HISTORY_FILE.delete();
      if (!deleted) {
        System.err.println("Failed to delete the history file.");
      }
    }
    try {
      ListIterator<Entry> iterator = consoleReader.getHistory().entries();
      try (FileWriter writer = new FileWriter(HISTORY_FILE)) {
        while (iterator.hasNext()) {
          writer.write(iterator.next().value().toString());
          writer.write('\n');
        }
      }
    } catch (IOException ignored) {
      System.err.println("ERROR: could not save history file into ~/.eureka_history");
    }
  }
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

public int searchBackwards(String searchTerm, int startIndex, boolean startsWith) {
  ListIterator<History.Entry> it = history.entries(startIndex);
  while (it.hasPrevious()) {
    History.Entry e = it.previous();
    if (startsWith) {
      if (e.value().toString().startsWith(searchTerm)) {
        return e.index();
      }
    } else {
      if (e.value().toString().contains(searchTerm)) {
        return e.index();
      }
    }
  }
  return -1;
}

代码示例来源:origin: org.apache.hive/hive-beeline

public boolean history(String line) {
 Iterator hist = beeLine.getConsoleReader().getHistory().entries();
 String[] tmp;
 while(hist.hasNext()){
  tmp = hist.next().toString().split(":", 2);
  tmp[0] = Integer.toString(Integer.parseInt(tmp[0]) + 1);
  beeLine.output(beeLine.getColorBuffer().pad(tmp[0], 6)
    .append(":" + tmp[1]));
 }
 return true;
}

代码示例来源:origin: org.spark-project.hive/hive-beeline

public boolean history(String line) {
 Iterator hist = beeLine.getConsoleReader().getHistory().entries();
 int index = 1;
 while(hist.hasNext()){
  beeLine.output(beeLine.getColorBuffer().pad(index + ".", 6)
    .append(hist.next().toString()));
 }
 return true;
}

代码示例来源:origin: com.github.hyukjinkwon/hive-beeline

public boolean history(String line) {
 Iterator hist = beeLine.getConsoleReader().getHistory().entries();
 int index = 1;
 while(hist.hasNext()){
  beeLine.output(beeLine.getColorBuffer().pad(index + ".", 6)
    .append(hist.next().toString()));
 }
 return true;
}

代码示例来源:origin: com.typesafe.sbt/incremental-compiler

public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
  if (startIndex >= history.size()) {
    startIndex = history.size() - 1;
  }
  ListIterator<History.Entry> it = history.entries(startIndex);
  if (searchIndex != -1 && it.hasNext()) {
    it.next();
  }
  while (it.hasNext()) {
    History.Entry e = it.next();
    if (startsWith) {
      if (e.value().toString().startsWith(searchTerm)) {
        return e.index();
      }
    } else {
      if (e.value().toString().contains(searchTerm)) {
        return e.index();
      }
    }
  }
  return -1;
}

代码示例来源:origin: org.apache.accumulo/accumulo-shell

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
  throws IOException {
 if (cl.hasOption(clearHist.getOpt())) {
  shellState.getReader().getHistory().clear();
 } else {
  Iterator<Entry> source = shellState.getReader().getHistory().entries();
  Iterator<String> historyIterator = Iterators.transform(source, new Function<Entry,String>() {
   @Override
   public String apply(Entry input) {
    return String.format("%d: %s", input.index() + 1, input.value());
   }
  });
  shellState.printLines(historyIterator, !cl.hasOption(disablePaginationOpt.getOpt()));
 }
 return 0;
}

代码示例来源:origin: dariober/ASCIIGenome

ListIterator<Entry> iter = cmdHistory.entries();
List<String>lastCommands= new ArrayList<String>();
int max_cmds= 2000; // Maximum number of commands to write out to asciigenomo_history.

相关文章