从另一个文件调用时,一组字符串不保存数据
我有两个类文件,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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 while 循环没有执行。
如果队列为空怎么办?你能说出该属性设置在哪里吗?
It seems while loop is not executing.
what if the queue is empty ? Can you tell where that property is set ?