//# 0 errors, 107 messages
//#
/*
    //#StringLengthValidator.java:1:1: class: com.dmdirc.config.prefs.validator.StringLengthValidator
    //#StringLengthValidator.java:1:1: method: com.dmdirc.config.prefs.validator.StringLengthValidator.com.dmdirc.config.prefs.validator.StringLengthValidator__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 the length of a string is within certain bounds.
 * 
 * @author chris
 */
public class StringLengthValidator implements Validator<String> {
    //#StringLengthValidator.java:29: method: ValidationResponse com.dmdirc.config.prefs.validator.StringLengthValidator.validate(Object)
    //#input(ValidationResponse validate(Object)): " characters long"._tainted
    //#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/StringLengthValidator]
    //#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)): 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#3*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#3*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#3*).failure
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#5*) num objects
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#5*).__Tag
    //#output(ValidationResponse validate(Object)): new ValidationResponse(validate#5*).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#3*)
    //#new obj(ValidationResponse validate(Object)): new ValidationResponse(validate#5*)
    //#pre[2] (ValidationResponse validate(Object)): this.__Tag == com/dmdirc/config/prefs/validator/StringLengthValidator
    //#pre[5] (ValidationResponse validate(Object)): x0 != null
    //#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#3*), &new ValidationResponse(validate#5*)}
    //#post(ValidationResponse validate(Object)): return_value in Addr_Set{&new ValidationResponse(validate#1*),&new ValidationResponse(validate#3*),&new ValidationResponse(validate#5*)}
    //#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 == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#3*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#3*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#3*).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#5*) num objects <= 1
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#5*).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(Object)): new ValidationResponse(validate#5*).failure == null
    //#unanalyzed(ValidationResponse validate(Object)): Effects-of-calling:java.lang.String:length
    //#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
    //#StringLengthValidator.java:29: end of method: ValidationResponse com.dmdirc.config.prefs.validator.StringLengthValidator.validate(Object)
    
    /** The minimum string length. */
    protected final int min;
    
    /** The maximum string length. */
    protected final int max;

    /**
     * Creates a new string length validator that requires a string be between
     * the specified min/max length.
     * 
     * @param min The minimum length of the string, or -1 for unlimited.
     * @param max The maximum length of the string, or -1 for unlimited.
     */
    public StringLengthValidator(int min, int max) {
    //#StringLengthValidator.java:44: method: void com.dmdirc.config.prefs.validator.StringLengthValidator.com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)
    //#input(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): max
    //#input(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): min
    //#input(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): this
    //#output(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): this.max
    //#output(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): this.min
    //#post(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): this.max == max
    //#post(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): init'ed(this.max)
    //#post(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): this.min == min
    //#post(void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)): init'ed(this.min)
        this.min = min;
        this.max = max;
    }
    //#StringLengthValidator.java:47: end of method: void com.dmdirc.config.prefs.validator.StringLengthValidator.com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)

    /** {@inheritDoc} */
    @Override
    public ValidationResponse validate(final String object) {
        if (object.length() < min && min != -1) {
    //#StringLengthValidator.java:52: method: ValidationResponse com.dmdirc.config.prefs.validator.StringLengthValidator.validate(String)
    //#StringLengthValidator.java:52: Warning: test always goes same way
    //#    Test predetermined because this.min in {1..4_294_967_295}
    //#    severity: LOW
    //#    class: com.dmdirc.config.prefs.validator.StringLengthValidator
    //#    method: ValidationResponse validate(String)
    //#    from bb: bb_2
    //#    live edge: bb_2-->bb_3
    //#    tested vn: this.min + 1
    //#    tested vn values: {2..4_294_967_296}
    //#input(ValidationResponse validate(String)): " characters long"._tainted
    //#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#3) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#3).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#3).failure
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#5) num objects
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#5).__Tag
    //#output(ValidationResponse validate(String)): new ValidationResponse(validate#5).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#3)
    //#new obj(ValidationResponse validate(String)): new ValidationResponse(validate#5)
    //#pre[1] (ValidationResponse validate(String)): object != null
    //#post(ValidationResponse validate(String)): java.lang.StringBuilder:toString(...)._tainted == 0
    //#post(ValidationResponse validate(String)): return_value in Addr_Set{&new ValidationResponse(validate#1),&new ValidationResponse(validate#3),&new ValidationResponse(validate#5)}
    //#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 == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#3) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#3).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#3).failure == &java.lang.StringBuilder:toString(...)
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#5) num objects <= 1
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#5).__Tag == com/dmdirc/config/prefs/validator/ValidationResponse
    //#post(ValidationResponse validate(String)): new ValidationResponse(validate#5).failure == null
    //#test_vector(ValidationResponse validate(String)): this.max: {0..4_294_967_294}, {-1}
            return new ValidationResponse("Must be at least " + min + " characters long");
        } else if (object.length() > max && max != -1) {
            return new ValidationResponse("Must be at most " + max + " characters long");
        } else {
            return new ValidationResponse();
    //#StringLengthValidator.java:57: end of method: ValidationResponse com.dmdirc.config.prefs.validator.StringLengthValidator.validate(String)
        }
    }

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