I have learned java from two month but it's hard.
I'm trying to figure out how to code collecting of all objects in one list and then filling specific objects in another list. I have to ask you for help.
I wrote something like this:
public class Alarm implements IStrategy {
//containers
private List<AlarmLine> lineList;
private List<IChartObject> chartObjectList;
private Iterator<IChartObject> chartObjectIterator;
private Iterator<AlarmLine> alarmLineIterator;
//Other data
....
}
AlarmLine is my extended interface like this:
public interface AlarmLine extends IHorizontalLineChartObject{
public enum AlarmDirection {
UP,
DOWN,
DISABLED
};
Then in onStart I'm filling list in line 20:
@Override
public void onStart(IContext context) throws JFException {
// TODO Auto-generated method stub
this.context = context;
this.chart = context.getChart(this.instrument);
this.console = context.getConsole();
this.history = context.getHistory();
this.formerTick = history.getLastTick(this.instrument);
if(this.chart == null) {
console.getErr().println("No chart opened for " + this.instrument);
context.stop(); //stop the strategy
}
if(this.chart.getAll().size()>0) {
this.startObjectCount = chart.getAll().size();
this.objectCount = this.startObjectCount;
//fill the list
this.chartObjectList.addAll(chart.getAll());
}
//ITick tick = history.getLastTick(this.instrument);
if(this.chartObjectList.isEmpty()) {
console.getWarn().println("Add objects on chart!");
}
}
And then onTick but I don't know how to search all objects IChartObject in chartObjectList and copy AlarmLine objects to lineList. I wrote something like this in the line 20 below but it doesn't work and it's stupid but I have no idea
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {
// get number of objects and if it's changed clear both lists
objectCount = chart.getAll().size();
if(objectCount != startObjectCount) {
if(lineList.size() != 0 && chartObjectList.size() != 0) {
lineList.clear();
chartObjectList.clear();
}
if(chart.getAll().size()>0) {
startObjectCount = chart.getAll().size();
objectCount = startObjectCount;
//fill the list again
chartObjectList.addAll(chart.getAll());
}
for(chartObjectIterator = chartObjectList.iterator(); chartObjectIterator.hasNext();) {
//comparing all objects
if(chartObjectList.iterator() == IHorizontalLine) {
lineList.add(chartObjectList.iterator());
}
}
startObjectCount = objectCount;
}
}
Anyway I want to select from chartObjectList objects of IHorizontalLine type. Do you have any suggestions?