Почему я не могу передать эти значения ArrayList в другой метод в качестве параметров? - PullRequest
0 голосов
/ 29 апреля 2020

Чтобы все было как можно проще, я пытаюсь передать значения ArrayList, используемые для метода, в отдельный класс в моей программе. Проблема в том, что, что бы я ни настраивал, значения, хранящиеся в retailerID и prodCat, никогда, кажется, никогда не попадают в метод подписки в другом классе, как упоминалось ранее. Вот фрагмент, который я сейчас пытаюсь преодолеть. Пожалуйста, следите за закомментированными частями, поскольку это были предыдущие попытки, от которых я еще не избавился.

publi c 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();

}

}

Здесь класс Retailer с методом подписки и как мне нужно использовать необходимые строки, если это поможет.

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);
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...