Java Code Examples for org.apache.olingo.commons.api.edm.EdmType#equals()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmType#equals() . 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: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
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());
  }
}
 
Example 2
Source File: TypedOperand.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public TypedOperand castToCommonType(final VisitorOperand otherOperand) throws ODataApplicationException {
    final TypedOperand other = otherOperand.asTypedOperand();
    final EdmType oType = other.getType();
    // In case of numeric values make sure that the EDM type is equals, check also the java type.
    // So it is possible, that there is an conversation even if the same
    // EdmType is provided.
    // For example consider an Edm16 (internal Integer) and Edm16(internal
    // Short)
    // shortInstance.equals(intInstance) will always be false!
    if (type == oType && value != null && other.getValue() != null &&
        value.getClass() == other.getValue().getClass()) {
        return this;
    } else if (is(ODataConstants.primitiveNull) || other.is(ODataConstants.primitiveNull)) {
        return this;
    }
    if (type.equals(ODataConstants.primitiveDouble) || oType.equals(ODataConstants.primitiveDouble)) {
        return asTypedOperand(ODataConstants.primitiveDouble);
    } else if (type.equals(ODataConstants.primitiveSingle) || oType.equals(ODataConstants.primitiveSingle)) {
        return asTypedOperand(ODataConstants.primitiveSingle);
    } else if (type.equals(ODataConstants.primitiveDecimal) || oType.equals(ODataConstants.primitiveDecimal)) {
        return asTypedOperand(ODataConstants.primitiveDecimal);
    } else if (type.equals(ODataConstants.primitiveInt64) || oType.equals(ODataConstants.primitiveInt64)) {
        return asTypedOperand(ODataConstants.primitiveInt64);
    } else if (type.equals(ODataConstants.primitiveInt32) || oType.equals(ODataConstants.primitiveInt32)) {
        return asTypedOperand(ODataConstants.primitiveInt32);
    } else if (type.equals(ODataConstants.primitiveInt16) || oType.equals(ODataConstants.primitiveInt16)) {
        return asTypedOperand(ODataConstants.primitiveInt16);
    } else {
        return asTypedOperand((EdmPrimitiveType) type);
    }
}
 
Example 3
Source File: TypedOperand.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public TypedOperand castToCommonType(final VisitorOperand otherOperand) throws ODataApplicationException {
  final TypedOperand other = otherOperand.asTypedOperand();
  final EdmType oType = other.getType();
  
  // In case of numberic values make sure that the EDM type is equal, check also the java type.
  // It is possible that there is an conversion even if the same EdmType is provided.
  // For example consider an Edm.Int32 (internal Integer) and an Edm.Int16 (internal Short) value:
  // shortInstance.equals(intInstance) will always be false!
  if (type == oType && value != null && other.getValue() != null
      && value.getClass() == other.getValue().getClass()) {
    return this;
  } else if (is(primNull) || other.is(primNull)) {
    return this;
  }

  if (type.equals(primDouble) || oType.equals(primDouble)) {
    return (value instanceof ArrayList) ? asTypedOperandForCollection(primDouble) : asTypedOperand(primDouble);
  } else if (type.equals(primSingle) || oType.equals(primSingle)) {
    return (value instanceof ArrayList) ? asTypedOperandForCollection(primSingle) : asTypedOperand(primSingle);
  } else if (type.equals(primDecimal) || oType.equals(primDecimal)) {
    return (value instanceof ArrayList) ? asTypedOperandForCollection(primDecimal) : asTypedOperand(primDecimal);
  } else if (type.equals(primInt64) || oType.equals(primInt64)) {
    return (value instanceof ArrayList) ? asTypedOperandForCollection(primInt64) : asTypedOperand(primInt64);
  } else if (type.equals(primInt32) || oType.equals(primInt32)) {
    return (value instanceof ArrayList) ? asTypedOperandForCollection(primInt32) : asTypedOperand(primInt32);
  } else if (type.equals(primInt16) || oType.equals(primInt16)) {
    return (value instanceof ArrayList) ? asTypedOperandForCollection(primInt16) : asTypedOperand(primInt16);
  } else {
    return (value instanceof ArrayList) ? asTypedOperandForCollection((EdmPrimitiveType) type) : 
      asTypedOperand((EdmPrimitiveType) type);
  }
}
 
Example 4
Source File: FilterParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public FilterOption parse(UriTokenizer tokenizer, final EdmType referencedType,
    final Collection<String> crossjoinEntitySetNames, final Map<String, AliasQueryOption> aliases)
    throws UriParserException, UriValidationException {
  final Expression filterExpression = new ExpressionParser(edm, odata)
      .parse(tokenizer, referencedType, crossjoinEntitySetNames, aliases);
  final EdmType type = ExpressionParser.getType(filterExpression);
  if (type == null || type.equals(odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean))) {
    return new FilterOptionImpl().setExpression(filterExpression);
  } else {
    throw new UriParserSemanticException("Filter expressions must be boolean.",
        UriParserSemanticException.MessageKeys.TYPES_NOT_COMPATIBLE,
        "Edm.Boolean", type.getFullQualifiedName().getFullQualifiedNameAsString());
  }
}
 
Example 5
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean isType(final EdmType type, final EdmPrimitiveTypeKind... kinds) throws UriParserException {
  if (type == null) {
    return true;
  }
  for (final EdmPrimitiveTypeKind kind : kinds) {
    if (type.equals(odata.createPrimitiveTypeInstance(kind))) {
      return true;
    }
  }
  return false;
}
 
Example 6
Source File: ParserHelper.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected static AliasQueryOption parseAliasValue(final String name, final EdmType type, final boolean isNullable,
    final boolean isCollection, final Edm edm, final EdmType referringType,
    final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException {
  final EdmTypeKind kind = type == null ? null : type.getKind();
  final AliasQueryOption alias = aliases.get(name);
  if (alias != null && alias.getText() != null) {
    UriTokenizer aliasTokenizer = new UriTokenizer(alias.getText());
    if (kind == null
        || !((isCollection || kind == EdmTypeKind.COMPLEX || kind == EdmTypeKind.ENTITY ?
        aliasTokenizer.next(TokenKind.jsonArrayOrObject) :
        nextPrimitiveTypeValue(aliasTokenizer, (EdmPrimitiveType) type, isNullable))
        && aliasTokenizer.next(TokenKind.EOF))) {
      // The alias value is not an allowed literal value, so parse it again as expression.
      aliasTokenizer = new UriTokenizer(alias.getText());
      // Don't pass on the current alias to avoid circular references.
      Map<String, AliasQueryOption> aliasesInner = new HashMap<>(aliases);
      aliasesInner.remove(name);
      final Expression expression = new ExpressionParser(edm, odata)
          .parse(aliasTokenizer, referringType, null, aliasesInner);
      final EdmType expressionType = ExpressionParser.getType(expression);
      if (aliasTokenizer.next(TokenKind.EOF)
          && (expressionType == null || type == null || expressionType.equals(type))) {
        ((AliasQueryOptionImpl) alias).setAliasValue(expression);
      } else {
        throw new UriParserSemanticException("Illegal value for alias '" + alias.getName() + "'.",
            UriParserSemanticException.MessageKeys.UNKNOWN_PART, alias.getText());
      }
    }
  }
  return alias;
}