当前位置: 首页>>代码示例>>Java>>正文


Java Expression类代码示例

本文整理汇总了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;
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:29,代码来源:RequestCreator.java

示例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);
    }
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:22,代码来源:ODataExpressionVisitor.java

示例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);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:17,代码来源:ExpressionTest.java

示例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;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:26,代码来源:FilterValidator.java

示例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;
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:ExpressionParser.java

示例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);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:24,代码来源:ExpressionParser.java

示例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;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:17,代码来源:ExpressionParser.java

示例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);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:18,代码来源:ExpressionParser.java

示例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);
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:26,代码来源:ExpressionParser.java

示例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());
  }
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:27,代码来源:ExpressionParser.java

示例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;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:21,代码来源:ApplyParser.java

示例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;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:19,代码来源:OrderByParser.java

示例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'");
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:23,代码来源:ExpressionParserTest.java

示例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());
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:20,代码来源:ExpressionParserTest.java

示例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");
}
 
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:9,代码来源:ElasticsearchExpressionVisitor.java


注:本文中的org.apache.olingo.server.api.uri.queryoption.expression.Expression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。