File Source: NoDuplicatesInListValidator.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.profiles.NoDuplicatesInListValidator__static_init
          */
     1  /*
     2   * 
     3   * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
     4   * 
     5   * Permission is hereby granted, free of charge, to any person obtaining a copy
     6   * of this software and associated documentation files (the "Software"), to deal
     7   * in the Software without restriction, including without limitation the rights
     8   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     9   * copies of the Software, and to permit persons to whom the Software is
    10   * furnished to do so, subject to the following conditions:
    11   * 
    12   * The above copyright notice and this permission notice shall be included in
    13   * all copies or substantial portions of the Software.
    14   * 
    15   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    16   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    17   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    18   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    19   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    20   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    21   * SOFTWARE.
    22   */
    23  
    24  package com.dmdirc.addons.ui_swing.dialogs.profiles;
    25  
    26  import com.dmdirc.config.prefs.validator.ValidationResponse;
    27  import com.dmdirc.config.prefs.validator.Validator;
    28  
    29  import javax.swing.DefaultListModel;
    30  
    31  /**
    32   * Validator to check for duplicate values in a list.
    33   */
         /* 
    P/P   *  Method: ValidationResponse validate(Object)
          * 
          *  Preconditions:
          *    this.model != null
          * 
          *  Postconditions:
          *    return_value == One-of{&new ValidationResponse(validate#1*), &new ValidationResponse(validate#2*)}
          *    return_value in Addr_Set{&new ValidationResponse(validate#1*),&new ValidationResponse(validate#2*)}
          *    new ValidationResponse(validate#1*) num objects <= 1
          *    new ValidationResponse(validate#2*) num objects <= 1
          */
    34  public class NoDuplicatesInListValidator implements Validator<String> {
    35  
    36      /** List to validate. */
    37      private DefaultListModel model;
    38  
    39      /**
    40       * Creates a new validator.
    41       *
    42       * @param model Model to validate
    43       */
             /* 
    P/P       *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.NoDuplicatesInListValidator(DefaultListModel)
              * 
              *  Postconditions:
              *    this.model == model
              *    init'ed(this.model)
              */
    44      public NoDuplicatesInListValidator(final DefaultListModel model) {
    45          this.model = model;
    46      }
    47  
    48      /** {@inheritDoc} */
    49      @Override
    50      public ValidationResponse validate(final String object) {
                 /* 
    P/P           *  Method: ValidationResponse validate(String)
                  * 
                  *  Preconditions:
                  *    this.model != null
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&amp;new ValidationResponse(validate#2),&amp;new ValidationResponse(validate#1)}
                  *    new ValidationResponse(validate#1) num objects <= 1
                  *    new ValidationResponse(validate#2) num objects <= 1
                  * 
                  *  Test Vectors:
                  *    javax.swing.DefaultListModel:contains(...)@51: {0}, {1}
                  */
    51          if (model.contains(object)) {
    52              return new ValidationResponse("Value is a duplicate");
    53          } else {
    54              return new ValidationResponse();
    55          }
    56      }
    57  
    58  }








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