package org.xander.katas;

import java.util.regex.Pattern;

public class StringCalculator {
    static final int zero = 0;
    static final String negativeNumberMessage = "Negative number is not allowed ";

    public int add() {
        return zero;
    }

    public int add(String number) {
        if (verifyNumberIsZero(number)) return 0;
        return calculateNumber(number);
    }

    public Integer add(String numberOne, String numberTwo) {

        if (validateElementForNegativity(numberOne.toCharArray())
                && validateElementForNegativity(numberTwo.toCharArray()))
            throw new NumberFormatException(negativeNumberMessage + "\'" + numberOne + "\'" + " " + "\'" + numberTwo + "\'");
        else if (!validateElementForNegativity(numberOne.toCharArray())
                && validateElementForNegativity(numberTwo.toCharArray()))
            throw new NumberFormatException(negativeNumberMessage + "\'" + numberTwo + "\'");
        else if (validateElementForNegativity(numberOne.toCharArray())
                && !validateElementForNegativity(numberTwo.toCharArray()))
            throw new NumberFormatException(negativeNumberMessage + "\'" + numberOne + "\'");

        return (verifyNumberIsZero(numberOne) && verifyNumberIsZero(numberTwo)) ? 0 :
                (verifyNumberIsZero(numberOne)) ? calculateNumber(numberTwo) :
                        (verifyNumberIsZero(numberTwo)) ? calculateNumber(numberOne) :
                                calculateNumber(numberOne) + calculateNumber(numberTwo);
    }

    private boolean validateElementForNegativity(char[] elementInArray1) {
        for (int elementInArray : elementInArray1)
            return String.valueOf((char) elementInArray).equals("-");
        return false;
    }

    private int calculateNumber(String number) {
        int sum = zero;
        if (stringContainsOnlyNumbers(number) && Integer.parseInt(number) > 1000) {
            return zero;
        } else {
            if (number.trim().equals(""))
                return zero;
            String result = "0";

            for (int elementInArray : number.toCharArray()) {
                if (stringContainsOnlyNumbers(String.valueOf((char) elementInArray)))
                    result += Integer.parseInt(String.valueOf((char)elementInArray));
                else {
                    sum += Integer.parseInt(result);
                    result = "0";
                }
            }
            sum += Integer.parseInt(result);
        }
        return sum;
    }

    private boolean stringContainsOnlyNumbers(String number) {
        return !Pattern.compile(".*[^0-9].*").matcher(number).matches();
    }

    private boolean verifyNumberIsZero(String number) {
        return number.length() == zero || calculateNumber(number) == 0;
    }

    public Integer add(String... numbers) {
        int sum = 0;
        for (String element : numbers)
            sum += verifyNumberIsZero(element) ? 0 : calculateNumber(element);
        return sum;
    }
}

@@ -106,20 +106,20 @@
 nal int 
-zero
+ZERO
  = 0;%0A  
@@ -140,37 +140,46 @@
  String 
-negativeNumberMessage
+NEGATIVE_NUMBER_IS_NOT_ALLOWED
  = %22Nega
@@ -243,28 +243,28 @@
      return 
-zero
+ZERO
 ;%0A    %7D%0A%0A   
@@ -340,17 +340,41 @@
 r)) 
-return 0;
+%7B%0A            return 0;%0A        %7D
 %0A   
@@ -478,17 +478,16 @@
 rTwo) %7B%0A
-%0A
         
@@ -609,32 +609,34 @@
 .toCharArray()))
+ %7B
 %0A            thr
@@ -664,37 +664,46 @@
 ception(
-negativeNumberMessage
+NEGATIVE_NUMBER_IS_NOT_ALLOWED
  + %22%5C'%22 
@@ -754,32 +754,34 @@
 + %22%5C'%22);%0A       
+ %7D
  else if (!valid
@@ -894,32 +894,34 @@
 .toCharArray()))
+ %7B
 %0A            thr
@@ -949,37 +949,46 @@
 ception(
-negativeNumberMessage
+NEGATIVE_NUMBER_IS_NOT_ALLOWED
  + %22%5C'%22 
@@ -1011,24 +1011,26 @@
 '%22);%0A       
+ %7D
  else if (va
@@ -1155,16 +1155,18 @@
 rray()))
+ %7B
 %0A       
@@ -1206,29 +1206,38 @@
 ion(
-negativeNumberMessage
+NEGATIVE_NUMBER_IS_NOT_ALLOWED
  + %22
@@ -1261,16 +1261,25 @@
  %22%5C'%22);%0A
+        %7D
 %0A       
@@ -1354,18 +1354,16 @@
 wo)) ? 0
- :
 %0A       
@@ -1362,32 +1362,34 @@
 %0A               
+ :
  (verifyNumberIs
@@ -1433,18 +1433,16 @@
 mberTwo)
- :
 %0A       
@@ -1457,16 +1457,18 @@
         
+ :
  (verify
@@ -1520,18 +1520,16 @@
 mberOne)
- :
 %0A       
@@ -1549,19 +1549,17 @@
         
-   
+:
  calcula
@@ -1740,16 +1740,18 @@
 nArray1)
+ %7B
 %0A       
@@ -1809,24 +1809,34 @@
 quals(%22-%22);%0A
+        %7D%0A
         retu
@@ -1919,20 +1919,20 @@
 t sum = 
-zero
+ZERO
 ;%0A      
@@ -2020,36 +2020,36 @@
          return 
-zero
+ZERO
 ;%0A        %7D else
@@ -2092,16 +2092,18 @@
 als(%22%22))
+ %7B
 %0A       
@@ -2122,14 +2122,28 @@
 urn 
-zero
+ZERO
 ;%0A
+            %7D%0A
     
@@ -2319,16 +2319,18 @@
 Array)))
+ %7B
 %0A       
@@ -2390,16 +2390,17 @@
 f((char)
+ 
 elementI
@@ -2424,16 +2424,18 @@
         
+ %7D
  else %7B%0A
@@ -2872,12 +2872,12 @@
  == 
-zero
+ZERO
  %7C%7C 
@@ -3016,16 +3016,18 @@
 numbers)
+ %7B
 %0A       
@@ -3094,24 +3094,34 @@
 r(element);%0A
+        %7D%0A
         retu

Update StringCalculator.java