private static boolean compareScalarValues()

in core/src/main/java/com/jetbrains/youtrackdb/internal/core/record/impl/EntityHelper.java [1282:1355]


  private static boolean compareScalarValues(
      Object myValue,
      DatabaseSessionInternal iMyDb,
      Object otherValue,
      DatabaseSessionInternal iOtherDb,
      RIDMapper ridMapper) {
    if (myValue == null && otherValue != null || myValue != null && otherValue == null) {
      return false;
    }

    if (myValue == null) {
      return true;
    }

    if (myValue.getClass().isArray() && !otherValue.getClass().isArray()
        || !myValue.getClass().isArray() && otherValue.getClass().isArray()) {
      return false;
    }

    if (myValue.getClass().isArray()) {
      final var myArraySize = Array.getLength(myValue);
      final var otherArraySize = Array.getLength(otherValue);

      if (myArraySize != otherArraySize) {
        return false;
      }

      for (var i = 0; i < myArraySize; i++) {
        final var first = Array.get(myValue, i);
        final var second = Array.get(otherValue, i);
        if (first == null && second != null) {
          return false;
        }
        if (first instanceof EntityImpl && second instanceof EntityImpl) {
          return hasSameContentOf(
              (EntityImpl) first, iMyDb, (EntityImpl) second, iOtherDb, ridMapper);
        }

        if (first != null && !first.equals(second)) {
          return false;
        }
      }

      return true;
    }

    if (myValue instanceof Number myNumberValue && otherValue instanceof Number otherNumberValue) {

      if (isInteger(myNumberValue) && isInteger(otherNumberValue)) {
        return myNumberValue.longValue() == otherNumberValue.longValue();
      } else if (isFloat(myNumberValue) && isFloat(otherNumberValue)) {
        return myNumberValue.doubleValue() == otherNumberValue.doubleValue();
      }
    }

    if (ridMapper != null
        && myValue instanceof Identifiable myIdentifiableValue
        && otherValue instanceof Identifiable otherIdentifiableValue) {
      myValue = myIdentifiableValue.getIdentity();
      otherValue = otherIdentifiableValue.getIdentity();
      if (((RID) myValue).isPersistent()) {
        var convertedValue = ridMapper.map((RID) myValue);
        if (convertedValue != null) {
          myValue = convertedValue;
        }
      }
    }

    if (myValue instanceof Date && otherValue instanceof Date) {
      return ((Date) myValue).getTime() / 1000 == ((Date) otherValue).getTime() / 1000;
    }

    return myValue.equals(otherValue);
  }