Results 1 to 6 of 6

Thread: how to combine two if statements

  1. #1
    Join Date
    Sep 2012
    Beans
    8

    Lightbulb how to combine two if statements

    if (timedSyllables.size() > 0) {
    if (timedSyllables.get(0).getMilliSeconds() <= nowMs) {
    timedHighlightText = timedSyllables.get(0)
    .getSyllable().trim();
    if( !timedHighlightText.equals( MainConstants.STRINDEXFILENEWLINE ) && !timedHighlightText.equals( MainConstants.STRBLANK )) {
    System.out.println(":::" + timedHighlightText + ":::" + timedSyllables.get(0).getMilliSeconds() + " : " + nowMs);
    lyricsHandler.sendEmptyMessage(2);
    }
    timedSyllables.remove(0);

    System.gc();
    }
    }


    if (lyricsLines.size() > 0) {
    if ( lyricsLines.get(0).getMicroSeconds() <= elapsedMs ) {
    strLine = lyricsLines.get(0).getPhrase();
    System.out.println("Line :::" + strLine + ":::" + (lyricsLines.get(0).getMicroSeconds()) + " : " + nowMs);
    lyricsHandler.sendEmptyMessage(1);
    lyricsLines.remove(0);
    System.gc();
    }
    }

  2. #2
    Join Date
    Feb 2008
    Location
    Land of fire and drought
    Beans
    Hidden!
    Distro
    Xubuntu

    Re: how to combine this two if statements please need help... thanks

    Thread moved to Programming Talk.

  3. #3
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,675
    Distro
    Ubuntu

    Re: how to combine this two if statements please need help... thanks

    The title of the post suggests that you have two if statements that you would like to combine, but then the body of the post shows some Java code with five if statements?

    Is it just that you want to transform:

    Code:
    if (A) {
        if (B) {
            doSomething();
        }
    }
    into:

    Code:
    if (A && B) {
        doSomething();
    }
    Or is it something else? Perhaps you could explain what you would like to do?

    Could you also wrap any code that you post in [code]...[/code] tags so that it keeps its indentation?

    And why are you calling System.gc()?
    Please create new threads for new questions.
    Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].

  4. #4
    Join Date
    Apr 2013
    Beans
    23

    Re: how to combine this two if statements please need help... thanks

    Could you not use an IF ELSE statement?

    Code:
    if (lyricsLines.size() > 0) {
                             
                         } else if ( lyricsLines.get(0).getMicroSeconds() <= elapsedMs ) {
                                 strLine = lyricsLines.get(0).getPhrase();
                                 System.out.println("Line :::" + strLine +  ":::" + (lyricsLines.get(0).getMicroSeconds()) + " : " + nowMs);
                                 lyricsHandler.sendEmptyMessage(1);
                                 lyricsLines.remove(0);
                                 System.gc();
                             }

  5. #5
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: how to combine this two if statements please need help... thanks

    Quote Originally Posted by r-senior View Post
    Code:
    if (A && B) {
        doSomething();
    }
    +1 on r-senior's suggestion.

    Quote Originally Posted by r-senior View Post
    And why are you calling System.gc()?
    Again, I'm compelled to agree with r-senior.
    Why are you calling it? You don't know what sort of garbage collector you are running under. Some JVMs aren't that smart or for various reasons don't do it. You don't know what it's going to do. Also, it's not guaranteed to do anything. The JVM may just entirely ignore your request.
    Sometimes people suggest that calling gc() may return memory to the system. That's certainly not necessarily true - the Java heap itself grows independently of Java allocations.
    As in, the JVM will hold memory and grow the heap as necessary. It doesn't necessarily return that memory to the system even when you free Java objects; it is perfectly free to hold on to the allocated memory to use for future Java allocations.

  6. #6
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: how to combine this two if statements please need help... thanks

    Quote Originally Posted by r-senior View Post
    And why are you calling System.gc()?
    Voodoo programming... either you call the garbage collector or you gut a chicken in front of the servers rack. Both are about as efficient but the OP either has signed the PETA chart (Programmers for the Empirical Treatment of Animals) or wants to remain in good terms with the cleaning personnel.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •