Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Blame | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * File created by Jimmy
  3.  * at 2003-sep-07 11:26:29
  4.  */
  5. package Macbeth.Modules.modRemoteControl;
  6.  
  7. import java.util.LinkedList;
  8. import java.util.Iterator;
  9.  
  10. /**
  11.  * Keeps track of all modules that have requested a
  12.  * specific button.
  13.  * @author Jimmy
  14.  */
  15. public class ButtonRequests {
  16.  
  17.     private LinkedList modules;
  18.  
  19.     /**
  20.      * Creates a new instance of ButtonRequests.
  21.      * @param modulenames A list of modules that have requested
  22.      * this button.
  23.      */
  24.     public ButtonRequests(String[] modulenames) {
  25.         modules = new LinkedList();
  26.         if (modulenames!=null) {
  27.             for (int i=0; i<modulenames.length; i++) {
  28.                 addRequest(modulenames[i]);
  29.             }
  30.         }
  31.     }
  32.  
  33.     /**
  34.      * Creates a new instance of ButtonRequests.
  35.      */
  36.     public ButtonRequests() {
  37.         this(null);
  38.     }
  39.  
  40.     /**
  41.      * Adds a request for this button.
  42.      * @param module The location of the module that requests this button.
  43.      */
  44.     public void addRequest(String module) {
  45.         //if this module hasn't already requested this button
  46.         if (!modules.contains(module)) {
  47.             //add a request
  48.             modules.add(module);
  49.         }
  50.     }
  51.  
  52.     /**
  53.      * Returns a list of the names of all modules that have
  54.      * requested this button.
  55.      * @return A String array with all module names.
  56.      */
  57.     public String[] getModuleNames() {
  58.         String[] names = new String[modules.size()];
  59.         Iterator it = modules.iterator();
  60.         int i=0;
  61.         while (it.hasNext()) {
  62.             names[i++] = (String)it.next();
  63.         }
  64.         return names;
  65.     }
  66.  
  67. }
  68.