将返回值传递给两种不同的方法

时间:2017-11-28 13:33:27

标签: java dictionary

我有一个有两个方法的类:startAPI()调用API类来提取实体并返回实体和实体的出现。我需要在另一个类的两个不同方法中返回这个值,但是一旦我调用第二个方法(countApiOcc()),我传递的地图就是空的。如何以两种不同的方法使用返回的地图?

public class Topic {

    public void calculateNoFeedback(String language, List<String> api, List<String> corr) {
        Map<String, Object> apis = startAPI(api, textList);
        CountTopics countT = new CountTopics();
        ArrayList<String> topics = countT.getTopics(apis);
        countT.countApiOcc(topics, apis);
    }

    public Map<String, Object> startAPI(List<String> selectedAPI, List<String> text) {
        Map<String, Object> apisValues = new HashMap<String, Object>();
        //do stuff to extract the entities and return entities
        return apisValues;
    }
}

CountTopic()类如下所示,简而言之,用户可以选择要用于提取实体的API或在类CountTopic()中使用方法getTopics() }应该找到每个选定API的主题,countApiOcc()我需要所选实体的频率(所有这些都有效),它只是我在第二种方法中需要的地图。

public  ArrayList<String> getTopics(Map<String, Object> apiV) {
System.out.println("apiV: "+apiV);
        Iterator iterator = apiV.entrySet().iterator();
        mapSize = apiV.size();
        System.out.println("Size of the map: "+ mapSize);

        while (iterator.hasNext()) {
            Map.Entry entries = (Map.Entry)iterator.next();

            String key = entries.getKey().toString();

            switch(key) {

            case "valuesMS":
                Map<String, Object> mapMicrosoft = (Map<String, Object>) apiV.get(key);
                ArrayList<String> microsoft = (ArrayList<String>) mapMicrosoft.get("topicArrayMS");

                microsoftTopicLowerCase.addAll(microsoft);
                topicsMultiset.addAll(microsoft);

                break;

            case "valuesGate":
                Map<String, Object> mapGate = (Map<String, Object>) apiV.get(key);
                ArrayList<String> gate = (ArrayList<String>) mapGate.get("topicArrayGA");

                //store the values for finding the topics which are found from every selected API
                //store the values from the api to lower case to find the index later (needed for how often this api found the topic
                gateTopicLowerCase.addAll(gate);
                topicsMultiset.addAll(gate);

                break;  
            }

            iterator.remove(); 
        }

//rest code: compare the Arrays to find the same topics

0 个答案:

没有答案