File Source: Profile.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.profiles.Profile__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 com.dmdirc.config.Identity;
    26  import com.dmdirc.config.IdentityManager;
    27  
    28  import java.io.IOException;
    29  import java.util.Arrays;
    30  import java.util.List;
    31  
    32  /** Profile wrapper class. */
    33  public class Profile {
    34  
    35      /** Old Name. */
    36      private String oldName;
    37      /** Name. */
    38      private String name;
    39      /** Real name. */
    40      private String realname;
    41      /** Ident. */
    42      private String ident;
    43      /** Nicknames. */
    44      private List<String> nicknames;
    45      /** Does this profile need saving? */
    46      private boolean modified;
    47  
    48      /** Creates a new profile. */
    49      public Profile() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile()
                  * 
                  *  Postconditions:
                  *    this.ident == &amp;""
                  *    this.name == &amp;""
                  *    this.oldName == &amp;""
                  *    this.realname == &amp;""
                  *    this.modified == 1
                  *    init'ed(this.nicknames)
                  */
    50          this("");
    51      }
    52  
    53      /**
    54       * Creates a new profile.
    55       *
    56       * @param name Profile's name
    57       */
    58      public Profile(final String name) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile(String)
                  * 
                  *  Postconditions:
                  *    this.ident == &amp;""
                  *    this.realname == &amp;""
                  *    this.modified == 1
                  *    this.name == name
                  *    init'ed(this.name)
                  *    this.oldName == this.name
                  *    init'ed(this.nicknames)
                  */
    59          this(name, "");
    60      }
    61  
    62      /**
    63       * Creates a new profile.
    64       *
    65       * @param name Profile's name
    66       * @param nickname Profile's nickname
    67       */
    68      public Profile(final String name, final String nickname) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile(String, String)
                  * 
                  *  Postconditions:
                  *    this.ident == &amp;""
                  *    this.realname == &amp;""
                  *    this.modified == 1
                  *    this.name == name
                  *    init'ed(this.name)
                  *    this.oldName == this.name
                  *    init'ed(this.nicknames)
                  */
    69          this(name, nickname, "");
    70      }
    71  
    72      /**
    73       *
    74       *
    75       * @param name Profile's name
    76       * @param nickname Profile's nickname
    77       * @param realname Profile's realname
    78       */
    79      public Profile(final String name, final String nickname,
    80              final String realname) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile(String, String, String)
                  * 
                  *  Postconditions:
                  *    this.ident == &amp;""
                  *    this.modified == 1
                  *    this.name == name
                  *    init'ed(this.name)
                  *    this.oldName == this.name
                  *    init'ed(this.nicknames)
                  *    this.realname == realname
                  *    init'ed(this.realname)
                  */
    81          this(name, nickname, realname, "");
    82      }
    83  
    84      /**
    85       * Creates a new profile.
    86       *
    87       * @param name Profile's name
    88       * @param nickname Profile's nickname
    89       * @param realname Profile's realname
    90       * @param ident Profile's ident
    91       */
    92      public Profile(final String name, final String nickname,
    93              final String realname, final String ident) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile(String, String, String, String)
                  * 
                  *  Postconditions:
                  *    this.ident == ident
                  *    init'ed(this.ident)
                  *    this.modified == 1
                  *    this.name == name
                  *    init'ed(this.name)
                  *    this.oldName == this.name
                  *    init'ed(this.nicknames)
                  *    this.realname == realname
                  *    init'ed(this.realname)
                  */
    94          this(name, Arrays.asList(new String[]{nickname, }), realname, ident);
    95      }
    96  
    97      /**
    98       * Creates a new profile.
    99       *
   100       * @param name Profile's name
   101       * @param nicknames Profile's nicknames
   102       * @param realname Profile's realname
   103       * @param ident Profile's ident
   104       */
   105      public Profile(final String name, final List<String> nicknames,
   106              final String realname, final String ident) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile(String, List, String, String)
                  * 
                  *  Postconditions:
                  *    this.ident == ident
                  *    init'ed(this.ident)
                  *    this.modified == 1
                  *    this.name == name
                  *    init'ed(this.name)
                  *    this.oldName == this.name
                  *    this.nicknames == nicknames
                  *    init'ed(this.nicknames)
                  *    this.realname == realname
                  *    init'ed(this.realname)
                  */
   107          this(name, nicknames, realname, ident, true);
   108      }
   109  
   110      /**
   111       * Creates a new profile.
   112       *
   113       * @param name Profile's name
   114       * @param nicknames Profile's nickname
   115       * @param realname Profile's realname
   116       * @param ident Profile's ident
   117       * @param modified Has this profile been modified
   118       */
   119      public Profile(final String name, final List<String> nicknames,
   120              final String realname, final String ident,
                     /* 
    P/P               *  Method: void com.dmdirc.addons.ui_swing.dialogs.profiles.Profile(String, List, String, String, bool)
                      * 
                      *  Postconditions:
                      *    this.ident == ident
                      *    init'ed(this.ident)
                      *    this.modified == modified
                      *    init'ed(this.modified)
                      *    this.name == name
                      *    init'ed(this.name)
                      *    this.oldName == this.name
                      *    this.nicknames == nicknames
                      *    init'ed(this.nicknames)
                      *    this.realname == realname
                      *    ...
                      */
   121              final boolean modified) {
   122          this.oldName = name;
   123          this.name = name;
   124          this.nicknames = nicknames;
   125          this.realname = realname;
   126          this.ident = ident;
   127          this.modified = modified;
   128      }
   129  
   130      /**
   131       * Returns the name of this profile.
   132       *
   133       * @return Profile's name
   134       */
   135      public String getName() {
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Preconditions:
                  *    init'ed(this.name)
                  * 
                  *  Postconditions:
                  *    return_value == this.name
                  *    init'ed(return_value)
                  */
   136          return name;
   137      }
   138  
   139      /**
   140       * Sets the name of this profile.
   141       *
   142       * @param name Profile's new name
   143       */
   144      public void setName(final String name) {
                 /* 
    P/P           *  Method: void setName(String)
                  * 
                  *  Preconditions:
                  *    this.name != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.modified)
                  *    this.name == One-of{old this.name, name}
                  *    init'ed(this.name)
                  *    this.oldName == One-of{old this.oldName, old this.name}
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@145: {1}, {0}
                  */
   145          if (!this.name.equals(name)) {
   146              this.oldName = this.name;
   147              this.name = name;
   148              setModified(true);
   149          }
   150      }
   151      
   152      /**
   153       * Gets the nicknames list for this profile.
   154       *
   155       * @return Profile's nicknames list
   156       */
   157      public List<String> getNicknames() {
                 /* 
    P/P           *  Method: List getNicknames()
                  * 
                  *  Preconditions:
                  *    init'ed(this.nicknames)
                  * 
                  *  Postconditions:
                  *    return_value == this.nicknames
                  *    init'ed(return_value)
                  */
   158          return nicknames;
   159      }
   160  
   161      /**
   162       * Sets the nicknames list for this profile.
   163       *
   164       * @param nicknames Profile's new nicknames list
   165       */
   166      public void setNicknames(final List<String> nicknames) {
                 /* 
    P/P           *  Method: void setNicknames(List)
                  * 
                  *  Preconditions:
                  *    this.nicknames != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.modified)
                  *    this.nicknames == One-of{old this.nicknames, nicknames}
                  *    init'ed(this.nicknames)
                  * 
                  *  Test Vectors:
                  *    java.lang.Object:equals(...)@167: {1}, {0}
                  */
   167          if (!this.nicknames.equals(nicknames)) {
   168              this.nicknames = nicknames;
   169              setModified(true);
   170          }
   171      }
   172  
   173      /**
   174       * Adds a nickname to this profile.
   175       *
   176       * @param nickname A new nickname for the profile
   177       */
   178      public void addNickname(final String nickname) {
                 /* 
    P/P           *  Method: void addNickname(String)
                  * 
                  *  Preconditions:
                  *    this.nicknames != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.modified)
                  * 
                  *  Test Vectors:
                  *    java.util.List:contains(...)@179: {1}, {0}
                  */
   179          if (!nicknames.contains(nickname)) {
   180              nicknames.add(nickname);
   181              setModified(true);
   182          }
   183      }
   184  
   185      /**
   186       * Adds a nickname to this profile.
   187       *
   188       * @param nickname A new nickname for the profile
   189       * @param position Position for the new alternate nickname
   190       */
   191      public void addNickname(final String nickname, final int position) {
                 /* 
    P/P           *  Method: void addNickname(String, int)
                  * 
                  *  Preconditions:
                  *    this.nicknames != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.modified)
                  * 
                  *  Test Vectors:
                  *    java.util.List:contains(...)@192: {1}, {0}
                  */
   192          if (!nicknames.contains(nickname)) {
   193              nicknames.add(position, nickname);
   194              setModified(true);
   195          }
   196      }
   197  
   198      /**
   199       * Deletes a nickname from this profile.
   200       *
   201       * @param nickname An existing nickname from the profile
   202       */
   203      public void delNickname(final String nickname) {
                 /* 
    P/P           *  Method: void delNickname(String)
                  * 
                  *  Preconditions:
                  *    this.nicknames != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.modified)
                  * 
                  *  Test Vectors:
                  *    java.util.List:remove(...)@204: {0}, {1}
                  */
   204          if (nicknames.remove(nickname)) {
   205              setModified(true);
   206          }
   207      }
   208  
   209      /**
   210       * Gets the specified nickname for this profile
   211       *
   212       * @param index Index of the nickname to retrieve
   213       * 
   214       * @return Profile's nickname
   215       */
   216      public String getNickname(final int index) {
                 /* 
    P/P           *  Method: String getNickname(int)
                  * 
                  *  Preconditions:
                  *    this.nicknames != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   217          return nicknames.get(index);
   218      }
   219  
   220      /**
   221       * Gets the realname for this profile.
   222       *
   223       * @return Profile's realname
   224       */
   225      public String getRealname() {
                 /* 
    P/P           *  Method: String getRealname()
                  * 
                  *  Preconditions:
                  *    init'ed(this.realname)
                  * 
                  *  Postconditions:
                  *    return_value == this.realname
                  *    init'ed(return_value)
                  */
   226          return realname;
   227      }
   228  
   229      /**
   230       * Sets the realname for this profile.
   231       *
   232       * @param realname Profile's new realname
   233       */
   234      public void setRealname(final String realname) {
                 /* 
    P/P           *  Method: void setRealname(String)
                  * 
                  *  Preconditions:
                  *    this.realname != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(this.modified)
                  *    this.realname == One-of{old this.realname, realname}
                  *    init'ed(this.realname)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@235: {1}, {0}
                  */
   235          if (!this.realname.equals(realname)) {
   236              this.realname = realname;
   237              setModified(true);
   238          }
   239      }
   240  
   241      /**
   242       * Gets the ident for this profile.
   243       *
   244       * @return Profile's ident
   245       */
   246      public String getIdent() {
                 /* 
    P/P           *  Method: String getIdent()
                  * 
                  *  Preconditions:
                  *    init'ed(this.ident)
                  * 
                  *  Postconditions:
                  *    return_value == this.ident
                  *    init'ed(return_value)
                  */
   247          return ident;
   248      }
   249  
   250      /**
   251       * Sets the ident for this profile.
   252       *
   253       * @param ident Profile's new ident
   254       */
   255      public void setIdent(final String ident) {
                 /* 
    P/P           *  Method: void setIdent(String)
                  * 
                  *  Preconditions:
                  *    init'ed(this.ident)
                  * 
                  *  Postconditions:
                  *    this.ident == One-of{old this.ident, ident}
                  *    init'ed(this.ident)
                  *    possibly_updated(this.modified)
                  * 
                  *  Test Vectors:
                  *    this.ident: Addr_Set{null}, Inverse{null}
                  *    java.lang.String:equals(...)@256: {1}, {0}
                  */
   256          if (this.ident == null || !this.ident.equals(ident)) {
   257              this.ident = ident;
   258              setModified(true);
   259          }
   260      }
   261  
   262      /**
   263       * Has this profile been modified?
   264       *
   265       * @return true iif the profile has been modified
   266       */
   267      public boolean isModified() {
                 /* 
    P/P           *  Method: bool isModified()
                  * 
                  *  Preconditions:
                  *    init'ed(this.modified)
                  * 
                  *  Postconditions:
                  *    return_value == this.modified
                  *    init'ed(return_value)
                  */
   268          return modified;
   269      }
   270  
   271      /**
   272       * Sets whether the profile has been modified.
   273       *
   274       * @param modified Modified state for the profile
   275       */
   276      public void setModified(final boolean modified) {
                 /* 
    P/P           *  Method: void setModified(bool)
                  * 
                  *  Postconditions:
                  *    this.modified == modified
                  *    init'ed(this.modified)
                  */
   277          this.modified = modified;
   278      }
   279  
   280      /** Saves this profile. */
   281      public void save() {
                 /* 
    P/P           *  Method: void save()
                  * 
                  *  Preconditions:
                  *    init'ed(this.modified)
                  *    (soft) init'ed(this.oldName)
                  *    (soft) init'ed(this.ident)
                  *    (soft) init'ed(this.name)
                  *    (soft) init'ed(this.nicknames)
                  *    (soft) init'ed(this.realname)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.Identity:getName(...)@288 != null
                  *    com.dmdirc.config.IdentityManager:getProfiles(...)@284 != null
                  *    java.util.Iterator:next(...)@287 != null
                  * 
                  *  Postconditions:
                  *    this.modified == 0
                  *    this.oldName == One-of{old this.oldName, this.name}
                  *    init'ed(this.oldName)
                  * 
                  *  Test Vectors:
                  *    this.modified: {0}, {1}
                  *    java.lang.String:equalsIgnoreCase(...)@288: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@287: {0}, {1}
                  */
   282          if (modified) {
   283              final String profileString = "profile";
   284              final List<Identity> identities = IdentityManager.getProfiles();
   285              Identity profile = null;
   286  
   287              for (Identity identity : identities) {
   288                  if (identity.getName().equalsIgnoreCase(oldName)) {
   289                      profile = identity;
   290                      break;
   291                  }
   292              }
   293  
   294              if (profile == null) {
   295                  try {
   296                      profile = Identity.buildProfile(name);
   297                  } catch (IOException ex) {
   298                      // TODO: ??
   299                  }
   300              }
   301  
   302              profile.setOption("identity", "name", name);
   303              profile.setOption(profileString, "nicknames", nicknames);
   304              profile.setOption(profileString, "realname", realname);
   305              profile.setOption(profileString, "ident", ident);
   306              modified = false;
   307              this.oldName = name;
   308          }
   309      }
   310  
   311      /** Deletes the profile. */
   312      public void delete() {
                 /* 
    P/P           *  Method: void delete()
                  * 
                  *  Preconditions:
                  *    (soft) init'ed(this.name)
                  * 
                  *  Presumptions:
                  *    com.dmdirc.config.Identity:getName(...)@317 != null
                  *    com.dmdirc.config.IdentityManager:getProfiles(...)@313 != null
                  *    java.util.Iterator:next(...)@316 != null
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@317: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@316: {0}, {1}
                  */
   313          final List<Identity> identities = IdentityManager.getProfiles();
   314          Identity profile = null;
   315  
   316          for (Identity identity : identities) {
   317              if (identity.getName().equals(name)) {
   318                  profile = identity;
   319                  break;
   320              }
   321          }
   322  
   323          if (profile == null) {
   324              return;
   325          }
   326          profile.delete();
   327      }
   328  
   329      /** {@inheritDoc} */
   330      @Override
   331      public boolean equals(final Object obj) {
                 /* 
    P/P           *  Method: bool equals(Object)
                  * 
                  *  Preconditions:
                  *    (soft) init'ed(obj.ident)
                  *    (soft) init'ed(obj.name)
                  *    (soft) init'ed(obj.nicknames)
                  *    (soft) init'ed(obj.realname)
                  *    (soft) init'ed(this.ident)
                  *    (soft) this.name != null
                  *    (soft) this.nicknames != null
                  *    (soft) this.realname != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    obj: Inverse{null}, Addr_Set{null}
                  *    obj.ident: Addr_Set{null}, Inverse{null}
                  *    this.ident: Inverse{null}, Addr_Set{null}
                  *    java.lang.Object:equals(...)@344: {1}, {0}
                  *    java.lang.String:equals(...)@341: {1}, {0}
                  *    java.lang.String:equals(...)@347: {1}, {0}
                  *    java.lang.String:equals(...)@353: {1}, {0}
                  */
   332          if (obj == null) {
   333              return false;
   334          }
   335          if (getClass() != obj.getClass()) {
   336              return false;
   337          }
   338  
   339          final Profile other = (Profile) obj;
   340  
   341          if (!this.name.equals(other.name)) {
   342              return false;
   343          }
   344          if (!this.nicknames.equals(other.nicknames)) {
   345              return false;
   346          }
   347          if (!this.realname.equals(other.realname)) {
   348              return false;
   349          }
   350          if (this.ident == null && other.ident != null) {
   351              return false;
   352          }
   353          if (this.ident != null && !this.ident.equals(other.ident)) {
   354              return false;
   355          }
   356  
   357          return true;
   358      }
   359  
   360      /** {@inheritDoc} */
   361      @Override
   362      public int hashCode() {
                 /* 
    P/P           *  Method: int hashCode()
                  * 
                  *  Preconditions:
                  *    init'ed(this.ident)
                  *    init'ed(this.name)
                  *    init'ed(this.nicknames)
                  *    init'ed(this.realname)
                  * 
                  *  Presumptions:
                  *    java.lang.String:hashCode(...)@364 in {-55_068_322..27_540_102}
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   363          int hash = 5;
   364          hash = 79 * hash + (this.name != null ? this.name.hashCode() : 0);
   365          hash = 79 * hash +
   366                  (this.nicknames != null ? this.nicknames.hashCode() : 0);
   367          hash = 79 * hash +
   368                  (this.realname != null ? this.realname.hashCode() : 0);
   369          hash = 79 * hash + (this.ident != null ? this.ident.hashCode() : 0);
   370  
   371          return hash;
   372      }
   373  
   374      /** {@inheritDoc} */
   375      @Override
   376      protected Object clone() throws CloneNotSupportedException {
                 /* 
    P/P           *  Method: Object clone()
                  *    clone fails for all possible inputs
                  */
   377          throw new CloneNotSupportedException();
   378      }
   379  
   380      /** {@inheritDoc} */
   381      @Override
   382      public String toString() {
                 /* 
    P/P           *  Method: String toString()
                  * 
                  *  Preconditions:
                  *    init'ed(this.ident)
                  *    init'ed(this.modified)
                  *    init'ed(this.name)
                  *    init'ed(this.nicknames)
                  *    init'ed(this.realname)
                  * 
                  *  Postconditions:
                  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
                  *    return_value == &amp;java.lang.StringBuilder:toString(...)
                  */
   383          return "[Profile: name='" + name + "', nickname='" + nicknames +
   384                  "', realname='" + realname + "', ident='" + ident + 
   385                  "', modified='" + modified + "']";
   386      }
   387  }








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