Package ptolemy.data

Examples of ptolemy.data.BooleanToken


            }
        }

        int br;
        int code;
        BooleanToken posAck = new BooleanToken(true);
        BooleanToken negAck = new BooleanToken(false);

        while (true) {
            //
            // State 1: Wait for 1st Request
            //
View Full Code Here


        }));

        env.bind("$not", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    BooleanToken b = (BooleanToken) args[0];
                    return b.not();
                } catch (Exception ex) {
                    throw new FunctionCallException("$not", args[0], ex);
                }
            }

            public int arity() {
                return 1;
            }
        }));

        env.bind("$and", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    BooleanToken a = (BooleanToken) args[0];
                    BooleanToken b = (BooleanToken) args[1];
                    return a.and(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$and", args[0], args[1],
                            ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$or", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    BooleanToken a = (BooleanToken) args[0];
                    BooleanToken b = (BooleanToken) args[1];
                    return a.or(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$or", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$eq", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];
                    return a.isEqualTo(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$eq", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$ne", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];
                    return a.isEqualTo(b).not();
                } catch (Exception ex) {
                    throw new FunctionCallException("$ne", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$lt", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    ScalarToken a = (ScalarToken) args[0];
                    ScalarToken b = (ScalarToken) args[1];
                    return a.isLessThan(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$lt", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$le", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    ScalarToken a = (ScalarToken) args[0];
                    ScalarToken b = (ScalarToken) args[1];
                    return a.isGreaterThan(b).not();
                } catch (Exception ex) {
                    throw new FunctionCallException("$le", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$gt", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    ScalarToken a = (ScalarToken) args[0];
                    ScalarToken b = (ScalarToken) args[1];
                    return a.isGreaterThan(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$gt", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$ge", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    ScalarToken a = (ScalarToken) args[0];
                    ScalarToken b = (ScalarToken) args[1];
                    return a.isLessThan(b).not();
                } catch (Exception ex) {
                    throw new FunctionCallException("$ge", args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$negate", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    ScalarToken a = (ScalarToken) args[0];

                    return a.zero().subtract(a);
                } catch (Exception ex) {
                    throw new FunctionCallException("$negate", args[0], ex);
                }
            }

            public int arity() {
                return 1;
            }
        }));

        env.bind("$add", _theContext.createFunction(new Function() {
            // Compute the add operation on scalar arguments, the
            // list concatenation operation on lists, or the set
            // union on sets.
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];

                    if (a instanceof ObjectToken && b instanceof ObjectToken) {
                        Object oa = ((ObjectToken) a).getValue();
                        Object ob = ((ObjectToken) b).getValue();

                        if (oa instanceof Collection
                                && ob instanceof Collection) {
                            Collection result;

                            if (oa instanceof Set) {
                                result = new HashSet((Set) oa);
                            } else if (oa instanceof List) {
                                result = new ArrayList((List) oa);
                            } else {
                                throw new Exception(
                                        "Unknown object type: expected Set or List.");
                            }

                            result.addAll((Collection) ob);
                            return new ObjectToken(result);
                        } else {
                            throw new Exception(
                                    "Unknown object types: expected Collection.");
                        }
                    } else {
                        return a.add(b);
                    }
                } catch (Exception ex) {
                    throw new FunctionCallException("$add", args[0], args[1],
                            ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$mul", _theContext.createFunction(new Function() {
            // Compute the multiply operation on scalar arguments,
            // or the set intersection operation on sets.
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];

                    if (a instanceof ObjectToken && b instanceof ObjectToken) {
                        Object oa = ((ObjectToken) a).getValue();
                        Object ob = ((ObjectToken) b).getValue();

                        if (oa instanceof Set && ob instanceof Collection) {
                            Set result = new HashSet((Set) oa);
                            result.retainAll((Collection) ob);
                            return new ObjectToken(result);
                        } else {
                            throw new InterpreterException(
                                    "Unknown object types: expected Set and Collection.");
                        }
                    } else {
                        return a.multiply(b);
                    }
                } catch (Exception ex) {
                    throw new FunctionCallException("$mul", args[0], args[1],
                            ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$sub", _theContext.createFunction(new Function() {
            // Compute the subtraction operation on scalar arguments,
            // or the set subtraction operation on sets.
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];

                    if (a instanceof ObjectToken && b instanceof ObjectToken) {
                        Object oa = ((ObjectToken) a).getValue();
                        Object ob = ((ObjectToken) b).getValue();

                        if (oa instanceof Collection
                                && ob instanceof Collection) {
                            Collection result;

                            if (oa instanceof Set) {
                                result = new HashSet((Set) oa);
                            } else if (oa instanceof List) {
                                result = new ArrayList((List) oa);
                            } else {
                                throw new Exception(
                                        "Unknown object type: expected Set or List.");
                            }

                            result.removeAll((Collection) ob);
                            return new ObjectToken(result);
                        } else {
                            throw new InterpreterException(
                                    "Unknown object types: expected Collection.");
                        }
                    } else {
                        return a.subtract(b);
                    }
                } catch (Exception ex) {
                    throw new FunctionCallException("$sub", args[0], args[1],
                            ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$div", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];
                    return a.divide(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$div", args[0], args[1],
                            ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$mod", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];
                    Token b = (Token) args[1];
                    return a.modulo(b);
                } catch (Exception ex) {
                    throw new FunctionCallException("$mod", args[0], args[1],
                            ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$size", _theContext.createFunction(new Function() {
            // Compute the number of elements in the given set,
            // list, or array.
            public Object apply(Object[] args) {
                try {
                    Token a = (Token) args[0];

                    if (a instanceof ObjectToken) {
                        Object oa = ((ObjectToken) a).getValue();

                        if (oa instanceof Collection) {
                            return new IntToken(((Collection) oa).size());
                        } else {
                            throw new InterpreterException(
                                    "Unknown object type: expected Collection.");
                        }
                    } else if (a instanceof ArrayToken) {
                        return _theContext.createInteger(((ArrayToken) a)
                                .length());
                    } else {
                        throw new InterpreterException(
                                "Unknown type: expected Array, Set, or List");
                    }
                } catch (Exception ex) {
                    throw new FunctionCallException("$size", args[0], ex);
                }
            }

            public int arity() {
                return 1;
            }
        }));

        env.bind("$createList", _theContext.createFunction(new Function() {
            // Create a list that contains the results of applying
            // the second argument (a one argument function) to
            // every element in the first argument (a collection).
            public Object apply(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    FunctionToken f = (FunctionToken) args[1];
                    Object[] argument = new Object[1];
                    List res = new ArrayList();

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();

                        Object listFragment = _theContext.applyFunction(f,
                                argument);
                        res.addAll(_theContext.getCollection(listFragment));
                    }

                    return _theContext.createList(res);
                } catch (Exception ex) {
                    throw new FunctionCallException("Failed to create list.",
                            args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$createSet", _theContext.createFunction(new Function() {
            // Create a set that contains the results of applying
            // the second argument (a one argument function) to
            // every element in the first argument (a collection).
            public Object apply(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    FunctionToken f = (FunctionToken) args[1];
                    Object[] argument = new Object[1];
                    Set res = new HashSet();

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();

                        Object setFragment = _theContext.applyFunction(f,
                                argument);
                        res.addAll(_theContext.getCollection(setFragment));
                    }

                    return _theContext.createSet(res);
                } catch (Exception ex) {
                    throw new FunctionCallException("Failed to create set.",
                            args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$createMap", _theContext.createFunction(new Function() {
            // Create a map that contains the results of applying
            // the second argument (a one argument function) to
            // every element in the first argument (a collection).
            public Object apply(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    FunctionToken f = (FunctionToken) args[1];
                    Object[] argument = new Object[1];
                    Map res = new HashMap();

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();

                        Object mapFragment = _theContext.applyFunction(f,
                                argument);
                        res.putAll(_theContext.getMap(mapFragment));
                    }

                    return _theContext.createMap(res);
                } catch (Exception ex) {
                    throw new FunctionCallException("Failed to create map.",
                            args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("$iterate", _theContext.createProcedure(new Procedure() {
            // Invoke the second argument (a one argument
            // procedure) on every element of the first argument
            // (a collection).
            public void call(Object[] args) {
                try {
                    Collection c = _theContext.getCollection(args[0]);
                    Object proc = args[1];
                    Object[] argument = new Object[1];

                    for (Iterator i = c.iterator(); i.hasNext();) {
                        argument[0] = i.next();
                        _theContext.callProcedure(proc, argument);
                    }
                } catch (Exception ex) {
                    throw new FunctionCallException("Iteration failed.",
                            args[0], args[1], ex);
                }
            }

            public int arity() {
                return 2;
            }
        }));

        env.bind("listToArray", _theContext.createFunction(new Function() {
            // Convert the given list to an array.
            public Object apply(Object[] args) {
                try {
                    ObjectToken input = (ObjectToken) args[0];
                    List inputList = (List) input.getValue();
                    Token[] tokens = new Token[inputList.size()];
                    tokens = (Token[]) inputList.toArray(tokens);
                    return new ArrayToken(tokens);
                } catch (Exception ex) {
                    throw new FunctionCallException("listToArray", args[0], ex);
                }
            }

            public int arity() {
                return 1;
            }
        }));

        env.bind("listToMatrix", _theContext.createFunction(new Function() {
            // Convert the given list to an array.
            public Object apply(Object[] args) {
                try {
                    ObjectToken input = (ObjectToken) args[0];
                    List inputList = (List) input.getValue();
                    Token[] tokens = new Token[inputList.size()];
                    tokens = (Token[]) inputList.toArray(tokens);

                    int rows = _theContext.intValue(args[1]);
                    int columns = _theContext.intValue(args[2]);
                    return MatrixToken.arrayToMatrix(tokens, rows, columns);
                } catch (Exception ex) {
                    throw new FunctionCallException("listToArray", args[0], ex);
                }
            }

            public int arity() {
                return 3;
            }
        }));

        //
        // Xilinx SystemBuilder
        //
        //        constant YSCALE:   INT19 := conv_signed( integer( 1.164 * 256), 19 );
        //        constant RSCALE:   INT19 := conv_signed( integer( 1.596 * 256), 19 );
        //        constant GUSCALE:  INT19 := conv_signed( integer(-0.392 * 256), 19 );
        //        constant GVSCALE:  INT19 := conv_signed( integer(-0.813 * 256), 19 );
        //        constant BSCALE:   INT19 := conv_signed( integer( 2.017 * 256), 19 );
        //        constant YOFFSET:  INT19 := conv_signed(                    16, 19 );
        //        constant UVOFFSET: INT19 := conv_signed(                   128, 19 );
        //
        //        constant UINT9_zero: UINT9 := (others => '0' );
        //
        //        function INT19_mul( a: INT19; b: INT19 ) return INT19;
        //        function RGBCLIP( a: INT19 ) return UINT8;
        env.bind("UINT9_zero", _theContext.createInteger(0));
        env.bind("YSCALE", _theContext.createInteger((int) (1.164 * 256)));
        env.bind("RSCALE", _theContext.createInteger((int) (1.596 * 256)));
        env.bind("GUSCALE", _theContext.createInteger((int) (-0.392 * 256)));
        env.bind("GVSCALE", _theContext.createInteger((int) (-0.813 * 256)));
        env.bind("BSCALE", _theContext.createInteger((int) (2.017 * 256)));

        env.bind("YOFFSET", _theContext.createInteger(16));
        env.bind("UVOFFSET", _theContext.createInteger(128));

        env.bind("INT19_mul", _theContext.createFunction(new Function() {
            public Object apply(Object[] args) {
                try {
                    IntToken a = (IntToken) args[0];
                    IntToken b = (IntToken) args[1];
                    int res = (a.intValue() * b.intValue()); // & 0x7ffff;
                    return _theContext.createInteger(res);
                } catch (Exception ex) {
                    throw new InterpreterException(
                            "Function 'RGBCLIP': Cannot apply.", ex);
                }
View Full Code Here

                                continue;
                            }
                        }

                        if (isAttributeValueEnabled()) {
                            BooleanToken equality = token
                                    .isEqualTo(_attributeValue.getToken());
                            if (!equality.booleanValue()) {
                                continue;
                            }
                        }
                    } catch (IllegalActionException e) {
                        continue;
View Full Code Here

        maximumReceiverCapacity.setToken(new IntToken(0));

        runUntilDeadlockInOneIteration = new Parameter(this,
                "runUntilDeadlockInOneIteration");
        runUntilDeadlockInOneIteration.setTypeEquals(BaseType.BOOLEAN);
        runUntilDeadlockInOneIteration.setToken(new BooleanToken(false));
    }
View Full Code Here

        } else if (result instanceof Long) {
            resultToken = new LongToken(((Long) result).longValue());
        } else if (result instanceof String) {
            resultToken = new StringToken((String) result);
        } else if (result instanceof Boolean) {
            resultToken = new BooleanToken(((Boolean) result).booleanValue());
        } else if (result instanceof Complex) {
            resultToken = new ComplexToken((Complex) result);
        } else if (result instanceof FixPoint) {
            resultToken = new FixToken((FixPoint) result);
        } else {
View Full Code Here

            Thread.sleep(300);
        } catch (InterruptedException e) {
            throw new TerminateProcessException(this, "Terminated");
        }

        BooleanToken bToken = (BooleanToken) requestInput.get(0);

        if (bToken.booleanValue()) {
            // State 3
            _debug(new ExecEvent(this, ExecEvent.ACCESSING));

            try {
                Thread.sleep(300);
View Full Code Here

        output.setMultiport(true);
        output.setTypeEquals(BaseType.DOUBLE);
        sourceURL = new Parameter(this, "sourceURL", new StringToken(""));
        sourceURL.setTypeEquals(BaseType.STRING);

        refresh = new Parameter(this, "refresh", new BooleanToken(false));
        refresh.setTypeEquals(BaseType.BOOLEAN);

        if (_stdIn == null) {
            _stdIn = new BufferedReader(new InputStreamReader(System.in));
        }
View Full Code Here

            if (value == null) {
                return true;
            }

            ArrayToken boundsToken = (ArrayToken) value.get("bounds");
            BooleanToken maximizedToken = (BooleanToken) value.get("maximized");
            int x = ((IntToken) boundsToken.getElement(0)).intValue();
            int y = ((IntToken) boundsToken.getElement(1)).intValue();
            int width = ((IntToken) boundsToken.getElement(2)).intValue();
            int height = ((IntToken) boundsToken.getElement(3)).intValue();

            //System.out.println("x: " + x + "  y: " + y);
            //System.out.println("width: " + width + "  height: " + height);

            // If x or y is less than 0 or greater than the width or
            // height of the screen - 10, then offset them by 30 pixels so
            // the user can drag the window.
            // FIXME: If we change the size, should we mark the model
            // as dirty so it gets saved?
            // FIXME: will these changes cause problems with multiscreen
            // monitors?

            //CWB: changed behavior on 2008.03.06
            //Now if any part of the window is off the screen, either the
            //x or y position is set to 0.  This fixes several problems
            //with workflows being positioned off of the screen when saved
            //on a multi-head machine, then reopened on a single-head machine
            x = (x < 0 ? 30 : x);
            y = (y < 0 ? 30 : y);

            Toolkit tk = Toolkit.getDefaultToolkit();
            x = (x + width > tk.getScreenSize().width ? 0 : x);
            y = (y + height > tk.getScreenSize().height ? 0 : y);

            frame.setBounds(x, y, width, height);

            if (maximizedToken != null) {
                boolean maximized = maximizedToken.booleanValue();

                if (maximized) {
                    // FIXME: Regrettably, this doesn't make the window
                    // actually maximized under Windows, at least.
                    frame.setExtendedState(frame.getExtendedState()
View Full Code Here

            period = new Parameter(this, "period");
            period.setToken(new DoubleToken(_DEFAULT_GIOTTO_PERIOD));
            iterations = new Parameter(this, "iterations", new IntToken(0));

            synchronizeToRealTime = new Parameter(this,
                    "synchronizeToRealTime", new BooleanToken(false));

            timeResolution.setVisibility(Settable.FULL);
        } catch (KernelException ex) {
            throw new InternalErrorException("Cannot initialize director: "
                    + ex.getMessage());
View Full Code Here

                        // user to be able to put their own initial tokens;
                        // however some specific SDF actors may have their
                        // own buffers parameters that actually keep this
                        // initial tokens (similar to SampleDelay)
                        if (fromType.equals(BaseType.BOOLEAN)) {
                            currentReceiver.put(new BooleanToken(false));
                        } else if (fromType.equals(BaseType.DOUBLE)) {
                            currentReceiver.put(new DoubleToken(0.0));
                        } else if (fromType.equals(BaseType.INT)) {
                            currentReceiver.put(new IntToken(0));
                        }
View Full Code Here

TOP

Related Classes of ptolemy.data.BooleanToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.