Java Code Examples for com.googlecode.totallylazy.Option#isEmpty()
The following examples show how to use
com.googlecode.totallylazy.Option#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StaticMemberCompleter.java From java-repl with Apache License 2.0 | 6 votes |
public CompletionResult call(String expression) throws Exception { final int lastSeparator = lastIndexOfSeparator(characters(" "), expression) + 1; final String packagePart = expression.substring(lastSeparator); Option<Pair<Class<?>, String>> completion = completionFor(packagePart); if (!completion.isEmpty()) { Function1<CompletionCandidate, String> value = CompletionCandidate::value; Sequence<CompletionCandidate> candidates = reflectionOf(completion.get().first()) .declaredMembers() .filter(isStatic().and(isPublic()).and(not(isSynthetic()))) .groupBy(candidateName()) .map(candidate()) .filter(where(value, startsWith(completion.get().second()))); final int beginIndex = packagePart.lastIndexOf('.') + 1; return new CompletionResult(expression, lastSeparator + beginIndex, candidates); } else { return new CompletionResult(expression, 0, Sequences.empty(CompletionCandidate.class)); } }
Example 2
Source File: Main.java From java-repl with Apache License 2.0 | 6 votes |
public static void main(String... args) throws Exception { console = new ResultPrinter(printColors(args)); ConsoleReader consoleReader = new ConsoleReader(System.in, AnsiConsole.out); JavaREPLClient client = clientFor(hostname(args), port(args)); Sequence<String> initialExpressions = initialExpressionsFromFile().join(initialExpressionsFromArgs(args)); ExpressionReader expressionReader = expressionReaderFor(consoleReader, client, initialExpressions); Option<String> expression = none(); Option<EvaluationResult> result = none(); while (expression.isEmpty() || !result.isEmpty()) { expression = expressionReader.readExpression(); if (!expression.isEmpty()) { result = client.execute(expression.get()); if (!result.isEmpty()) { for (EvaluationLog log : result.get().logs()) { if (!handleTerminalCommand(log)) { handleTerminalMessage(log); } } } } } }
Example 3
Source File: WebConsoleResource.java From java-repl with Apache License 2.0 | 6 votes |
@POST @Hidden @Path("snap") @Produces(MediaType.APPLICATION_JSON) public Response snap(@FormParam("id") String id) { Option<WebConsoleClientHandler> clientHandler = agent.client(id); if (!clientHandler.isEmpty()) { String snapId = UUID.randomUUID().toString(); Files.write(clientHandler.get().history().toString("\n").getBytes(), snapFile(snapId)); return ok() .entity(emptyMap(String.class, Object.class) .insert("snap", snapId) .insert("uri", snapUri(snapId).toString()) ); } else { return response(BAD_REQUEST); } }
Example 4
Source File: UnfoldRightIterator.java From totallylazy with Apache License 2.0 | 5 votes |
@Override protected A getNext() throws Exception { Option<Pair<A, B>> result = callable.call(state); if (result.isEmpty()) return finished(); Pair<A, B> pair = result.get(); state = pair.second(); return pair.first(); }
Example 5
Source File: StaticMemberCompleter.java From java-repl with Apache License 2.0 | 5 votes |
private Option<Pair<Class<?>, String>> completionFor(String expression) { Option<Pair<String, Sequence<String>>> parsedClass = parseExpression(pair(expression, Sequences.empty(String.class))); if (!parsedClass.isEmpty() && !parsedClass.get().second().isEmpty()) { return some(Pair.<Class<?>, String>pair( evaluator.classFrom(parsedClass.get().first()).get(), parsedClass.get().second().toString(".").trim())); } else { return none(); } }
Example 6
Source File: Evaluator.java From java-repl with Apache License 2.0 | 5 votes |
public final Option<java.lang.reflect.Type> typeOfExpression(String expression) { Either<? extends Throwable, Evaluation> evaluation = tryEvaluate(expression); Option<java.lang.reflect.Type> expressionType = none(); if (evaluation.isRight()) { Option<Result> result = evaluation.right().result(); if (!result.isEmpty()) { expressionType = some(result.get().type()); } } return expressionType; }
Example 7
Source File: WebConsoleResource.java From java-repl with Apache License 2.0 | 5 votes |
@POST @Hidden @Path("remove") @Produces(MediaType.APPLICATION_JSON) public Response remove(@FormParam("id") String id) { Option<WebConsoleClientHandler> clientHandler = agent.removeClient(id); if (!clientHandler.isEmpty()) { return response(OK); } else { return response(BAD_REQUEST); } }
Example 8
Source File: WebConsoleResource.java From java-repl with Apache License 2.0 | 5 votes |
@GET @Hidden @Path("completions") @Produces(MediaType.APPLICATION_JSON) public Response completions(@QueryParam("id") String id, @QueryParam("expression") String expression) { Option<WebConsoleClientHandler> clientHandler = agent.client(id); if (!clientHandler.isEmpty()) { return clientHandler.get().completions(expression); } else { return response(BAD_REQUEST); } }
Example 9
Source File: WebConsoleResource.java From java-repl with Apache License 2.0 | 5 votes |
@POST @Hidden @Path("readExpression") @Produces(MediaType.APPLICATION_JSON) public Response readExpression(@FormParam("id") String id, @FormParam("line") String line) { Option<WebConsoleClientHandler> clientHandler = agent.client(id); if (!clientHandler.isEmpty()) { return clientHandler.get().readExpression(line); } else { return response(BAD_REQUEST); } }
Example 10
Source File: WebConsoleResource.java From java-repl with Apache License 2.0 | 5 votes |
@POST @Hidden @Path("execute") @Produces(MediaType.APPLICATION_JSON) public Response execute(@FormParam("id") String id, @FormParam("expression") String expression) { Option<WebConsoleClientHandler> clientHandler = agent.client(id); if (!clientHandler.isEmpty()) { return clientHandler.get().execute(expression); } else { return response(BAD_REQUEST); } }
Example 11
Source File: WebConsole.java From java-repl with Apache License 2.0 | 5 votes |
public synchronized Option<WebConsoleClientHandler> removeClient(String id) { Option<WebConsoleClientHandler> clientHandler = clients.lookup(id); if (!clientHandler.isEmpty()) { clientHandler.get().shutdown(); clients = clients.delete(clientHandler.get().id()); } return clientHandler; }
Example 12
Source File: EvaluationTemplate.java From java-repl with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public final <T> T valueOf(final String key) { Option<Result> result = context.results() .find(where(Result::key, equalTo(key))); if (result.isEmpty()) throw new IllegalArgumentException("Result '" + key + "' not found"); return (T) result.get().value(); }
Example 13
Source File: ArrayTrie.java From totallylazy with Apache License 2.0 | 5 votes |
@tailrec public Option<V> get(K[] key) { if (Arrays.isEmpty(key)) return value; Option<ArrayTrie<K, V>> child = childFor(key); if (child.isEmpty()) return none(); return child.get().get(tail(key)); }
Example 14
Source File: ArrayTrie.java From totallylazy with Apache License 2.0 | 5 votes |
@tailrec public boolean contains(K[] key) { if (Arrays.isEmpty(key)) return !value.isEmpty(); Option<ArrayTrie<K, V>> child = childFor(key); if (child.isEmpty()) return false; return child.get().contains(tail(key)); }
Example 15
Source File: ConsoleHistory.java From java-repl with Apache License 2.0 | 5 votes |
public static final ConsoleHistory historyFromFile(Predicate<String> ignored, Option<File> file) { if (file.isEmpty()) return emptyHistory(ignored, file); try { return new ConsoleHistory(Strings.lines(file.get()), ignored, file); } catch (Exception e) { return emptyHistory(ignored, file); } }
Example 16
Source File: covered_covered_t.java From coming with MIT License | 5 votes |
public final Option<java.lang.reflect.Type> typeOfExpression(String expression) { Either<? extends Throwable, Evaluation> evaluation = tryEvaluate(expression); Option<java.lang.reflect.Type> expressionType = none(); if (evaluation.isRight()) { Option<Result> result = evaluation.right().result(); if (!result.isEmpty()) { expressionType = some(result.get().type()); } } return expressionType; }
Example 17
Source File: EvaluateFromHistory.java From java-repl with Apache License 2.0 | 5 votes |
public void execute(String expression) { Integer historyItem = parseNumericCommand(expression).second().getOrElse(history.items().size()); Option<String> fromHistory = history.items().drop(historyItem - 1).headOption(); if (!fromHistory.isEmpty()) { console.execute(fromHistory.get()); } else { logger.error("Expression not found.\n"); } }
Example 18
Source File: Xml.java From totallylazy with Apache License 2.0 | 4 votes |
public static Element expectElement(final Node node, String xpath) { Option<Element> element = selectElement(node, xpath); if (element.isEmpty()) throw new NoSuchElementException("No element for xpath " + xpath); return element.get(); }
Example 19
Source File: Xml.java From totallylazy with Apache License 2.0 | 4 votes |
public static Node expectNode(final Node node, String xpath) { Option<Node> foundNode = selectNode(node, xpath); if (foundNode.isEmpty()) throw new NoSuchElementException("No node for xpath " + xpath); return foundNode.get(); }
Example 20
Source File: Trie.java From totallylazy with Apache License 2.0 | 4 votes |
public boolean contains(Segment<K> key){ if(key.isEmpty()) return !value.isEmpty(); Option<Trie<K, V>> child = childFor(key); return !child.isEmpty() && child.get().contains(key.tail()); }