Search in sources :

Example 1 with Association

use of com.cinchapi.common.collect.Association in project concourse by cinchapi.

the class Command method init.

/**
 * Inspect the operation and populate the operation variables if they
 * haven't already been {@link #initialized}.
 */
private void init() {
    if (!initialized) {
        String function = method.getName();
        String[] toks = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, function).split("-");
        Association args = Association.of();
        if (function.equals("getServerVersion")) {
            operation = function;
        } else if (function.equals("verifyOrSet")) {
            operation = function;
            args.put("key", params[0]);
            args.put("value", params[1]);
            args.put("record", params[2]);
        } else if (function.equals("verifyAndSwap")) {
            operation = function;
            args.put("key", params[0]);
            args.put("record", params[2]);
            args.put("values", ImmutableList.of(params[1], params[3]));
        } else if (function.equals("findOrInsertCclJson")) {
            operation = "findOrInsert";
            args.put("ccl", params[0]);
        } else if (function.equals("findOrInsertCriteriaJson")) {
            operation = "findOrInsert";
            args.put("criteria", params[0]);
        } else if (function.equals("findOrAddKeyValue")) {
            operation = "findOrAdd";
            args.put("key", params[0]);
            conditionKeys = ImmutableSet.of((String) params[0]);
        } else {
            operation = toks[0];
            for (int i = 1; i < toks.length; ++i) {
                args.put(toks[i].toLowerCase(), params[i - 1]);
            }
        }
        // Parser
        if (args.containsKey("ccl")) {
            String ccl = args.fetch("ccl");
            conditionTree = (ConditionTree) ConcourseCompiler.get().parse(ccl);
        } else if (args.containsKey("criteria")) {
            TCriteria tcriteria = args.fetch("criteria");
            Criteria criteria = Language.translateFromThriftCriteria(tcriteria);
            conditionTree = (ConditionTree) ConcourseCompiler.get().parse(criteria.ccl());
        } else {
            conditionTree = null;
        }
        // operationKeys
        if (args.containsKey("key")) {
            String key = args.fetch("key");
            operationKeys = Sets.newHashSet(key);
        } else if (args.containsKey("keys")) {
            Collection<String> keys = args.fetch("keys");
            operationKeys = Sets.newHashSet(keys);
        } else {
            operationKeys = ImmutableSet.of();
        }
        // operationRecords
        if (args.containsKey("record")) {
            long record = args.fetch("record");
            operationRecords = Sets.newHashSet(record);
        } else if (args.containsKey("records")) {
            Collection<Long> records = args.fetch("records");
            operationRecords = Sets.newHashSet(records);
        } else {
            operationRecords = ImmutableSet.of();
        }
        // order
        if (args.containsKey("order")) {
            TOrder torder = args.fetch("order");
            order = JavaThriftBridge.convert(torder);
        } else {
            order = null;
        }
        // methods above.
        if (conditionKeys == null && conditionTree != null) {
            conditionKeys = ConcourseCompiler.get().analyze(conditionTree).keys();
        } else if (function.startsWith("findKey")) {
            conditionKeys = ImmutableSet.of((String) params[0]);
        } else if (conditionKeys == null) {
            conditionKeys = ImmutableSet.of();
        }
        // operationTimestamp
        if (args.containsKey("time")) {
            operationTimestamp = args.fetch("time");
        }
        initialized = true;
    }
}
Also used : Association(com.cinchapi.common.collect.Association) ConditionTree(com.cinchapi.ccl.syntax.ConditionTree) Collection(java.util.Collection) TCriteria(com.cinchapi.concourse.thrift.TCriteria) TCriteria(com.cinchapi.concourse.thrift.TCriteria) Criteria(com.cinchapi.concourse.lang.Criteria) TOrder(com.cinchapi.concourse.thrift.TOrder)

Aggregations

ConditionTree (com.cinchapi.ccl.syntax.ConditionTree)1 Association (com.cinchapi.common.collect.Association)1 Criteria (com.cinchapi.concourse.lang.Criteria)1 TCriteria (com.cinchapi.concourse.thrift.TCriteria)1 TOrder (com.cinchapi.concourse.thrift.TOrder)1 Collection (java.util.Collection)1