File Source: AddonInfo.java

         /* 
    P/P   *  Method: com.dmdirc.addons.addonbrowser.AddonInfo__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.addonbrowser;
    24  
    25  import com.dmdirc.Main;
    26  import com.dmdirc.updater.UpdateChannel;
    27  import com.dmdirc.updater.UpdateChecker;
    28  import com.dmdirc.updater.UpdateComponent;
    29  import com.dmdirc.util.URLBuilder;
    30  
    31  import java.awt.Image;
    32  import java.util.Map;
    33  
    34  import javax.swing.ImageIcon;
    35  
    36  /**
    37   * Describes an addon.
    38   * 
    39   * @author chris
    40   */
    41  public class AddonInfo {
    42      
    43      /**
    44       * The possible addon types.
    45       */
             /* 
    P/P       *  Method: void com.dmdirc.addons.addonbrowser.AddonInfo$AddonType(String, int)
              */
    46      public static enum AddonType {
    47          /** Plugins. */
                 /* 
    P/P           *  Method: com.dmdirc.addons.addonbrowser.AddonInfo$AddonType__static_init
                  * 
                  *  Postconditions:
                  *    $VALUES == &new AddonInfo$AddonType[](AddonInfo$AddonType__static_init#4)
                  *    TYPE_ACTION_PACK == &new AddonInfo$AddonType(AddonInfo$AddonType__static_init#3)
                  *    $VALUES[2] == &new AddonInfo$AddonType(AddonInfo$AddonType__static_init#3)
                  *    TYPE_PLUGIN == &new AddonInfo$AddonType(AddonInfo$AddonType__static_init#1)
                  *    $VALUES[0] == &new AddonInfo$AddonType(AddonInfo$AddonType__static_init#1)
                  *    TYPE_THEME == &new AddonInfo$AddonType(AddonInfo$AddonType__static_init#2)
                  *    $VALUES[1] == &new AddonInfo$AddonType(AddonInfo$AddonType__static_init#2)
                  *    new AddonInfo$AddonType(AddonInfo$AddonType__static_init#1) num objects == 1
                  *    new AddonInfo$AddonType(AddonInfo$AddonType__static_init#2) num objects == 1
                  *    new AddonInfo$AddonType(AddonInfo$AddonType__static_init#3) num objects == 1
                  *    ...
                  */
    48          TYPE_PLUGIN,
    49          /** Themes. */
    50          TYPE_THEME,
    51          /** Action packs. */
    52          TYPE_ACTION_PACK;
    53  
    54          /** {@inheritDoc} */
    55          @Override
    56          public String toString() {
                     /* 
    P/P               *  Method: String toString()
                      * 
                      *  Postconditions:
                      *    java.lang.StringBuilder:toString(...)._tainted == 0
                      *    return_value == &java.lang.StringBuilder:toString(...)
                      */
    57              return super.toString().charAt(5) + 
    58                      super.toString().substring(6).toLowerCase().replace('_', ' ');
    59          }
    60      };
    61      
    62      private final int id;
    63      private final String stableDownload;
    64      private final String unstableDownload;
    65      private final String title;
    66      private final String author;
    67      private final int rating;
    68      private final String description;
    69      private final AddonType type;
    70      private final boolean verified;
    71      private final int date;
    72      private final ImageIcon screenshot;
    73  
             /* 
    P/P       *  Method: void com.dmdirc.addons.addonbrowser.AddonInfo(Map)
              * 
              *  Preconditions:
              *    entry != null
              * 
              *  Presumptions:
              *    java.util.Map:get(...)@79 != null
              *    java.util.Map:get(...)@85 != null
              *    java.util.Map:get(...)@87 != null
              *    javax.swing.ImageIcon:getImage(...)@90 != null
              * 
              *  Postconditions:
              *    init'ed(this.author)
              *    init'ed(this.date)
              *    init'ed(this.description)
              *    init'ed(this.id)
              *    init'ed(this.rating)
              *    this.screenshot in Addr_Set{&new ImageIcon(AddonInfo#3),&new ImageIcon(AddonInfo#1)}
              *    init'ed(this.stableDownload)
              *    init'ed(this.title)
              *    this.type == One-of{&com.dmdirc.addons.addonbrowser.AddonInfo$AddonType__static_init.new AddonInfo$AddonType(AddonInfo$AddonType__static_init#1), &com.dmdirc.addons.addonbrowser.AddonInfo$AddonType__static_init.new AddonInfo$AddonType(AddonInfo$AddonType__static_init#2...
              *    this.type in Addr_Set{&com.dmdirc.addons.addonbrowser.AddonInfo$AddonType__static_init.new AddonInfo$AddonType(AddonInfo$AddonType__static_init#3),&com.dmdirc.addons.addonbrowser.AddonInfo$AddonType__static_init.new AddonInfo$AddonType(AddonInfo$AddonType__static_init#2),&com.dmdirc.addons.addonbrowser.AddonInfo$AddonType__static_init.new AddonInfo$AddonType(AddonInfo$AddonType__static_init#1)}
              *    ...
              * 
              *  Test Vectors:
              *    java.lang.String:equals(...)@87: {0}, {1}
              */
    74      public AddonInfo(final Map<String, String> entry) {
    75          this.id = Integer.parseInt(entry.get("id"));
    76          this.title = entry.get("title");
    77          this.author = entry.get("user");
    78          this.rating = Integer.parseInt(entry.get("rating"));
    79          this.type = entry.get("type").equals("plugin") ?
    80              AddonType.TYPE_PLUGIN : entry.get("type").equals("theme") ?
    81                  AddonType.TYPE_THEME : AddonType.TYPE_ACTION_PACK;
    82          this.stableDownload = entry.get("stable");
    83          this.unstableDownload = entry.get("unstable");
    84          this.description = entry.get("description");
    85          this.verified = entry.get("verified").equals("yes");
    86          this.date = Integer.parseInt(entry.get("date"));
    87          if (entry.get("screenshot").equals("yes")) {
    88              this.screenshot = new ImageIcon(URLBuilder.buildURL(
    89                      "http://addons.dmdirc.com/addonimg/" + id));
    90              this.screenshot.setImage(this.screenshot.getImage().
    91                     getScaledInstance(150, 150,Image.SCALE_SMOOTH));
    92          } else {
    93              this.screenshot = new ImageIcon(URLBuilder.buildURL(
    94                      "dmdirc://com/dmdirc/res/logo.png"));
    95          }
    96      }
    97  
    98      public String getAuthor() {
                 /* 
    P/P           *  Method: String getAuthor()
                  * 
                  *  Postconditions:
                  *    return_value == this.author
                  *    init'ed(return_value)
                  */
    99          return author;
   100      }
   101  
   102      public int getDate() {
                 /* 
    P/P           *  Method: int getDate()
                  * 
                  *  Postconditions:
                  *    return_value == this.date
                  *    init'ed(return_value)
                  */
   103          return date;
   104      }
   105  
   106      public String getDescription() {
                 /* 
    P/P           *  Method: String getDescription()
                  * 
                  *  Postconditions:
                  *    return_value == this.description
                  *    init'ed(return_value)
                  */
   107          return description;
   108      }
   109  
   110      public int getId() {
                 /* 
    P/P           *  Method: int getId()
                  * 
                  *  Postconditions:
                  *    return_value == this.id
                  *    init'ed(return_value)
                  */
   111          return id;
   112      }
   113  
   114      public int getRating() {
                 /* 
    P/P           *  Method: int getRating()
                  * 
                  *  Postconditions:
                  *    return_value == this.rating
                  *    init'ed(return_value)
                  */
   115          return rating;
   116      }
   117  
   118      public String getStableDownload() {
                 /* 
    P/P           *  Method: String getStableDownload()
                  * 
                  *  Postconditions:
                  *    return_value == this.stableDownload
                  *    init'ed(return_value)
                  */
   119          return stableDownload;
   120      }
   121  
   122      public String getTitle() {
                 /* 
    P/P           *  Method: String getTitle()
                  * 
                  *  Postconditions:
                  *    return_value == this.title
                  *    init'ed(return_value)
                  */
   123          return title;
   124      }
   125  
   126      public AddonType getType() {
                 /* 
    P/P           *  Method: AddonInfo$AddonType getType()
                  * 
                  *  Postconditions:
                  *    return_value == this.type
                  *    init'ed(return_value)
                  */
   127          return type;
   128      }
   129  
   130      public String getUnstableDownload() {
                 /* 
    P/P           *  Method: String getUnstableDownload()
                  * 
                  *  Postconditions:
                  *    return_value == this.unstableDownload
                  *    init'ed(return_value)
                  */
   131          return unstableDownload;
   132      }
   133  
   134      public boolean isVerified() {
                 /* 
    P/P           *  Method: bool isVerified()
                  * 
                  *  Postconditions:
                  *    return_value == this.verified
                  *    init'ed(return_value)
                  */
   135          return verified;
   136      }
   137  
   138      public ImageIcon getScreenshot() {
                 /* 
    P/P           *  Method: ImageIcon getScreenshot()
                  * 
                  *  Postconditions:
                  *    return_value == this.screenshot
                  *    init'ed(return_value)
                  */
   139          return screenshot;
   140      }
   141      
   142      public boolean isInstalled() {
                 /* 
    P/P           *  Method: bool isInstalled()
                  * 
                  *  Presumptions:
                  *    com.dmdirc.updater.UpdateChecker:getComponents(...)@143 != null
                  *    com.dmdirc.updater.UpdateComponent:getName(...)@144 != null
                  *    java.util.Iterator:next(...)@143 != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    java.lang.String:equals(...)@144: {0}, {1}
                  *    java.util.Iterator:hasNext(...)@143: {0}, {1}
                  */
   143          for (UpdateComponent comp : UpdateChecker.getComponents()) {
   144              if (comp.getName().equals("addon-" + getId())) {
   145                  return true;
   146              }
   147          }
   148          
   149          return false;
   150      }
   151      
   152      public boolean isDownloadable() {
                 /* 
    P/P           *  Method: bool isDownloadable()
                  * 
                  *  Postconditions:
                  *    return_value == 0
                  */
   153          return false; /*!stableDownload.isEmpty() ||
   154                  (Main.UPDATE_CHANNEL != UpdateChannel.STABLE
   155                  && !unstableDownload.isEmpty());*/
   156      }
   157  
   158      public boolean matches(final String text) {
                 /* 
    P/P           *  Method: bool matches(String)
                  * 
                  *  Preconditions:
                  *    text != null
                  *    this.title != null
                  *    (soft) this.description != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   159          return title.toLowerCase().indexOf(text.toLowerCase()) > -1
   160                  || description.toLowerCase().indexOf(text.toLowerCase()) > -1;
   161      }
   162  
   163  }








SofCheck Inspector Build Version : 2.17854
AddonInfo.java 2009-Jun-25 01:54:24
AddonInfo.class 2009-Sep-02 17:04:14
AddonInfo$AddonType.class 2009-Sep-02 17:04:14