No not ok.
In your code you are not comparing the values of the strings but the references to the string objects. Since your Java VM tries to save memory by storing identical strings only once in the string pool your program might work as expected but this is not guaranteed! Identical strings might reside twice on the heap and as a result have different reference values.
You should use the equals() method if you really need to compare the values of strings:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
// check the instrument, e.g. EURUSD
if (!instrument.name().equals(recentInstrument.name())) {
return;
}
// check the time period
if (!Period.ONE_MIN.name().equals(period.name())) {
return;
}
....
}
It's much better and faster however to compare the reference values of the ENUM objects directly.
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
// check the instrument, e.g. EURUSD
if (instrument != recentInstrument) {
return;
}
// check the time period
if (Period.ONE_MIN != period) {
return;
}
}