To keep things as simple as I can, I am trying to pass an ArrayList holding values used for a method in a separate class in my program. The issue is that whatever I tweak, the values held in retailerID and prodCat never seem to make it to the subscribe method in the other class as previously mentioned. Here is the snippet I am trying to overcome at the moment. Please ingore the commented out portions as those were previous attempts I've yet to get rid of.
public class SupplyDemand {
Producer nProducer = new Producer();
Retailer nRetailer = new Retailer();
Broker nBroker = new Broker();
ArrayList<String> output = new ArrayList<String>();
ArrayList<String> inputCommand = new ArrayList<String>();
/**
* Class constructor - you may set up any needed objects and data here. Specification of constructor is optional - it is acceptable if you leave it blank.
*/
public SupplyDemand() {
}
/**
* This method accepts a single command and carry out the instruction given. You do not need to (and probably shouldn't) do everything in this method - delegate responsibilities to other classes.
*/
public void processInput(String command) {
//command.toLowerCase();
//String str[] = command.split(",");
inputCommand.add(command.toLowerCase());
//inputCommand = Arrays.asList(str);
if(inputCommand.contains("subscribe")){
String retailerID = inputCommand.get(1);
String prodCat = inputCommand.get(2);
nRetailer.subscribe(retailerID, prodCat);
}
else if(inputCommand.contains("unsubscribe")){
String retailerID = inputCommand.get(1);
String prodCat = inputCommand.get(2);
nRetailer.unsubscribe(retailerID, prodCat);
}
else if(inputCommand.contains("publish")){
String producerID = inputCommand.get(1);
String prodCat = inputCommand.get(2);
String brand = inputCommand.get(3);
nProducer.publish(brand, prodCat, producerID);
nBroker.checkMatch();
}
else{
}
//nBroker.checkMatch();
}
/**
* After each round of execution, this method would be called to fetch all output lines, if there are any. The lines must be ordered by the time they are received.
*/
public ArrayList<String> getAggregatedOutput() {
output = nRetailer.subscribeList;
return output;
}
/**
* Finally, this method would be called to clear all saved information in the system, so that information from previous round would not be carried to next round. After calling this method the system should be effectively starting anew.
*/
public void reset() {
nRetailer.subscribeList.clear();
nProducer.producerList.clear();
nBroker.buildMatch.clear();
}
}
Here is the Retailer class with the subscribe method and how I need to use the needed strings if its any help.
public class Retailer implements ISubscriber {
public String retailerID = " ";
public ArrayList<String> subscribeList = new ArrayList<String>();
/*/**
* @see SupplyDemand.ISubscriber#subscribe(String)
*/
public void subscribe(String retailerID, String prodCat) {
subscribeList.add("TEST1");
if(retailerID.equals(" ")){
subscribeList.add(retailerID);
subscribeList.add(prodCat);
}
else{
subscribeList.add("TEST2");
}
}
/*/**
* @see SupplyDemand.ISubscriber#unsubscribe(String)
*/
public void unsubscribe(String retailerID, String prodCat) {
int removeRetailer = subscribeList.indexOf(retailerID);
int removeProdCat = subscribeList.indexOf(removeRetailer + 1);
subscribeList.remove(removeProdCat);
subscribeList.remove(removeRetailer);
}
}