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

The following examples show how to use org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind#TimeOfDay . 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: 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 2
Source File: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private boolean matchTextualCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
  return node.isTextual() &&
      (primKind == EdmPrimitiveTypeKind.String
          || primKind == EdmPrimitiveTypeKind.Binary
          || primKind == EdmPrimitiveTypeKind.Date
          || primKind == EdmPrimitiveTypeKind.DateTimeOffset
          || primKind == EdmPrimitiveTypeKind.Duration
          || primKind == EdmPrimitiveTypeKind.Guid
          || primKind == EdmPrimitiveTypeKind.TimeOfDay);
}
 
Example 3
Source File: EdmConstantExpressionImpl.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private void build() {
  if (csdlExp.getType() == CsdlConstantExpression.ConstantExpressionType.EnumMember) {
    if (csdlExp.getValue() == null) {
      throw new EdmException("Expression value must not be null");
    }
    final List<String> localEnumValues = new ArrayList<>();
    for (String split : csdlExp.getValue().split(" ")) {
      final String[] enumSplit = split.split("/");
      if (enumSplit.length != 2) {
        throw new EdmException("Enum expression value must consist of enumTypeName/EnumMember.");
      }
      enumTypeName = enumSplit[0];
      localEnumValues.add(enumSplit[1]);
    }
    enumMembers = Collections.unmodifiableList(localEnumValues);
  } else {
    EdmPrimitiveTypeKind kind;
    switch (csdlExp.getType()) {
    case Binary:
      kind = EdmPrimitiveTypeKind.Binary;
      break;
    case Bool:
      kind = EdmPrimitiveTypeKind.Boolean;
      break;
    case Date:
      kind = EdmPrimitiveTypeKind.Date;
      break;
    case DateTimeOffset:
      kind = EdmPrimitiveTypeKind.DateTimeOffset;
      break;
    case Decimal:
      kind = EdmPrimitiveTypeKind.Decimal;
      break;
    case Duration:
      kind = EdmPrimitiveTypeKind.Duration;
      break;
    case Float:
      kind = EdmPrimitiveTypeKind.Single;
      break;
    case Guid:
      kind = EdmPrimitiveTypeKind.Guid;
      break;
    case Int:
      kind = EdmPrimitiveTypeKind.Int32;
      break;
    case TimeOfDay:
      kind = EdmPrimitiveTypeKind.TimeOfDay;
      break;
    case String:
    default:
      kind = EdmPrimitiveTypeKind.String;
    }
    type = EdmPrimitiveTypeFactory.getInstance(kind);
    try {
      primitive = type.valueOfString(csdlExp.getValue(), null, null, null, null, null, type.getDefaultType());
    } catch (EdmPrimitiveTypeException e) {
      throw new IllegalArgumentException(e);
    }
  }
  built = true;
}
 
Example 4
Source File: ParserHelper.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private static boolean nextPrimitiveTypeValue(UriTokenizer tokenizer,
    final EdmPrimitiveType primitiveType, final boolean nullable) {
  final EdmPrimitiveType type = primitiveType instanceof EdmTypeDefinition ?
      ((EdmTypeDefinition) primitiveType).getUnderlyingType() :
      primitiveType;
  if (tokenizer.next(TokenKind.ParameterAliasName)) {
    return true;
  } else if (nullable && tokenizer.next(TokenKind.NULL)) {
    return true;

  // Special handling for frequently-used types and types with more than one token kind.
  } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Boolean).equals(type)) {
    return tokenizer.next(TokenKind.BooleanValue);
  } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.String).equals(type)) {
    return tokenizer.next(TokenKind.StringValue);
  } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.SByte).equals(type)
      || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Byte).equals(type)
      || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int16).equals(type)
      || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int32).equals(type)
      || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Int64).equals(type)) {
    return tokenizer.next(TokenKind.IntegerValue);
  } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid).equals(type)) {
    return tokenizer.next(TokenKind.GuidValue);
  } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal).equals(type)) {
    // The order is important.
    // A decimal value should not be parsed as integer and let the tokenizer stop at the decimal point.
    return tokenizer.next(TokenKind.DecimalValue)
        || tokenizer.next(TokenKind.IntegerValue);
  } else if (odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Double).equals(type)
      || odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Single).equals(type)) {
    // The order is important.
    // A floating-point value should not be parsed as decimal and let the tokenizer stop at 'E'.
    // A decimal value should not be parsed as integer and let the tokenizer stop at the decimal point.
    return tokenizer.next(TokenKind.DoubleValue)
        || tokenizer.next(TokenKind.DecimalValue)
        || tokenizer.next(TokenKind.IntegerValue);
  } else if (type.getKind() == EdmTypeKind.ENUM) {
    return tokenizer.next(TokenKind.EnumValue);
  } else {
    // Check the types that have not been checked already above.
    for (final Entry<TokenKind, EdmPrimitiveTypeKind> entry : tokenToPrimitiveType.entrySet()) {
      final EdmPrimitiveTypeKind kind = entry.getValue();
      if ((kind == EdmPrimitiveTypeKind.Date || kind == EdmPrimitiveTypeKind.DateTimeOffset
          || kind == EdmPrimitiveTypeKind.TimeOfDay || kind == EdmPrimitiveTypeKind.Duration
          || kind == EdmPrimitiveTypeKind.Binary
          || kind.isGeospatial())
          && odata.createPrimitiveTypeInstance(kind).equals(type)) {
        return tokenizer.next(entry.getKey());
      }
    }
    return false;
  }
}
 
Example 5
Source File: MethodImpl.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public EdmType getType() {
  EdmPrimitiveTypeKind kind = null;
  switch (method) {
  case CONTAINS:
  case STARTSWITH:
  case ENDSWITH:
  case SUBSTRINGOF:
    kind = EdmPrimitiveTypeKind.Boolean;
    break;
  case LENGTH:
  case INDEXOF:
    kind = EdmPrimitiveTypeKind.Int32;
    break;
  case SUBSTRING:
  case TOLOWER:
  case TOUPPER:
  case TRIM:
  case CONCAT:
    kind = EdmPrimitiveTypeKind.String;
    break;
  case YEAR:
  case MONTH:
  case DAY:
  case HOUR:
  case MINUTE:
  case SECOND:
    kind = EdmPrimitiveTypeKind.Int32;
    break;
  case FRACTIONALSECONDS:
  case TOTALSECONDS:
    kind = EdmPrimitiveTypeKind.Decimal;
    break;
  case DATE:
    kind = EdmPrimitiveTypeKind.Date;
    break;
  case TIME:
    kind = EdmPrimitiveTypeKind.TimeOfDay;
    break;
  case TOTALOFFSETMINUTES:
    kind = EdmPrimitiveTypeKind.Int32;
    break;
  case MINDATETIME:
  case MAXDATETIME:
  case NOW:
    kind = EdmPrimitiveTypeKind.DateTimeOffset;
    break;
  case ROUND:
  case FLOOR:
  case CEILING:
    // Needs to be refined if Decimal must be distinguished from Double.
    kind = EdmPrimitiveTypeKind.Double;
    break;
  case GEODISTANCE:
  case GEOLENGTH:
    kind = EdmPrimitiveTypeKind.Double;
    break;
  case GEOINTERSECTS:
    kind = EdmPrimitiveTypeKind.Boolean;
    break;
  case CAST:
    return ((TypeLiteral) parameters.get(parameters.size() - 1)).getType();
  case ISOF:
    kind = EdmPrimitiveTypeKind.Boolean;
    break;
  }
  return new ODataImpl().createPrimitiveTypeInstance(kind);
}