All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.cmu.tetradapp.model.SessionNodeWrapper Maven / Gradle / Ivy

The newest version!
///////////////////////////////////////////////////////////////////////////////
// For information as to what this class does, see the Javadoc, below.       //
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,       //
// 2007, 2008, 2009, 2010, 2014, 2015, 2022 by Peter Spirtes, Richard        //
// Scheines, Joseph Ramsey, and Clark Glymour.                               //
//                                                                           //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
//                                                                           //
// This program is distributed in the hope that it will be useful,           //
// but WITHOUT ANY WARRANTY; without even the implied warranty of            //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
// GNU General Public License for more details.                              //
//                                                                           //
// You should have received a copy of the GNU General Public License         //
// along with this program; if not, write to the Free Software               //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA //
///////////////////////////////////////////////////////////////////////////////

package edu.cmu.tetradapp.model;

import edu.cmu.tetrad.graph.GraphNode;
import edu.cmu.tetrad.graph.NodeType;
import edu.cmu.tetrad.util.TetradLogger;
import edu.cmu.tetrad.util.TetradSerializableUtils;
import edu.cmu.tetradapp.session.SessionNode;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serial;

/**
 * A node in a SessionWrapper; wraps a SessionNode and presents it as a GraphNode.
 *
 * @author josephramsey
 * @version $Id: $Id
 * @see SessionNode
 * @see edu.cmu.tetrad.graph.GraphNode
 * @see SessionWrapper
 */
public class SessionNodeWrapper extends GraphNode {
    private static final long serialVersionUID = 23L;

    /**
     * The SessionNode being wrapped.
     *
     * @serial Cannot be null.
     */
    private final SessionNode sessionNode;

    /**
     * The button type of the session node (some string defined in the config file). "???" indicates that no button type
     * has been set.
     *
     * @serial Cannot be null.
     */
    private String buttonType = "???";

    //==========================CONSTRUCTORS==========================//

    /**
     * Wraps the given SessionNode as a SessionNodeWrapper for use in a SessionWrapper. The name of the SessionNode is
     * used as the name of the SessionNodeWrapper. A button type may optionally be set.
     *
     * @param sessionNode a {@link SessionNode} object
     */
    public SessionNodeWrapper(SessionNode sessionNode) {
        super(sessionNode.getDisplayName());
        this.sessionNode = sessionNode;
        setNodeType(NodeType.SESSION);
    }

    /**
     * Generates a simple exemplar of this class to test serialization.
     *
     * @return a {@link edu.cmu.tetrad.graph.GraphNode} object
     * @see TetradSerializableUtils
     */
    public static GraphNode serializableInstance() {
        return new SessionNodeWrapper(SessionNode.serializableInstance());
    }

    //===========================PUBLIC METHODS=======================//

    /**
     * 

getSessionName.

* * @return the session name. (Should return the same as getNode.) */ public String getSessionName() { return this.sessionNode.getDisplayName(); } /** * Sets the session name. This method should be used in preference to setName, which only sets the name in the * superclass. * * @param name a {@link java.lang.String} object */ public void setSessionName(String name) { // if (!NamingProtocol.isLegalName(name)) { // throw new IllegalArgumentException( // NamingProtocol.getProtocolDescription() + ": " + name); // } // Implementation note: the test for null is necessary to // account for the fact that when first constructed the // session node cannot be set before the superclass calls this // (overriding) method. jdramsey 12/29/01 if (this.sessionNode != null) { this.setName(name); this.sessionNode.setDisplayName(name); } } /** * Gets the buttonType of the node, which is the buttonType of the wrapped SessionNode. * * @return a {@link java.lang.String} object */ public String getButtonType() { return this.buttonType; } /** * Sets the buttonType of the node, which is the buttonType of the wrapped SessionNode. * * @param buttonType a {@link java.lang.String} object */ public void setButtonType(String buttonType) { if (buttonType == null) { throw new NullPointerException("Button type cannot be null."); } this.buttonType = buttonType; } /** *

Getter for the field sessionNode.

* * @return the SessionNode being wrapped. */ public SessionNode getSessionNode() { return this.sessionNode; } /** *

getRepetition.

* * @return a int */ public int getRepetition() { return this.sessionNode.getRepetition(); } /** *

setRepetition.

* * @param repetition a int */ public void setRepetition(int repetition) { this.sessionNode.setRepetition(repetition); } /** * Must override hashCode in GraphNode to make sure that this object doesn't get hashed differently if its name * changes. If it does, session box deletion won't work. * * @return a int */ public int hashCode() { return 1; } /** * {@inheritDoc} *

* Must override equals in GraphNode to make sure equality is object identity. In particular, change of name does * not constitute change of identity. */ public boolean equals(Object o) { return this == o; } /** *

toString.

* * @return a string representation of the node. */ public String toString() { return "SessionNodewrapper (type " + getButtonType() + ", name " + getSessionName() + ")"; } /** * Writes the object to the specified ObjectOutputStream. * * @param out The ObjectOutputStream to write the object to. * @throws IOException If an I/O error occurs. */ @Serial private void writeObject(ObjectOutputStream out) throws IOException { try { out.defaultWriteObject(); } catch (IOException e) { TetradLogger.getInstance().log("Failed to serialize object: " + getClass().getCanonicalName() + ", " + e.getMessage()); throw e; } } /** * Reads the object from the specified ObjectInputStream. This method is used during deserialization * to restore the state of the object. * * @param in The ObjectInputStream to read the object from. * @throws IOException If an I/O error occurs. * @throws ClassNotFoundException If the class of the serialized object cannot be found. */ @Serial private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { try { in.defaultReadObject(); } catch (IOException e) { TetradLogger.getInstance().log("Failed to deserialize object: " + getClass().getCanonicalName() + ", " + e.getMessage()); throw e; } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy