File Source: StringLengthValidator.java

         /* 
    P/P   *  Method: com.dmdirc.config.prefs.validator.StringLengthValidator__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  package com.dmdirc.config.prefs.validator;
    23  
    24  /**
    25   * Validates that the length of a string is within certain bounds.
    26   * 
    27   * @author chris
    28   */
         /* 
    P/P   *  Method: ValidationResponse validate(Object)
          * 
          *  Preconditions:
          *    x0 != null
          * 
          *  Postconditions:
          *    java.lang.StringBuilder:toString(...)._tainted == 0
          *    return_value == One-of{&new ValidationResponse(validate#1*), &new ValidationResponse(validate#3*), &new ValidationResponse(validate#5*)}
          *    return_value in Addr_Set{&new ValidationResponse(validate#1*),&new ValidationResponse(validate#3*),&new ValidationResponse(validate#5*)}
          *    new ValidationResponse(validate#1*) num objects <= 1
          *    new ValidationResponse(validate#1*).failure == &amp;java.lang.StringBuilder:toString(...)
          *    new ValidationResponse(validate#3*) num objects <= 1
          *    new ValidationResponse(validate#3*).failure == &amp;java.lang.StringBuilder:toString(...)
          *    new ValidationResponse(validate#5*) num objects <= 1
          *    new ValidationResponse(validate#5*).failure == null
          */
    29  public class StringLengthValidator implements Validator<String> {
    30      
    31      /** The minimum string length. */
    32      protected final int min;
    33      
    34      /** The maximum string length. */
    35      protected final int max;
    36  
    37      /**
    38       * Creates a new string length validator that requires a string be between
    39       * the specified min/max length.
    40       * 
    41       * @param min The minimum length of the string, or -1 for unlimited.
    42       * @param max The maximum length of the string, or -1 for unlimited.
    43       */
             /* 
    P/P       *  Method: void com.dmdirc.config.prefs.validator.StringLengthValidator(int, int)
              * 
              *  Postconditions:
              *    this.max == max
              *    init'ed(this.max)
              *    this.min == min
              *    init'ed(this.min)
              */
    44      public StringLengthValidator(int min, int max) {
    45          this.min = min;
    46          this.max = max;
    47      }
    48  
    49      /** {@inheritDoc} */
    50      @Override
    51      public ValidationResponse validate(final String object) {
                 /* 
    P/P           *  Method: ValidationResponse validate(String)
                  * 
                  *  Preconditions:
                  *    object != null
                  * 
                  *  Postconditions:
                  *    java.lang.StringBuilder:toString(...)._tainted == 0
                  *    return_value in Addr_Set{&amp;new ValidationResponse(validate#1),&amp;new ValidationResponse(validate#3),&amp;new ValidationResponse(validate#5)}
                  *    new ValidationResponse(validate#1) num objects <= 1
                  *    new ValidationResponse(validate#1).failure == &amp;java.lang.StringBuilder:toString(...)
                  *    new ValidationResponse(validate#3) num objects <= 1
                  *    new ValidationResponse(validate#3).failure == &amp;java.lang.StringBuilder:toString(...)
                  *    new ValidationResponse(validate#5) num objects <= 1
                  *    new ValidationResponse(validate#5).failure == null
                  * 
                  *  Test Vectors:
                  *    this.max: {0..232-2}, {-1}
                  */
    52          if (object.length() < min && min != -1) {
    53              return new ValidationResponse("Must be at least " + min + " characters long");
    54          } else if (object.length() > max && max != -1) {
    55              return new ValidationResponse("Must be at most " + max + " characters long");
    56          } else {
    57              return new ValidationResponse();
    58          }
    59      }
    60  
    61  }








SofCheck Inspector Build Version : 2.17854
StringLengthValidator.java 2009-Jun-25 01:54:24
StringLengthValidator.class 2009-Sep-02 17:04:16