public static Object[] upsert(final Object[] keyValues, final Object key, final Object val) {
        if (!getKeys(keyValues).contains(key))
            return Stream.concat(Stream.of(keyValues), Stream.of(key, val)).toArray();
        else {
            final Object[] kvs = new Object[keyValues.length];
            for (int i = 0; i < keyValues.length; i = i + 2) {
                kvs[i] = keyValues[i];
                if (keyValues[i].equals(key))
                    kvs[i + 1] = val;
                else
                    kvs[i + 1] = keyValues[i + 1];
            }

            return kvs;
        }
    }
Append a key/value pair to a list of existing key/values. If the key already exists in the keyValues then
that value is overwritten with the provided value.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java