You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Call.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. |<--- this code is formatted to fit into 80 columns --->|
  10. |<--- this code is formatted to fit into 80 columns --->|
  11. |<--- this code is formatted to fit into 80 columns --->|
  12. */
  13. package telecom;
  14. import java.util.Vector;
  15. import java.util.Enumeration;
  16. /**
  17. * A call supports the process of a customer trying to
  18. * connect to others.
  19. */
  20. public class Call {
  21. private Customer caller, receiver;
  22. private Vector connections = new Vector();
  23. /**
  24. * Create a new call connecting caller to receiver
  25. * with a new connection. This should really only be
  26. * called by Customer.call(..)
  27. */
  28. public Call(Customer caller, Customer receiver) {
  29. this.caller = caller;
  30. this.receiver = receiver;
  31. Connection c;
  32. if (receiver.localTo(caller)) {
  33. c = new Local(caller, receiver);
  34. } else {
  35. c = new LongDistance(caller, receiver);
  36. }
  37. connections.addElement(c);
  38. }
  39. /**
  40. * picking up a call completes the current connection
  41. * (this means that you shouldnt merge calls until
  42. * they are completed)
  43. */
  44. public void pickup() {
  45. Connection connection = (Connection)connections.lastElement();
  46. connection.complete();
  47. }
  48. /**
  49. * Is the call in a connected state?
  50. */
  51. public boolean isConnected(){
  52. return ((Connection)connections.lastElement()).getState()
  53. == Connection.COMPLETE;
  54. }
  55. /**
  56. * hanging up a call drops the connection
  57. */
  58. public void hangup(Customer c) {
  59. for(Enumeration e = connections.elements(); e.hasMoreElements();) {
  60. ((Connection)e.nextElement()).drop();
  61. }
  62. }
  63. /**
  64. * is Customer c one of the customers in this call?
  65. */
  66. public boolean includes(Customer c){
  67. boolean result = false;
  68. for(Enumeration e = connections.elements(); e.hasMoreElements();) {
  69. result = result || ((Connection)e.nextElement()).connects(c);
  70. }
  71. return result;
  72. }
  73. /**
  74. * Merge all connections from call 'other' into 'this'
  75. */
  76. public void merge(Call other){
  77. for(Enumeration e = other.connections.elements(); e.hasMoreElements();){
  78. Connection conn = (Connection)e.nextElement();
  79. other.connections.removeElement(conn);
  80. connections.addElement(conn);
  81. }
  82. }
  83. }