001 /* 002 * InputChannelVector.java 003 * 004 * Developed for the "Rethinking CS101" project. See http://www.cs101.org, the 005 * CS101 homepage or email las@olin.edu. 006 * 007 * Please do not redistribute without obtaining permission. 008 */ 009 010 package nodenet; 011 012 import nodenet.Node; 013 014 import java.util.Vector; 015 import java.util.Enumeration; 016 017 import java.io.Serializable; 018 019 /** 020 * InputChannelVector is something which acts like a <code>Vector</code> 021 * of <code>InputChannel</code>s instead of Objects.<p> The methods of 022 * this class were previously synchronized, but Sun's Vector class uses 023 * synchronized methods. Since our only data field is the already 024 * synchronized Vector, locking on this object is redundant. <p> 025 * 026 * @author Todd C. Parnell, tparnell@ai.mit.edu 027 * @author Patrick G. Heck, gus.heck@olin.edu 028 * @version $Id: InputChannelVector.java,v 1.7 2004/01/14 20:23:21 gus Exp $ 029 */ 030 public class InputChannelVector implements Serializable { 031 032 private Vector myVector; 033 private Node owner; 034 035 /** 036 * Constructs a new InputChannelVector. 037 */ 038 public InputChannelVector(Node owner) { 039 this.owner = owner; 040 this.myVector = new Vector( ); 041 } 042 043 /** 044 * Find out who the owner of this object is. 045 * 046 * @return a reference to the owning <code>Node</code> 047 */ 048 public Node getOwner() { 049 return owner; 050 } 051 052 /** 053 * Adds an object to the InputChannelVector. 054 */ 055 public final void addElement( InputChannel obj ) { 056 this.myVector.addElement( obj ); 057 } 058 059 /** 060 * Checks to see if it contains an element. 061 */ 062 public final boolean contains( Object elem ) { 063 return this.myVector.contains( elem ); 064 } 065 066 /** 067 * Returns the InputChannel at a certain index. 068 * 069 * @param index index of the InputChannel being looked up 070 */ 071 public final InputChannel elementAt( int index ) { 072 return (InputChannel)this.myVector.elementAt( index ); 073 } 074 075 076 /** 077 * Transforms InputChannelVector into yet another type 078 * of collection of objects, called an Enumeration. 079 */ 080 public final Enumeration elements( ) { 081 return this.myVector.elements( ); 082 } 083 084 /** 085 * Returns the first InputChannel in the InputChannelVector. 086 */ 087 public final InputChannel firstElement( ) { 088 return (InputChannel)this.myVector.firstElement( ); 089 } 090 091 /** 092 * Returns true if the InputChannelVector is empty. 093 */ 094 public final boolean isEmpty( ) { 095 return this.myVector.isEmpty( ); 096 } 097 098 /** 099 * Returns the last InputChannel in the InputChannelVector. 100 */ 101 public final InputChannel lastElement( ) { 102 return (InputChannel)this.myVector.lastElement( ); 103 } 104 105 /** 106 * Removes all elements from the InputChannelVector. 107 */ 108 public final void removeAllElements( ) { 109 this.myVector.removeAllElements( ); 110 } 111 112 /** 113 * Removes a specific element from the InputChannelVector. 114 * 115 * @param obj the object being removed 116 */ 117 public final boolean removeElement( InputChannel obj ) { 118 return this.myVector.removeElement( obj ); 119 } 120 121 /** 122 * Returns the size of the InputChannelVector. 123 */ 124 public final int size( ) { 125 return this.myVector.size( ); 126 } 127 128 } 129 130 /* 131 * $Log: InputChannelVector.java,v $ 132 * Revision 1.7 2004/01/14 20:23:21 gus 133 * Javadoc and comment cleanup 134 * 135 * Revision 1.6 2003/02/24 16:04:15 gus 136 * Make input and output channel vectors aware of their owners, and able to report 137 * who their owner is. 138 * 139 * Revision 1.5 2003/02/21 17:50:54 gus 140 * fixed log comment 141 * 142 */