use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ListValue method iterationAsArray.
private AnyValue[] iterationAsArray() {
List<AnyValue> values = new ArrayList<>();
int size = 0;
for (AnyValue value : this) {
values.add(value);
size++;
}
return values.toArray(new AnyValue[size]);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ListValue method distinct.
public ListValue distinct() {
long keptValuesHeapSize = 0;
Set<AnyValue> seen = new HashSet<>();
List<AnyValue> kept = new ArrayList<>();
for (AnyValue value : this) {
if (seen.add(value)) {
kept.add(value);
keptValuesHeapSize += value.estimatedHeapUsage();
}
}
return new JavaListListValue(kept, keptValuesHeapSize);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class BoltResponseMessageTest method shouldSerializeRelationship.
@Test
void shouldSerializeRelationship() throws Throwable {
RelationshipValue rel = relationshipValue(12L, nodeValue(1L, stringArray(), VirtualValues.EMPTY_MAP), nodeValue(2L, stringArray(), VirtualValues.EMPTY_MAP), stringValue("KNOWS"), VirtualValues.map(new String[] { "name", "age" }, new AnyValue[] { stringValue("Bob"), intValue(14) }));
assertThat(serialized(rel)).isEqualTo("B1 71 91 B5 52 0C 01 02 85 4B 4E 4F 57 53 A2 84" + lineSeparator() + "6E 61 6D 65 83 42 6F 62 83 61 67 65 0E");
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class Neo4jPackV1Test method shouldPackUtf8.
@Test
void shouldPackUtf8() throws IOException {
// Given
String value = "\uD83D\uDE31";
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
TextValue textValue = utf8Value(bytes, 0, bytes.length);
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = neo4jPack.newPacker(output);
packer.pack(textValue);
// When
AnyValue unpacked = unpacked(output.bytes());
assertThat(unpacked).isInstanceOf(UTF8StringValue.class);
// Then
assertThat(unpacked).isEqualTo(textValue);
}
use of org.neo4j.values.AnyValue in project neo4j by neo4j.
the class ValueUtils method of.
/**
* Creates an AnyValue by doing type inspection. Do not use in production code where performance is important.
*
* @param object the object to turned into a AnyValue
* @return the AnyValue corresponding to object.
*/
@SuppressWarnings("unchecked")
public static AnyValue of(Object object) {
if (object instanceof AnyValue) {
return (AnyValue) object;
}
Value value = Values.unsafeOf(object, true);
if (value != null) {
return value;
} else {
if (object instanceof Entity) {
if (object instanceof Node) {
return fromNodeEntity((Node) object);
} else if (object instanceof Relationship) {
return fromRelationshipEntity((Relationship) object);
} else {
throw new IllegalArgumentException("Unknown entity + " + object.getClass().getName());
}
} else if (object instanceof Iterable<?>) {
if (object instanceof Path) {
return fromPath((Path) object);
} else if (object instanceof List<?>) {
return asListValue((List<Object>) object);
} else {
return asListValue((Iterable<Object>) object);
}
} else if (object instanceof Map<?, ?>) {
return asMapValue((Map<String, Object>) object);
} else if (object instanceof Iterator<?>) {
ListValueBuilder builder = ListValueBuilder.newListBuilder();
Iterator<?> iterator = (Iterator<?>) object;
while (iterator.hasNext()) {
builder.add(ValueUtils.of(iterator.next()));
}
return builder.build();
} else if (object instanceof Object[]) {
Object[] array = (Object[]) object;
if (array.length == 0) {
return VirtualValues.EMPTY_LIST;
}
ListValueBuilder builder = ListValueBuilder.newListBuilder(array.length);
for (Object o : array) {
builder.add(ValueUtils.of(o));
}
return builder.build();
} else if (object instanceof Stream<?>) {
return asListValue(((Stream<Object>) object).collect(Collectors.toList()));
} else if (object instanceof Geometry) {
return asGeometryValue((Geometry) object);
} else {
ClassLoader classLoader = object.getClass().getClassLoader();
throw new IllegalArgumentException(String.format("Cannot convert %s of type %s to AnyValue, classloader=%s, classloader-name=%s", object, object.getClass().getName(), classLoader != null ? classLoader.toString() : "null", classLoader != null ? classLoader.getName() : "null"));
}
}
}
Aggregations