view src/pathfinder/ChannelSimulator.java @ 68:735e70091564

EditorSimulator1 in TestNetwork
author kent
date Thu, 08 Nov 2007 12:56:56 +0900
parents 2e5bd7bffa4b
children eda73e0a0388
line wrap: on
line source

package pathfinder;

import java.util.LinkedList;
import java.util.Queue;

public class ChannelSimulator<P> {
	public NetworkSimulator<P> ns;
	public Queue<P>[] q;
/*
	public ChannelSimulator(NetworkSimulator<P> ns){
		q = new Queue<P>[2];
		q[0] = new LinkedList<P>(); 
		q[1] = new LinkedList<P>(); 
		this.ns = ns;
	}
*/
	public ChannelSimulator(NetworkSimulator<P> _ns){
		this(new LinkedList<P>(), new LinkedList<P>(), _ns);
	}
	public ChannelSimulator(Queue<P> _a, Queue<P> _b, NetworkSimulator<P> ns){
		q = new Queue[2];
		q[0] = _a;
		q[1] = _b;
		this.ns = ns;
	}

	public P read(){
		return ns.read(q[0]);
	}

	public boolean write(P p){
		return ns.write(q[1],p);
	}

	public ChannelSimulator<P> getServerChannel() {
		return new ChannelSimulator<P>(q[1], q[0],ns);
	}
}