001 /* 002 * OutputChannelVector.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 * OutputChannelVector is something which acts like a <code>Vector</code> 021 * of <code>OutputChannel</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 * Copyright (c) 1998 Massachusetts Institute of Technology 027 * 028 * @author Todd C. Parnell, tparnell@ai.mit.edu 029 * @version $Id: OutputChannelVector.java,v 1.7 2004/01/14 20:23:21 gus Exp $ 030 */ 031 public class OutputChannelVector implements Serializable { 032 033 private Vector myVector; 034 private Node owner; 035 036 /** 037 * Constructs a new OutputChannelVector 038 */ 039 public OutputChannelVector(Node owner) { 040 this.owner = owner; 041 this.myVector = new Vector( ); 042 } 043 044 /** 045 * Find out who the owner of this object is. 046 * 047 * @return a reference to the owning <code>Node</code> 048 */ 049 public Node getOwner() { 050 return owner; 051 } 052 053 /** 054 * Adds an object to the OutputChannelVector. 055 */ 056 public final void addElement( OutputChannel obj ) { 057 this.myVector.addElement( obj ); 058 } 059 060 /** 061 * Checks to see if it contains an element. 062 */ 063 public final boolean contains( Object elem ) { 064 return this.myVector.contains( elem ); 065 } 066 067 /** 068 * Returns the OutputChannel at a certain index. 069 * 070 * @param index index of the OutputChannel being looked up 071 */ 072 public final OutputChannel elementAt( int index ) { 073 return (OutputChannel)this.myVector.elementAt( index ); 074 } 075 076 /** 077 * Transforms OutputChannelVector into yet another type 078 * of collection of objects, called an Enumeration. 079 */ 080 public final Enumeration elements( ) // allows to turn into another type of collection?? thingie 081 { 082 return this.myVector.elements( ); // should return Enum of IChannels? 083 } 084 085 /** 086 * Returns the first OutputChannel in the OutputChannelVector. 087 */ 088 public final OutputChannel firstElement( ) { 089 return (OutputChannel)this.myVector.firstElement( ); 090 } 091 092 /** 093 * Returns true if the OutputChannelVector is empty. 094 */ 095 public final boolean isEmpty( ) { 096 return this.myVector.isEmpty( ); 097 } 098 099 /** 100 * Returns the last OutputChannel in the OutputChannelVector. 101 */ 102 public final OutputChannel lastElement( ) { 103 return (OutputChannel)this.myVector.lastElement( ); 104 } 105 106 /** 107 * Removes all elements from the OutputChannelVector. 108 */ 109 public final void removeAllElements( ) { 110 this.myVector.removeAllElements( ); 111 } 112 113 /** 114 * Removes a specific element from the OutputChannelVector. 115 * 116 * @param obj the object being removed 117 */ 118 public final boolean removeElement( OutputChannel obj ) { 119 return this.myVector.removeElement( obj ); 120 } 121 122 /** 123 * Returns the size of the InputChannelVector. 124 */ 125 public final int size( ) { 126 return this.myVector.size( ); 127 } 128 } 129 130 /* 131 * $Log: OutputChannelVector.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:11 gus 140 * fixed log comment 141 * 142 */