public static PropertyTypeInternal getType()

in core/src/main/java/com/jetbrains/youtrackdb/internal/core/serialization/serializer/record/string/RecordSerializerStringAbstract.java [206:319]


  public static PropertyTypeInternal getType(final String iValue) {
    if (iValue.length() == 0) {
      return null;
    }

    final var firstChar = iValue.charAt(0);

    if (firstChar == RID.PREFIX)
    // RID
    {
      return PropertyTypeInternal.LINK;
    } else if (firstChar == '\'' || firstChar == '"') {
      return PropertyTypeInternal.STRING;
    } else if (firstChar == StringSerializerHelper.BINARY_BEGINEND) {
      return PropertyTypeInternal.BINARY;
    } else if (firstChar == StringSerializerHelper.EMBEDDED_BEGIN) {
      return PropertyTypeInternal.EMBEDDED;
    } else if (firstChar == StringSerializerHelper.LIST_BEGIN) {
      return PropertyTypeInternal.EMBEDDEDLIST;
    } else if (firstChar == StringSerializerHelper.SET_BEGIN) {
      return PropertyTypeInternal.EMBEDDEDSET;
    } else if (firstChar == StringSerializerHelper.MAP_BEGIN) {
      return PropertyTypeInternal.EMBEDDEDMAP;
    }

    // BOOLEAN?
    if (iValue.equalsIgnoreCase("true") || iValue.equalsIgnoreCase("false")) {
      return PropertyTypeInternal.BOOLEAN;
    }

    // NUMBER OR STRING?
    var integer = true;
    for (var index = 0; index < iValue.length(); ++index) {
      final var c = iValue.charAt(index);
      if (c < '0' || c > '9') {
        if ((index == 0 && (c == '+' || c == '-'))) {
          continue;
        } else if (c == DECIMAL_SEPARATOR) {
          integer = false;
        } else {
          if (index > 0) {
            if (!integer && c == 'E') {
              // CHECK FOR SCIENTIFIC NOTATION
              if (index < iValue.length()) {
                if (iValue.charAt(index + 1) == '-')
                // JUMP THE DASH IF ANY (NOT MANDATORY)
                {
                  index++;
                }
                continue;
              }
            } else if (c == 'f') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.FLOAT;
            } else if (c == 'c') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.DECIMAL;
            } else if (c == 'l') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.LONG;
            } else if (c == 'd') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.DOUBLE;
            } else if (c == 'b') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.BYTE;
            } else if (c == 'a') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.DATE;
            } else if (c == 't') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.DATETIME;
            } else if (c == 's') {
              return index != (iValue.length() - 1) ? PropertyTypeInternal.STRING
                  : PropertyTypeInternal.SHORT;
            } else if (c == 'e') { // eg. 1e-06
              try {
                Double.parseDouble(iValue);
                return PropertyTypeInternal.DOUBLE;
              } catch (Exception ignore) {
                return PropertyTypeInternal.STRING;
              }
            }
          }

          return PropertyTypeInternal.STRING;
        }
      }
    }

    if (integer) {
      // AUTO CONVERT TO LONG IF THE INTEGER IS TOO BIG
      final var numberLength = iValue.length();
      if (numberLength > MAX_INTEGER_DIGITS
          || (numberLength == MAX_INTEGER_DIGITS && iValue.compareTo(MAX_INTEGER_AS_STRING) > 0)) {
        return PropertyTypeInternal.LONG;
      }

      return PropertyTypeInternal.INTEGER;
    }

    // CHECK IF THE DECIMAL NUMBER IS A FLOAT OR DOUBLE
    final var dou = Double.parseDouble(iValue);
    if (dou <= Float.MAX_VALUE
        && dou >= Float.MIN_VALUE
        && Double.toString(dou).equals(Float.toString((float) dou))
        && (double) Double.valueOf(dou).floatValue() == dou) {
      return PropertyTypeInternal.FLOAT;
    } else if (!Double.toString(dou).equals(iValue)) {
      return PropertyTypeInternal.DECIMAL;
    }

    return PropertyTypeInternal.DOUBLE;
  }