View Javadoc

1   package org.lsst.ccs.command;
2   
3   import java.util.ArrayList;
4   
5   /**
6    *
7    * @author tonyj
8    */
9   class MethodBasedCommandDictionary extends ArrayList<DictionaryCommand> implements Dictionary {
10  
11      @Override
12      public boolean containsCommand(BasicCommand tc) {
13          return findCommand(tc) != null;
14      }
15  
16      @Override
17      public DictionaryCommand findCommand(BasicCommand tc) {
18          return findCommand(tc.getCommand(), tc.getArgumentCount());
19      }
20  
21      @Override
22      public boolean containsCommand(String command, int argumentCount) {
23          return findCommand(command, argumentCount) != null;
24      }
25  
26      @Override
27      public DictionaryCommand findCommand(String command, int argumentCount) {
28          for (DictionaryCommand def : this) {
29              if (def.getCommandName().equals(command) && (argumentCount == def.getArguments().length || (argumentCount >= def.getArguments().length-1 && def.isVarArgs()))) {
30                  return def;
31              }
32              for (String alias : def.getAliases()) {
33                  if (alias.equals(command) && (argumentCount == def.getArguments().length || (argumentCount >= def.getArguments().length-1 && def.isVarArgs()))) {
34                      return def;
35                  }
36              }
37          }
38          return null;
39      }
40      
41  }