Java 类javax.el.LambdaExpression 实例源码

项目:beyondj    文件:Stream.java   
public Stream filter(final LambdaExpression le) {
    Iterator<Object> downStream = new OpIterator() {
        @Override
        protected void findNext() {
            while (iterator.hasNext()) {
                Object obj = iterator.next();
                if (ELSupport.coerceToBoolean(null, le.invoke(obj),
                        true).booleanValue()) {
                    next = obj;
                    foundNext = true;
                    break;
                }
            }
        }
    };
    return new Stream(downStream);
}
项目:beyondj    文件:Stream.java   
public Stream flatMap(final LambdaExpression le) {
    Iterator<Object> downStream = new OpIterator() {

        private Iterator<?> inner;

        @Override
        protected void findNext() {
            while (iterator.hasNext() ||
                    (inner != null && inner.hasNext())) {
                if (inner == null || !inner.hasNext()) {
                    inner = ((Stream) le.invoke(iterator.next())).iterator;
                }

                if (inner.hasNext()) {
                    next = inner.next();
                    foundNext = true;
                    break;
                }
            }
        }
    };
    return new Stream(downStream);
}
项目:beyondj    文件:Optional.java   
public Object orElseGet(Object le) {
    if (obj == null) {
        // EL 3.0 specification says parameter is LambdaExpression but it
        // may already have been evaluated. If that is the case, the
        // original parameter will have been checked to ensure it was a
        // LambdaExpression before it was evaluated.

        if (le instanceof LambdaExpression) {
            return ((LambdaExpression) le).invoke((Object[]) null);
        } else {
            return le;
        }
    } else {
        return obj;
    }
}
项目:beyondj    文件:Stream.java   
public Stream map(final LambdaExpression le) {
    Iterator<Object> downStream = new OpIterator() {
        @Override
        protected void findNext() {
            if (iterator.hasNext()) {
                Object obj = iterator.next();
                next = le.invoke(obj);
                foundNext = true;
            }
        }
    };
    return new Stream(downStream);
}
项目:beyondj    文件:Stream.java   
public Stream peek(final LambdaExpression le) {
    Iterator<Object> downStream = new OpIterator() {
        @Override
        protected void findNext() {
            if (iterator.hasNext()) {
                Object obj = iterator.next();
                le.invoke(obj);
                next = obj;
                foundNext = true;
            }
        }
    };
    return new Stream(downStream);
}
项目:beyondj    文件:Stream.java   
public Optional reduce(LambdaExpression le) {
    Object seed = null;

    if (iterator.hasNext()) {
        seed = iterator.next();
    }

    if (seed == null) {
        return Optional.EMPTY;
    } else {
        return new Optional(reduce(seed, le));
    }
}
项目:beyondj    文件:Stream.java   
public Object reduce(Object seed, LambdaExpression le) {
    Object result = seed;

    while (iterator.hasNext()) {
        result = le.invoke(result, iterator.next());
    }

    return result;
}
项目:beyondj    文件:Stream.java   
public Optional anyMatch(LambdaExpression le) {
    if (!iterator.hasNext()) {
        return Optional.EMPTY;
    }

    Boolean match = Boolean.FALSE;

    while (!match.booleanValue() && iterator.hasNext()) {
        match = (Boolean) le.invoke(iterator.next());
    }

    return new Optional(match);
}
项目:beyondj    文件:Stream.java   
public Optional allMatch(LambdaExpression le) {
    if (!iterator.hasNext()) {
        return Optional.EMPTY;
    }

    Boolean match = Boolean.TRUE;

    while (match.booleanValue() && iterator.hasNext()) {
        match = (Boolean) le.invoke(iterator.next());
    }

    return new Optional(match);
}
项目:beyondj    文件:Stream.java   
public Optional noneMatch(LambdaExpression le) {
    if (!iterator.hasNext()) {
        return Optional.EMPTY;
    }

    Boolean match = Boolean.FALSE;

    while (!match.booleanValue() && iterator.hasNext()) {
        match = (Boolean) le.invoke(iterator.next());
    }

    return new Optional(new Boolean(!match.booleanValue()));
}
项目:beyondj    文件:Stream.java   
public Object forEach(final LambdaExpression le) {
    while (iterator.hasNext()) {
        le.invoke(iterator.next());
    }
    return null;
}
项目:beyondj    文件:Stream.java   
public Optional max(LambdaExpression le) {
    return compare(true, le);
}
项目:beyondj    文件:Stream.java   
public Optional min(LambdaExpression le) {
    return compare(false, le);
}
项目:beyondj    文件:Stream.java   
public LambdaExpressionComparator(LambdaExpression le) {
    this.le = le;
}
项目:beyondj    文件:Optional.java   
public void ifPresent(LambdaExpression le) {
    if (obj != null) {
        le.invoke(obj);
    }
}
项目:beyondj    文件:AstLambdaExpression.java   
@Override
public Object getValue(EvaluationContext ctx) throws ELException {

    // Correct evaluation requires knowledge of the whole set of nested
    // expressions, not just the current expression
    NestedState state = getNestedState();

    // Check that there are not more sets of parameters than there are
    // nested expressions.
    int methodParameterSetCount = jjtGetNumChildren() - 2;
    if (methodParameterSetCount > state.getNestingCount()) {
        throw new ELException(MessageFactory.get(
                "error.lambda.tooManyMethodParameterSets"));
    }

    // First child is always parameters even if there aren't any
    AstLambdaParameters formalParametersNode =
            (AstLambdaParameters) children[0];
    Node[] formalParamNodes = formalParametersNode.children;

    // Second child is a value expression
    ValueExpressionImpl ve = new ValueExpressionImpl("", children[1],
            ctx.getFunctionMapper(), ctx.getVariableMapper(), null);

    // Build a LambdaExpression
    List<String> formalParameters = new ArrayList<>();
    if (formalParamNodes != null) {
        for (Node formalParamNode : formalParamNodes) {
            formalParameters.add(formalParamNode.getImage());
        }
    }
    LambdaExpression le = new LambdaExpression(formalParameters, ve);
    le.setELContext(ctx);

    if (jjtGetNumChildren() == 2) {
        // No method parameters
        // Can only invoke the expression if none of the lambda expressions
        // in the nesting declare parameters
        if (state.getHasFormalParameters()) {
            return le;
        } else {
            return le.invoke(ctx, (Object[]) null);
        }
    }

    /*
     * This is a (possibly nested) lambda expression with one or more sets
     * of parameters provided.
     *
     * If there are more nested expressions than sets of parameters this may
     * return a LambdaExpression.
     *
     * If there are more sets of parameters than nested expressions an
     * ELException will have been thrown by the check at the start of this
     * method.
     */

    // Always have to invoke the outer-most expression
    int methodParameterIndex = 2;
    Object result = le.invoke(((AstMethodParameters)
            children[methodParameterIndex]).getParameters(ctx));
    methodParameterIndex++;

    while (result instanceof LambdaExpression &&
            methodParameterIndex < jjtGetNumChildren()) {
        result = ((LambdaExpression) result).invoke(((AstMethodParameters)
                children[methodParameterIndex]).getParameters(ctx));
        methodParameterIndex++;
    }

    return result;
}