我尝试检查名为interLinks
和intraLinks
的Priority Queuue结构中的两种链接。根据下面的URLremoveCondition()
方法,如果我interLinks
intraLinks
,我会尝试从PQueue
删除所有这两种网址链接MaxWaitTime
和10 Seconds
将其设置为URLremoveCondition()
该方法将删除这些链接。
但问题是方法interLinks
仅从PQueue
中删除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);
}
}
<?php
// connects to the DB
include ('connectdb.php');
//query that gets the "trade_id" from the table with all the trades, where the "open_time" is older than 30 days, "close_price" is NULL.
$result = $db->query("SELECT trade_id FROM trades WHERE open_time < (NOW() - INTERVAL 30 DAYS) AND close_price IS NULL");
// create an array
$rows = array();
// loop through the table and drop the data into the array
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$rows[] = $row;
}
$count = count($rows);
$i = 0;
//loops through the table
while($i < $count){
//updates the table "orders" where the unique_ID matches the trade_ID, and will change the column "notified" to -1
$update = $db->prepare("UPDATE orders SET notified=? WHERE unique_id=$rows[$i]");
$update->execute(array(-1));
//updates the table "trades" where the trade_ID matches the trade_ID, and will change the column "close_price" to -1
$update2 = $db->prepare("UPDATE trades SET close_price=? WHERE trade_id=$rows[$i]");
$update2->execute(array(-1));
$i++;
}
// Closes connection
$db = null;
?>
答案 0 :(得分:0)
我通过为getter
生成setter
intraLinks
到LinkNodeLight
类来解决问题
protected boolean intraLinks;
public boolean isIntraLinks() {
return intraLinks;
}
public void setInterLinks(boolean interLinks) {
this.interLinks = interLinks;
}
public void setIntraLinks(boolean intraLinks) {
this.intraLinks = intraLinks;
}