本文整理汇总了Java中org.apache.olingo.server.api.uri.queryoption.expression.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于org.apache.olingo.server.api.uri.queryoption.expression包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toSort
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
/**
* Converts {@link OrderByItem} to {@link Sort} needed for
* {@link Pagination}.
*
* @param orderByItem
* order by item
* @return sort instance, or null in case order by item wasn't specific type
*/
protected Sort toSort(OrderByItem orderByItem) {
Expression expression = orderByItem.getExpression();
if (expression instanceof Member) {
UriInfoResource resourcePath = ((Member) expression).getResourcePath();
UriResource uriResource = resourcePath.getUriResourceParts().get(0);
if (uriResource instanceof UriResourcePrimitiveProperty) {
EdmProperty edmProperty = ((UriResourcePrimitiveProperty) uriResource)
.getProperty();
String property = edmProperty.getName();
if (edmProperty instanceof ElasticEdmProperty) {
ElasticEdmProperty entityTypeProperty = (ElasticEdmProperty) edmProperty;
property = addKeywordIfNeeded(entityTypeProperty.getEField(),
entityTypeProperty.getAnnotations());
}
return new Sort(property,
orderByItem.isDescending() ? Sort.Direction.DESC : Sort.Direction.ASC);
}
}
return null;
}
示例2: accept
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
public void accept(Expression expr) {
if (expr instanceof Alias) {
visit((Alias) expr);
} else if (expr instanceof Binary) {
visit((Binary) expr);
} else if (expr instanceof Enumeration) {
visit((Enumeration) expr);
} else if (expr instanceof LambdaRef) {
visit((LambdaRef) expr);
} else if (expr instanceof Literal) {
visit((Literal) expr);
} else if (expr instanceof Member) {
visit((Member) expr);
} else if (expr instanceof Method) {
visit((Method) expr);
} else if (expr instanceof TypeLiteral) {
visit((TypeLiteral) expr);
} else if (expr instanceof Unary) {
visit((Unary) expr);
}
}
示例3: binaryExpression
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
@Test
public void binaryExpression() throws Exception {
Expression expressionLeft = new LiteralImpl("2", odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte));
Expression expressionRight = new LiteralImpl("-1", odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte));
BinaryImpl expression = new BinaryImpl(expressionLeft, BinaryOperatorKind.SUB, expressionRight,
odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte));
assertEquals(expressionLeft, expression.getLeftOperand());
assertEquals(expressionRight, expression.getRightOperand());
assertEquals(BinaryOperatorKind.SUB, expression.getOperator());
assertEquals(odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte), expression.getType());
String output = expression.accept(new FilterTreeToText());
assertEquals("<<2> sub <-1>>", output);
}
示例4: isParameterText
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
public FilterValidator isParameterText(final int parameterIndex, final String parameterText)
throws ExpressionVisitException, ODataApplicationException {
if (curExpression instanceof MethodImpl) {
MethodImpl methodCall = (MethodImpl) curExpression;
Expression parameter = methodCall.getParameters().get(parameterIndex);
String actualParameterText = FilterTreeToText.Serialize(parameter);
assertEquals(parameterText, actualParameterText);
} else if (curExpression instanceof MemberImpl) {
final MemberImpl member = (MemberImpl) curExpression;
final List<UriResource> uriResourceParts = member.getResourcePath().getUriResourceParts();
if (!uriResourceParts.isEmpty() && uriResourceParts.get(0) instanceof UriResourceFunctionImpl) {
assertEquals(parameterText, ((UriResourceFunctionImpl) uriResourceParts.get(0)).getParameters()
.get(parameterIndex).getText());
} else {
fail("Current expression is not a method or function");
}
} else {
fail("Current expression is not a method or function");
}
return this;
}
示例5: parseExprRel
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private Expression parseExprRel() throws UriParserException, UriValidationException {
if (tokenizer.next(TokenKind.IsofMethod)) {
// The isof method is a terminal. So no further operators are allowed.
return parseIsOfOrCastMethod(MethodKind.ISOF);
} else {
Expression left = parseExprAdd();
TokenKind operatorTokenKind = ParserHelper.next(tokenizer,
TokenKind.GreaterThanOperator, TokenKind.GreaterThanOrEqualsOperator,
TokenKind.LessThanOperator, TokenKind.LessThanOrEqualsOperator);
// Null for everything other than GT or GE or LT or LE
while (operatorTokenKind != null) {
final Expression right = parseExprAdd();
checkRelationTypes(left, right);
left = new BinaryImpl(left, tokenToBinaryOperator.get(operatorTokenKind), right,
odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean));
operatorTokenKind = ParserHelper.next(tokenizer,
TokenKind.GreaterThanOperator, TokenKind.GreaterThanOrEqualsOperator,
TokenKind.LessThanOperator, TokenKind.LessThanOrEqualsOperator);
}
return left;
}
}
示例6: parseIsOfOrCastMethod
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private Expression parseIsOfOrCastMethod(final MethodKind kind) throws UriParserException, UriValidationException {
// The TokenKind 'IsOfMethod' consumes also the opening parenthesis.
// The first parameter could be an expression or a type literal.
List<Expression> parameters = new ArrayList<Expression>();
ParserHelper.bws(tokenizer);
parameters.add(parseExpression());
if (!(parameters.get(0) instanceof TypeLiteral)) {
// The first parameter is not a type literal, so there must be a second parameter.
ParserHelper.bws(tokenizer);
ParserHelper.requireNext(tokenizer, TokenKind.COMMA);
ParserHelper.bws(tokenizer);
parameters.add(parseExpression());
ParserHelper.bws(tokenizer);
// The second parameter must be a type literal.
if (!(parameters.get(1) instanceof TypeLiteral)) {
throw new UriParserSemanticException("Type literal expected.",
UriParserSemanticException.MessageKeys.INCOMPATIBLE_TYPE_FILTER);
}
}
ParserHelper.requireNext(tokenizer, TokenKind.CLOSE);
return new MethodImpl(kind, parameters);
}
示例7: parseExprMul
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private Expression parseExprMul() throws UriParserException, UriValidationException {
Expression left = parseExprUnary();
TokenKind operatorTokenKind = ParserHelper.next(tokenizer,
TokenKind.MulOperator, TokenKind.DivOperator, TokenKind.ModOperator);
// Null for everything other than MUL or DIV or MOD
while (operatorTokenKind != null) {
checkNumericType(left);
final Expression right = parseExprUnary();
checkNumericType(right);
left = new BinaryImpl(left, tokenToBinaryOperator.get(operatorTokenKind), right,
odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double));
operatorTokenKind = ParserHelper.next(tokenizer,
TokenKind.MulOperator, TokenKind.DivOperator, TokenKind.ModOperator);
}
return left;
}
示例8: parsePrimitive
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private Expression parsePrimitive(final TokenKind primitiveTokenKind) throws UriParserException {
final String primitiveValueLiteral = tokenizer.getText();
if (primitiveTokenKind == TokenKind.EnumValue) {
return createEnumExpression(primitiveValueLiteral);
} else {
EdmPrimitiveTypeKind primitiveTypeKind = ParserHelper.tokenToPrimitiveType.get(primitiveTokenKind);
if (primitiveTypeKind == EdmPrimitiveTypeKind.Int64) {
primitiveTypeKind = determineIntegerType(primitiveValueLiteral);
}
final EdmPrimitiveType type = primitiveTypeKind == null ?
// Null handling
null :
odata.createPrimitiveTypeInstance(primitiveTypeKind);
return new LiteralImpl(primitiveValueLiteral, type);
}
}
示例9: parseLambdaRest
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private UriResourcePartTyped parseLambdaRest(final TokenKind lastTokenKind, final UriResourcePartTyped lastResource)
throws UriParserException, UriValidationException {
ParserHelper.requireNext(tokenizer, TokenKind.OPEN);
if (lastTokenKind == TokenKind.ANY && tokenizer.next(TokenKind.CLOSE)) {
return new UriResourceLambdaAnyImpl(null, null);
}
ParserHelper.requireNext(tokenizer, TokenKind.ODataIdentifier);
final String lambbdaVariable = tokenizer.getText();
ParserHelper.requireNext(tokenizer, TokenKind.COLON);
lambdaVariables.addFirst(new UriResourceLambdaVarImpl(lambbdaVariable,
lastResource == null ? referringType : lastResource.getType()));
// The ABNF suggests that the "lambaPredicateExpr" must contain at least one lambdaVariable,
// so arguably this could be checked in expression parsing or later in validation.
final Expression lambdaPredicateExpr = parseExpression();
lambdaVariables.removeFirst();
ParserHelper.requireNext(tokenizer, TokenKind.CLOSE);
if (lastTokenKind == TokenKind.ALL) {
return new UriResourceLambdaAllImpl(lambbdaVariable, lambdaPredicateExpr);
} else if (lastTokenKind == TokenKind.ANY) {
return new UriResourceLambdaAnyImpl(lambbdaVariable, lambdaPredicateExpr);
} else {
throw new UriParserSyntaxException("Unexpected token.", UriParserSyntaxException.MessageKeys.SYNTAX);
}
}
示例10: checkEqualityTypes
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private void checkEqualityTypes(final Expression left, final Expression right) throws UriParserException {
checkNoCollection(left);
checkNoCollection(right);
final EdmType leftType = getType(left);
final EdmType rightType = getType(right);
if (leftType == null || rightType == null || leftType.equals(rightType)) {
return;
}
// Numeric promotion for Edm.Byte and Edm.SByte
if (isType(leftType, EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte)
&& isType(rightType, EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte)) {
return;
}
if (leftType.getKind() != EdmTypeKind.PRIMITIVE
|| rightType.getKind() != EdmTypeKind.PRIMITIVE
|| !(((EdmPrimitiveType) leftType).isCompatible((EdmPrimitiveType) rightType)
|| ((EdmPrimitiveType) rightType).isCompatible((EdmPrimitiveType) leftType))) {
throw new UriParserSemanticException("Incompatible types.",
UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE,
leftType.getFullQualifiedName().getFullQualifiedNameAsString(),
rightType.getFullQualifiedName().getFullQualifiedNameAsString());
}
}
示例11: parseComputeTrafo
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private Compute parseComputeTrafo(EdmStructuredType referencedType)
throws UriParserException, UriValidationException {
ComputeImpl compute = new ComputeImpl();
do {
final Expression expression = new ExpressionParser(edm, odata)
.parse(tokenizer, referencedType, crossjoinEntitySetNames, aliases);
final EdmType expressionType = ExpressionParser.getType(expression);
if (expressionType.getKind() != EdmTypeKind.PRIMITIVE) {
throw new UriParserSemanticException("Compute expressions must return primitive values.",
UriParserSemanticException.MessageKeys.ONLY_FOR_PRIMITIVE_TYPES, "compute");
}
final String alias = parseAsAlias(referencedType, true);
((DynamicStructuredType) referencedType).addProperty(createDynamicProperty(alias, expressionType));
compute.addExpression(new ComputeExpressionImpl()
.setExpression(expression)
.setAlias(alias));
} while (tokenizer.next(TokenKind.COMMA));
ParserHelper.requireNext(tokenizer, TokenKind.CLOSE);
return compute;
}
示例12: parse
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
public OrderByOption parse(UriTokenizer tokenizer, final EdmStructuredType referencedType,
final Collection<String> crossjoinEntitySetNames, final Map<String, AliasQueryOption> aliases)
throws UriParserException, UriValidationException {
OrderByOptionImpl orderByOption = new OrderByOptionImpl();
do {
final Expression orderByExpression = new ExpressionParser(edm, odata)
.parse(tokenizer, referencedType, crossjoinEntitySetNames, aliases);
OrderByItemImpl item = new OrderByItemImpl();
item.setExpression(orderByExpression);
if (tokenizer.next(TokenKind.AscSuffix)) {
item.setDescending(false);
} else if (tokenizer.next(TokenKind.DescSuffix)) {
item.setDescending(true);
}
orderByOption.addOrder(item);
} while (tokenizer.next(TokenKind.COMMA));
return orderByOption;
}
示例13: relational
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
@Test
public void relational() throws Exception {
Expression expression = parseExpression("5 gt 5");
assertEquals("{5 GT 5}", expression.toString());
expression = parseExpression("5 ge 5");
assertEquals("{5 GE 5}", expression.toString());
expression = parseExpression("5 lt 5");
assertEquals("{5 LT 5}", expression.toString());
expression = parseExpression("5 le 5");
assertEquals("{5 LE 5}", expression.toString());
assertEquals("{5 LE 5.1}", parseExpression("5 le 5.1").toString());
assertEquals("{1 GT null}", parseExpression("1 gt null").toString());
assertEquals("{null GE 2}", parseExpression("null ge 2").toString());
assertEquals("{null LE null}", parseExpression("null le null").toString());
wrongExpression("5 gt duration'PT5H'");
}
示例14: parseMethod
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
private void parseMethod(TokenKind kind, String... parameters) throws UriParserException, UriValidationException {
final String methodName = kind.name().substring(0, kind.name().indexOf("Method")).toLowerCase(Locale.ROOT)
.replace("geo", "geo.");
String expressionString = methodName + '(';
boolean first = true;
for (final String parameter : parameters) {
if (first) {
first = false;
} else {
expressionString += ',';
}
expressionString += parameter;
}
expressionString += ')';
final Expression expression = parseExpression(expressionString);
assertEquals('{' + methodName + ' ' + Arrays.toString(parameters) + '}',
expression.toString());
}
示例15: visitLambdaExpression
import org.apache.olingo.server.api.uri.queryoption.expression.Expression; //导入依赖的package包/类
@Override
public Object visitLambdaExpression(
String lambdaFunction,
String lambdaVariable,
Expression expression) throws ExpressionVisitException, ODataApplicationException {
throw new NotImplementedException("visitLambdaExpression not implemented");
}