001/* Clone an actor and compare the type constraints with the master.
002
003 Copyright (c) 2015-2018 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.actor.parameters.test;
029
030import java.util.Set;
031
032import ptolemy.actor.TypedAtomicActor;
033import ptolemy.actor.lib.ArrayContains;
034import ptolemy.graph.Inequality;
035import ptolemy.kernel.CompositeEntity;
036import ptolemy.kernel.util.Workspace;
037
038/**
039 Clone an actor and compare the type constraints with the master.
040
041 <p>Invoke with:</p>
042 <pre>
043 java -classpath $PTII ptolemy.actor.parameters.test.CloneTest
044 </pre>
045
046 @author Christopher Brooks
047 @version $Id$
048 @since Ptolemy II 11.0
049 @Pt.ProposedRating Red (cxh)
050 @Pt.AcceptedRating Red (cxh)
051 */
052public class CloneTest {
053    public static void main(String[] args) throws Throwable {
054        Workspace workspace = new Workspace();
055        CompositeEntity compositeEntity = new CompositeEntity(workspace);
056
057        // Use ArrayContains because it has few type constraints.
058        TypedAtomicActor actor = new ArrayContains(compositeEntity, "myActor");
059        TypedAtomicActor clone = (TypedAtomicActor) actor.clone(workspace);
060
061        Set<Inequality> masterConstraints = actor.typeConstraints();
062        System.out.println(
063                masterConstraints.size() + " master type constraints:");
064        Inequality firstElement = null;
065        Inequality secondElement = null;
066        Inequality lastElement = null;
067        for (Inequality inequality : masterConstraints) {
068            if (firstElement == null) {
069                firstElement = inequality;
070            } else if (secondElement == null) {
071                secondElement = inequality;
072            }
073            lastElement = inequality;
074            System.out.println(inequality);
075        }
076        System.out.println(secondElement.equals(lastElement));
077
078        Set<Inequality> cloneConstraints = clone.typeConstraints();
079        System.out.println(
080                "\n\n" + cloneConstraints.size() + " clone type constraints:");
081        for (Inequality inequality : cloneConstraints) {
082            System.out.println(inequality);
083        }
084        System.out.println("\n\n");
085
086        if (masterConstraints.size() != cloneConstraints.size()) {
087            throw new Exception("The number of type constraints in the master ("
088                    + masterConstraints.size()
089                    + ") is not equal to the number of type constraints in the clone ("
090                    + cloneConstraints.size() + ")");
091        }
092
093        if (masterConstraints.equals(cloneConstraints)) {
094            throw new Exception(
095                    "The master type constraints and the clone type constraints are not equal.");
096        }
097    }
098}