Esempio n. 1
0
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer();
   buf.append("[UnitGroup ");
   buf.append(id);
   buf.append(" :type ");
   buf.append(type);
   buf.append(" :ownerId ");
   buf.append(ownerId);
   buf.append(" (:required");
   for (Argument arg : unitTypeReqs) {
     buf.append(" ");
     buf.append(arg.getName());
     buf.append(" ");
     buf.append(arg.getValue());
   }
   buf.append(") (:actual");
   if (!isEmpty()) {
     for (Map.Entry<String, Integer> entry : getRepresentative().getUnitTypes().entrySet()) {
       buf.append(" ");
       buf.append(entry.getKey());
       buf.append(" ");
       buf.append(entry.getValue());
     }
   }
   buf.append(")]");
   return buf.toString();
 }
  /** Bind and add argument's binding into the scope of the method */
  public void bindArguments() {

    if (this.arguments != null) {
      // by default arguments in abstract/native methods are considered to be used (no complaint is
      // expected)
      if (this.binding == null) {
        for (int i = 0, length = this.arguments.length; i < length; i++) {
          this.arguments[i].bind(this.scope, null, true);
        }
        return;
      }
      boolean used = this.binding.isAbstract() || this.binding.isNative();
      AnnotationBinding[][] paramAnnotations = null;
      for (int i = 0, length = this.arguments.length; i < length; i++) {
        Argument argument = this.arguments[i];
        argument.bind(this.scope, this.binding.parameters[i], used);
        if (argument.annotations != null) {
          if (paramAnnotations == null) {
            paramAnnotations = new AnnotationBinding[length][];
            for (int j = 0; j < i; j++) {
              paramAnnotations[j] = Binding.NO_ANNOTATIONS;
            }
          }
          paramAnnotations[i] = argument.binding.getAnnotations();
        } else if (paramAnnotations != null) {
          paramAnnotations[i] = Binding.NO_ANNOTATIONS;
        }
      }
      if (paramAnnotations != null) this.binding.setParameterAnnotations(paramAnnotations);
    }
  }
Esempio n. 3
0
 public String toUsageString() {
   StringBuilder sb = new StringBuilder();
   for (Argument a : parameters.values()) {
     sb.append(a.toUsageString("\t"));
   }
   return sb.toString();
 }
Esempio n. 4
0
 @Test(expected = IllegalArgumentException.class)
 public void testcheckNotBlankFail() {
   Argument.checkNotBlank(null, "message");
   Argument.checkNotBlank("", "message");
   Argument.checkNotBlank(" ", "message");
   Argument.checkNotBlank(" \n\r\t ", "message");
 }
Esempio n. 5
0
 /**
  * Set the value of an input parameter before a message service call
  *
  * @param parameterName the parameter name
  * @param parameterValue the date parameter value, will be automatically translated to the correct
  *     ISO 8601 date format for the given action input param related state variable
  * @return the current ActionMessage object instance
  * @throws IllegalArgumentException if the provided parameterName is not valid for this message or
  *     if no input parameters are required for this message
  */
 public ActionMessage setInputParameter(String parameterName, Date parameterValue)
     throws IllegalArgumentException {
   if (serviceAction.getInputActionArguments() == null) {
     throw new IllegalArgumentException("No input parameters required for this message");
   }
   Argument arg = serviceAction.getInputActionArgument(parameterName);
   if (arg == null) {
     throw new IllegalArgumentException(
         "Wrong input argument name for this action:"
             + parameterName
             + " available parameters are : "
             + serviceAction.getInputActionArguments());
   }
   StateVariable linkedVar = arg.getRelatedStateVariable();
   if (linkedVar.dataType.equals(StateVariableTypes.TIME)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoTime(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.TIME_TZ)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoTimeZone(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.DATE)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoDate(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.DATETIME)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoDateTime(parameterValue));
   } else if (linkedVar.dataType.equals(StateVariableTypes.DATETIME_TZ)) {
     return setInputParameter(parameterName, ISO8601Date.getIsoDateTimeZone(parameterValue));
   } else {
     throw new IllegalArgumentException(
         "Related input state variable " + linkedVar.name + " is not of an date type");
   }
 }
