src/main/java/com/mobiquityinc/packer/Parser.java
protected static List<Thing> parseThings(String things) throws APIException {
        if (!ALL_ITEMS_PATTERN.matcher(things).matches()) {
            throw new APIException(String.format("Sequence '%s' doesn't match the pattern.", things));
        }
        List<Thing> result = new ArrayList<>();
        Matcher matcher = ITEM_PATTERN.matcher(things);
        while (matcher.find()) {
            int index = Integer.parseInt(matcher.group(1));
            double weight = Double.parseDouble(matcher.group(2));
            if (weight > MAX_ITEM_COST_AND_WEIGHT) {
                throw new APIException(String.format("Max weight of an item must be ≤ 100, " +
                        "but input weight is %.2f", weight));
            }
            int cost = Integer.parseInt(matcher.group(4));
            if (cost > MAX_ITEM_COST_AND_WEIGHT) {
                throw new APIException(String.format("Max cost of an item must be ≤ 100, " +
                        "but input cost is %d", cost));
            }
            result.add(Thing.builder().index(index).weight(weight).cost(cost).build());
        }
        if (result.size() > MAX_ITEMS_NUMBER) {
            throw new APIException(String.format("Max number of items must be 15, " +
                    "but input contains %d items", result.size()));
        }
        return result;
    }
/**
     * @param things a list contains one or more items in brackets.
     * @return the list of things need to be chosen.
     * @throws APIException if the list of things doesn't match the pattern
     * or if number of all items, weight or cost of any item exceeds constraints.
     */
@param things a list contains one or more items in brackets.
@return the list of things need to be chosen.
@throws APIException if the list of things doesn't match the pattern
or if number of all items, weight or cost of any item exceeds constraints.
@param things a list contains one or more items in brackets . @return the list of things need to be chosen . @throws APIException if the list of things doesn ' t match the pattern or if number of all items weight or cost of any item exceeds constraints .
protected static List<Thing> parseThings(String things) throws APIException {
        if (!ALL_ITEMS_PATTERN.matcher(things).matches()) {
            throw new APIException(String.format("Sequence '%s' doesn't match the pattern.", things));
        }
        List<Thing> result = new ArrayList<>();
        Matcher matcher = ITEM_PATTERN.matcher(things);
        while (matcher.find()) {
            int index = Integer.parseInt(matcher.group(1));
            double weight = Double.parseDouble(matcher.group(2));
            if (weight > MAX_ITEM_COST_AND_WEIGHT) {
                throw new APIException(String.format("Max weight of an item must be ≤ 100, " +
                        "but input weight is %.2f", weight));
            }
            int cost = Integer.parseInt(matcher.group(4));
            if (cost > MAX_ITEM_COST_AND_WEIGHT) {
                throw new APIException(String.format("Max cost of an item must be ≤ 100, " +
                        "but input cost is %d", cost));
            }
            result.add(Thing.builder().index(index).weight(weight).cost(cost).build());
        }
        if (result.size() > MAX_ITEMS_NUMBER) {
            throw new APIException(String.format("Max number of items must be 15, " +
                    "but input contains %d items", result.size()));
        }
        return result;
    }
protected static List < Thing > parseThings ( String things ) throws APIException { if ( ! ALL_ITEMS_PATTERN . matcher ( things ) . matches ( ) ) { throw new APIException ( String . format ( "Sequence '%s' doesn't match the pattern." , things ) ) ; } List < Thing > result = new ArrayList < > ( ) ; Matcher matcher = ITEM_PATTERN . matcher ( things ) ; while ( matcher . find ( ) ) { int index = Integer . parseInt ( matcher . group ( 1 ) ) ; double weight = Double . parseDouble ( matcher . group ( 2 ) ) ; if ( weight > MAX_ITEM_COST_AND_WEIGHT ) { throw new APIException ( String . format ( "Max weight of an item must be ≤ 100, " + "but input weight is %.2f" , weight ) ) ; } int cost = Integer . parseInt ( matcher . group ( 4 ) ) ; if ( cost > MAX_ITEM_COST_AND_WEIGHT ) { throw new APIException ( String . format ( "Max cost of an item must be ≤ 100, " + "but input cost is %d" , cost ) ) ; } result . add ( Thing . builder ( ) . index ( index ) . weight ( weight ) . cost ( cost ) . build ( ) ) ; } if ( result . size ( ) > MAX_ITEMS_NUMBER ) { throw new APIException ( String . format ( "Max number of items must be 15, " + "but input contains %d items" , result . size ( ) ) ) ; } return result ; }
@param things a list contains one or more items in brackets.
@param things a list contains one or more items in brackets .