/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015 Lachlan Dowding
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package permafrost.tundra.math;

/**
 * A collection of convenience methods for working with integers.
 */
public class IntegerHelper {
    /**
     * Disallow instantiation of this class.
     */
    private IntegerHelper() {}

    /**
     * Parses the given string as an integer.
     *
     * @param input A string to be parsed as integer.
     * @return      Integer representing the given string, or 0 if the given string was null.
     */
    public static int parse(String input) {
        return parse(input, 0);
    }

    /**
     * Parses the given string as an integer.
     *
     * @param input        A string to be parsed as integer.
     * @param defaultValue The value returned if the given string is null.
     * @return             Integer representing the given string, or defaultValue if the given string is null.
     */
    public static int parse(String input, int defaultValue) {
        if (input == null) return defaultValue;
        return Integer.parseInt(input);
    }
}

@@ -1278,16 +1278,137 @@
 elper %7B%0A
+    /**%0A     * The default value used when parsing a null string.%0A     */%0A    private static int DEFAULT_INT_VALUE = 0;%0A%0A
     /**%0A
@@ -1452,16 +1452,16 @@
  class.%0A
-
      */%0A
@@ -1781,17 +1781,33 @@
 (input, 
-0
+DEFAULT_INT_VALUE
 );%0A    %7D
@@ -2234,16 +2234,16 @@
 tValue;%0A
-
         
@@ -2279,11 +2279,1683 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Parses the given strings as integers.%0A     *%0A     * @param input         A list of strings to be parsed as integers.%0A     * @return              A list of integers representing the given strings.%0A     */%0A    public static int%5B%5D parse(String%5B%5D input) %7B%0A        return parse(input, DEFAULT_INT_VALUE);%0A    %7D%0A%0A    /**%0A     * Parses the given strings as integers.%0A     *%0A     * @param input         A list of strings to be parsed as integers.%0A     * @param defaultValue  The value returned if a string in the list is null.%0A     * @return              A list of integers representing the given strings.%0A     */%0A    public static int%5B%5D parse(String%5B%5D input, int defaultValue) %7B%0A        if (input == null) return null;%0A        int%5B%5D output = new int%5Binput.length%5D;%0A%0A        for (int i = 0; i %3C input.length; i++) %7B%0A            output%5Bi%5D = parse(input%5Bi%5D, defaultValue);%0A        %7D%0A%0A        return output;%0A    %7D%0A%0A    /**%0A     * Serializes the given integer as a string.%0A     *%0A     * @param input The integer to be serialized.%0A     * @return      A string representation of the given integer.%0A     */%0A    public static String emit(int input) %7B%0A        return Integer.toString(input);%0A    %7D%0A%0A    /**%0A     * Serializes the given integers as strings.%0A     *%0A     * @param input A list of integers to be serialized.%0A     * @return      A list of string representations of the given integers.%0A     */%0A    public static String%5B%5D emit(int%5B%5D input) %7B%0A        if (input == null) return null;%0A        String%5B%5D output = new String%5Binput.length%5D;%0A%0A        for (int i = 0; i %3C input.length; i++) %7B%0A            output%5Bi%5D = emit(input%5Bi%5D);%0A        %7D%0A%0A        return output;%0A    %7D
 %0A%7D%0A

Add IntegerHelper.parse and .emit methods for arrays