You are on page 1of 3

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package q1latency;
/**
*
* @author sunethe
*/
public class Network {
int networkTime;
Node one, two, three, four;
public Network() {
networkTime = 0;
one = new Node(2, 0);
two = new Node(3, 0);
three = new Node(3, 2);
four = new Node(2, 0);
}
public void sendOrders() {
while (!isNwEmpty()) {
printNodeInfo();
networkTime++;
checkRoutingTable();
}
}
public void checkRoutingTable() {
//

if (!one.isNodeEmpty()) {
System.out.println("!one.isNodeEmpty()");
if ((networkTime - one.getPrevProcCompTime()) == one.getNextProcTime

()) {
if ((one.getQueue().get(0) == 'A') || (one.getQueue().get(0) ==
'B')) {
if (two.isNodeEmpty()) {
two.setPrevProcCompTime(networkTime);
}
two.setCurrOrderType(one.getCurrOrderType());
order type
two.getQueue().add(one.getQueue().remove(0));
if (!one.isNodeEmpty()) {
one.setCurrOrderType(one.getQueue().get(0));
}
one.setPrevProcCompTime(networkTime);
two.setNextProcTime(two.getProcTime());

//setting

}
}
}
//
//
pe());

if (!two.isNodeEmpty()) {
System.out.println("!two.isNodeEmpty()");
System.out.println("two.getCurrOrderType(): " + two.getCurrOrderTy
if ((networkTime - two.getPrevProcCompTime()) == two.getNextProcTime

()) {
if (two.getQueue().get(0) == 'A') {
four.setCurrOrderType(two.getCurrOrderType());
if (four.isNodeEmpty()) {
four.setPrevProcCompTime(networkTime);
}
four.getQueue().add(two.getQueue().remove(0));
two.setPrevProcCompTime(networkTime);
two.setPrevOrderType(two.getCurrOrderType());
four.setNextProcTime(four.getProcTime());
}
else if (two.getQueue().get(0) == 'B') {
System.out.println("HERE <<<<<<<<< ");
three.setCurrOrderType(two.getCurrOrderType());
if (three.isNodeEmpty()) {
three.setPrevProcCompTime(networkTime);
}
three.getQueue().add(two.getQueue().remove(0));
two.setPrevProcCompTime(networkTime);
two.setPrevOrderType(two.getCurrOrderType());
three.setNextProcTime(three.getProcTime());
}
}
}
if (!three.isNodeEmpty()) {
System.out.println("!three.isNodeEmpty()");
if ((networkTime - three.getPrevProcCompTime()) == three.getNextProc
Time()) {
if (three.getQueue().get(0) == 'A') {
four.setCurrOrderType(three.getCurrOrderType());
if (four.isNodeEmpty()) {
four.setPrevProcCompTime(networkTime);
}
four.getQueue().add(three.getQueue().remove(0));
three.setPrevProcCompTime(networkTime);
three.setPrevOrderType(three.getCurrOrderType());
//

four.setNextProcTime(four.getProcTime());
}
else if (three.getQueue().get(0)== 'B') {
four.setCurrOrderType(three.getCurrOrderType());
if (four.isNodeEmpty()) {

four.setPrevProcCompTime(networkTime);
}
four.getQueue().add(three.getQueue().remove(0));
three.setPrevProcCompTime(networkTime);
three.setPrevOrderType(three.getCurrOrderType());
four.setNextProcTime(four.getProcTime());
}
}
}
if (!four.isNodeEmpty()) {
System.out.println("!four.isNodeEmpty()");
if ((networkTime - four.getPrevProcCompTime()) == four.getNextProcTi

//
me()) {

if (four.getQueue().get(0) == 'A') {
four.getQueue().remove(0);
four.setPrevProcCompTime(networkTime);
four.setPrevOrderType(four.getCurrOrderType());
}
else if (four.getQueue().get(0)== 'B') {
four.getQueue().remove(0);
four.setPrevProcCompTime(networkTime);
four.setPrevOrderType(four.getCurrOrderType());
}
}
}
}
public boolean isNwEmpty() {
if (one.isNodeEmpty() && two.isNodeEmpty() && three.isNodeEmpty() && fou
r.isNodeEmpty()) {
return true;
} else {
return false;
}
}
public void printNodeInfo() {
System.out.println("Time = " + networkTime);
System.out.println("One
: " + one.getQueue());
System.out.println("Two
: " + two.getQueue());
System.out.println("Three : " + three.getQueue());
System.out.println("Four
: " + four.getQueue());
System.out.println("========================");
}
}

You might also like