class CategoricalAttributeDao extends NamedParameterJdbcDaoSupport {

    public static List<CategoricalAttribute> convertPairsToAttributesList(final List<Pair<String, String>> pairs) {
        return pairs.stream()
            .collect(Collectors.groupingBy(Pair::getKey,
                                           Collector.of(ArrayList<String>::new,
                                               (list, pair) -> list.add(pair.getValue()),
                                               (left, right) -> {
                                                   left.addAll(right);
                                                   return left;
                                               },
                                               Function.identity())))
            .entrySet()
            .stream()
            .map(e -> new CategoricalAttribute(e.getKey(),
                                               e.getValue().stream()
                                                   .map(v -> new CategoricalAttributeValue(e.getKey(), v))
                                                   .collect(Collectors.toList())))
            .collect(Collectors.toList());
    }

}