I was just wondering which of these is faster to check the int values and set the boolean to the right value?
switch (type) {
case INCREASING:
if (currentVal >= duration) { done = true; }
break;
case DECREASING:
if (currentVal <= 0) { done = true; }
break;
default:
done = false;
break;
}
or
done = (type == INCREASING ? currentVal >= duration ? true : false : false) || (type == DECREASING ? currentVal <= 0 ? true : false : false);
with
public static final int INCREASING = 1;
public static final int DECREASING = -1;
private float currentVal;
private float duration; //is set in the constructur
private boolean done = false;
They both do the same in terms of what i want to achieve with it. I just thought the switch statement might be a little faster because it doesn't check everything? I like the advantage of having it in one line though so is the difference actually worth considering?