hi ! There two classes
Node.java
DataPacket.java
The problem is I can't compare the field of the passed object "dp" with the field of the stored dataPacket, data packets are stored in the ArrayList "dataPackets". At the end I add also the full code for the Node class.
the Node.java contains the following method
public void acceptDPacket(DataPacket dp){ boolean packetHere; for (int j = 0; j < dataPackets.size(); j++) { if (dp.getSeqNo() = dataPackets[j].getSeqNo()){ packetHere = true; break; } } if (packetHere = true){ } else dataPackets.add(dp); }
public class DataPacket { private Node dest; private Node source; private int seqNo; private String content; public DataPacket(String cont, Node dest, Node src) { this.content = cont; this.dest = dest; this.source = src; } public int getSeqNo(){ return seqNo; } public String getContent(){ return content; } }
import java.util.ArrayList; public class Node extends Thread{ // constants initialization final int MAP_LENGTH = 1000; final int MAP_WIDTH = 1000; private int x = 0; private int y = 0; private int node_id; ArrayList<DataPacket> dataPackets = new ArrayList<DataPacket>(); //node_id = thread's name public Node(String node_id) { super(node_id); this.x = (int) (MAP_LENGTH * Math.random()); this.y = (int) (MAP_WIDTH * Math.random()); } public void run(){ System.out.println("Inside of node"+getNodeId()+" thread!"); } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } public int getNodeId() { return this.node_id; } public void setNodeId(int nid){ this.node_id = nid; } public void acceptDPacket(DataPacket dp){ boolean packetHere; for (int j = 0; j < dataPackets.size(); j++) { if (dp.getSeqNo() = dataPackets[j].getSeqNo()){ packetHere = true; break; } } if (packetHere = true){ } else dataPackets.add(dp); } }