@Override public Optional<ValueChange> compare(BigDecimal left, BigDecimal right, GlobalId affectedId, Property property) { if (equals(left, right)){ return Optional.empty(); } return Optional.of(new ValueChange(affectedId, property.getName(), left, right)); }
@Override public ValueChange fromJson(JsonElement json, JsonDeserializationContext context) { JsonObject jsonObject = (JsonObject) json; PropertyChangeStub stub = deserializeStub(jsonObject, context); Object leftValue = context.deserialize(jsonObject.get(LEFT_VALUE_FIELD), stub.property.getGenericType()); Object rightValue = context.deserialize(jsonObject.get(RIGHT_VALUE_FIELD), stub.property.getGenericType()); CommitMetadata commitMetadata = deserializeCommitMetadata(jsonObject, context); return new ValueChange(stub.id, stub.getPropertyName(), leftValue, rightValue, ofNullable(commitMetadata)); }
public PropertyChange calculateChanges(Object leftValue, Object rightValue, GlobalId affectedId, JaversProperty property) { OptionalType optionalType = ((JaversProperty) property).getType(); JaversType contentType = typeMapper.getJaversType(optionalType.getItemType()); Optional leftOptional = normalize((Optional) leftValue); Optional rightOptional = normalize((Optional) rightValue); if (contentType instanceof ManagedType){ GlobalId leftId = getAndDehydrate(leftOptional, contentType); GlobalId rightId = getAndDehydrate(rightOptional, contentType); if (Objects.equals(leftId, rightId)) { return null; } return new ReferenceChange(affectedId, property.getName(), leftId, rightId, leftValue, rightValue); } if (contentType instanceof PrimitiveOrValueType) { if (leftOptional.equals(rightOptional)) { return null; } return new ValueChange(affectedId, property.getName(), leftOptional, rightOptional); } throw new JaversException(UNSUPPORTED_OPTIONAL_CONTENT_TYPE, contentType); }
/** * @param property supported property (of PrimitiveType or ValueObjectType) */ @Override public ValueChange calculateChanges(NodePair pair, JaversProperty property) { Object leftValue = pair.getLeftPropertyValue(property); Object rightValue = pair.getRightPropertyValue(property); //special treatment for EmbeddedId - could be ValueObjects without good equals() implementation if (isIdProperty(pair, property)) { //For idProperty, only initial change is possible (from null to value). //If we have values on both sides, we know that they have the same String representation if (leftValue != null && rightValue != null) { return null; } } else { if (property.getType().equals(leftValue, rightValue)) { return null; } } return new ValueChange(pair.getGlobalId(), property.getName(), leftValue, rightValue); }