org.apache.olingo.odata2.api.uri.expression.UnaryOperator Java Examples

The following examples show how to use org.apache.olingo.odata2.api.uri.expression.UnaryOperator. 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: FunctionalVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression ue, UnaryOperator operator, Object operand)
{
   // operand is a Node<?> (Expression Tree)
   // Returns an instance of Transformer<?> (functional java) as a Node<?> (Expression Tree)
   Transformer trans;
   switch (operator)
   {
      case   NOT: trans = Transformers.not();   break;
      case MINUS: trans = Transformers.minus(); break;

      default:
         throw new UnsupportedOperationException("Unsupported operator: " + operator.toUriLiteral());
   }
   ExecutableExpressionTree.Node param = ExecutableExpressionTree.Node.class.cast(operand);

   return ExecutableExpressionTree.Node.createNode(trans, param);
}
 
Example #2
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression unary_expression,
      UnaryOperator operator, Object operand)
{
   switch (operator)
   {
      case MINUS:
      {
         if (operand instanceof Long)
         {
            return -((Long) operand);
         }
         else if (operand instanceof Double)
         {
            return -((Double) operand);
         }
         else
         {
            throw new UnsupportedOperationException("Invalid expression: " +
                  unary_expression.getUriLiteral());
         }
      }
      case NOT:
      {
         return Restrictions.not((Criterion) operand);
      }
      default:
         break;
   }
   throw new UnsupportedOperationException("Unsupported operator: " +
         operator.toUriLiteral());
}
 
Example #3
Source File: JsonVisitor.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitUnary(final UnaryExpression unaryExpression, final UnaryOperator operator, final Object operand) {
  try {
    StringWriter writer = new StringWriter();
    JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(writer);
    jsonStreamWriter.beginObject().namedStringValueRaw("nodeType", unaryExpression.getKind().toString()).separator()
        .namedStringValueRaw("operator", operator.toUriLiteral()).separator().namedStringValueRaw("type",
            getType(unaryExpression)).separator().name("operand").unquotedValue(operand.toString()).endObject();
    writer.flush();
    return writer.toString();
  } catch (final IOException e) {
    return null;
  }
}
 
Example #4
Source File: InfoUnaryOperator.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public InfoUnaryOperator(final UnaryOperator operator, final String category,
    final ParameterSetCombination combination) {
  this.operator = operator;
  this.category = category;
  syntax = operator.toUriLiteral();
  this.combination = combination;
}
 
Example #5
Source File: FilterToJsonTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonUnary() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "not 'a'");
  String jsonString = toJson(expression);

  LinkedTreeMap<String, Object> jsonMap = new Gson().fromJson(jsonString, LinkedTreeMap.class);
  checkUnary(jsonMap, UnaryOperator.NOT, null);

  LinkedTreeMap<String, Object> operand = (LinkedTreeMap<String, Object>) jsonMap.get(OPERAND);
  checkLiteral(operand, "Edm.String", "a");
}
 
Example #6
Source File: FilterToJsonTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void
    checkUnary(final LinkedTreeMap<String, Object> unary, final UnaryOperator expectedOperator,
        final String expectedType) {
  assertEquals(ExpressionKind.UNARY.toString(), unary.get(NODETYPE));
  assertEquals(expectedOperator.toString(), unary.get(OPERATOR));
  assertEquals(expectedType, unary.get(TYPE));
  assertNotNull(unary.get(OPERAND));
}
 
Example #7
Source File: UnaryExpressionImpl.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public UnaryOperator getOperator() {
  return operatorInfo.operator;
}
 
Example #8
Source File: InfoUnaryOperator.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
public UnaryOperator getOperator() {
  return operator;
}
 
Example #9
Source File: VisitorTool.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitUnary(final UnaryExpression unaryExpression, final UnaryOperator operator, final Object operand) {
  return "{" + operator.toUriLiteral() + " " + operand.toString() + "}";
}
 
Example #10
Source File: ODataParser.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression unaryExpression, UnaryOperator operator, Object operand) {
    throw new SearchParseException("Unsupported operation visitUnary: " + unaryExpression
        + "," + operator + "," + operand);
}