Esempio n. 6
0
  protected void buildPython(IndentingAppender ia) throws IOException {
    String name = getClass().getSimpleName();

    ia.append("def ").append(name).append("(self");
    ia.incrementIndent().incrementIndent();
    for (Argument arg : _arguments) {
      ia.append(", ").append(arg._name);
      if (!arg._required) ia.append("=None");
    }
    ia.appendln("):");
    ia.decrementIndent().decrementIndent();
    ia.incrementIndent();
    ia.appendln("'''");
    ia.appendln(Objects.firstNonNull(_requestHelp, "MISSING HELP STRING"));

    if (!_arguments.isEmpty()) ia.appendln("Arguments:");
    ia.incrementIndent();
    for (Argument arg : _arguments) {
      ia.append(arg._name).append(" -- ");
      if (arg._required) ia.append("required -- ");
      ia.appendln(arg.queryDescription());
      ia.incrementIndent();
      ia.appendln(Objects.firstNonNull(arg._requestHelp, "MISSING HELP STRING"));
      ia.decrementIndent();
    }
    ia.decrementIndent();
    ia.appendln("'''");
    ia.appendln("pass");
    ia.decrementIndent();
  }
Esempio n. 7
0
 private void displayCommand(Command c, Player p) {
   p.sendMessage("-------------Command Arguments---------------");
   p.sendMessage("--------------------------------------------");
   for (Argument arg : c.listArguments()) {
     p.sendMessage(arg.toString());
   }
 }
Esempio n. 8
0
File: Cmd.java Progetto: Rojoss/Boxx
  /**
   * Register a regular command argument/parameter for this command.
   *
   * <p>When adding multiple arguments the order you add them in determines the indexing of the
   * argument!
   *
   * @param name The argument name/key used to identify the argument. This name must be used with
   *     the {@link CmdData} result to get the argument value.
   * @param requirement The requirement for this argument. (See {@link ArgRequirement} for more
   *     info)
   * @param option The {@link SingleOption} used for parsing the argument. This option determines
   *     the argument value and everything else. For example if it's a {@link PlayerO} the argument
   *     value must be a player and the result value would be a player.
   * @return The added {@link Argument}
   * @throws IllegalArgumentException if an argument with the specified name is already registered
   *     for this command if the argument option is a sub command option and the command already has
   *     an sub command argument or if the argument option is a sub command option and the command
   *     is a sub command.
   */
  public Argument addArgument(String name, ArgRequirement requirement, SingleOption option) {
    Argument argument = new Argument(name, requirement, option);

    if (getAllArguments().containsKey(name.toLowerCase())) {
      throw new IllegalArgumentException(
          "The command already has an argument with the name '" + name + "'!");
    }

    if (argument.option() instanceof SubCmdO) {
      if (isSub()) {
        throw new IllegalArgumentException(
            "Sub commands can not have sub command arguments. [argument=" + name + "]");
      }
      for (Argument arg : arguments.values()) {
        if (arg.option() instanceof SubCmdO) {
          throw new IllegalArgumentException(
              "The command already has a sub command argument."
                  + "Commands can only have one sub command option. [argument="
                  + name
                  + "]");
        }
      }
    }

    arguments.put(name.toLowerCase(), argument);
    return argument;
  }
Esempio n. 9
0
 @Test
 public void testcheckBlank() {
   Argument.checkBlank(null, "message");
   Argument.checkBlank("", "message");
   Argument.checkBlank(" ", "message");
   Argument.checkBlank(" \n\r\t ", "message");
 }
