-1
我嘗試檢查名爲interLinks
和intraLinks
的Priority Queuue結構中的兩種鏈接。根據下面的方法URLremoveCondition()
,我試圖從我的PQueue
中刪除所有這兩種URL鏈接interLinks
和intraLinks
,如果它們達到了MaxWaitTime
,我將它設置爲10 Seconds
該方法將刪除這些鏈接。根據某些條件從PriorityQueue刪除不同類型的項目
但問題是,該方法URLremoveCondition()
從PQueue
僅interLinks
刪除和不刪除intraLinks
。我如何解決這個問題,以刪除interLinks
和intraLinks
?
這是我的方法URLremoveCondition()
public static PriorityQueue <LinkNodeLight> PQueue = new PriorityQueue <>();
private static Integer MaxWaitTime = new Integer (10000); // 10 Seconds
public void URLremoveCondition() {
synchronized (PQueue) {
Iterator<LinkNodeLight> iterator = PQueue.iterator();
while(iterator.hasNext()){
LinkNodeLight URL = iterator.next();
long URLWaitingTime = System.currentTimeMillis() - URL.enqueTime.getMillis();
if(URLWaitingTime > MaxWaitTime){
iterator.remove();
System.out.println("DELETED NODE: " + URL.url + " WAITTIME: " + Long.toString(URLWaitingTime));
}
}
}
}
,這是我LinkNodeLight
類:
import org.joda.time.DateTime;
public class LinkNodeLight implements Comparable<LinkNodeLight> {
protected String url;
protected float weight;
protected DateTime enqueTime;
protected boolean interLinks;
public String getUrl() {
return url;
}
public float getWeight() {
return weight;
}
public void setWeight(float weight) {
this.weight = weight;
}
public DateTime getEnqueTime() {
return enqueTime;
}
public LinkNodeLight(String url) {
this.url = url;
}
public boolean isInterLinks() {
return interLinks;
}
public void setInterLinks(boolean interLinks) {
this.interLinks = interLinks;
}
public void setEnqueTime(DateTime enqueTime) {
this.enqueTime = enqueTime;
}
@Override
public int compareTo(LinkNodeLight link) {
if (this.weight < link.weight) return 1;
else if (this.weight > link.weight) return -1;
return 0;
}
}
編輯:
在這裏,我創建interLinks
和intraLinks
import java.util.LinkedList;
import java.util.List;
public class URLWeight {
public static List<LinkNodeLight> weight(LinkNode sourceLink, List<LinkNodeLight> links) {
List<LinkNodeLight> interLinks = new LinkedList<>();
List<LinkNodeLight> intraLinks = new LinkedList<>();
for (LinkNodeLight link : links) {
if (isIntraLink(sourceLink, link)) {
intraLinks.add(link);
link.setInterLinks(false);
} else {
interLinks.add(link);
link.setInterLinks(true);
}
}
在哪裏,你如何創建列表? – nautical
您提供的代碼中沒有任何內容根據它們的'interLinks'屬性的值區分'LinkNodeLight'實例,所以我傾向於不相信它中的任何一個對您所觀察到的行爲負責。如果您需要幫助,請發佈[MCVE](http://stackoverflow.com/help/mcve)。 –
@nautical我在URLWeight.java內創建列表我將編輯問題並添加關於代碼 – medo0070