Reputation: 1577
I wrote following code fragment with loop.But when Variable 'X' given always 'false' in IDEA , this line
final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail) || X)
;
I need some explain it is not necessary put that or condition there.
boolean isFirstDose = true;
boolean isFirstDoseIsPeriodicOrWholePRNOrEoOrOneOff = false;
for (final DDT: dd)
{
final boolean X=
DosageToolkit.INSTANCE.hasEOTypeDosage(new DoseDetailMutableDTOToBaseDoseDetailAdapter(dd));
final boolean isOneOffDose = CommonToolkit.INSTANCE.isOneOffDose(dd);
if (dd.isWholeWhenNeeded() || X|| isOneOffDose)
{
if (isFirstDose)
{
isFirstDoseIsPeriodicOrWholePRNOrEoOrOneOff=true;
isFirstDose = false;
}
continue;
}
final List<DIT> doseInstances =
new ArrayList<DIT>(dd.getDoseInstances());
Collections.sort(doseInstances, CommonToolkit.INSTANCE.getDoseInstanceComparator());
final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail) || X);
for (final DITdoseInstance : doseInstances)
{
}
Upvotes: 0
Views: 103
Reputation: 2220
Look, you verify X
two times and both times is using ||
operator.
If X
is true then first condition will be met and loop will continue to next iteration.
It means that when you verify X
at final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail) || X);
then it is always false because if it is true then execution cannot reach this point.
IDEA suggests you simplify to final boolean isCurrentDoseIsPeriodicOrEO = (CommonToolkit.INSTANCE.isPeriodicDosage(doseDetail));
Upvotes: 2