/** * Ends the receiver's voice communication * * @param voice The ending voice communication * @throws IncompatibleModeException the incompatible mode for communication exception */ public void endReceiverVoiceCommunication(Voice voice) throws IncompatibleModeException { final boolean ableToCommunicate = this.getMode().ableToReceiveVoice(); System.out.println(voice.getDuration()); if (ableToCommunicate) { throw new IncompatibleModeException( "Cannot End Call: No call being received because its able to receive", this.getOperator().getSeqNumber()); } // se o iniciador foi este numero de telemovel e o receptor o "speakingTo" if (!this.getIsCallInitiator() && voice.getCallerID().equals(this.getSpeakingTo())) { addReceivedVoice(voice); // (forca porque o busy nao tolera mudanca de estado) this.setMode(this.getModeBeforeCall()); this.setSpeakingTo(null); } else { throw new IncompatibleModeException( "Cannot End Call: Not Receiver", this.getOperator().getSeqNumber()); } }