You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.7 KiB
70 lines
1.7 KiB
package data;
|
|
|
|
import java.util.Set;
|
|
import java.util.Map;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Objects;
|
|
|
|
public abstract class DataSource {
|
|
protected HashMap<String, StockType> targets;
|
|
protected String name;
|
|
protected String url;
|
|
protected String apiKey;
|
|
|
|
public DataSource(String name, String url, String apiKey) {
|
|
this.targets = new HashMap<String, StockType>();
|
|
this.name = name;
|
|
this.url = url;
|
|
this.apiKey = apiKey;
|
|
}
|
|
|
|
//Effect: add target to this
|
|
// add this to target if not already done
|
|
//Modifies: this, stype
|
|
public void addStype(StockType stype) {
|
|
String sname = stype.getName();
|
|
if (!this.targets.containsKey(sname)) {
|
|
targets.put(sname,stype);
|
|
stype.addSource(this);
|
|
}
|
|
}
|
|
|
|
//Effect: del target to this
|
|
// del this to target if not already done
|
|
//Modifies: this, stype
|
|
public void delStype(StockType stype) {
|
|
String sname = stype.getName();
|
|
if (this.targets.containsKey(sname)) {
|
|
targets.remove(sname,stype);
|
|
stype.delSource(this);
|
|
}
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (obj == this) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof DataSource)) {
|
|
return false;
|
|
}
|
|
DataSource temp = (DataSource) obj;
|
|
if (temp.getName().equals(name)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(name);
|
|
}
|
|
|
|
public abstract double[] update(String stype, String idstring);
|
|
}
|