All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vertexium.cypher.functions.string.SplitFunction Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher.functions.string;

import com.google.common.collect.Lists;
import org.vertexium.VertexiumException;
import org.vertexium.cypher.VertexiumCypherQueryContext;
import org.vertexium.cypher.functions.SimpleCypherFunction;

import static org.vertexium.cypher.functions.FunctionUtils.assertArgumentCount;

public class SplitFunction extends SimpleCypherFunction {
    @Override
    protected Object executeFunction(VertexiumCypherQueryContext ctx, Object[] arguments) {
        assertArgumentCount(arguments, 2);
        Object stringArgObj = arguments[0];
        Object delimiterArgObj = arguments[1];

        if (!(stringArgObj instanceof String)) {
            throw new VertexiumException("Expected a string as the first argument, found " + stringArgObj.getClass().getName());
        }
        String stringArg = (String) stringArgObj;

        if (!(delimiterArgObj instanceof String)) {
            throw new VertexiumException("Expected a string as the second argument, found " + stringArgObj.getClass().getName());
        }
        String delimiterArg = (String) delimiterArgObj;

        return Lists.newArrayList(stringArg.split(delimiterArg));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy