use of org.neo4j.values.virtual.ListValueBuilder in project neo4j by neo4j.
the class ValueUtils method asListValue.
public static ListValue asListValue(List<?> collection) {
int size = collection.size();
if (size == 0) {
return VirtualValues.EMPTY_LIST;
}
ListValueBuilder values = ListValueBuilder.newListBuilder(size);
for (Object o : collection) {
values.add(ValueUtils.of(o));
}
return values.build();
}
use of org.neo4j.values.virtual.ListValueBuilder 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"));
}
}
}
use of org.neo4j.values.virtual.ListValueBuilder in project neo4j by neo4j.
the class AbstractCypherAdapterStream method convertNotifications.
private static AnyValue convertNotifications(Iterable<Notification> notifications) {
ListValueBuilder listValueBuilder = ListValueBuilder.newListBuilder();
for (Notification notification : notifications) {
// position is optional
InputPosition pos = notification.getPosition();
boolean includePosition = !pos.equals(InputPosition.empty);
int size = includePosition ? 5 : 4;
MapValueBuilder builder = new MapValueBuilder(size);
builder.add("code", utf8Value(notification.getCode()));
builder.add("title", utf8Value(notification.getTitle()));
builder.add("description", utf8Value(notification.getDescription()));
builder.add("severity", utf8Value(notification.getSeverity().toString()));
if (includePosition) {
// only add the position if it is not empty
builder.add("position", VirtualValues.map(new String[] { "offset", "line", "column" }, new AnyValue[] { intValue(pos.getOffset()), intValue(pos.getLine()), intValue(pos.getColumn()) }));
}
listValueBuilder.add(builder.build());
}
return listValueBuilder.build();
}
use of org.neo4j.values.virtual.ListValueBuilder in project neo4j by neo4j.
the class StringValue method splitNonRegex.
/**
* Splits a string based on a single delimiter string
*
* @param input String to be split
* @param delim delimiter, must not be not empty
* @return the split string as a List of TextValues
*/
private static ListValue splitNonRegex(String input, String delim) {
ListValueBuilder substrings = ListValueBuilder.newListBuilder();
int offset = 0;
int index;
do {
index = input.indexOf(delim, offset);
offset = updateSubstringsAndOffset(substrings, offset, input, index, delim);
} while (index != -1);
return substrings.build();
}
use of org.neo4j.values.virtual.ListValueBuilder in project neo4j by neo4j.
the class StringValue method splitNonRegex.
/**
* Splits a string with multiple separator strings
*
* @param input String to be split
* @param delims delimiters, must not be not empty
* @return the split string as a List of TextValues
*/
private static ListValue splitNonRegex(String input, List<String> delims) {
ListValueBuilder substrings = ListValueBuilder.newListBuilder();
int offset = 0;
Pair<Integer, String> nextSubstring;
do {
nextSubstring = firstIndexOf(input, offset, delims);
offset = updateSubstringsAndOffset(substrings, offset, input, nextSubstring.first(), nextSubstring.other());
} while (nextSubstring.first() != -1);
return substrings.build();
}
Aggregations