|
|
|
@ -44,12 +44,13 @@ public class WatchList extends Observable implements Load,Save {
|
|
|
|
if (!listdata.containsKey(target)) {
|
|
|
|
if (!listdata.containsKey(target)) {
|
|
|
|
throw new StockNotExistsException();
|
|
|
|
throw new StockNotExistsException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int index = new ArrayList(listdata.keySet()).indexOf(target);
|
|
|
|
int index = new ArrayList(listdata.keySet()).indexOf(target);
|
|
|
|
this.listdata.remove(target);
|
|
|
|
this.listdata.remove(target);
|
|
|
|
setChanged();
|
|
|
|
setChanged();
|
|
|
|
notifyObservers(new Wevent(Etype.DEL, index));
|
|
|
|
notifyObservers(new Wevent(Etype.DEL, index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Effects: return an array of all Stock names in list
|
|
|
|
public String[] getNames() {
|
|
|
|
public String[] getNames() {
|
|
|
|
return listdata.keySet().toArray(new String[0]);
|
|
|
|
return listdata.keySet().toArray(new String[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -61,6 +62,7 @@ public class WatchList extends Observable implements Load,Save {
|
|
|
|
return entryset.iterator();
|
|
|
|
return entryset.iterator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Effects: return a stockentry given its index
|
|
|
|
public StockEntry getStock(int index) {
|
|
|
|
public StockEntry getStock(int index) {
|
|
|
|
String key = (String) listdata.keySet().toArray()[index];
|
|
|
|
String key = (String) listdata.keySet().toArray()[index];
|
|
|
|
return (StockEntry) listdata.get(key);
|
|
|
|
return (StockEntry) listdata.get(key);
|
|
|
|
@ -71,6 +73,7 @@ public class WatchList extends Observable implements Load,Save {
|
|
|
|
return listdata.size();
|
|
|
|
return listdata.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Effect: save list to a file, save to DEFAULT_SAVEFILE if filename is empty
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void save(String filename) {
|
|
|
|
public void save(String filename) {
|
|
|
|
if (filename.equals("")) {
|
|
|
|
if (filename.equals("")) {
|
|
|
|
@ -93,12 +96,15 @@ public class WatchList extends Observable implements Load,Save {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Effect: return true if filename exists and is a file
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean fileExists(String filename) {
|
|
|
|
public boolean fileExists(String filename) {
|
|
|
|
File fileObj = new File(filename);
|
|
|
|
File fileObj = new File(filename);
|
|
|
|
return fileObj.isFile();
|
|
|
|
return fileObj.isFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Effect: load list from file, load from DEFAULT_SAVEFILE if filename is empty
|
|
|
|
|
|
|
|
//Modifies: this
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void load(String filename) {
|
|
|
|
public void load(String filename) {
|
|
|
|
if (filename.equals("")) {
|
|
|
|
if (filename.equals("")) {
|
|
|
|
@ -120,6 +126,8 @@ public class WatchList extends Observable implements Load,Save {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Effect: perform price and %update for @ stockentry in list
|
|
|
|
|
|
|
|
//Modifies: this, stockentries
|
|
|
|
public void updateList() {
|
|
|
|
public void updateList() {
|
|
|
|
Iterator watchit = iterator();
|
|
|
|
Iterator watchit = iterator();
|
|
|
|
boolean changed = false;
|
|
|
|
boolean changed = false;
|
|
|
|
|