Esempio n. 10
0
 private void declTexteFormu(Programme prog, StringBuffer buf, int indent, Argument arg) {
   if (arg.avecTexteRadio()) {
     String zone = "zone_" + arg.nom;
     zone = Divers.remplacer(zone, ".", "_");
     String group = "group_" + arg.nom;
     group = Divers.remplacer(group, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "ButtonGroup " + group + "; ");
     String p_group = "p_" + group;
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JPanel " + p_group + "; ");
     String[] liste = arg.getTexteRadio();
     int n = liste.length;
     for (int i = 0; i < n; i++) {
       Divers.indenter(buf, indent);
       String zone_bouton = "zone_" + liste[i] + "_" + arg.nom;
       zone_bouton = Divers.remplacer(zone_bouton, ".", "_");
       Divers.ecrire(buf, "JRadioButton " + zone_bouton + "; ");
     }
   } else if (arg.avecTexteListe()) {
     String zone = "zone_" + arg.nom;
     zone = Divers.remplacer(zone, ".", "_");
     String model = "model_" + arg.nom;
     model = Divers.remplacer(model, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JList " + zone + "; ");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "DefaultListModel " + model + "; ");
   } else {
     String zone = "zone_" + arg.nom;
     zone = Divers.remplacer(zone, ".", "_");
     Divers.indenter(buf, indent);
     Divers.ecrire(buf, "JTextField " + zone + "; ");
   }
 }
Esempio n. 11
0
  @Test
  public void argTest() {
    startTest("arg test");

    attr = Method.Create("name():String");
    assertNotNull(attr);
    assertTrue(attr.getParameters().isEmpty());

    attr = Method.Create("name ( ) : String");
    assertNotNull(attr);
    assertTrue(attr.getParameters().isEmpty());

    attr = Method.Create(" name ( index : int ): String ");
    assertNotNull(attr);

    // only type of an argument matters
    assertTrue(attr.getParameters().contains(Argument.Create("x : int")));
    assertTrue(attr.getParameters().size() == 1);

    attr = Method.Create("add ( int x, int y ) : int");
    assertNotNull(attr);
    assertTrue(attr.getParameters().contains(Argument.Create("x : int")));
    assertTrue(attr.getParameters().size() == 2);

    passed();
  }
Esempio n. 12
0
  public LightDevice() throws InvalidDescriptionException {
    super(new File(DESCRIPTION_FILE_NAME));
    setSSDPBindAddress(HostInterface.getInetAddress(HostInterface.IPV4_BITMASK, null));
    setHTTPBindAddress(HostInterface.getInetAddress(HostInterface.IPV4_BITMASK, null));

    Action getPowerAction = getAction("GetPower");
    getPowerAction.setActionListener(this);

    Action setPowerAction = getAction("SetPower");
    setPowerAction.setActionListener(this);

    ServiceList serviceList = getServiceList();
    Service service = serviceList.getService(0);
    service.setQueryListener(this);

    powerVar = getStateVariable("Power");

    Argument powerArg = getPowerAction.getArgument("Power");
    StateVariable powerState = powerArg.getRelatedStateVariable();
    AllowedValueList allowList = powerState.getAllowedValueList();
    for (int n = 0; n < allowList.size(); n++)
      System.out.println("[" + n + "] = " + allowList.getAllowedValue(n));

    AllowedValueRange allowRange = powerState.getAllowedValueRange();
    System.out.println("maximum = " + allowRange.getMaximum());
    System.out.println("minimum = " + allowRange.getMinimum());
    System.out.println("step = " + allowRange.getStep());
  }
Esempio n. 13
0
  @Override
  public boolean equals(Object o) {
    if ((o instanceof Argument) == false) return false;

    Argument p = (Argument) o;

    return this.name.equals(p.getName());
  }
Esempio n. 14
0
 /**
  * converts a argument scope to a regular array
  *
  * @param arg argument scope to convert
  * @return resulting array
  */
 public static Array toArray(Argument arg) {
   ArrayImpl trg = new ArrayImpl();
   int[] keys = arg.intKeys();
   for (int i = 0; i < keys.length; i++) {
     trg.setEL(keys[i], arg.get(keys[i], null));
   }
   return trg;
 }
Esempio n. 15
0
  /*
  verifies that each of our registered parameters has a value, either given or default

  throws an exeption otherwise
   */
  private void verify() throws Exception {
    for (Argument parameter : parameters.values()) {
      if (parameter.getValue() == null && parameter.getDefaultValue() == null) {
        throw new Exception(
            String.format("Argument '%s' is required.  Please see usage.", parameter.name));
      }
    }
  }
Esempio n. 16
0
 @Override
 public <T> T getArgumentValue(String name) {
   Argument arg = cli.getArgument(name);
   if (arg == null) {
     return null;
   }
   return getArgumentValue(arg.getIndex());
 }
Esempio n. 17
0
 /**
  * Chooses between two non null items based on the value of one of their argument
  *
  * @param first The first item on which make the choice
  * @param second The second item on which make the choice
  * @return The choosen item
  */
 @Override
 protected T choose(T first, T second) {
   A firstArgument = argument.evaluate(first);
   if (firstArgument == null) return second;
   A secondArgument = argument.evaluate(second);
   if (secondArgument == null) return first;
   return chooseOnArgument(first, firstArgument, second, secondArgument);
 }
Esempio n. 18
0
 void setService(Service s) {
   serviceNode = s.getServiceNode();
   /*To ensure integrity of the XML structure*/
   Iterator<Argument> i = getArgumentList().iterator();
   while (i.hasNext()) {
     Argument arg = i.next();
     arg.setService(s);
   }
 }
Esempio n. 19
0
 private void clearOutputAgumentValues() {
   ArgumentList allArgList = getArgumentList();
   int allArgCnt = allArgList.size();
   for (int n = 0; n < allArgCnt; n++) {
     Argument arg = allArgList.getArgument(n);
     if (arg.isOutDirection() == false) continue;
     arg.setValue("");
   }
 }
  /**
   * Finds the argument named <code>strArgName</code> in the specific intrinsic argument list and
   * returns its number.
   *
   * @param rgArgs The array of arguments
   * @param strArgName The generic name of the argument (defined in {@link Globals}) for which to
   *     look
   * @return The number of the argument (i.e., the index within the <code>rgArgs</code> array), or
   *     {@link InstructionListTranslator#UNDEFINED} if the argument couldn't be found
   */
  private static int getArgNum(Argument[] rgArgs, String strArgName) {
    Argument arg = null;

    if (Globals.ARGNAME_LHS.equals(strArgName)) arg = Arguments.getLHS(rgArgs);
    else if (Globals.ARGNAME_RHS.equals(strArgName)) arg = Arguments.getRHS(rgArgs);
    else arg = Arguments.getNamedArgument(rgArgs, strArgName);

    return arg == null ? UNDEFINED : arg.getNumber();
  }
Esempio n. 21
0
 /**
  * Helper to specify which arguments trigger a refresh on change
  *
  * @param ver
  */
 @Override
 protected void registered(RequestServer.API_VERSION ver) {
   super.registered(ver);
   for (Argument arg : _arguments) {
     if (arg._name.equals("validation")) {
       arg.setRefreshOnChange();
     }
   }
 }
Esempio n. 22
0
 @Override
 public Set<VariableRef> getReadsFrom() {
   Set<VariableRef> s = new HashSet<VariableRef>();
   for (Argument a : args) {
     if (a.getValue() instanceof VariableRef) {
       s.add((VariableRef) a.getValue());
     }
   }
   return s;
 }
Esempio n. 23
0
 public Argument getArgument(String name) {
   int nArgs = size();
   for (int n = 0; n < nArgs; n++) {
     Argument arg = getArgument(n);
     String argName = arg.getName();
     if (argName == null) continue;
     if (argName.equals(name) == true) return arg;
   }
   return null;
 }
Esempio n. 24
0
 /** @deprecated */
 public void set(ArgumentList inArgList) {
   int nInArgs = inArgList.size();
   for (int n = 0; n < nInArgs; n++) {
     Argument inArg = inArgList.getArgument(n);
     String inArgName = inArg.getName();
     Argument arg = getArgument(inArgName);
     if (arg == null) continue;
     arg.setValue(inArg.getValue());
   }
 }
Esempio n. 25
0
  @Override
  public boolean isDynamic() {
    for (Argument argument : getArguments()) {
      if (argument.isDynamic()) {
        return true;
      }
    }

    return false;
  }
Esempio n. 26
0
 protected JsonObject serveHelp() {
   JsonObject r = new JsonObject();
   r.addProperty(NAME, getClass().getSimpleName());
   r.addProperty(DESCRIPTION, _requestHelp);
   JsonArray args = new JsonArray();
   for (Argument arg : _arguments) {
     args.add(arg.requestHelp());
   }
   r.add(ARGUMENTS, args);
   return r;
 }
Esempio n. 27
0
  /**
   * Add a return argument to this entity.
   *
   * @exception IllegalActionException If the argument with the name "return" is not of an
   *     acceptable class for the container.
   * @exception NameDuplicationException If there is already an argument with the name "return"
   */
  public void addArgumentReturn() throws IllegalActionException, NameDuplicationException {
    try {
      _workspace.getReadAccess();

      Argument ret = new Argument(this, "return");
      ret.setReturn(true);
      ret.setCType("void");
    } finally {
      _workspace.doneReading();
    }
  }
Esempio n. 28
0
 public ArgumentList getOutputArgumentList() {
   ArgumentList allArgList = getArgumentList();
   int allArgCnt = allArgList.size();
   ArgumentList argList = new ArgumentList();
   for (int n = 0; n < allArgCnt; n++) {
     Argument arg = allArgList.getArgument(n);
     if (arg.isOutDirection() == false) continue;
     argList.add(arg);
   }
   return argList;
 }
Esempio n. 29
0
File: Cmd.java Progetto: Rojoss/Boxx
 /**
  * Try to get an array with sub commands that this command has.
  *
  * <p>If this command doesn't have sub commands this will return {@code null}. See {@link
  * #hasSubCmds()}
  *
  * @return Array with {@link SubCmd}s (May be {@code null} when the command doesn't have sub
  *     commands)
  */
 public SubCmd[] getSubCmds() {
   if (isSub() || arguments.size() < 1) {
     return null;
   }
   for (Argument arg : arguments.values()) {
     if (arg.option() instanceof SubCmdO) {
       return ((SubCmdO) arg.option()).getSubCmds();
     }
   }
   return null;
 }
Esempio n. 30
0
 void updateArgumentList(TreeNode parentNode, Action action) {
   ArgumentList argList = action.getArgumentList();
   int nArguments = argList.size();
   for (int n = 0; n < nArguments; n++) {
     Argument arg = argList.getArgument(n);
     String argName = arg.getName() + "(" + arg.getDirection() + ")";
     TreeNode argNode = new TreeNode(argName);
     argNode.setUserData(arg);
     parentNode.add(argNode);
   }
 }