Search in sources :

Example 1 with TupleBuilder

use of org.springframework.tuple.TupleBuilder in project spring-cloud-gateway by spring-cloud.

the class RouteDefinitionRouteLocator method getTuple.

@SuppressWarnings("Duplicates")
// TODO: remove after Tuple is removed
@Deprecated
static /* for testing */
Tuple getTuple(ShortcutConfigurable shortcutConf, Map<String, String> args, SpelExpressionParser parser, BeanFactory beanFactory) {
    TupleBuilder builder = TupleBuilder.tuple();
    List<String> argNames = shortcutConf.shortcutFieldOrder();
    if (!argNames.isEmpty()) {
        // ensure size is the same for key replacement later
        if (shortcutConf.validateFieldsExist() && args.size() != argNames.size()) {
            throw new IllegalArgumentException("Wrong number of arguments. Expected " + argNames + " " + argNames + ". Found " + args.size() + " " + args + "'");
        }
    }
    int entryIdx = 0;
    for (Map.Entry<String, String> entry : args.entrySet()) {
        String key = normalizeKey(entry.getKey(), entryIdx, shortcutConf, args);
        Object value = getValue(parser, beanFactory, entry.getValue());
        builder.put(key, value);
        entryIdx++;
    }
    Tuple tuple = builder.build();
    if (shortcutConf.validateFieldsExist()) {
        for (String name : argNames) {
            if (!tuple.hasFieldName(name)) {
                throw new IllegalArgumentException("Missing argument '" + name + "'. Given " + tuple);
            }
        }
    }
    return tuple;
}
Also used : TupleBuilder(org.springframework.tuple.TupleBuilder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Tuple(org.springframework.tuple.Tuple)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Tuple (org.springframework.tuple.Tuple)1 TupleBuilder (org.springframework.tuple.TupleBuilder)1