Java Code Examples for org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#SByte

The following examples show how to use org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#SByte . 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: EdmEnumTypeImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final CsdlEnumType enumType) {
  super(edm, enumName, EdmTypeKind.ENUM, enumType);

  if (enumType.getUnderlyingType() == null) {
    underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
  } else {
    final EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
    if (underlyingTypeKind == EdmPrimitiveTypeKind.Byte
        || underlyingTypeKind == EdmPrimitiveTypeKind.SByte
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int16
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int32
        || underlyingTypeKind == EdmPrimitiveTypeKind.Int64) {
      underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
    } else {
      throw new EdmException("Not allowed as underlying type: " + underlyingTypeKind);
    }
  }

  this.enumType = enumType;
  this.enumName = enumName;
}
 
Example 2
Source File: ExpressionParser.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private EdmPrimitiveTypeKind determineIntegerType(final String intValueAsString) throws UriParserSyntaxException {
  EdmPrimitiveTypeKind typeKind = null;
  try {
    final long value = Long.parseLong(intValueAsString);
    if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
      typeKind = EdmPrimitiveTypeKind.SByte;
    } else if (value >= 0 && value <= 255) {
      typeKind = EdmPrimitiveTypeKind.Byte;
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
      typeKind = EdmPrimitiveTypeKind.Int16;
    } else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
      typeKind = EdmPrimitiveTypeKind.Int32;
    } else {
      typeKind = EdmPrimitiveTypeKind.Int64;
    }
  } catch (final NumberFormatException e) {
    // The number cannot be formatted wrongly because the tokenizer already checked the format
    // but it is too large for Long and therefore too large for Edm.Int64.
    typeKind = EdmPrimitiveTypeKind.Decimal;
  }
  return typeKind;
}
 
Example 3
Source File: EdmTypeInfo.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public static EdmPrimitiveTypeKind determineTypeKind(final Object value) {
  if (value == null) {
    return null;
  } else if (value instanceof Boolean) {
    return EdmPrimitiveTypeKind.Boolean;
  } else if (value instanceof String) {
    return EdmPrimitiveTypeKind.String;
  } else if (value instanceof UUID) {
    return EdmPrimitiveTypeKind.Guid;
  } else if (value instanceof Long || value instanceof BigInteger) {
    return EdmPrimitiveTypeKind.Int64;
  } else if (value instanceof Integer) {
    return EdmPrimitiveTypeKind.Int32;
  } else if (value instanceof Short) {
    return EdmPrimitiveTypeKind.Int16;
  } else if (value instanceof Byte) {
    return EdmPrimitiveTypeKind.SByte;
  } else if (value instanceof BigDecimal) {
    return EdmPrimitiveTypeKind.Decimal;
  } else if (value instanceof Double) {
    return EdmPrimitiveTypeKind.Double;
  } else if (value instanceof Float) {
    return EdmPrimitiveTypeKind.Single;
  } else if (value instanceof Calendar || value instanceof Date || value instanceof java.sql.Timestamp) {
    return EdmPrimitiveTypeKind.DateTimeOffset;
  } else if (value instanceof java.sql.Date) {
    return EdmPrimitiveTypeKind.Date;
  } else if (value instanceof java.sql.Time) {
    return EdmPrimitiveTypeKind.TimeOfDay;
  } else if (value instanceof byte[] || value instanceof Byte[]) {
    return EdmPrimitiveTypeKind.Binary;
  }
  return null;
}
 
Example 4
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean matchNumberCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
  return node.isNumber() &&
      (primKind == EdmPrimitiveTypeKind.Int16
          || primKind == EdmPrimitiveTypeKind.Int32
          || primKind == EdmPrimitiveTypeKind.Byte
          || primKind == EdmPrimitiveTypeKind.SByte
          || primKind == EdmPrimitiveTypeKind.Single
          || primKind == EdmPrimitiveTypeKind.Double);
}