package com.pedro.stringcalculator;

import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Main class of this application. StringCalculator is an application created to analyze one string, extract the
 * numeric values and return an integer that represents the sum of the numeric values. Some interesting conditions
 * are described in the application documentation.
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class StringCalculator {

    /*
     * Constants
     */

    private final String ONE_DIGIT_OR_MORE_REG_EX = "\\d+";

    /*
     * Public methods
     */

    /**
     * Parse an string and sum all the numeric values removing the non numeric characters.
     *
     * @param numbers to analyze and sum.
     * @return the sum value with some restrictions described in the project documentation.
     */
    public int add(final String numbers) {
        List<Integer> numberList = extractNumberList(numbers);
        return sumNumbers(numberList);
    }



    /*
     * Auxiliary methods
     */

    private List<Integer> extractNumberList(String numbers) {
        List<Integer> result = new LinkedList<Integer>();
        if (!numbers.isEmpty()) {
            result = getNumbersUsingRegEx(numbers);
        }
        return result;
    }

    private List<Integer> getNumbersUsingRegEx(String string) {
        LinkedList<Integer> numbers = new LinkedList<Integer>();
        Pattern p = Pattern.compile(ONE_DIGIT_OR_MORE_REG_EX);
        Matcher m = p.matcher(string);
        while (m.find()) {
            int number = Integer.parseInt(m.group());
            numbers.add(number);
        }
        return numbers;
    }

    private int sumNumbers(List<Integer> numberList) {
        int sum = 0;
        for (Integer num : numberList) {
            sum += num;
        }
        return sum;
    }

}

@@ -30,16 +30,99 @@
 lator;%0A%0A
+import com.pedro.stringcalculator.exception.NegativeNumbersNotSupportedException;%0A%0A
 import j
@@ -679,16 +679,18 @@
 G_EX = %22
+-?
 %5C%5Cd+%22;%0A%0A
@@ -1007,32 +1007,76 @@
  String numbers)
+ throws NegativeNumbersNotSupportedException
  %7B%0A        List%3C
@@ -1137,38 +1137,547 @@
     
-return sumNumbers(numberList);
+checkIfThereAreNegativeNumbers(numberList);%0A        return sumNumbers(numberList);%0A    %7D%0A%0A    private void checkIfThereAreNegativeNumbers(List%3CInteger%3E numberList) throws NegativeNumbersNotSupportedException %7B%0A        List%3CInteger%3E negativeNumbers = new LinkedList%3CInteger%3E();%0A        for (Integer num : numberList) %7B%0A            if (num %3C 0) %7B%0A                negativeNumbers.add(num);%0A            %7D%0A        %7D%0A        if (negativeNumbers.size() %3E 0) %7B%0A            throw new NegativeNumbersNotSupportedException(negativeNumbers);%0A        %7D
 %0A   

Change regular expression to support negative numbers. GREEN