Added 1-1 mapping.

deliverable_8
asdfasdf 6 years ago
parent 5e722ceba6
commit 08d7475257

@ -0,0 +1,43 @@
package data;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
public class DataSource {
private HashMap<String, StockType> targets;
private String name;
private String url;
private String apiKey;
private String defapi;
public DataSource(String name, String url, String apiKey, String defapi) {
this.name = name;
this.url = url;
this.apiKey = apiKey;
this.defapi = defapi;
}
//Effect: add target to this
// add this to target if not already done
//Modifies: this, stype
public void addStype(StockType stype) {
String sname = stype.getClass().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.getClass().getName();
if (this.targets.containsKey(sname)) {
targets.remove(sname,stype);
stype.delSource(this);
}
}
}

@ -24,9 +24,46 @@ public abstract class StockType {
return result; return result;
} }
//Effects: add source to this
// add this to source, if not already added
//Modifies: this, source
public void addSource(DataSource source) {
if (!this.sources.contains(source)) {
this.sources.add(source);
source.addStype(this);
}
}
//Effects: add source to this
// add this to source, if not already added
//Modifies: this, source
public void delSource(DataSource source) {
if (this.sources.contains(source)) {
this.sources.remove(source);
source.delStype(this);
}
}
//Effects: return name of type //Effects: return name of type
//Require: working sources //Require: working sources
public String getName() { public String getName() {
return this.name; return this.name;
} }
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof StockType)) {
return false;
}
StockType sobj = (StockType) obj;
return this.name.equals(sobj.getName());
}
@Override
public int hashCode() {
return Objects.hash(name);
}
} }

Loading…
Cancel
Save