org.apache.olingo.commons.api.edm

## Interface EdmPrimitiveType

- All Superinterfaces:
    EdmNamed, EdmType
  All Known Subinterfaces:
    EdmEnumType, EdmTypeDefinition

      public interface EdmPrimitiveType
      extends EdmType

  EdmPrimitiveType is a primitive type as defined in the Entity Data Model (EDM).
  There are methods to convert EDM primitive types from and to Java objects, respectively. The following Java types are supported:

  EDM primitive type | Java types
  --- | ---
  Binary | byte[], `Byte`[]
  Boolean | `Boolean`
  Byte | `Short`, `Byte`, `Integer`, `Long`, `BigInteger`
  Date | `Calendar`, `Date`, `Timestamp`, `Time`, `Long`
  DateTimeOffset | `Timestamp`, `Calendar`, `Date`, `Time`, `Long`
  Decimal | `BigDecimal`, `BigInteger`, `Double`, `Float`, `Byte`, `Short`, `Integer`, `Long`
  Double | `Double`, `Float`, `BigDecimal`, `Byte`, `Short`, `Integer`, `Long`
  Duration | `BigDecimal`, `BigInteger`, `Double`, `Float`, `Byte`, `Short`, `Integer`, `Long`
  Guid | `UUID`
  Int16 | `Short`, `Byte`, `Integer`, `Long`, `BigInteger`
  Int32 | `Integer`, `Byte`, `Short`, `Long`, `BigInteger`
  Int64 | `Long`, `Byte`, `Short`, `Integer`, `BigInteger`
  SByte | `Byte`, `Short`, `Integer`, `Long`, `BigInteger`
  Single | `Float`, `Double`, `BigDecimal`, `Byte`, `Short`, `Integer`, `Long`
  String | `String`
  TimeOfDay | `Calendar`, `Date`, `Timestamp`, `Time`, `Long`

  The first Java type is the default type for the respective EDM primitive type.

  For all EDM primitive types, the `Nullable` facet is taken into account. For `Binary` and `String`, `MaxLength` is also applicable. For `String`, the facet `Unicode` is considered additionally. The EDM primitive types `DateTimeOffset`, `Decimal`, `Duration`, and `TimeOfDay` can have a `Precision` facet. Additionally, `Decimal` can have the facet `Scale`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `EDM_NAMESPACE`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `fromUriLiteral(String literal)` Converts URI literal representation to default literal representation.
    `Class<?>` | `getDefaultType()` Returns the default Java type for this EDM primitive type as described in the documentation of `EdmPrimitiveType`.
    `boolean` | `isCompatible(EdmPrimitiveType primitiveType)` Checks type compatibility.
    `String` | `toUriLiteral(String literal)` Converts default literal representation to URI literal representation.
    `boolean` | `validate(String value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode)` Validates literal value.
    `default boolean` | `validateDecimals(String value, Boolean isNullable, Integer maxLength, Integer precision, String scale, Boolean isUnicode)` Validates literal value for Decimal values in V4.01
    `<T> T` | `valueOfString(String value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode, Class<T> returnType)` Converts literal representation of value to system data type.
    `String` | `valueToString(Object value, Boolean isNullable, Integer maxLength, Integer precision, Integer scale, Boolean isUnicode)` Converts system data type to literal representation of value.

    - ### Methods inherited from interface org.apache.olingo.commons.api.edm.EdmType

      `getFullQualifiedName, getKind, getNamespace`

    - ### Methods inherited from interface org.apache.olingo.commons.api.edm.EdmNamed

      `getName`

- - ### Field Detail

    - #### EDM_NAMESPACE

          static final String EDM_NAMESPACE

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### isCompatible

          boolean isCompatible(EdmPrimitiveType primitiveType)

      Checks type compatibility.
      Parameters:
        `primitiveType` - the `EdmPrimitiveType` to be tested for compatibility
      Returns:
        `true` if the provided type is compatible to this type

    - #### getDefaultType

          Class<?> getDefaultType()

      Returns the default Java type for this EDM primitive type as described in the documentation of `EdmPrimitiveType`.
      Returns:
        the default Java type

    - #### validate

          boolean validate(String value,
                           Boolean isNullable,
                           Integer maxLength,
                           Integer precision,
                           Integer scale,
                           Boolean isUnicode)

      Validates literal value.
      Parameters:
        `value` - the literal value
        `isNullable` - whether the `null` value is allowed
        `maxLength` - the maximum length
        `precision` - the precision
        `scale` - the scale
        `isUnicode` - whether non-ASCII characters are allowed (relevant only for Edm.String)
      Returns:
        `true` if the validation is successful

    - #### valueOfString

          <T> T valueOfString(String value,
                              Boolean isNullable,
                              Integer maxLength,
                              Integer precision,
                              Integer scale,
                              Boolean isUnicode,
                              Class<T> returnType)
                       throws EdmPrimitiveTypeException

      Converts literal representation of value to system data type.
      Parameters:
        `value` - the literal representation of value
        `isNullable` - whether the `null` value is allowed
        `maxLength` - the maximum length
        `precision` - the precision
        `scale` - the scale
        `isUnicode` - whether non-ASCII characters are allowed (relevant only for Edm.String)
        `returnType` - the class of the returned value; it must be one of the list in the documentation of `EdmPrimitiveType`
      Returns:
        the value as an instance of the class the parameter `returnType` indicates
      Throws:
        `EdmPrimitiveTypeException`

    - #### valueToString

          String valueToString(Object value,
                               Boolean isNullable,
                               Integer maxLength,
                               Integer precision,
                               Integer scale,
                               Boolean isUnicode)
                        throws EdmPrimitiveTypeException

      Converts system data type to literal representation of value.

      Returns `null` if value is `null` and `null` is an allowed value.

      Parameters:
        `value` - the Java value as Object; its type must be one of the list in the documentation of `EdmPrimitiveType`
        `isNullable` - whether the `null` value is allowed
        `maxLength` - the maximum length
        `precision` - the precision
        `scale` - the scale
        `isUnicode` - whether non-ASCII characters are allowed (relevant only for Edm.String)
      Returns:
        literal representation as String
      Throws:
        `EdmPrimitiveTypeException`

    - #### toUriLiteral

          String toUriLiteral(String literal)

      Converts default literal representation to URI literal representation.

      Returns `null` if the literal is `null`. Does not perform any validation.

      Parameters:
        `literal` - the literal in default representation
      Returns:
        URI literal representation as String

    - #### fromUriLiteral

          String fromUriLiteral(String literal)
                         throws EdmPrimitiveTypeException

      Converts URI literal representation to default literal representation.

      Returns `null` if the literal is `null`. Checks the presence of a required prefix and of required surrounding quotation marks but does not perform any further validation.

      Parameters:
        `literal` - the literal in URI representation
      Returns:
        default literal representation as String
      Throws:
        `EdmPrimitiveTypeException` - if a required prefix or required surrounding quotation marks are missing

    - #### validateDecimals

          default boolean validateDecimals(String value,
                                           Boolean isNullable,
                                           Integer maxLength,
                                           Integer precision,
                                           String scale,
                                           Boolean isUnicode)

      Validates literal value for Decimal values in V4.01
      Parameters:
        `value` - the literal value
        `isNullable` - whether the `null` value is allowed
        `maxLength` - the maximum length
        `precision` - the precision
        `scale` - the scale (could be variable or floating)
        `isUnicode` - whether non-ASCII characters are allowed (relevant only for Edm.String)
      Returns:
        `true` if the validation is successful

Copyright © 2013–2022 The Apache Software Foundation. All rights reserved.