use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ValueUtilsTest method shouldHandleCollection.
@Test
void shouldHandleCollection() {
// Given
Collection<Integer> collection = Arrays.asList(1, 2, 3);
// When
AnyValue of = ValueUtils.of(collection);
// Then
assertThat(of).isInstanceOf(ListValue.class);
ListValue listValue = (ListValue) of;
assertThat(listValue.value(0)).isEqualTo(intValue(1));
assertThat(listValue.value(1)).isEqualTo(intValue(2));
assertThat(listValue.value(2)).isEqualTo(intValue(3));
assertThat(listValue.size()).isEqualTo(3);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class TemporalValue method updateFieldMapWithConflictingSubseconds.
static <TEMP extends Temporal, VALUE> VALUE updateFieldMapWithConflictingSubseconds(MapValue fields, TemporalUnit unit, TEMP temporal, BiFunction<MapValue, TEMP, VALUE> mapFunction) {
boolean conflictingMilliSeconds = unit == ChronoUnit.MILLIS && (fields.containsKey("microsecond") || fields.containsKey("nanosecond"));
boolean conflictingMicroSeconds = unit == ChronoUnit.MICROS && fields.containsKey("nanosecond");
if (conflictingMilliSeconds) {
AnyValue millis = Values.intValue(temporal.get(ChronoField.MILLI_OF_SECOND));
AnyValue micros = fields.get("microsecond");
AnyValue nanos = fields.get("nanosecond");
int newNanos = validNano(millis, micros, nanos);
TEMP newTemporal = (TEMP) temporal.with(ChronoField.NANO_OF_SECOND, newNanos);
MapValue filtered = fields.filter((k, ignore) -> !k.equals("microsecond") && !k.equals("nanosecond"));
return mapFunction.apply(filtered, newTemporal);
} else if (conflictingMicroSeconds) {
AnyValue micros = Values.intValue(temporal.get(ChronoField.MICRO_OF_SECOND));
AnyValue nanos = fields.get("nanosecond");
int newNanos = validNano(null, micros, nanos);
TEMP newTemporal = (TEMP) temporal.with(ChronoField.NANO_OF_SECOND, newNanos);
MapValue filtered = fields.filter((k, ignore) -> !k.equals("nanosecond"));
return mapFunction.apply(filtered, newTemporal);
} else {
return mapFunction.apply(fields, temporal);
}
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class LocalTimeValue method builder.
private static TimeValue.TimeBuilder<LocalTimeValue> builder(Supplier<ZoneId> defaultZone) {
return new TimeValue.TimeBuilder<>(defaultZone) {
@Override
protected boolean supportsTimeZone() {
return false;
}
@Override
public LocalTimeValue buildInternal() {
LocalTime result;
if (fields.containsKey(TemporalFields.time)) {
AnyValue time = fields.get(TemporalFields.time);
if (!(time instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct local time from: %s", time));
}
result = ((TemporalValue) time).getLocalTimePart();
} else {
result = DEFAULT_LOCAL_TIME;
}
result = assignAllFields(result);
return localTime(result);
}
@Override
protected LocalTimeValue selectTime(AnyValue time) {
if (!(time instanceof TemporalValue)) {
throw new InvalidArgumentException(String.format("Cannot construct local time from: %s", time));
}
TemporalValue v = (TemporalValue) time;
LocalTime lt = v.getLocalTimePart();
return localTime(lt);
}
};
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class VirtualValues method map.
public static MapValue map(String[] keys, AnyValue[] values) {
assert keys.length == values.length;
long payloadSize = 0;
Map<String, AnyValue> map = new HashMap<>((int) ((float) keys.length / 0.75f + 1.0f));
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
AnyValue value = values[i];
map.put(key, value);
payloadSize += sizeOf(key) + value.estimatedHeapUsage();
}
return new MapValue.MapWrappingMapValue(map, payloadSize);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ListValue method iterationWriteTo.
private <E extends Exception> void iterationWriteTo(AnyValueWriter<E> writer) throws E {
writer.beginList(size());
for (AnyValue value : this) {
value.writeTo(writer);
}
writer.endList();
}
Aggregations