Java Code Examples for com.googlecode.totallylazy.Sequences#empty()

The following examples show how to use com.googlecode.totallylazy.Sequences#empty() . 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 vote down vote up
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: ByNamingConventionMessageProducer.java    From yatspec with Apache License 2.0 5 votes vote down vote up
public Iterable<SequenceDiagramMessage> messages(CapturedInputAndOutputs inputAndOutputs) {
    Sequence<SequenceDiagramMessage> result = Sequences.empty();
    Set<String> keys = inputAndOutputs.getTypes().keySet();
    for (String key : keys) {
        Matcher matcher = pattern.matcher(key);
        if (matcher.matches()) {
            final String what = matcher.group(1).trim();
            final String from = matcher.group(2).trim();
            final String to = matcher.group(3).trim();
            result = result.append(new SequenceDiagramMessage(from, to, what, key.replaceAll(" ","_").replaceAll("\\(","_").replaceAll("\\)","_")));
        }
    }
    return result;
}
 
Example 3
Source File: WebConsoleClientHandler.java    From java-repl with Apache License 2.0 5 votes vote down vote up
public Sequence<String> history() {
    createProcess();

    try {
        return new JavaREPLClient("localhost", port.get()).history();
    } catch (Exception e) {
        e.printStackTrace();
        return Sequences.empty();
    }
}
 
Example 4
Source File: InstanceMemberCompleter.java    From java-repl with Apache License 2.0 5 votes vote down vote up
public CompletionResult call(String expression) throws Exception {
    final int lastSeparator = lastIndexOfSeparator(characters(" "), expression) + 1;
    final String packagePart = expression.substring(lastSeparator);
    final Boolean canComplete = packagePart.matches("[a-zA-Z0-9\\$_\\\\.\\(\\[\\]]*") && packagePart.contains(".");

    final int beginIndex = packagePart.lastIndexOf('.') + 1;
    Option<Class<?>> aClass = canComplete
            ? evaluator.typeOfExpression(packagePart.substring(0, beginIndex - 1)).map(Types::classOf)
            : none();

    if (aClass.isDefined()) {
        ClassReflection classReflection = reflectionOf(aClass.get());

        Sequence<MemberReflection<?>> join = Sequences.empty()
                .join(classReflection.declaredFields())
                .join(classReflection.declaredMethods())
                .unique()
                .unsafeCast();

        Sequence<CompletionCandidate> candidates = join
                .filter(isPublic().and(not(isStatic())))
                .groupBy(candidateName())
                .map(candidate())
                .filter(where(CompletionCandidate::value, startsWith(packagePart.substring(beginIndex))));

        return new CompletionResult(expression, lastSeparator + beginIndex, candidates);
    } else {
        return new CompletionResult(expression, 0, Sequences.empty(CompletionCandidate.class));
    }
}
 
Example 5
Source File: ExpressionReader.java    From java-repl with Apache License 2.0 5 votes vote down vote up
public Option<String> readExpression() {
    Sequence<String> lines = Sequences.empty();

    do {
        lines = lines.append(lineReader.apply(lines));
    } while (!expressionIsTerminated(lines));

    return lines.contains(null)
            ? none(String.class)
            : some(lines.toString("\n").trim());
}
 
Example 6
Source File: RestConsoleExpressionReader.java    From java-repl with Apache License 2.0 5 votes vote down vote up
public Option<String> readExpression(String line) {
    lines = lines.append(line);
    if (expressionIsTerminated(lines)) {
        Option<String> result = some(lines.toString("\n"));
        lines = Sequences.empty();
        return result;
    } else {
        return none();
    }
}
 
Example 7
Source File: AbstractEmptyTreeMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Override
public Sequence<Pair<K, V>> toSequence() {
    return Sequences.empty();
}
 
Example 8
Source File: AbstractEmptyTreeMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Override
public Sequence<K> keys() {
    return Sequences.empty();
}
 
Example 9
Source File: AbstractEmptyTreeMap.java    From totallylazy with Apache License 2.0 4 votes vote down vote up
@Override
public Sequence<V> values() {
    return Sequences.empty();
}
 
Example 10
Source File: ConsoleLogger.java    From java-repl with Apache License 2.0 4 votes vote down vote up
public void reset() {
    logs = Sequences.empty();
}