Java Code Examples for org.apache.tinkerpop.gremlin.structure.util.ElementHelper#asMap()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.util.ElementHelper#asMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FakeObjects.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public FakeEdge(String label, Vertex outVertex, Vertex inVertex,
                Object... keyValues) {
    this.label = label;
    this.outVertex = outVertex;
    this.inVertex = inVertex;
    this.values = ElementHelper.asMap(keyValues);
}
 
Example 2
Source File: ConfigurationGroovyCustomizer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance using configuration values specified
 */
ConfigurationGroovyCustomizer(final Object... keyValues) {
    if (null == keyValues || keyValues.length == 0)
        throw new IllegalArgumentException("ConfigurationCustomizerProvider must have key/values specified");

    if (keyValues.length % 2 != 0)
        throw new IllegalArgumentException("The keyValues must have an even number of values");

    properties = ElementHelper.asMap(keyValues);
}
 
Example 3
Source File: FakeObjects.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public FakeVertex(Object... keyValues) {
    this.label = ElementHelper.getLabelValue(keyValues).get();
    this.values = ElementHelper.asMap(keyValues);

    this.values.remove("label");
}
 
Example 4
Source File: DriverRemoteAcceptor.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Object configure(final List<String> args) throws RemoteException {
    final String option = args.size() == 0 ? "" : args.get(0);
    if (!POSSIBLE_TOKENS.contains(option))
        throw new RemoteException(String.format("The 'config' option expects one of ['%s'] as an argument", String.join(",", POSSIBLE_TOKENS)));

    final List<String> arguments = args.subList(1, args.size());

    if (option.equals(TOKEN_HELP)) {
        return ":remote config [timeout [<ms>|none]|alias [reset|show|<alias> <actual>]|help]";
    } else if (option.equals(TOKEN_TIMEOUT)) {
        final String errorMessage = "The timeout option expects a positive integer representing milliseconds or 'none' as an argument";
        if (arguments.size() != 1) throw new RemoteException(errorMessage);
        try {
            // first check for MAX timeout then NONE and finally parse the config to int.
            timeout = arguments.get(0).equals(TOKEN_NONE) ? NO_TIMEOUT : Integer.parseInt(arguments.get(0));
            if (timeout < NO_TIMEOUT) throw new RemoteException("The value for the timeout cannot be less than " + NO_TIMEOUT);
            return timeout == NO_TIMEOUT ? "Remote timeout is disabled" : "Set remote timeout to " + timeout + "ms";
        } catch (Exception ignored) {
            throw new RemoteException(errorMessage);
        }
    } else if (option.equals(TOKEN_ALIAS)) {
        if (arguments.size() == 1 && arguments.get(0).equals(TOKEN_RESET)) {
            aliases.clear();
            return "Aliases cleared";
        }

        if (arguments.size() == 1 && arguments.get(0).equals(TOKEN_SHOW)) {
            return aliases;
        }

        if (arguments.size() % 2 != 0)
            throw new RemoteException("Arguments to alias must be 'reset' to clear any existing alias settings or key/value alias/binding pairs");

        final Map<String,Object> aliasMap = ElementHelper.asMap(arguments.toArray());
        aliases.clear();
        aliasMap.forEach((k,v) -> aliases.put(k, v.toString()));
        return aliases;
    }

    return this.toString();
}