Stop me if you've heard this before...



  • I have vague recollections of posting this already. If I have, I'm sorry, but I'm going to do it again, because I can, and because I ran into it again and it made me a smidge angry.

    If it is new, well, once again, welcome to my nightmare...

    private boolean booleanValue = false;
    

    private boolean booleanvalue = null;

    public boolean isBooleanValue() {

    return booleanValue;

    }

    public void setValue(boolean booleanValue) {

    this.booleanValue = newValue;

    }

    public String getValueAsString() {

    if (booleanValue != false ) {

    booleanvalue = "T";
    

    }

    return booleanvalue;

    }

    public void setValue(String booleanvalue) {

    this.booleanvalue = booleanvalue;

    if ( booleanvalue != null ) {

    if ( booleanvalue.trim().toUpperCase().equals("T") ) {
    
      this.booleanValue = true;
    
    } else {
    
      this.booleanValue = false;
    
    }
    

    }

    }

    I didn't feel like typing in the comments because, as you may have guessed, they're about equally useless as the WTF code.

    Note:

    • if you use the class 'correctly', getValueAsString() will only ever return null and "T" and will only return "T" if booleanValue is set to not false (i.e., true)
    • setValue(boolean) doesn't synchronize the value of the String version of the value
    • setValue(String) doesn't trim or otherwise normalize the input which is ultimately stored in the String booleanvalue, so it is left up to the user of this class to do that when they use getValueAsString() after it is set to "Albuquerque!!!!111oneone     "
    • seriously? two variables to manage one flag?


  • This is indeed one big collection of wtf's. Don't even know where to start....

    @zelmak said:

    public boolean isBooleanValue() {

    return booleanValue;

    }

    isBooleanValue??? WTF?

    More unit tests are needed. More black box testing, more white box testing, more management, more integration testing, more more more. I'm pretty sure that will solve all -our- IT problems, and if not, more testing! yay.[/cynism]



  • @Weps said:

    This is indeed one big collection of wtf's. Don't even know where to start....

    @zelmak said:

    public boolean isBooleanValue() { return booleanValue; }

    isBooleanValue??? WTF?

    More unit tests are needed. More black box testing, more white box testing, more management, more integration testing, more more more. I'm pretty sure that will solve all -our- IT problems, and if not, more testing! yay.[/cynism]

    Well, of course I anonymized it from the original variable name ... but other than that, its all there ... getter/setter 'bean patterns' ... mentally replace booleanvalue/booleanValue with flagSet and I guess it is more understandable.

    Perhaps I over anonymized ...



  • @zelmak said:

    @Weps said:

    This is indeed one big collection of wtf's. Don't even know where to start....

    @zelmak said:

    public boolean isBooleanValue() { return booleanValue; }

    isBooleanValue??? WTF?

    More unit tests are needed. More black box testing, more white box testing, more management, more integration testing, more more more. I'm pretty sure that will solve all -our- IT problems, and if not, more testing! yay.[/cynism]

    Well, of course I anonymized it from the original variable name ... but other than that, its all there ... getter/setter 'bean patterns' ... mentally replace booleanvalue/booleanValue with flagSet and I guess it is more understandable.

    Perhaps I over anonymized ...

    Ah no you didn't. Wasn't referring to you, but to the code. Having a class that holds a boolean value (or two lol) and then providing a function that answers  "are you a boolean value?"....

     Unless "isbooleanvalue" is meant to do something else. And in that case it's a wtf too ;)



  • @Weps said:

    Ah no you didn't. Wasn't referring to you, but to the code. Having a class that holds a boolean value (or two lol) and then providing a function that answers  "are you a boolean value?"....

     Unless "isbooleanvalue" is meant to do something else. And in that case it's a wtf too ;)

    Yeah, that would be one of the mental replacements:

    public boolean isFlagSet() {
        return flagSet;
    }

    Sorry for the confusion.



  • @zelmak said:

    @Weps said:

    Ah no you didn't. Wasn't referring to you, but to the code. Having a class that holds a boolean value (or two lol) and then providing a function that answers  "are you a boolean value?"....

     Unless "isbooleanvalue" is meant to do something else. And in that case it's a wtf too ;)

    Yeah, that would be one of the mental replacements:

    public boolean isFlagSet() {
        return flagSet;
    }

    Sorry for the confusion.

    See, isFlagset is also a wtf ;)



  • @zelmak said:

    Perhaps I over anonymized ...

    It seems you mistyped booleanvalue as a boolean instead of a String.



  • @zelmak said:

    public void setValue(boolean booleanValue) {

    this.booleanValue = newValue;

    }

    Huh?



  • @PJH said:

    @zelmak said:
    public void setValue(boolean booleanValue) {

    this.booleanValue = newValue;

    }

    Huh?

    Yeah, "this" is completely unnecessary.



  • @zelmak said:

    Perhaps I over anonymized ...

    For one thing, if this is Java, it won't compile, so in that case you would indeed have over-anonymised.

     



  • You missed the obvious one:

    setValue(False);

    getValueAsString(); => None

    setValue(True);

    getValueAsString(); => "T"

    setValue(False);

    getValueAsString(); => "T"



    It's awesome. It's a latching boolean. I want this in my code base.



  • @zelmak said:


    private boolean booleanValue = false;

    private String booleanvalue = null;

    //Check to see if booleanValue is set to true or false
    public boolean isBooleanValue() {
    return booleanValue;
    }

    //Set booleanValue to new value
    public void setValue(boolean booleanValue) {
    this.booleanValue = booleanValue;
    }

    //Return "T" if booleanValue is not false, otherwise does exactly what you would expect
    public String getValueAsString() {
    if (booleanValue != false ) {
    booleanvalue = "T";
    }
    return booleanvalue;
    }

    //Set booleanvalue to new value
    public void setValue(String booleanvalue) {
    this.booleanvalue = booleanvalue;
    if ( booleanvalue != null ) {
    if ( booleanvalue.trim().toUpperCase().equals("T") ) {
    this.booleanValue = true;
    } else {
    this.booleanValue = false;
    }
    }
    }

    FTFY


  • @airdrik said:

    @zelmak said:
    private boolean booleanValue = false;

    private String booleanvalue = null;

    //Check to see if booleanValue is set to true or false
    public boolean isBooleanValue() {
    return booleanValue;
    }

    //Set booleanValue to new value
    public void setValue(boolean booleanValue) {
    this.booleanValue = booleanValue;
    }

    //Return "T" if booleanValue is not false, otherwise does exactly what you would expect
    public String getValueAsString() {
    if (booleanValue != false ) {
    booleanvalue = "T";
    }
    return booleanvalue;
    }

    //Set booleanvalue to new value
    public void setValue(String booleanvalue) {
    this.booleanvalue = booleanvalue;
    if ( booleanvalue != null ) {
    if ( booleanvalue.trim().toUpperCase().equals("T") ) {
    this.booleanValue = true;
    } else {
    this.booleanValue = false;
    }
    }
    }

    FTFY

    oops ... I'm not allowed to have development tools on my internet-facing computer, so I can't test my re-types ...

    Sorry.

    What airdrik has here is what should have ultimately been the WTF ...



  • @Daid said:

    You missed the obvious one:
    setValue(False);
    getValueAsString(); => None
    setValue(True);
    getValueAsString(); => "T"
    setValue(False);
    getValueAsString(); => "T"

    It's awesome. It's a latching boolean. I want this in my code base.

    setValue("Albuquerque!!!111oneone     ");

    isBooleanValue() / isFlagSet() == false



  • @zelmak said:

    setValue(String) doesn't trim or otherwise normalize the input which is ultimately stored in the String booleanvalue, so it is left up to the user of this class to do that when they use getValueAsString() after it is set to "Albuquerque!!!!111oneone     "
     

    ...a magical, far away place where the sun is always shining, and the air smells like warm root beer, and the towels are oh so fluffy!  Where the shriners and the lepers play their ukuleles all day long, and anyone on the street will glady shave your back for a nickel!

     


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.