class LocaleParser implements Parser<List<Locale>> {

    @Override
    public List<Locale> parse(final String input) throws MalformedInputException {
        String[] localesStr = input.split(LOCALE_SEPARATOR);
        List<LocaleWithWeight> localesWithWeight = new ArrayList<>();

        for (String locale : localesStr) {
            double weight = 1.0;
            String[] localeParts = locale.split(WEIGHT_SEPARATOR);

            if (localeParts.length == 0) {
                continue;
            }

            if (localeParts[0].length() != 2) {
                continue;
            }

            if (localeParts.length > 1 && localeParts[1].length() > 0) {
                if (localeParts[1].startsWith(WEIGHT_PREFIX)) {
                    weight = Double.parseDouble(localeParts[1].substring(2));
                } else {
                    continue;
                }
            }

            localesWithWeight.add(new LocaleWithWeight(new Locale(localeParts[0]), weight));
        }

        return toLocales(localesWithWeight);
    }

}