001/* A pair of states. 002 003 Copyright (c) 1999-2014 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 */ 027package ptolemy.domains.modal.kernel.ia; 028 029import ptolemy.domains.modal.kernel.State; 030 031/////////////////////////////////////////////////////////////////// 032//// StatePair 033 034/** 035 A pair of states. 036 This class is used in the representation of alternating simulation. 037 @see InterfaceAutomaton#computeAlternatingSimulation 038 039 @author Yuhong Xiong 040 @version $Id$ 041 @since Ptolemy II 8.0 042 @Pt.ProposedRating Red (yuhong) 043 @Pt.AcceptedRating Red (yuhong) 044 */ 045public class StatePair { 046 /** Construct an instance with the specified states. 047 * @param first The first state in the pair. 048 * @param second The second state in the pair. 049 */ 050 public StatePair(State first, State second) { 051 _first = first; 052 _second = second; 053 } 054 055 /////////////////////////////////////////////////////////////////// 056 //// public methods //// 057 058 /** Override the base class method to return true if the specified 059 * object is an instance of StatePair and it contains the same 060 * states as this one. 061 * @param object An object to compare with this one. 062 * @return True if the specified object is an instance of StatePair 063 * and this one contains the same states, false otherwise. 064 */ 065 @Override 066 public boolean equals(Object object) { 067 if (object instanceof StatePair) { 068 return this.first() == ((StatePair) object).first() 069 && this.second() == ((StatePair) object).second(); 070 } 071 072 return false; 073 } 074 075 /** Return the first state in this pair. 076 * @return The first state in this pair. 077 */ 078 public State first() { 079 return _first; 080 } 081 082 /** Override the base class method to ensure that the pairs that 083 * are equal (according to the equals() method) have the same 084 * hash code. 085 * @return The hash code. 086 */ 087 @Override 088 public int hashCode() { 089 return _first.hashCode() + _second.hashCode(); 090 } 091 092 /** Return the second state in this pair. 093 * @return The second state in this pair. 094 */ 095 public State second() { 096 return _second; 097 } 098 099 /** Return a string representation of this pair. The string contains 100 * the name of the first state, followed by a " - ", followed by 101 * the name of the second state. 102 * @return A string containing the names of the two states separated 103 * by a " - ". 104 */ 105 @Override 106 public String toString() { 107 return _first.getName() + " - " + _second.getName(); 108 } 109 110 /////////////////////////////////////////////////////////////////// 111 //// private variables //// 112 private State _first; 113 114 private State _second; 115}