use of org.neo4j.values.virtual.ListValue 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.virtual.ListValue in project neo4j by neo4j.
the class HeapTrackingListValueBuilderTest method streamAndCollectElements.
@Test
void streamAndCollectElements() {
int iterations = rnd.nextInt(10, 1000);
ArrayList<LongValue> list = new ArrayList<>(iterations);
for (int i = 0; i < iterations; i++) {
list.add(Values.longValue(i));
}
var collector = HeapTrackingListValueBuilder.collector(memoryTracker);
ListValue listValue = list.stream().collect(collector);
// Validate value size
long memoryTrackerActualSize = meter.measureDeep(memoryTracker);
long actualValueSize = meter.measureDeep(listValue) - memoryTrackerActualSize;
long estimatedValueSize = listValue.estimatedHeapUsage();
assertEquals(actualValueSize, estimatedValueSize);
// Validate items
Iterator<AnyValue> iterator = listValue.iterator();
for (int i = 0; i < iterations; i++) {
assertTrue(iterator.hasNext());
assertEquals(i, ((LongValue) iterator.next()).longValue());
}
assertFalse(iterator.hasNext());
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class BuiltInProceduresIT method dbIndexesResult.
private static AnyValue[] dbIndexesResult(long id, String name, String state, Double populationPercent, String uniqueness, String type, String entityType, List<String> labelsOrTypes, List<String> properties, String provider) {
ListValue labelsOrTypesList = VirtualValues.list(labelsOrTypes.stream().map(Values::stringValue).toArray(AnyValue[]::new));
ListValue propertiesList = VirtualValues.list(properties.stream().map(Values::stringValue).toArray(AnyValue[]::new));
return new AnyValue[] { longValue(id), stringValue(name), stringValue(state), doubleValue(populationPercent), stringValue(uniqueness), stringValue(type), stringValue(entityType), labelsOrTypesList, propertiesList, stringValue(provider) };
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class InCacheTest method shouldHandleListWithNoNulls.
@Test
void shouldHandleListWithNoNulls() {
InCache cache = new InCache();
ListValue list = list(stringValue("a"), stringValue("b"), stringValue("c"));
Map<Value, Value> expected = Map.of(stringValue("a"), TRUE, stringValue("b"), TRUE, stringValue("c"), TRUE, stringValue("d"), FALSE, NO_VALUE, NO_VALUE);
for (Entry<Value, Value> entry : shuffled(expected)) {
assertThat(cache.check(entry.getKey(), list, EmptyMemoryTracker.INSTANCE)).isEqualTo(entry.getValue());
}
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class TextValueTest method split.
@ParameterizedTest
@MethodSource("functions")
void split(Function<String, TextValue> value) {
assertThat(value.apply("HELLO").split("LL")).isEqualTo(stringArray("HE", "O"));
assertThat(value.apply("Separating,by,comma,is,a,common,use,case").split(",")).isEqualTo(stringArray("Separating", "by", "comma", "is", "a", "common", "use", "case"));
assertThat(value.apply("HELLO").split("HELLO")).isEqualTo(stringArray("", ""));
// splitting on empty separator
ListValue helloSplitOnEmpty = value.apply("HELLO").split("");
assertThat(helloSplitOnEmpty).isEqualTo(Values.stringArray("H", "E", "L", "L", "O"));
ArrayValue helloSplitOnEmptyStorable = helloSplitOnEmpty.toStorableArray();
// is not CharArray
assertThat(helloSplitOnEmptyStorable).isInstanceOf(StringArray.class);
// is not char[]
assertThat(helloSplitOnEmptyStorable.asObject()).isEqualTo(new String[] { "H", "E", "L", "L", "O" });
}
Aggregations