File Source: ActionGroup.java

         /* 
    P/P   *  Method: com.dmdirc.actions.ActionGroup__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.actions;
    24  
    25  import com.dmdirc.config.prefs.PreferencesSetting;
    26  
    27  import java.util.ArrayList;
    28  import java.util.HashMap;
    29  import java.util.Iterator;
    30  import java.util.List;
    31  import java.util.Map;
    32  
    33  /**
    34   * Represents a group of actions, along with their meta-data.
    35   * 
    36   * @author chris
    37   */
    38  public class ActionGroup implements Iterable<Action> {
    39      
    40      /**
    41       * A version number for this class. It should be changed whenever the class
    42       * structure is changed (or anything else that would prevent serialized
    43       * objects being unserialized with the new class).
    44       */
    45      private static final long serialVersionUID = 1;    
    46      
    47      /** The actions in this group. */
    48      private final List<Action> actions = new ArrayList<Action>();
    49      
    50      /** The name of this action group. */
    51      private final String name;
    52      
    53      /** The description of this action group. */
    54      private String description = null;
    55      
    56      /** The author of this action group. */
    57      private String author = null;
    58      
    59      /** The component number of this action group (for updating). */
    60      private int component = -1;
    61      
    62      /** The version number of this action group. */
    63      private int version = -1;
    64      
    65      /** A list of settings used by this action group. */
    66      private final Map<String, PreferencesSetting> settings
    67              = new HashMap<String, PreferencesSetting>();
    68  
    69      /**
    70       * Creates a new instance of ActionGroup.
    71       * 
    72       * @param name The name of this action group
    73       */
    74      public ActionGroup(final String name) {
                 /* 
    P/P           *  Method: void com.dmdirc.actions.ActionGroup(String)
                  * 
                  *  Postconditions:
                  *    this.actions == &amp;new ArrayList(ActionGroup#1)
                  *    this.author == null
                  *    this.description == null
                  *    this.component == -1
                  *    this.version == -1
                  *    this.name == name
                  *    init'ed(this.name)
                  *    this.settings == &amp;new HashMap(ActionGroup#2)
                  *    new ArrayList(ActionGroup#1) num objects == 1
                  *    new HashMap(ActionGroup#2) num objects == 1
                  */
    75          super();
    76          
    77          this.name = name;
    78      }
    79  
    80      /**
    81       * Retrieves the author of this ActionGroup.
    82       * 
    83       * @return This action group's author, or null if the author isn't specified
    84       */
    85      public String getAuthor() {
                 /* 
    P/P           *  Method: String getAuthor()
                  * 
                  *  Preconditions:
                  *    init'ed(this.author)
                  * 
                  *  Postconditions:
                  *    return_value == this.author
                  *    init'ed(return_value)
                  */
    86          return author;
    87      }
    88  
    89      /**
    90       * Sets the author of this ActionGroup.
    91       * 
    92       * @param author The new author for this action group
    93       */
    94      public void setAuthor(final String author) {
                 /* 
    P/P           *  Method: void setAuthor(String)
                  * 
                  *  Postconditions:
                  *    this.author == author
                  *    init'ed(this.author)
                  */
    95          this.author = author;
    96      }
    97  
    98      /**
    99       * Retrieves the description of this action group.
   100       * 
   101       * @return This action group's description, or null if none is specified
   102       */
   103      public String getDescription() {
                 /* 
    P/P           *  Method: String getDescription()
                  * 
                  *  Preconditions:
                  *    init'ed(this.description)
                  * 
                  *  Postconditions:
                  *    return_value == this.description
                  *    init'ed(return_value)
                  */
   104          return description;
   105      }
   106  
   107      /**
   108       * Sets the description for this action group.
   109       * 
   110       * @param description The new description for this action group
   111       */
   112      public void setDescription(final String description) {
                 /* 
    P/P           *  Method: void setDescription(String)
                  * 
                  *  Postconditions:
                  *    this.description == description
                  *    init'ed(this.description)
                  */
   113          this.description = description;
   114      }
   115  
   116      /**
   117       * Retrieves the name of this action group.
   118       * 
   119       * @return This action group's name
   120       */
   121      public String getName() {
                 /* 
    P/P           *  Method: String getName()
                  * 
                  *  Postconditions:
                  *    return_value == this.name
                  *    init'ed(return_value)
                  */
   122          return name;
   123      }
   124  
   125      /**
   126       * Retrieves a map settings used by this action group.
   127       * 
   128       * @return A map of setting names to values
   129       */
   130      public Map<String, PreferencesSetting> getSettings() {
                 /* 
    P/P           *  Method: Map getSettings()
                  * 
                  *  Postconditions:
                  *    return_value == this.settings
                  *    init'ed(return_value)
                  */
   131          return settings;
   132      }
   133  
   134      /**
   135       * Retrieves the version number of this action group.
   136       * 
   137       * @return This action group's version number, or -1 if none is specified.
   138       */
   139      public int getVersion() {
                 /* 
    P/P           *  Method: int getVersion()
                  * 
                  *  Preconditions:
                  *    init'ed(this.version)
                  * 
                  *  Postconditions:
                  *    return_value == this.version
                  *    init'ed(return_value)
                  */
   140          return version;
   141      }
   142  
   143      /**
   144       * Sets the version of this action group.
   145       * 
   146       * @param version This action group's new version number.
   147       */
   148      public void setVersion(final int version) {
                 /* 
    P/P           *  Method: void setVersion(int)
                  * 
                  *  Postconditions:
                  *    this.version == version
                  *    init'ed(this.version)
                  */
   149          this.version = version;
   150      }
   151  
   152      /**
   153       * Retrieves the addon site component number for this action group.
   154       * 
   155       * @return The component number for this action group, or -1 if none is
   156       * specified.
   157       */
   158      public int getComponent() {
                 /* 
    P/P           *  Method: int getComponent()
                  * 
                  *  Preconditions:
                  *    init'ed(this.component)
                  * 
                  *  Postconditions:
                  *    return_value == this.component
                  *    init'ed(return_value)
                  */
   159          return component;
   160      }
   161  
   162      /**
   163       * Sets the addon site component number for this action group.
   164       * 
   165       * @param component The component number for this action group
   166       */
   167      public void setComponent(final int component) {
                 /* 
    P/P           *  Method: void setComponent(int)
                  * 
                  *  Postconditions:
                  *    this.component == component
                  *    init'ed(this.component)
                  */
   168          this.component = component;
   169      }
   170      
   171      /**
   172       * Determines the size of this group.
   173       * 
   174       * @return The size of this group
   175       */
   176      public int size() {
                 /* 
    P/P           *  Method: int size()
                  * 
                  *  Preconditions:
                  *    this.actions != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   177          return actions.size();
   178      }
   179  
   180      /**
   181       * Removes the specified action from this group.
   182       * 
   183       * @param action The action to be removed
   184       */
   185      public void remove(final Action action) {
                 /* 
    P/P           *  Method: void remove(Action)
                  * 
                  *  Preconditions:
                  *    this.actions != null
                  */
   186          actions.remove(action);
   187      }
   188  
   189      /** {@inheritDoc} */
   190      @Override
   191      public Iterator<Action> iterator() {
                 /* 
    P/P           *  Method: Iterator iterator()
                  * 
                  *  Preconditions:
                  *    this.actions != null
                  * 
                  *  Postconditions:
                  *    return_value != null
                  */
   192          return actions.iterator();
   193      }
   194  
   195      /**
   196       * Retrieves the action at the specified index.
   197       * 
   198       * @param index The index of the action to return
   199       * @return The action at the specified index
   200       */
   201      public Action get(final int index) {
                 /* 
    P/P           *  Method: Action get(int)
                  * 
                  *  Preconditions:
                  *    this.actions != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   202          return actions.get(index);
   203      }
   204  
   205      /**
   206       * Determines if this group contains the specified action.
   207       * 
   208       * @param action The action to search for
   209       * @return True if the action is contained in this list, false otherwise
   210       */
   211      public boolean contains(final Action action) {
                 /* 
    P/P           *  Method: bool contains(Action)
                  * 
                  *  Preconditions:
                  *    this.actions != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   212          return actions.contains(action);
   213      }
   214  
   215      /**
   216       * Removes all actions from this group, and removes all meta-data.
   217       */
   218      public void clear() {
                 /* 
    P/P           *  Method: void clear()
                  * 
                  *  Preconditions:
                  *    this.settings != null
                  *    (soft) this.actions != null
                  * 
                  *  Presumptions:
                  *    java.util.ArrayList:iterator(...)@219 != null
                  * 
                  *  Postconditions:
                  *    possibly_updated(com/dmdirc/ServerManager.me)
                  *    this.author == null
                  *    this.description == null
                  *    this.component == -1
                  *    this.version == -1
                  *    init'ed(new ArrayList(ServerManager#1) num objects)
                  *    init'ed(new ServerManager(getServerManager#1) num objects)
                  *    init'ed(new ServerManager(getServerManager#1).servers)
                  * 
                  *  Test Vectors:
                  *    java.util.Iterator:hasNext(...)@219: {0}, {1}
                  */
   219          for (Action action : new ArrayList<Action>(actions)) {
   220              remove(action);
   221          }
   222          
   223          settings.clear();
   224          description = null;
   225          author = null;
   226          component = -1;
   227          version = -1;
   228      }
   229  
   230      /**
   231       * Adds the specified action to this group.
   232       * 
   233       * @param action The action to be added
   234       */
   235      public void add(final Action action) {
                 /* 
    P/P           *  Method: void add(Action)
                  * 
                  *  Preconditions:
                  *    this.actions != null
                  */
   236          actions.add(action);
   237      }
   238      
   239      /**
   240       * Retrieves a copy of the list of all actions in this group.
   241       * 
   242       * @return A list of actions in this group
   243       */
   244      public List<Action> getActions() {
                 /* 
    P/P           *  Method: List getActions()
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new ArrayList(getActions#1)
                  *    new ArrayList(getActions#1) num objects == 1
                  */
   245          return new ArrayList<Action>(actions);
   246      }
   247      
   248      /**
   249       * Determines if this action group is delible or not.
   250       * 
   251       * @return True if the group may be deleted, false if it may not.
   252       */
   253      public boolean isDelible() {
                 /* 
    P/P           *  Method: bool isDelible()
                  * 
                  *  Postconditions:
                  *    return_value == 1
                  */
   254          return true;
   255      }
   256      
   257  }








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