Could anyone please helpe me in understanding why my code could generate the following output?
Please note, that f is here for debug purpose, f[0]=(lastLine!=null) is just an equivalent to lastLine!=null test, so it is not the bug.
boolean f[] = new boolean[6];
if (f[0]=(lastLine!=null) // есть следующая строка
|| (f[1]=isEdgeTime) // конец сессии
|| (f[2]=td.getHour() <10) // или уже утро, после полуночи все свечки хороши
|| (f[3]=(td.getHour() == 23 && td.getMinute() >=50))
|| (f[4]=currServerHour > lineHour) // или час сменился
|| (f[5]=currServerMinutesPeriod > linesMinutesPeriod)
){
answer.append(classCode).append(".")
.append(TickerUtils.getRoot(ticker))
.append(";").append(minutes).append(";")
.append(line)
.append("\n");
System.out.println(Arrays.toString(f));
if (f[0])
System.out.printf("\"%s\" : %d, currServerMinute=%d; %d > %d\n", lastLine, (lastLine!=null? 1: 0), currServerMinute, currServerMinutesPeriod, linesMinutesPeriod);
line = lastLine;
}
output:
[true, false, false, false, false, true]
"null" : 0, currServerMinute=50; 10 > 9
that I can't understand is why "lastLine" is not null, as f[0]
is true and at the same time lastLine != null
gives me false, so it is null, actually, how this could be?
If looks like you are assigning to
f[0]
the following :Therefore
f[0]
can be true even thoughlastLine
is null.Try to change your condition to:
if you want
f[0]
to contain the value of(lastLine!=null)
.This will take care of the value of
f[0]
. However, iff[i]
is true for anyi
,f[i+1]
won't be evaluated due to short circuit evaluation of the||
condition, so you'll always have at most onetrue
value in thef
array. I'm not sure if that's what you want.