DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Mark Guest

    Difficult "if" statement

    Hello all:

    I've inherited 6000 lines of code. I'm only 1 month old into Java - and
    things have been going quite well. Unfortunately, this little if statement
    has got me stumped. This particular part of the code is reading an HTML
    template. Can anyone offer some insight into lines 6 and 7?

    The if statement goes like this...

    1 //logoPicName = "http://images.inspec.com/" +
    2 //convertToRelativePath(rs.getString("LogoPath").replace
    3 //('\\', '/'));
    5 if ("$ClientLogo".equals(insert)) {
    6 replacement = null==logoPicName || "".equals(logoPicName.trim
    7 ()) ? " " : "<IMG SRC=\"" + logoPicName + "\" ALIGN=center>";
    8 ...
    9 //lots of else ifs...
    10 }

    Some questions that come to mind are...
    1. What is the question mark for? It is not the ?: operator is it?
    2. This is the biggest part of my question, I cannot figure out where the
    double-quotes begin and end (in several places) to make the syntax make sense.
    3. The following syntax is elusive "replacement = null==logoPicName". null==logoPicName
    seems like an odd statement.

    Thanks for your help and have a great July 4th weekend!


  2. #2
    Eric L Guest

    Re: Difficult "if" statement

    >5 if ("$ClientLogo".equals(insert)) {
    >6 replacement = null==logoPicName || "".equals(logoPicName.trim()) ? "

    " : "<IMG SRC=\"" + logoPicName + "\" ALIGN=center>";

    Ugly code, but I'll give it a shot.

    First, replacement is a String variable, and it is being assigned the HTML
    tag of the logoPicName.

    The ? operator is definatly being used. || is the short-circuit-or operator.
    logoPicName is also a String variable.

    So, if logoPicName==null, or logoPicName has not been set to a string, or

    ".equals(logoPicName.trim()). "" indicates an empty string. String.trim
    removes all leading and trailing spaces in a string. This line checks to
    see if there is anything in the logoPicName variable.

    So, as far as I can understand it, this if statement checks to see if logoPicName
    is null, or an empty string, and sets Replacement to " " if true else set
    Replacement to the <IMG SCR> tag.

    This is my best guess. It is ugly code for a beginner to look at.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.