use of org.neo4j.values.SequenceValue in project neo4j by neo4j.
the class ProcedureCompilation method toByteArray.
/**
* Byte arrays needs special treatment since it is not a proper Cypher type
* @param input either a ByteArray or ListValue of bytes
* @return input value converted to a byte[]
*/
public static byte[] toByteArray(AnyValue input) {
if (input instanceof ByteArray) {
return ((ByteArray) input).asObjectCopy();
}
if (input instanceof SequenceValue) {
SequenceValue list = (SequenceValue) input;
if (list.iterationPreference() == RANDOM_ACCESS) {
byte[] bytes = new byte[list.length()];
for (int a = 0; a < bytes.length; a++) {
bytes[a] = asByte(list.value(a));
}
return bytes;
} else {
// list.length may have linear complexity, still worth doing it upfront
byte[] bytes = new byte[list.length()];
int i = 0;
for (AnyValue anyValue : list) {
bytes[i++] = asByte(anyValue);
}
return bytes;
}
} else {
throw new IllegalArgumentException("Cannot convert " + input.getClass().getSimpleName() + " to byte[] for input to procedure");
}
}
use of org.neo4j.values.SequenceValue in project neo4j by neo4j.
the class CypherFunctions method last.
@CalledFromGeneratedCode
public static AnyValue last(AnyValue container) {
assert container != NO_VALUE : "NO_VALUE checks need to happen outside this call";
if (container instanceof SequenceValue) {
SequenceValue sequence = (SequenceValue) container;
int length = sequence.length();
if (length == 0) {
return NO_VALUE;
}
return sequence.value(length - 1);
} else {
throw new CypherTypeException(format("Invalid input for function 'last()': Expected %s to be a list", container));
}
}
use of org.neo4j.values.SequenceValue in project neo4j by neo4j.
the class GenericIndexKeyValidator method worstCaseLength.
private static int worstCaseLength(AnyValue value) {
if (value.isSequenceValue()) {
SequenceValue sequenceValue = (SequenceValue) value;
if (sequenceValue instanceof TextArray) {
TextArray textArray = (TextArray) sequenceValue;
int length = 0;
for (int i = 0; i < textArray.length(); i++) {
length += stringWorstCaseLength(textArray.stringValue(i).length());
}
return length;
}
return sequenceValue.length() * BIGGEST_STATIC_SIZE;
} else {
if (((Value) value).valueGroup().category() == ValueCategory.TEXT) {
// For text, which is very dynamic in its nature do a worst-case off of number of characters in it
return stringWorstCaseLength(((TextValue) value).length());
}
// For all else then use the biggest possible value for a non-dynamic, non-array value a state can occupy
return BIGGEST_STATIC_SIZE;
}
}
Aggregations