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