use of org.neo4j.values.storable.DoubleValue in project neo4j by neo4j.
the class ProcedureCompilation method toAnyValue.
/**
* Takes an expression evaluating to one of the supported java values and turns
* it into the corresponding AnyValue
*
* @param expression the expression to evaluate
* @param userType the type of the expression to map
* @return an expression properly mapped to AnyValue
*/
private static Expression toAnyValue(Expression expression, Class<?> userType, Expression context) {
if (AnyValue.class.isAssignableFrom(userType)) {
return nullCheck(expression, cast(userType, expression));
}
String type = userType.getCanonicalName();
if (type.equals(LONG)) {
return invoke(methodReference(Values.class, LongValue.class, "longValue", long.class), expression);
} else if (type.equals(BOXED_LONG)) {
return nullCheck(expression, invoke(methodReference(Values.class, LongValue.class, "longValue", long.class), unbox(expression)));
} else if (type.equals(DOUBLE)) {
return invoke(methodReference(Values.class, DoubleValue.class, "doubleValue", double.class), expression);
} else if (type.equals(BOXED_DOUBLE)) {
return nullCheck(expression, invoke(methodReference(Values.class, DoubleValue.class, "doubleValue", double.class), unbox(expression)));
} else if (type.equals(NUMBER)) {
return nullCheck(expression, invoke(methodReference(Values.class, NumberValue.class, "numberValue", Number.class), expression));
} else if (type.equals(BOOLEAN)) {
return invoke(methodReference(Values.class, BooleanValue.class, "booleanValue", boolean.class), expression);
} else if (type.equals(BOXED_BOOLEAN)) {
return nullCheck(expression, invoke(methodReference(Values.class, BooleanValue.class, "booleanValue", boolean.class), unbox(expression)));
} else if (type.equals(STRING)) {
return invoke(methodReference(Values.class, Value.class, "stringOrNoValue", String.class), expression);
} else if (type.equals(BYTE_ARRAY)) {
return nullCheck(expression, invoke(methodReference(Values.class, ByteArray.class, "byteArray", byte[].class), expression));
} else if (type.equals(LIST)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, ListValue.class, "asListValue", Iterable.class), expression));
} else if (type.equals(MAP)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, MapValue.class, "asMapValue", Map.class), expression));
} else if (type.equals(ZONED_DATE_TIME)) {
return nullCheck(expression, invoke(methodReference(DateTimeValue.class, DateTimeValue.class, "datetime", ZonedDateTime.class), expression));
} else if (type.equals(OFFSET_TIME)) {
return nullCheck(expression, invoke(methodReference(TimeValue.class, TimeValue.class, "time", OffsetTime.class), expression));
} else if (type.equals(LOCAL_DATE)) {
return nullCheck(expression, invoke(methodReference(DateValue.class, DateValue.class, "date", LocalDate.class), expression));
} else if (type.equals(LOCAL_TIME)) {
return nullCheck(expression, invoke(methodReference(LocalTimeValue.class, LocalTimeValue.class, "localTime", LocalTime.class), expression));
} else if (type.equals(LOCAL_DATE_TIME)) {
return nullCheck(expression, invoke(methodReference(LocalDateTimeValue.class, LocalDateTimeValue.class, "localDateTime", LocalDateTime.class), expression));
} else if (type.equals(TEMPORAL_AMOUNT)) {
return nullCheck(expression, invoke(methodReference(Values.class, DurationValue.class, "durationValue", TemporalAmount.class), expression));
} else if (type.equals(NODE)) {
Expression internalTransaction = invoke(context, methodReference(Context.class, InternalTransaction.class, "internalTransactionOrNull"));
Expression getNode = invoke(internalTransaction, methodReference(InternalTransaction.class, Entity.class, "validateSameDB", Entity.class), expression);
return nullCheck(expression, invoke(methodReference(ValueUtils.class, NodeValue.class, "fromNodeEntity", Node.class), getNode));
} else if (type.equals(RELATIONSHIP)) {
Expression internalTransaction = invoke(context, methodReference(Context.class, InternalTransaction.class, "internalTransactionOrNull"));
Expression getRelationship = invoke(internalTransaction, methodReference(InternalTransaction.class, Entity.class, "validateSameDB", Entity.class), expression);
return nullCheck(expression, invoke(methodReference(ValueUtils.class, RelationshipValue.class, "fromRelationshipEntity", Relationship.class), getRelationship));
} else if (type.equals(PATH)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, PathValue.class, "fromPath", Path.class), expression));
} else if (type.equals(POINT)) {
return nullCheck(expression, invoke(methodReference(ValueUtils.class, PointValue.class, "asPointValue", Point.class), expression));
} else {
return invoke(methodReference(ValueUtils.class, AnyValue.class, "of", Object.class), expression);
}
}
use of org.neo4j.values.storable.DoubleValue in project neo4j by neo4j.
the class AbstractCypherAdapterStreamTest method assertMapEqualsWithDelta.
private static void assertMapEqualsWithDelta(MapValue a, MapValue b, double delta) {
assertThat(a.size()).as("Map should have same size").isEqualTo(b.size());
a.foreach((key, value) -> {
// assertThat( "Missing key", b.get( key ) != Values.NO_VALUE );
AnyValue aValue = value;
AnyValue bValue = b.get(key);
if (aValue instanceof MapValue) {
assertThat(bValue instanceof MapValue).as("Value mismatch").isTrue();
assertMapEqualsWithDelta((MapValue) aValue, (MapValue) bValue, delta);
} else if (aValue instanceof DoubleValue) {
assertThat(((DoubleValue) aValue).doubleValue()).as("Value mismatch").isCloseTo(((DoubleValue) bValue).doubleValue(), offset(delta));
} else {
assertThat(aValue).as("Value mismatch").isEqualTo(bValue);
}
});
}
Aggregations