private static void coerceCapabilityClauses()

in winegrower-core/src/main/java/org/apache/winegrower/deployer/BundleImpl.java [679:734]


        private static void coerceCapabilityClauses(final List<HeaderClause> clauses) {
            clauses.forEach(clause -> clause.types.forEach((key, type) -> {
                if (!type.equals("String")) {
                    if (type.equals("Double")) {
                        clause.attributes.put(
                                key,
                                new Double(clause.attributes.get(key).toString().trim()));
                    } else if (type.equals("Version")) {
                        clause.attributes.put(
                                key,
                                new Version(clause.attributes.get(key).toString().trim()));
                    } else if (type.equals("Long")) {
                        clause.attributes.put(
                                key,
                                Long.valueOf(clause.attributes.get(key).toString().trim()));
                    } else if (type.startsWith("List")) {
                        final int startIdx = type.indexOf('<');
                        final int endIdx = type.indexOf('>');
                        if ((startIdx > 0 && endIdx <= startIdx) || (startIdx < 0 && endIdx > 0)) {
                            throw new IllegalArgumentException("Invalid Provide-Capability attribute list type for '"
                                    + key + "' : " + type);
                        }

                        final String listType;
                        if (endIdx > startIdx) {
                            listType = type.substring(startIdx + 1, endIdx).trim();
                        } else {
                            listType = "String";
                        }

                        final List<String> tokens = parseDelimitedString(
                                clause.attributes.get(key).toString(), ",", false);
                        clause.attributes.put(key, tokens.stream()
                                .map(token -> {
                                    switch (listType) {
                                        case "String":
                                            return token;
                                        case "Double":
                                            return Double.valueOf(token.trim());
                                        case "Version":
                                            return new Version(token.trim());
                                        case "Long":
                                            return Long.valueOf(token.trim());
                                        default:
                                            throw new IllegalArgumentException(
                                                    "Unknown Provide-Capability attribute list type for '"
                                                            + key + "' : " + type);
                                    }
                                }).collect(toList()));
                    } else {
                        throw new IllegalArgumentException("Unknown Provide-Capability attribute type for '" +
                                key + "' : " + type);
                    }
                }
            }));
        }