i was looking some code of some GWT classes, and, shamefully, i was unable to understand this part of code:
private void toggleHover() {
// Toggle hovering.
int newFaceID = getCurrentFace().getFaceID() ^ HOVERING_ATTRIBUTE;
// Remove disabled.
newFaceID &= ~DISABLED_ATTRIBUTE;
setCurrentFace(newFaceID);
}
I do not know very well the java operators, so, my question is:
What exactly happens in:
a) getCurrentFace().getFaceID() ^ HOVERING_ATTRIBUTE
b) newFaceID &= ~DISABLED_ATTRIBUTE;
The & is a bitwise AND and ^ is a bitwise exclusive OR operator. This is all I knew about this. But, I dont understand the ~DISABLED_ATTRIBUTE and what happens in the assings of the values.
This piece of code is from GWT com.google.gwt.user.client.ui.CustomButton class.
Thanks in advance.
There must be a bit in the ID that is reserved for the hover status. The expression
getCurrentFace().getFaceID() ^ HOVERING_ATTRIBUTEappears to toggle the hovering attribute of the current face. In other words, if theHOVERING_ATTRIBUTEbit is one, it is set to zero; if it’s zero, it is set to one.Another bit must be the disabled status. The expression
newFaceID &= ~DISABLED_ATTRIBUTEclears this bit. That is, theDISABLED_ATTRIBUTEbit is set to zero.