/** * Return a new token whose value is the logical AND of the value of this token and the the value * of the argument token. If this token is nil, or the argument is nil, then {@link #NIL} is * returned. * * @param rightArgument The BooleanToken to OR with this one. * @return A new BooleanToken containing the result. */ public BooleanToken and(BooleanToken rightArgument) { if (isNil() || rightArgument.isNil()) { return BooleanToken.NIL; } if (_value && rightArgument.booleanValue()) { return TRUE; } else { return FALSE; } }
/** * Retrieve the value of the parameter "evaluatedValue" of the model. * * @return The value of the "evaluatedValue" parameter. * @exception IllegalActionException If the model does not have a settable attribute named * "evaluatedValue". */ private boolean _getResult() throws IllegalActionException { Attribute attribute = _model.getAttribute("evaluatedValue"); if (attribute instanceof Variable) { Token t = ((Variable) attribute).getToken(); return ((BooleanToken) t).booleanValue(); } else if (attribute instanceof Settable) { BooleanToken t = new BooleanToken(((Settable) attribute).getExpression()); return t.booleanValue(); } else { throw new IllegalActionException( this, "The specified model does not have an evaluatedValue parameter."); } }
public void initialize() throws IllegalActionException { super.initialize(); IntToken it = (IntToken) LS0Bytes.getToken(); _LS0Bytes = it.intValue(); BooleanToken _bt = (BooleanToken) LS0Map.getToken(); _LS0Map = _bt.booleanValue(); it = (IntToken) S.getToken(); _S = it.intValue(); _fastReg = 0; _interReg = 0; _frameCounter = 0; _checkParameters(); }
/** * Test for ordering of the values of this Token and the argument Token. It is assumed that the * type of the argument is PetiteToken. The argument token is then adjusted to the range of a * PetiteToken. * * @param rightArgument The token to compare this token with. * @exception IllegalActionException If this method is not supported by the derived class. * @return A new Token containing the result. */ protected BooleanToken _isLessThan(ScalarToken rightArgument) throws IllegalActionException { PetiteToken convertedArgument = (PetiteToken) rightArgument; return BooleanToken.getInstance(_value < convertedArgument.doubleValue()); }
public void fire() throws IllegalActionException { super.fire(); // first, checks for acks from remote buffers, updating the // values within txack[]. for (int i = 0; i < 5; i++) { if (ack[i].getWidth() > 0) { while (ack[i].hasToken(0)) { // consumes the token BooleanToken ackt = (BooleanToken) ack[i].get(0); if (_debugging) _debug("Consuming ack from " + ack[i]); if (ackt.booleanValue()) txack[i] = true; else txack[i] = false; if (_debugging) _debug("ack: " + txack[i]); } } } // second, handle the current request from the arbiter if (hasRequest()) { // get the index of the port with the request int j = nextRequest(); if (_debugging) _debug("Arbiter gives turn to input " + j); if (j != -1) { // packet header flit RecordToken record = (RecordToken) inputreq[j].get(0); // calculate route information int dir = route(record); // verify if the output port is free, otherwise // do nothing and wait for another request boolean isfree = freeoutput[dir]; boolean hasspace = txack[dir]; if (isfree & hasspace) { // allocate outputport direction[j] = new IntToken(dir); freeoutput[dir] = false; if (_debugging) _debug("Input " + j + " connected to output " + dir); // deletes original header flit from buffer read[j].send(0, new Token()); // signalize state machine to prepare for size state[j] = SIZE; // sends copy of the header flit to output output[dir].send(0, record); txack[dir] = false; // updates the last granted input port sel = j; } } } // clear all unatended requests (they will be asked again next cycle) clearRequests(); // third, handle tokens on the inputs for (int i = 0; i < 5; i++) { if (inputreq[i].getWidth() > 0 & inputreq[i].hasToken(0)) { if (state[i] == SIZE | state[i] == PAYLOAD) { if (_debugging) _debug(inputreq[i] + " has size/payload token"); // payload flit // get the direction assigned to this input port int dir = direction[i].intValue(); // check if the remote buffer in that direction is free if (txack[dir]) { // check if it is a size flit or a regular flit if (state[i] == SIZE) { // set the size of the packet RecordToken record = (RecordToken) inputreq[i].get(0); packetsize[i] = ((IntToken) record.get("size")).intValue(); if (_debugging) _debug("Packet size " + packetsize[i]); // prepare for payload state[i] = PAYLOAD; // deletes original header flit from buffer read[i].send(0, new Token()); // send the token to the remote output buffer output[dir].send(0, record); if (_debugging) _debug(inputreq[i] + " sent size token to " + output[dir]); txack[dir] = false; } else if (state[i] == PAYLOAD) { // send the token to the remote output buffer output[dir].send(0, inputreq[i].get(0)); txack[dir] = false; // deletes original header flit from buffer read[i].send(0, new Token()); if (_debugging) _debug(inputreq[i] + " sent token to " + output[dir]); packetsize[i]--; if (_debugging) _debug("packet size " + packetsize[i]); // if package is finished, // release output port and prepare for new header if (packetsize[i] == 0) { freeoutput[dir] = true; state[i] = REQUESTING; if (_debugging) _debug("packet is over"); } } } // end if direction is free else { inputreq[i].get(0); } } // end if state } // end if width > 1 } // end for if (clocked) { // fourth: requests write on all inputs with packet payload or size // and whose respective output ports received acks for (int i = 0; i < 5; i++) { if (state[i] == PAYLOAD | state[i] == SIZE) { if (txack[direction[i].intValue()]) peek[i].send(0, new Token()); } } // fifth: requests write on remote buffers for (int i = 0; i < 5; i++) { // if(!txack[i]){ outputtx[i].send(0, new Token()); // } txack[i] = false; // consumes unused acks } // requests copy of request from all requesting input buffers for (int i = 0; i < 5; i++) { if (state[i] == REQUESTING) { peek[i].send(0, new Token()); if (_debugging) { _debug("Peek for request on direction " + i); } } } clocked = false; } }
/** * Evaluate a logical AND or OR on the children of the specified node. * * @param node The specified node. * @exception IllegalActionException If an evaluation error occurs. */ public void visitLogicalNode(ASTPtLogicalNode node) throws IllegalActionException { if (node.isConstant() && node.isEvaluated()) { _evaluatedChildToken = node.getToken(); return; } // Note that we do not always evaluate all of the children... // We perform short-circuit evaluation instead and evaluate the // children in order until the final value is determined, after // which point no more children are evaluated. int numChildren = node.jjtGetNumChildren(); _assert(numChildren > 0, node, "The number of child nodes must be greater than zero"); _evaluateChild(node, 0); ptolemy.data.Token result = _evaluatedChildToken; if (!(result instanceof BooleanToken)) { throw new IllegalActionException( "Cannot perform logical " + "operation on " + result + " which is a " + result.getClass().getName()); } // Make sure that exactly one of AND or OR is set. _assert(node.isLogicalAnd() ^ node.isLogicalOr(), node, "Invalid operation"); // Perform both the short-circuit AND and short-circuit OR in // one piece of code. // FIXME: I dislike that this is not done in the token classes... boolean flag = node.isLogicalAnd(); for (int i = 0; i < numChildren; i++) { ASTPtRootNode child = (ASTPtRootNode) node.jjtGetChild(i); // Evaluate the child child.visit(this); // Get its value. ptolemy.data.Token nextToken = _evaluatedChildToken; if (!(nextToken instanceof BooleanToken)) { throw new IllegalActionException( "Cannot perform logical " + "operation on " + nextToken + " which is a " + result.getClass().getName()); } if (flag != ((BooleanToken) nextToken).booleanValue()) { _evaluatedChildToken = (BooleanToken.getInstance(!flag)); // Note short-circuit eval. return; } } _evaluatedChildToken = (BooleanToken.getInstance(flag)); if (node.isConstant()) { node.setToken(_evaluatedChildToken); } }
/** * Test for equality of the values of this Token and the argument Token. Two function tokens are * equal if they correspond to the same expression, under renaming of any bound variables. * * @param rightArgument The token to compare to this token. * @return A token containing true if the value element of the first argument is equal to the * value of this token. */ public BooleanToken isEqualTo(Token rightArgument) { FunctionToken convertedArgument = (FunctionToken) rightArgument; return BooleanToken.getInstance(convertedArgument._function.isCongruent(_function)); }
/** * Process this event. If the mode is {@link Mode#ERROR}, a message is shown in an error dialog. * If the mode is {@link Mode#EXCEPTION}, a message is shown in the form of an exception. If the * mode is {@link Mode#MESSAGE}, a message is shown in a message dialog. If the mode is {@link * Mode#TABLEAU}, a tableau is opened to show the message. The default tableau is the one defined * in the {@link #tableau} parameter. However, if {@link #referredTableau} is not an empty string, * its value is interpreted as the name of the tableau parameter in the model, whose tableau * should be used instead of the default one. If the mode is {@link Mode#WARNING}, a message is * shown in a warning dialog. If the mode is {@link Mode#YES_OR_NO}, a query dialog is shown with * the message, which allows the user to answer with yes or no. The answer is stored in {@link * #response}. * * @param arguments The arguments used to process this event, which must be either an ArrayToken * or a RecordToken. * @return A refiring data structure that contains a non-negative double number if refire() should * be called after that amount of model time, or null if refire() need not be called. * @exception IllegalActionException If the tableau cannot be used, or if thrown by the * superclass. */ public RefiringData fire(Token arguments) throws IllegalActionException { RefiringData data = super.fire(arguments); Mode choice = (Mode) mode.getChosenValue(); String text = message.stringValue(); MessageHandler oldHandler; switch (choice) { case ERROR: oldHandler = MessageHandler.getMessageHandler(); try { MessageHandler.setMessageHandler(_MESSAGE_HANDLER); MessageHandler.error(text); } finally { MessageHandler.setMessageHandler(oldHandler); } break; case MESSAGE: oldHandler = MessageHandler.getMessageHandler(); try { MessageHandler.setMessageHandler(_MESSAGE_HANDLER); MessageHandler.message(text); } finally { MessageHandler.setMessageHandler(oldHandler); } break; case EXCEPTION: throw new RuntimeException(text); case TABLEAU: Effigy effigy = EventUtils.findToplevelEffigy(this); if (effigy == null) { // The effigy may be null if the model is closed. return data; } Tableau tableau = EventUtils.getTableau(this, referredTableau, this.tableau); if (tableau != null && !(tableau.getFrame() instanceof TextEditor)) { EventUtils.setTableau(this, referredTableau, this.tableau, null); EventUtils.closeTableau(tableau); tableau = null; } boolean openNewWindow = true; String previousText = null; if (tableau != null) { JFrame frame = tableau.getFrame(); if (frame instanceof TextEditor) { TextEditor editor = (TextEditor) frame; if (editor.getEffigy() == null) { previousText = editor.text.getText(); } else { openNewWindow = false; } } } TextEditor frame; if (openNewWindow) { TextEffigy textEffigy; try { textEffigy = TextEffigy.newTextEffigy(effigy, ""); } catch (Exception e) { throw new IllegalActionException(this, e, "Unable to " + "create effigy."); } try { tableau = new Tableau(textEffigy, "tableau"); } catch (NameDuplicationException e) { throw new IllegalActionException(this, e, "Unable to " + "create tableau."); } frame = new TextEditor(tableau.getTitle(), textEffigy.getDocument()); frame.text.setColumns(((IntToken) columnsDisplayed.getToken()).intValue()); frame.text.setRows(((IntToken) rowsDisplayed.getToken()).intValue()); tableau.setFrame(frame); frame.setTableau(tableau); EventUtils.setTableau(this, referredTableau, this.tableau, tableau); frame.pack(); frame.setVisible(true); if (previousText != null) { frame.text.setText(previousText); } } else { frame = (TextEditor) tableau.getFrame(); } frame.text.append(text + "\n"); try { int lineOffset = frame.text.getLineStartOffset(frame.text.getLineCount() - 1); frame.text.setCaretPosition(lineOffset); } catch (BadLocationException ex) { // Ignore ... worst case is that the scrollbar // doesn't move. } break; case WARNING: try { oldHandler = MessageHandler.getMessageHandler(); try { MessageHandler.setMessageHandler(_MESSAGE_HANDLER); MessageHandler.warning(text); } finally { MessageHandler.setMessageHandler(oldHandler); } response.setToken(BooleanToken.TRUE); } catch (CancelException e) { response.setToken(BooleanToken.FALSE); } break; case YES_OR_NO: oldHandler = MessageHandler.getMessageHandler(); boolean success = false; boolean answer; try { MessageHandler.setMessageHandler(_MESSAGE_HANDLER); answer = MessageHandler.yesNoQuestion(text); success = true; } finally { MessageHandler.setMessageHandler(oldHandler); } if (success) { response.setToken(BooleanToken.getInstance(answer)); } break; default: throw new IllegalActionException( "Unrecognized mode choice \"" + mode.getExpression() + "\"."); } return data; }
/** * @param attribute The changed Attribute. * @throws ptolemy.kernel.util.IllegalActionException When bad things happen. */ public void attributeChanged(ptolemy.kernel.util.Attribute attribute) throws ptolemy.kernel.util.IllegalActionException { log.debug("attributeChanged() start."); if (attribute == opendapURLParameter || attribute == opendapCEParameter) { String url = opendapURLParameter.getExpression(); String ce = opendapCEParameter.getExpression(); if (attribute == opendapURLParameter) log.debug("--- attributeChanged() url: " + url + " Current URL: " + opendapURL); if (attribute == opendapCEParameter) log.debug("--- attributeChanged() ce: \"" + ce + "\" Current CE: \"" + opendapCE + "\""); boolean reload = false; if (!opendapURL.equals(url)) { opendapURL = url; // only reload if not empty. if (!url.equals("")) { reload = true; } } if (!opendapCE.equals(ce)) { opendapCE = ce; // *** I think this should test if url.equals(""). jhrg reload = true; } if (reload) { try { log.debug("OPeNDAP URL: " + opendapURL); dapConnection = new DConnect2(opendapURL); DDS dds = dapConnection.getDDS(opendapCE); log.debug("Got DDS."); // dds.print(System.out); log.debug("Squeezing arrays."); squeezeArrays(dds); // log.debug("Before ports configured."); // dds.print(System.out); log.debug("Configuring ports."); configureOutputPorts(dds); // log.debug("After ports configured."); // dds.print(System.out); } catch (Exception e) { e.printStackTrace(); throw new IllegalActionException( "Problem accessing " + "OPeNDAP Data Source: " + e.getMessage()); } } } // *** Remove the ODC option. jhrg else if (attribute == runODC) { BooleanToken token = (BooleanToken) runODC.getToken(); if (token.booleanValue()) { // start ODC in separate thread ODCThread tr = new ODCThread(); tr.start(); runODC.setExpression("false"); } } }