Need help to interpret the code

M

mike

Hi,

I found the following code ( see below) I need help to understand what
it does:

boolean newIsSymbolicLink = newState.isLink();
changed |= newIsSymbolicLink != this.isSymbolicLink();
setFlag(SYM_LINK, newIsSymbolicLink);


/**
* @return
*/
public boolean isSymbolicLink() {
return getFlag(SYM_LINK);
}

public boolean isLink() {
return 0 != (state & ClearCase.LINK);
}

All help appreciated for a novice :)

//mike
 
M

Mark Space

mike said:
public boolean isSymbolicLink() {
return getFlag(SYM_LINK);

This is pretty easy, it returns whatever getFlag() returns.
}

public boolean isLink() {
return 0 != (state & ClearCase.LINK);


"state" here is likely an int, with several "bits" indicating different
things. Probably one bit is the "link" bit. Let's say it's bit 3 (4th
from the right.) So ClearCase.LINK would then be 8, and "state &
ClearCase.LINK" would mask off all bits except that one.

Then the result compared with 0. If the result is 0, then the != part
returns false. If the result is 8 (which it would be if bit 3 was set),
then the result is "0 != 8" which is true.

We'd need some more info on the exact value of ClearCase.LINK and how
"state" is manipulated to be more explicit. You should be able to
follow that example and figure the rest out on your own though. The
others are just like it.
 
K

Knute Johnson

mike said:
Hi,

I found the following code ( see below) I need help to understand what
it does:

boolean newIsSymbolicLink = newState.isLink();

newIsSymbolicLink is set to the value returned by newState.isLink()
changed |= newIsSymbolicLink != this.isSymbolicLink();

newIsSymbolicLink is compared with isSymbolicLink() for inequality, then
the result is or'd with changed and that value is then assigned to changed

changed before newIsSymbolicLink isSymbolicLink() changed after
false false false false
false false true true
false true false true
false true true false
true doesn't matter doesn't matter true
setFlag(SYM_LINK, newIsSymbolicLink);


/**
* @return
*/
public boolean isSymbolicLink() {
return getFlag(SYM_LINK);
}

public boolean isLink() {
return 0 != (state & ClearCase.LINK);

state is or'd with ClearCase.LINK, that value is compared for inequality
with 0 and the result is returned.
}

All help appreciated for a novice :)

//mike

Is that what you were looking for?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top