• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java History类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中jline.console.history.History的典型用法代码示例。如果您正苦于以下问题:Java History类的具体用法?Java History怎么用?Java History使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



History类属于jline.console.history包,在下文中一共展示了History类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: searchBackwards

import jline.console.history.History; //导入依赖的package包/类
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;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:17,代码来源:ConsoleReader.java


示例2: searchForwards

import jline.console.history.History; //导入依赖的package包/类
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;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:26,代码来源:ConsoleReader.java


示例3: getJLineHistory

import jline.console.history.History; //导入依赖的package包/类
/**
 * Load the History from disk if a $HOME directory is defined, otherwise fall back to using an in-memory history object
 * 
 * @return
 * @throws IOException
 */
protected History getJLineHistory() throws IOException {
  String home = System.getProperty("HOME");
  if (null == home) {
    home = System.getenv("HOME");
  }
  
  // Get the home directory
  File homeDir = new File(home);
  
  // Make sure it actually exists
  if (homeDir.exists() && homeDir.isDirectory()) {
    // Check for, and create if necessary, the directory for cosmos to use
    File historyDir = new File(homeDir, ".cosmos");
    if (!historyDir.exists() && !historyDir.mkdirs()) {
      log.warn("Could not create directory for history at {}, using temporary history.", historyDir);
    }
    
    // Get a file for jline history
    File historyFile = new File(historyDir, "history");
    return new FileHistory(historyFile);
  } else {
    log.warn("Home directory not found: {}, using temporary history", homeDir);
    return new MemoryHistory();
  }
}
 
开发者ID:joshelser,项目名称:cosmos,代码行数:32,代码来源:CosmosConsole.java


示例4: createMainEnvironment

import jline.console.history.History; //导入依赖的package包/类
protected CliEnvironment createMainEnvironment(final AtomicReference<InputReader> dynamicInputReaderRef,
                                               final AtomicReference<History> dynamicHistoryAtomicReference) {
    final Map<String, ?> data = new HashMap<String, Object>();
    return new CliEnv() {
        @Override
        public History history() {
            return dynamicHistoryAtomicReference.get();
        }

        @Override
        public InputReader reader() {
            return dynamicInputReaderRef.get();
        }

        @Override
        public Map<String, ?> userData() {
            return data;
        }
    };
}
 
开发者ID:tomitribe,项目名称:crest,代码行数:21,代码来源:CrestCli.java


示例5: start

