从另一个文件调用时,一组字符串不保存数据

发布于 2025-01-02 06:36:48 字数 2004 浏览 3 评论 0原文

我有两个类文件,GraphBFS 和 FriendRec(它是 GraphBFS 的扩展)。我在 GraphBFS 中有这个方法(getNodesAtDepth),如下所示,在 FriendRec 中有一个名为 getFriendRecommendations,也包括在下面。当在 getNodesAtDepth 中创建节点列表时,它会按预期工作并包含应有的所有字符串;但是,当在 getFriendRecommendations 中调用它时,它是空的并且什么也没有。有人知道发生了什么事吗?

public Set<String> getNodesAtDepth(int depths) {
    Set<String> ret = new HashSet<String>();        
    setInitialNode(initNode);
    while (!queue.isEmpty()) {
        String node = fetchFromQueue();
        setExploredNode(node);
        if(depths<depth.get(node)){
            break;
        }
        if(depth.get(node)==depths){
            ret.add(node);
        }
        Set<String> neighbors = graph.getNeighbors(node);
        for (String n : neighbors) {
            if (status.get(n) == null) {
                System.out.println("Node" + n);
                setFrontierNode(n);
                depth.put(n, (depth.get(node)+1));
                addToQueue(n);
                //ret.add(n);
            }
        }
    }
    System.out.println("Nodes at Depth Level" + depths + ":");
    System.out.println(ret.toString());

    return ret;
}

public List<Recommendation> getFriendRecommendationsInRankOrder(String node, int threshold) {
    List<Recommendation> recs = new ArrayList<Recommendation>();
    Set<String> friendsOfFriends = getNodesAtDepth(2);
    System.out.println("Geoffroy:" + getNodesAtDepth(2).toString());
    System.out.println("Blank Number" +friendsOfFriends.size());
    for (String n: friendsOfFriends){
        System.out.println("Support = "+getSupportFor(n));
        if(getSupportFor(n)>=threshold){
            System.out.println("BRANKKK");              
            Recommendation recTemp = new Recommendation(n,getSupportFor(n));
            recs.add(recTemp);
        }
    }
    System.out.print("t");
    // Now sort in reverse order of support
    Collections.sort(recs, Collections.reverseOrder());
    return recs;
}

I have two class files, GraphBFS and FriendRec (which is an extension of GraphBFS). I have this method(getNodesAtDepth) within GraphBFS, included below, and one in FriendRec called getFriendRecommendations, also included below. When the list of nodes is created in getNodesAtDepth, it works as expected and includes all of the strings it should; however, when it is called in getFriendRecommendations, it is empty and has nothing there. Anyone have an idea what is going on?

public Set<String> getNodesAtDepth(int depths) {
    Set<String> ret = new HashSet<String>();        
    setInitialNode(initNode);
    while (!queue.isEmpty()) {
        String node = fetchFromQueue();
        setExploredNode(node);
        if(depths<depth.get(node)){
            break;
        }
        if(depth.get(node)==depths){
            ret.add(node);
        }
        Set<String> neighbors = graph.getNeighbors(node);
        for (String n : neighbors) {
            if (status.get(n) == null) {
                System.out.println("Node" + n);
                setFrontierNode(n);
                depth.put(n, (depth.get(node)+1));
                addToQueue(n);
                //ret.add(n);
            }
        }
    }
    System.out.println("Nodes at Depth Level" + depths + ":");
    System.out.println(ret.toString());

    return ret;
}

public List<Recommendation> getFriendRecommendationsInRankOrder(String node, int threshold) {
    List<Recommendation> recs = new ArrayList<Recommendation>();
    Set<String> friendsOfFriends = getNodesAtDepth(2);
    System.out.println("Geoffroy:" + getNodesAtDepth(2).toString());
    System.out.println("Blank Number" +friendsOfFriends.size());
    for (String n: friendsOfFriends){
        System.out.println("Support = "+getSupportFor(n));
        if(getSupportFor(n)>=threshold){
            System.out.println("BRANKKK");              
            Recommendation recTemp = new Recommendation(n,getSupportFor(n));
            recs.add(recTemp);
        }
    }
    System.out.print("t");
    // Now sort in reverse order of support
    Collections.sort(recs, Collections.reverseOrder());
    return recs;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

通知家属抬走 2025-01-09 06:36:48

看起来 while 循环没有执行。

while (!queue.isEmpty())

如果队列为空怎么办?你能说出该属性设置在哪里吗?

It seems while loop is not executing.

while (!queue.isEmpty())

what if the queue is empty ? Can you tell where that property is set ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文