File Source: ProfileListModel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileListModel__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  
    23  package com.dmdirc.addons.ui_swing.dialogs.profiles;
    24  
    25  import java.util.ArrayList;
    26  import java.util.Iterator;
    27  import java.util.List;
    28  
    29  import javax.swing.DefaultListModel;
    30  
    31  /** Profile list model. */
         /* 
    P/P   *  Method: Object getElementAt(int)
          * 
          *  Preconditions:
          *    this.profiles != null
          * 
          *  Postconditions:
          *    init'ed(return_value)
          */
    32  public class ProfileListModel extends DefaultListModel implements Iterable<Profile> {
    33  
    34      /**
    35       * A version number for this class. It should be changed whenever the class
    36       * structure is changed (or anything else that would prevent serialized
    37       * objects being unserialized with the new class).
    38       */
    39      private static final long serialVersionUID = 1;
    40      /** Profile list. */
    41      private final List<Profile> profiles;
    42  
    43      /** Creates a new profile list model. */
    44      public ProfileListModel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileListModel()
                  * 
                  *  Postconditions:
                  *    this.profiles == &amp;new ArrayList(ProfileListModel#1)
                  *    new ArrayList(ProfileListModel#1) num objects == 1
                  */
    45          this(new ArrayList<Profile>());
    46      }
    47  
    48      /**
    49       * Creates a new profile list model.
    50       *
    51       * @param profiles Profile list to use
    52       */
             /* 
    P/P       *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileListModel(List)
              * 
              *  Postconditions:
              *    this.profiles == profiles
              *    init'ed(this.profiles)
              */
    53      public ProfileListModel(final List<Profile> profiles) {
    54          this.profiles = profiles;
    55      }
    56  
    57      /** {@inheritDoc} */
    58      @Override
    59      public int getSize() {
                 /* 
    P/P           *  Method: int getSize()
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    60          return profiles.size();
    61      }
    62  
    63      /** {@inheritDoc} */
    64      @Override
    65      public Profile getElementAt(int index) {
                 /* 
    P/P           *  Method: Profile getElementAt(int)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    66          return profiles.get(index);
    67      }
    68  
    69      /**
    70       * Removes the index from the model.
    71       *
    72       * @param index Index to remove
    73       *
    74       * @return the profile that was removed
    75       */
    76      @Override
    77      public Profile remove(int index) {
                 /* 
    P/P           *  Method: Profile remove(int)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    78          final Profile returnValue = profiles.remove(index);
    79  
    80          fireIntervalRemoved(this, index, index);
    81  
    82          return returnValue;
    83      }
    84  
    85      /**
    86       * Removes the object from the model.
    87       *
    88       * @param p object to remove from the model
    89       *
    90       * @return true if the object was removed
    91       */
    92      public boolean remove(Profile p) {
                 /* 
    P/P           *  Method: bool remove(Profile)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    93          final int index = profiles.indexOf(p);
    94          final boolean returnValue = profiles.remove(p);
    95  
    96          fireIntervalRemoved(this, index, index);
    97  
    98          return returnValue;
    99      }
   100  
   101      /**
   102       * Checks if the model is empty.
   103       *
   104       * @return true if the model is empty
   105       */
   106      @Override
   107      public boolean isEmpty() {
                 /* 
    P/P           *  Method: bool isEmpty()
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   108          return profiles.isEmpty();
   109      }
   110  
   111      /**
   112       * Returns the index of the object.
   113       *
   114       * @param p object to find the index of
   115       *
   116       * @return index of the specified object
   117       */
   118      public int indexOf(Profile p) {
                 /* 
    P/P           *  Method: int indexOf(Profile)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   119          return profiles.indexOf(p);
   120      }
   121  
   122      /**
   123       * Returns the profile at the index.
   124       *
   125       * @param index index to retrieve
   126       *
   127       * @return the profile that was removed
   128       */
   129      @Override
   130      public Profile get(int index) {
                 /* 
    P/P           *  Method: Profile get(int)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   131          return profiles.get(index);
   132      }
   133      
   134      /**
   135       * Returns a list of all profiles
   136       * 
   137       * @return Profile list
   138       */
   139      public List<Profile> getProfiles() {
                 /* 
    P/P           *  Method: List getProfiles()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new ArrayList(getProfiles#1)
                  *    new ArrayList(getProfiles#1) num objects == 1
                  */
   140          return new ArrayList<Profile>(profiles);
   141      }
   142  
   143      /**
   144       *
   145       * Checks if the model contains the profile
   146       *
   147       * @param p profile to check for
   148       *
   149       * @return true if the model contains the profile
   150       */
   151      public boolean contains(Profile p) {
                 /* 
    P/P           *  Method: bool contains(Profile)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   152          return profiles.contains(p);
   153      }
   154  
   155      /**
   156       *
   157       * Checks if the model contains a profile with the specified name.
   158       *
   159       * @param name name to match against
   160       *
   161       * @return true if the model contains a profile with the specified name
   162       */
   163      public boolean contains(String name) {
                 /* 
    P/P           *  Method: bool contains(String)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Presumptions:
                  *    java.util.Iterator:next(...)@165 != null
                  *    profile.name@165 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@166: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@165: {0}, {1}
                  */
   164          synchronized (profiles) {
   165              for (Profile profile : profiles) {
   166                  if (profile.getName().equals(name)) {
   167                      return true;
   168                  }
   169              }
   170  
   171              return false;
   172          }
   173      }
   174  
   175      /**
   176       * Clears the model.
   177       */
   178      @Override
   179      public void clear() {
                 /* 
    P/P           *  Method: void clear()
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  */
   180          final int size = profiles.size();
   181          profiles.clear();
   182          fireIntervalRemoved(this, 0, size);
   183      }
   184  
   185      /**
   186       * Adds a profile at the index
   187       *
   188       * @param index index to add the profile
   189       * @param element profile to add
   190       */
   191      public void add(int index, Profile element) {
                 /* 
    P/P           *  Method: void add(int, Profile)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  */
   192          profiles.add(index, element);
   193  
   194          fireIntervalAdded(this, index, index);
   195      }
   196  
   197      /**
   198       * Adds the profile to the model
   199       *
   200       * @param p profile to add
   201       *
   202       * @return true if the item was added
   203       */
   204      public boolean add(Profile p) {
                 /* 
    P/P           *  Method: bool add(Profile)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   205          final boolean returnValue = profiles.add(p);
   206          final int index = profiles.indexOf(p);
   207  
   208          fireIntervalAdded(this, index, index);
   209  
   210          return returnValue;
   211      }
   212  
   213      /**
   214       * Returns an iterator for this model.
   215       *
   216       * @return Iterator for the model
   217       */
   218      @Override
   219      public Iterator<Profile> iterator() {
                 /* 
    P/P           *  Method: Iterator iterator()
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    return_value != null
                  */
   220          return profiles.iterator();
   221      }
   222  
   223      /** {@inheritDoc} */
   224      @Override
   225      public boolean equals(Object obj) {
                 /* 
    P/P           *  Method: bool equals(Object)
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   226          return profiles.equals(obj);
   227      }
   228  
   229      /** {@inheritDoc} */
   230      @Override
   231      public int hashCode() {
                 /* 
    P/P           *  Method: int hashCode()
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   232          return profiles.hashCode();
   233      }
   234      
   235      /** {@inheritDoc} */
   236      @Override
   237      public String toString() {
                 /* 
    P/P           *  Method: String toString()
                  * 
                  *  Preconditions:
                  *    this.profiles != null
                  * 
                  *  Postconditions:
                  *    java.lang.Object:toString(...)._tainted == this.profiles._tainted
                  *    init'ed(java.lang.Object:toString(...)._tainted)
                  *    return_value == &amp;java.lang.Object:toString(...)
                  */
   238          return profiles.toString();
   239      }
   240  }








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