BooleanToYes and booleanToOn



  •  I just found these methods, one after the other, in some code I have been forced to work with. Where is FILE_NOT_FOUND?

         /*
         * Convert boolean to YES/NO.
         * @param b TRUE/FALSE
         * @return YES/NO.
         /
        protected static String booleanToYes( Boolean b )
        {
            if ( b == null )
            {
                return null;
            }
            if ( b.booleanValue() )
            {
                return DTComponentOptions.YES;
            }
            return DTComponentOptions.NO;
        }

        /

         * Convert boolean to on/off
         * @param b TRUE/FALSE
         * @return ON/OFF
         */
        protected static String booleanToOn( Boolean b )
        {
            if ( b == null )
            {
                return null;
            }
            if ( b.booleanValue() )
            {
                return DTComponentOptions.ON;
            }
            return DTComponentOptions.OFF;
        }



  • @MatDeLong said:

    Where is FILE_NOT_FOUND?

    Look, it's right there:

    @MatDeLong said:

            if ( b == null )
            {
                return null;
            }

    Of course, DTComponentOptions should have a FILE_NOT_FOUND constant that is simply null for that matter (if that is even possible; I'm thinking Ruby here). But nobody's perfect.



  • OK - so what is the WTF?  The code looks reasonable...The biggest problem I see is with the "Boolean" class...but that doesn't appear to be the subject of your ire!



  •  The "Yes/No" and the "On/Off" are used only in places where a Boolean would be just as reasonable.



  • True.  But there is no indication of where the values are actually being used.  If the values returned are used by a 3-rd party library, the coder would have no choice but to use the predefined values.



  •  Yeah, I could have been more specific... this is all in-house code, sadly.



  • TRWTF is Java's type system.


Log in to reply
 

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