Beispiel #1
0
  /**
   * Consume the input ArrayToken and produce the outputs.
   *
   * @exception IllegalActionException If a runtime type conflict occurs.
   */
  public void fire() throws IllegalActionException {
    super.fire();

    ArrayToken token = (ArrayToken) input.get(0);
    int rate = ((IntToken) arrayLength.getToken()).intValue();
    boolean enforce = ((BooleanToken) enforceArrayLength.getToken()).booleanValue();

    if (enforce && token.length() != rate) {
      throw new IllegalActionException(
          this,
          "The "
              + "number of elements in the input ArrayToken ("
              + token.length()
              + ") is not the same as the arrayLength "
              + "parameter ("
              + rate
              + ").");
    }

    Token[] elements = token.arrayValue();

    // We no longer send the complete array all at once, since this might in
    // for example PN lead to larger buffer sizes than strictly necessary.
    // output.send(0, elements, elements.length);

    for (Token newToken : elements) {
      output.send(0, newToken);
    }
  }
Beispiel #2
0
  public void initialize() throws IllegalActionException {
    ptolemy.data.Token[] tokens = initialOutputs_CGToken.arrayValue();
    int i = initialOutputs_CGToken.length();

    for (int i_1_ = 0; i_1_ < i; i_1_++) {
      ptolemy.data.Token token = tokens[i_1_];
      DoubleToken doubletoken;

      if (token instanceof DoubleToken) {
        doubletoken = (DoubleToken) token;
      } else {
        if (!(token instanceof IntToken)) {
          throw new IllegalActionException("Token Exception");
        }

        doubletoken = new DoubleToken(((IntToken) token).doubleValue());
      }

      System.out.println("token = " + doubletoken.toString());
    }
  }