import jline.console.history.History; //导入依赖的package包/类
public void start() throws Exception {
    console = new ConsoleReader();
    console.getTerminal().setEchoEnabled(false);
    console.setPrompt("\u001B[32menkan\u001B[0m> ");
    History history = new FileHistory(new File(System.getProperty("user.home"), ".enkan_history"));
    console.setHistory(history);

    CandidateListCompletionHandler handler = new CandidateListCompletionHandler();
    console.setCompletionHandler(handler);
    consoleHandler = new ConsoleHandler(console);
    clientThread.execute(consoleHandler);
    clientThread.shutdown();
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:14,代码来源:ReplClient.java


示例6: getCommandHistory

import jline.console.history.History; //导入依赖的package包/类
/**Read the asciigenome history file and put it a list as current history. Or
 * return empty history file does not exist or can't be read. 
 * */
public History getCommandHistory(){
	History cmdHistory= new MemoryHistory();
	for(String x : this.getCommands()){
		cmdHistory.add(x);
	}
	return cmdHistory;
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:11,代码来源:ASCIIGenomeHistory.java


示例7: testHistory

import jline.console.history.History; //导入依赖的package包/类
@Test
public void testHistory() throws IOException{
	
	ConsoleReader console= new ConsoleReader();
	//History history= new History(new File(System.getProperty("user.home") + File.separator + ".asciigenome_history"));
	History history= new MemoryHistory();
	history.add("foobar");
	history.add("baz");
	console.setHistory(history);
	System.out.println(console.getHistory());
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:12,代码来源:UtilsTest.java


示例8: LineReader

import jline.console.history.History; //导入依赖的package包/类
LineReader(History history, Completer... completers)
        throws IOException
{
    setExpandEvents(false);
    setBellEnabled(true);
    setHandleUserInterrupt(true);
    setHistory(history);
    setHistoryEnabled(false);
    for (Completer completer : completers) {
        addCompleter(completer);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:13,代码来源:LineReader.java


示例9: history

import jline.console.history.History; //导入依赖的package包/类
public void history(String line, DispatchCallback callback) {
    int index = 1;
    for (History.Entry entry : sqlLine.getConsoleReader().getHistory()) {
        index++;
        sqlLine.output(
                sqlLine.getColorBuffer().pad(index + ".", 6)
                .append(entry.toString()));
    }
    callback.setToSuccess();
}
 
开发者ID:mozafari,项目名称:verdict,代码行数:11,代码来源:Commands.java


示例10: testAddToHistory

import jline.console.history.History; //导入依赖的package包/类
@Test
public void testAddToHistory() throws Exception{
    History h = c.getReader().getHistory();
    c.clearHistory();
    c.addToHistory("Test");
    Assert.assertEquals("Test", h.get(0));
}
 
开发者ID:vladimirvivien,项目名称:clamshell-cli,代码行数:8,代码来源:CliConsoleTest.java


示例11: sendHistory

import jline.console.history.History; //导入依赖的package包/类
private void sendHistory() throws IOException {
	History history = console.getHistory();
	ListIterator<Entry> entries = history.entries();
	HistoryResponse response = new HistoryResponse();

	response.setHistoryLines(new ArrayList<String>(history.size()));

	while(entries.hasNext()){
		Entry entry = entries.next();
		response.getHistoryLines().set(entry.index(), entry.value().toString());
	}

	connector.send(response);
}
 
开发者ID:rainu,项目名称:jsimpleshell-rc,代码行数:15,代码来源:Handshaker.java


示例12: history

import jline.console.history.History; //导入依赖的package包/类
public void history(String line, DispatchCallback callback) {
  int index = 1;
  for (History.Entry entry : sqlLine.getConsoleReader().getHistory()) {
    index++;
    sqlLine.output(
        sqlLine.getColorBuffer().pad(index + ".", 6)
            .append(entry.toString()));
  }
  callback.setToSuccess();
}
 
开发者ID:julianhyde,项目名称:sqlline,代码行数:11,代码来源:Commands.java


示例13: history

import jline.console.history.History; //导入依赖的package包/类
protected Iterable<String> history() {
    return Lists.newArrayList(Iterators.transform(consoleReader.getHistory().entries(), new Function<History.Entry, String>() {
        @Override
        public String apply(final History.Entry entry) {
            return entry.value().toString();
        }
    }));
}
 
开发者ID:shopzilla,项目名称:hadoop-in-a-box,代码行数:9,代码来源:REPL.java


示例14: getHistoryEntries

import jline.console.history.History; //导入依赖的package包/类
@Override
public Iterator<CharSequence> getHistoryEntries() {
    if (fileHistory == null) {
        return new ArrayList<CharSequence>().iterator();
    }
    return Iterators.transform(fileHistory.iterator(), new Function<History.Entry, CharSequence>() {
        @Override
        public CharSequence apply(jline.console.history.History.Entry entry) {
            return entry.value();
        }
    });
}
 
开发者ID:javanna,项目名称:elasticshell,代码行数:13,代码来源:JLineConsole.java


示例15: writeYamlHistory

import jline.console.history.History; //导入依赖的package包/类
/** On shutdown, prepare and write the history file. Not that the existing 
 * yaml file is overwritten.  */
private static void writeYamlHistory(final ASCIIGenomeHistory current, 
									 final History cmdHistory, 
									 final TrackSet trackSet,
		                             final GenomicCoordsHistory gch 
		                             ){

	Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
		public void run() {

		ASCIIGenomeHistory newYamlHistory= null;
		try {
			newYamlHistory = new ASCIIGenomeHistory(null);
		} catch (IOException e1) {
			e1.printStackTrace();
		} 
		try{
			// List of commands
			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.
			while(iter.hasNext()){
				if(max_cmds == 0){
					break;
				}
				max_cmds--;
				lastCommands.add(iter.next().value().toString());
			}
			newYamlHistory.setCommands(lastCommands);
			
			// List of files
			List<String> opened= new ArrayList<String>();
			for(String f : trackSet.getOpenedFiles()){
				if(new File(f).getName().startsWith(".asciigenome.")){
					continue;
				}
				opened.add(f);
			}						
			List<String>lastFiles= new ArrayList<String>(opened);
			int max_files= 200; // Maximum number of files to write out to asciigenomo_history.
			lastFiles= lastFiles.subList(Math.max(0, lastFiles.size() - max_files), lastFiles.size());
			newYamlHistory.setFiles(lastFiles);
			
			// Positions
			List<String> lastPos= gch.prepareHistoryForHistoryFile(newYamlHistory.getFileName(), 100);
			newYamlHistory.setPositions(lastPos);

			// Fasta ref
			if(gch.current().getFastaFile() != null && ! gch.current().getFastaFile().trim().isEmpty()){
				String fasta= new File(gch.current().getFastaFile()).getAbsolutePath();
				List<String> ff= Arrays.asList(new String[] {fasta});
				newYamlHistory.setReference(ff);					
			} else {
				newYamlHistory.setReference(current.getReference());
			}
			
			// Write yaml
			newYamlHistory.write();
			
		} catch (Exception e) {
			e.printStackTrace();
				System.err.println("Unable to write history to " + newYamlHistory.getFileName());
			}
		}
    }, "Shutdown-thread"));
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:68,代码来源:Main.java


示例16: setHistory

import jline.console.history.History; //导入依赖的package包/类
public void setHistory(final History history) {
    this.history = history;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:4,代码来源:ConsoleReader.java


示例17: getHistory

import jline.console.history.History; //导入依赖的package包/类
public History getHistory() {
    return history;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:4,代码来源:ConsoleReader.java


示例18: history

import jline.console.history.History; //导入依赖的package包/类
@Command
public static void history(final CliEnvironment env, @Out final PrintStream out) {
    for (final History.Entry entry : env.history()) {
        out.println(String.format("[%3d] %s", entry.index() + 1, entry.value()));
    }
}
 
开发者ID:tomitribe,项目名称:crest,代码行数:7,代码来源:CrestCli.java


示例19: pipeEnvironment

import jline.console.history.History; //导入依赖的package包/类
protected CliEnvironment pipeEnvironment(final CliEnvironment env, final InputStream in, final PrintStream out) {
    return new CliEnvironment() {
        @Override
        public History history() {
            return env.history();
        }

        @Override
        public InputReader reader() {
            return env.reader();
        }

        @Override
        public Map<String, ?> userData() {
            return env.userData();
        }

        @Override
        public InputStream getInput() {
            return in;
        }

        @Override
        public PrintStream getOutput() {
            return out;
        }

        @Override
        public PrintStream getError() {
            return env.getError();
        }

        @Override
        public Properties getProperties() {
            return env.getProperties();
        }

        @Override
        public <T> T findService(final Class<T> type) {
            return env.findService(type);
        }
    };
}
 
开发者ID:tomitribe,项目名称:crest,代码行数:44,代码来源:CrestCli.java


示例20: newTestCli

import jline.console.history.History; //导入依赖的package包/类
private CrestCli newTestCli(final String input, final ByteArrayOutputStream out, final File alias) {
    return new CrestCli() {
            @Override
            protected CliEnvironment createMainEnvironment(final AtomicReference<InputReader> dynamicInputReaderRef,
                                                           final AtomicReference<History> historyAtomicReference) {
                final CliEnvironment mainEnvironment = super.createMainEnvironment(dynamicInputReaderRef, historyAtomicReference);
                final InputStream is = new ByteArrayInputStream(input.getBytes());
                final PrintStream stdout = new PrintStream(out);
                return new CliEnvironment() {
                    @Override
                    public History history() {
                        return historyAtomicReference.get();
                    }

                    @Override
                    public InputReader reader() {
                        return dynamicInputReaderRef.get();
                    }

                    @Override
                    public Map<String, ?> userData() {
                        return mainEnvironment.userData();
                    }

                    @Override
                    public PrintStream getOutput() {
                        return stdout;
                    }

                    @Override
                    public PrintStream getError() {
                        return mainEnvironment.getError();
                    }

                    @Override
                    public InputStream getInput() {
                        return is;
                    }

                    @Override
                    public Properties getProperties() {
                        return mainEnvironment.getProperties();
                    }

                    @Override
                    public <T> T findService(final Class<T> type) {
                        return mainEnvironment.findService(type);
                    }
                };
            }

            @Override
            protected void onMainCreated(final DefaultsContext ctx, final Main main) {
                main.processClass(ctx, MyTestCmd.class);
            }

            @Override
            protected String nextPrompt() {
                return "prompt$";
            }

            @Override
            protected File aliasesFile() {
                return alias;
            }
        };
}
 
开发者ID:tomitribe,项目名称:crest,代码行数:68,代码来源:CrestCliTest.java



注:本文中的jline.console.history.History类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WriteFuture类代码示例发布时间:2022-05-21
下一篇:
Java OHLCDataItem类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap