package uk.ac.ebi.quickgo.ontology.coterms;

/**
 * @author Tony Wardell
 * Date: 29/09/2016
 * Time: 16:08
 * Created with IntelliJ IDEA.
 */
public class CoTermLimit {

    int defaultLimit;

    public CoTermLimit(int defaultLimit) {
        this.defaultLimit = defaultLimit;
    }

    public int workoutLimit(String limit) {
        int limitNumeric = 0;
        if (limit == null) {
            limitNumeric = defaultLimit;
        } else {
            if (LimitValue.ALL.toString().equalsIgnoreCase(limit)) {
                limitNumeric = Integer.MAX_VALUE;
            } else {
                if (limit.trim().length() == 0) {
                    limitNumeric = defaultLimit;
                } else {
                    try {
                        limitNumeric = Integer.parseInt(limit);

                        if (limitNumeric == 0) {
                            limitNumeric = defaultLimit;
                        }
                    } catch (NumberFormatException e) {
                        throw new IllegalArgumentException("The value for co-occurring terms limit is not ALL, or a " +
                                "number");
                    }
                }
            }
        }
        return limitNumeric;
    }

    enum LimitValue {
        ALL
    }
}

@@ -42,12 +42,92 @@
 s;%0A%0A
+%0A
 /**%0A
+ * Logic for determining the limit to use for retrieving co-occurring terms%0A *%0A
  * @
@@ -275,95 +275,335 @@
     
-public CoTermLimit(int defaultLimit) %7B%0A        this.defaultLimit = defaultLimit;%0A    %7D%0A
+/**%0A     *%0A     * @param defaultLimit The limit to use under some circumstances.%0A     */%0A    public CoTermLimit(int defaultLimit) %7B%0A        this.defaultLimit = defaultLimit;%0A    %7D%0A%0A    /**%0A     * Determine the limit value to use for retrieving co-occurring terms.%0A     * @param limit value to be checked.%0A     * @return%0A     */
 %0A   
@@ -671,12 +671,8 @@
 eric
- = 0
 ;%0A  
@@ -1044,183 +1044,623 @@
     
-try %7B%0A                        limitNumeric = Integer.parseInt(limit);%0A%0A                        if (l
+limitNumeric = processLimitAsANumeric(limit);%0A                %7D%0A            %7D%0A        %7D%0A        return limitNumeric;%0A    %7D%0A%0A    /**%0A     * Now that other values for limit have been attempted, treat the argument as a numeric and deal with any%0A     * problems that occur if it is not.%0A     * @param limit%0A     * @return a limit value.%0A     */%0A    private int processL
 imit
+AsA
 Numeric
- == 0) %7B%0A                            limitNumeric = defaultLimit
+(String limit) %7B%0A        int limitNumeric;%0A        try %7B%0A            limitNumeric = Integer.parseInt(limit);%0A%0A            if(limitNumeric %3C 0)%7B%0A                throw new IllegalArgumentException(%22The value for limit cannot be negative%22)
 ;%0A  
@@ -1661,32 +1661,35 @@
 %22);%0A            
+%7D%0A%0A
             %7D%0A  
@@ -1680,38 +1680,108 @@
             
-%7D%0A            
+if (limitNumeric == 0) %7B%0A                limitNumeric = defaultLimit;%0A            %7D%0A
         %7D ca
@@ -1808,36 +1808,24 @@
 eption e) %7B%0A
-            
             
@@ -1944,84 +1944,18 @@
     
-            %22number%22);%0A                    %7D%0A                %7D%0A            %7D
+%22number%22);
 %0A   

Add some javadoc. Detect if the limit is a negative number. Extract method for processing the limit value as a numeric.