//# 0 errors, 140 messages
//#
/*
    //#NumericalValidator.java:1:1: class: com.dmdirc.config.prefs.validator.NumericalValidator
    //#NumericalValidator.java:1:1: method: com.dmdirc.config.prefs.validator.NumericalValidator.com.dmdirc.config.prefs.validator.NumericalValidator__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * 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 com.dmdirc.config.prefs.validator;

/**
 * Validates that a number is within certain bounds.
 * 
 * @author chris
 */
public class NumericalValidator implements Validator<String> {
    //#NumericalValidator.java:29: method: ValidationResponse com.dmdirc.config.prefs.validator.NumericalValidator.validate(Object)
    //#NumericalValidator.java:29: Warning: suspicious precondition
    //#    The precondition for this.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.config.prefs.validator.NumericalValidator
    //#    method: ValidationResponse validate(Object)
    //#    suspicious precondition index: [2]
    //#input(ValidationResponse validate(Object)): "Must be at least "._tainted
    //#input(ValidationResponse validate(Object)): "Must be at most "._tainted
    //#input(ValidationResponse validate(Object)): __Descendant_Table[com/dmdirc/config/prefs/validator/NumericalValidator]
    //#input(ValidationResponse validate(Object)): __Descendant_Table[com/dmdirc/config/prefs/validator/PortValidator]
    //#input(ValidationResponse validate(Object)): __Descendant_Table[others]
    //#input(ValidationResponse validate(Object)): __Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): com/dmdirc/config/prefs/validator/PortValidator.__Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#input(ValidationResponse validate(Object)): this
    //#input(ValidationResponse validate(Object)): this.__Tag
    //#input(ValidationResponse validate(Object)): this.max
    //#input(ValidationResponse validate(Object)): this.min
    //#input(ValidationResponse validate(Object)): x0
    //#output(ValidationResponse validate(Object)): java.lang.StringBuilder:toString(...)._tainted
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).failure
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#2*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).failure
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#4*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).failure
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#6*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#6*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#6*).failure
    //#output(ValidationResponse validate(Object)): return_value
    //#new obj(ValidationResponse validate(Object)): java.lang.StringBuilder:toString(...)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#1*)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#2*)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#4*)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#6*)
    //#pre[2] (ValidationResponse validate(Object)): this.__Tag in {com/dmdirc/config/prefs/validator/NumericalValidator, com/dmdirc/config/prefs/validator/PortValidator}
    //#post(ValidationResponse validate(Object)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(ValidationResponse validate(Object)): return_value == One-of{&new ValidationResponse(validate#1*), &new ValidationResponse(validate#2*), &new ValidationResponse(validate#4*), &new ValidationResponse(validate#6*)}
    //#post(ValidationResponse validate(Object)): return_value in Addr_Set{&new ValidationResponse(validate#1*),&new ValidationResponse(validate#2*),&new ValidationResponse(validate#4*),&new ValidationResponse(validate#6*)}
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#1*).failure == &"Must be a valid number"
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#2*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#2*).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#4*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#4*).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#6*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#6*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#6*).failure == null
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.Integer:parseInt
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.StringBuilder
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.StringBuilder:append
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.StringBuilder:toString
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.Throwable:__curr_excep_obj
    //#NumericalValidator.java:29: end of method: ValidationResponse com.dmdirc.config.prefs.validator.NumericalValidator.validate(Object)
    
    /** The minimum value for this number. */
    protected final int min;
    
    /** The maximum value for this number. */
    protected final int max;

    /**
     * Creates a new numerical validator with the specified bounds.
     * 
     * @param min The minimum value for the number, or -1 for unlimited.
     * @param max The maximum value for the number, or -1 for unlimited.
     */
    public NumericalValidator(int min, int max) {
    //#NumericalValidator.java:43: method: void com.dmdirc.config.prefs.validator.NumericalValidator.com.dmdirc.config.prefs.validator.NumericalValidator(int, int)
    //#input(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): max
    //#input(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): min
    //#input(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): this
    //#output(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): this.max
    //#output(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): this.min
    //#post(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): this.max == max
    //#post(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): init'ed(this.max)
    //#post(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): this.min == min
    //#post(void com.dmdirc.config.prefs.validator.NumericalValidator(int, int)): init'ed(this.min)
        this.min = min;
        this.max = max;
    }
    //#NumericalValidator.java:46: end of method: void com.dmdirc.config.prefs.validator.NumericalValidator.com.dmdirc.config.prefs.validator.NumericalValidator(int, int)

    /**
     * Retrieves the maximum value that this validator will allow.
     * 
     * @return This validator's maximum value
     */
    public int getMax() {
        return max == -1 ? Integer.MAX_VALUE : max;
    //#NumericalValidator.java:54: method: int com.dmdirc.config.prefs.validator.NumericalValidator.getMax()
    //#input(int getMax()): this
    //#input(int getMax()): this.max
    //#output(int getMax()): return_value
    //#post(int getMax()): return_value == One-of{2_147_483_647, this.max}
    //#post(int getMax()): return_value != -1
    //#NumericalValidator.java:54: end of method: int com.dmdirc.config.prefs.validator.NumericalValidator.getMax()
    }

    /**
     * Retrieves the minimum value that this validator will allow.
     * 
     * @return This validator's minimum value
     */    
    public int getMin() {
        return min == -1 ? Integer.MIN_VALUE : min;
    //#NumericalValidator.java:63: method: int com.dmdirc.config.prefs.validator.NumericalValidator.getMin()
    //#input(int getMin()): this
    //#input(int getMin()): this.min
    //#output(int getMin()): return_value
    //#post(int getMin()): return_value == One-of{-2_147_483_648, this.min}
    //#post(int getMin()): return_value != -1
    //#NumericalValidator.java:63: end of method: int com.dmdirc.config.prefs.validator.NumericalValidator.getMin()
    }
    
    /** {@inheritDoc} */
    @Override
    public ValidationResponse validate(final String object) {
        int intv;
        
        try {
            intv = Integer.parseInt(object);
    //#NumericalValidator.java:72: method: ValidationResponse com.dmdirc.config.prefs.validator.NumericalValidator.validate(String)
    //#input(ValidationResponse validate(String)): "Must be at least "._tainted
    //#input(ValidationResponse validate(String)): "Must be at most "._tainted
    //#input(ValidationResponse validate(String)): object
    //#input(ValidationResponse validate(String)): this
    //#input(ValidationResponse validate(String)): this.max
    //#input(ValidationResponse validate(String)): this.min
    //#output(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)._tainted
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#1) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#1).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#1).failure
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#2) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#2).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#2).failure
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#4) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#4).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#4).failure
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#6) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#6).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#6).failure
    //#output(ValidationResponse validate(String)): return_value
    //#new obj(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#1)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#2)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#4)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#6)
    //#post(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(ValidationResponse validate(String)): return_value in Addr_Set{&new ValidationResponse(validate#2),&new ValidationResponse(validate#4),&new ValidationResponse(validate#6),&new ValidationResponse(validate#1)}
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#1) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#1).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#1).failure == &"Must be a valid number"
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#2) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#2).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#2).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#4) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#4).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#4).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#6) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#6).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#6).failure == null
    //#test_vector(ValidationResponse validate(String)): this.max: {-1}, {-2_147_483_648..-2, 0..4_294_967_294}
    //#test_vector(ValidationResponse validate(String)): this.min: {-1}, {-2_147_483_647..-2, 0..4_294_967_295}
    //#test_vector(ValidationResponse validate(String)): java.lang.Integer:parseInt(...)@72: {-2_147_483_648..-2}, {0..4_294_967_295}
        } catch (NumberFormatException ex) {
            return new ValidationResponse("Must be a valid number");
        }
        
        if (intv < min && min != -1) {
            return new ValidationResponse("Must be at least " + min);
        } else if (intv > max && max != -1) {
            return new ValidationResponse("Must be at most " + max);
        } else {
            return new ValidationResponse();
    //#NumericalValidator.java:82: end of method: ValidationResponse com.dmdirc.config.prefs.validator.NumericalValidator.validate(String)
        }
    }

}
    //#output(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Descendant_Table[com/dmdirc/config/prefs/validator/NumericalValidator]
    //#output(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.getMax()I
    //#output(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.getMin()I
    //#output(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#output(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse;
    //#output(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/NumericalValidator]
    //#post(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Descendant_Table[com/dmdirc/config/prefs/validator/NumericalValidator] == &__Dispatch_Table
    //#post(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): com/dmdirc/config/prefs/validator/Validator.__Descendant_Table[com/dmdirc/config/prefs/validator/NumericalValidator] == &__Dispatch_Table
    //#post(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.getMax()I == &getMax
    //#post(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.getMin()I == &getMin
    //#post(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.validate(Ljava/lang/Object;)Lcom/dmdirc/config/prefs/validator/ValidationResponse; == &validate
    //#post(com.dmdirc.config.prefs.validator.NumericalValidator__static_init): __Dispatch_Table.validate(Ljava/lang/String;)Lcom/dmdirc/config/prefs/validator/ValidationResponse; == &validate
    //#NumericalValidator.java:: end of method: com.dmdirc.config.prefs.validator.NumericalValidator.com.dmdirc.config.prefs.validator.NumericalValidator__static_init
    //#NumericalValidator.java:: end of class: com.dmdirc.config.prefs.validator.NumericalValidator
