Is it possible to simplify this?
public void setDisabled(boolean disabled) {
if(disabled)
this._rflags |= 1 << B1;
else
this._rflags &= ~(1 << B1);
}
It sets 1 bit of a byte (B1 = 2)
-edit-
Important info i missed
private char _rflags;
public static final char B1 = 1 << 2;
I wanted to keep it as a char and access single or multiple bits as different types because the data comes from C structs with unions. I will also be sending this data back over UDP.
There's no real tidy way to make it shorter in Java. If you're going to repeat it, I'd say stick to the DRY principle and just put it in another method.
public void setDisabled(final boolean disabled) {
toggleFlag(B1, disabled);
}
private void toggleFlag(final int bit, final boolean on) {
if (on)
this._rflags |= 1 << bit;
else
this._rflags &= ~(1 << bit);
}