Results 1 to 15 of 15
  1. #1
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default TreeMap Quandary

    Hello All,

    I have the below snipped of code that is giving me problems. The code is called when the user clicks on the "NEXT" button of the form. Can someone please explain why despite getting into the Lines 32-36 I am not able to update the BorderPane? Lines 23-31 appear to work as expected. In the case below there are 3 entries within the TreeMap. You can see this within the Output provided by NetBeans shown below.

    NetBeans Output
    Next Button Clicked.
    1 => BorderPane@5bee8c9b <----------- Entry 1
    Next Button Clicked.
    1 => BorderPane@5bee8c9b <----------- Entry 1
    MATCH!
    2 => BorderPane@e857ac <------------ Entry 2
    UPDATING! BorderPane@15d3ddab <------------ Entry 3
    Cancel Button Clicked.

    Java Code:
      boolean isNewWizard = false;  
      boolean isBorderPaneMatchFound = false;  
      Wizard activeWizard;  
      Iterator iterator;  
      BorderPane nextBorderPaneToDisplay = new BorderPane();  
      // Did the user select a new wizard?  
      if (this.userSelectedWizard != null) {  
      // Becuase the userSelectedWizard within the wizardTracker. Because the userSelectedWizard is  
      // no longer "selected" but instead being tracked, it can now be set to null to help determine  
      // when the user makes another selection change.  
      WizardPage.wizardTracker.put(WizardPage.wizardTracker.lastKey() + 1, this.userSelectedWizard);  
      this.userSelectedWizard = null;  
      isNewWizard = true;  
      }  
      // The last entry within the wizardTracker identifies the wizard to be in use. Get its value and  
      // set up an iterator to determine its contents and establish page navigation.  
      activeWizard = WizardPage.wizardTracker.lastEntry().getValue();  
      iterator = activeWizard.getOrderedWizardPages().entrySet().iterator();  
      for (Map.Entry entry : activeWizard.getOrderedWizardPages().entrySet()) {  
      Integer key = (Integer) entry.getKey();  
      BorderPane value = (BorderPane) entry.getValue();  
      System.out.println(key + " => " + value);  
      if (isNewWizard) {  
      nextBorderPaneToDisplay = value;  
      break;  
      }  
      if (value.hashCode() == this.borderPaneMaster.hashCode()) {  
      System.out.println("MATCH!");  
      isBorderPaneMatchFound = true;  
      continue;  
      }  
      if (isBorderPaneMatchFound) {  
      System.out.println("UPDATING! " + nextBorderPaneToDisplay);  
      nextBorderPaneToDisplay = value;  
      break;  
      }  
      }  
      this.borderPaneMaster.getChildren().clear();  
      this.setBorderPaneMasterTop(nextBorderPaneToDisplay.getTop());  
      this.setBorderPaneMasterLeft(nextBorderPaneToDisplay.getLeft());  
      this.setBorderPaneMasterCenter(nextBorderPaneToDisplay.getCenter());  
      this.setBorderPaneMasterRight(nextBorderPaneToDisplay.getRight());  
      this.setBorderPaneMasterBottom(nextBorderPaneToDisplay.getBottom());

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,510
    Rep Power
    5

    Default Re: TreeMap Quandary

    It is very hard to tell because:

    1. You have not included a small version that demonstrates the problem.
    2. Your code is hard to read due to lack of formatting.

    However,

    In the following code fragment

    Java Code:
    if (value.hashCode() == this.borderPaneMaster.hashCode()) {  
       System.out.println("MATCH!");  
       isBorderPaneMatchFound = true;  
       continue;  
    }  
    if (isBorderPaneMatchFound) {  
       System.out.println("UPDATING! " + nextBorderPaneToDisplay);  
       nextBorderPaneToDisplay = value;  
       break;  
    }
    I assume you realize that the continue statement will simply continue for the next iteration of the enclosing loop. Thus, the following if block will not be executed and the value you set to true will not be checked. And if the following if block is executed, the break statement will terminate the enclosing loop.

    So you may want to remove the continue statement.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: TreeMap Quandary

    Hello Jim and thank you for your reply.

    You are focusing in on the exact area I am concerned about. Your assumptions are correct but they are also intended for the following reasons. Regardless, my code still does not work so I am open to suggestions.

    If the value of the TreeMap.hashCode() matches the borderPaneMaster.hashCode() currently displayed to the user then I set isBorderPaneMatchFound equal to True and then continue out of the statement intentionally. Why? Because now that I have found what I am looking for the next iteration should reveal the next BorderPane to be used and update the user display. At the point of continue and next iteration the value of isBorderPaneMatchFound is now True and the HashCode() checks are now False and enclosed code skipped. At this point I know, at least in theory, the logic works because of the output displayed within NetBeans. The TreeMap has 3 Key/Value pairs. Notice how the output below shows the System.out.println("UPDATING!") statement and also the place in memory where the 3rd Key/Value pair resides.

    NetBeans Output
    Next Button Clicked.
    1 => BorderPane@5bee8c9b <----------- Entry 1
    Next Button Clicked.
    1 => BorderPane@5bee8c9b <----------- Entry 1
    MATCH!
    2 => BorderPane@e857ac <------------ Entry 2
    UPDATING! BorderPane@15d3ddab <------------ Entry 3
    Cancel Button Clicked.

    Am I very confused? Thank you for your continued patience and assistance.

    Regards,
    Edwin

  4. #4
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: TreeMap Quandary

    Below is the entire code for the Next button. In it I updated the IF statements to remove the CONTINUE.

    I still get the same results. Does this better help explain my problem?

    Java Code:
     private void handleNextButton() {
            System.out.println("Next Button Clicked.");
    
            boolean isNewWizard = false;
            boolean isBorderPaneMatchFound = false;
    
    
            Wizard activeWizard;
            Iterator iterator;
            BorderPane nextBorderPaneToDisplay = new BorderPane();
    
    
            // Did the user select a new wizard?
            if (this.userSelectedWizard != null) {
                // Becuase the userSelectedWizard within the wizardTracker. Because the userSelectedWizard is
                // no longer "selected" but instead being tracked, it can now be set to null to help determine
                // when the user makes another selection change.
                WizardPage.wizardTracker.put(WizardPage.wizardTracker.lastKey() + 1, this.userSelectedWizard);
                this.userSelectedWizard = null;
    
    
                isNewWizard = true;
            }
    
    
            // The last entry within the wizardTracker identifies the wizard to be in use. Get its value and
            // set up an iterator to determine its contents and establish page navigation.
            activeWizard = WizardPage.wizardTracker.lastEntry().getValue();
            iterator = activeWizard.getOrderedWizardPages().entrySet().iterator();
            
            for (Map.Entry entry : activeWizard.getOrderedWizardPages().entrySet()) {
                Integer key = (Integer) entry.getKey();
                BorderPane value = (BorderPane) entry.getValue();
    
    
                System.out.println();
                System.out.println("    Iteration " + key + " => " + value);
    
    
                if (isNewWizard) {
                    System.out.println("    New Page: " + value);
                    nextBorderPaneToDisplay = value;
                    
                    isNewWizard = false;
                    break;
                } else {
                    if (value.hashCode() == this.borderPaneMaster.hashCode()) {
                        System.out.println("    Found Matching Page:" + value);
                        isBorderPaneMatchFound = true;
                    } else if (isBorderPaneMatchFound) {
                        System.out.println("    Updated Page: " + value);
                        nextBorderPaneToDisplay = value;
                        System.out.println("    Updated Page: " + nextBorderPaneToDisplay);
                        break;
                    }
                }
            }
            
            this.setBorderPaneMasterTop(nextBorderPaneToDisplay.getTop());
            this.setBorderPaneMasterLeft(nextBorderPaneToDisplay.getLeft());
            this.setBorderPaneMasterCenter(nextBorderPaneToDisplay.getCenter());
            this.setBorderPaneMasterRight(nextBorderPaneToDisplay.getRight());
            this.setBorderPaneMasterBottom(nextBorderPaneToDisplay.getBottom());
        }

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: TreeMap Quandary

    How can the code be compiled and executed for testing? Can you add a small class and main() to execute the code for testing?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: TreeMap Quandary

    Hello Norm and thank you for the help. Attached is the source code for review. At this point I am only focusing on the NEXT button but obviously I will want to do the same for the PREVIOUS button but of course in reverse. The ultimate goal is to create a framework that will accept a TreeMap of any size used to define steps in a wizard. The thought is also in that as needs changed the ordering of the TreeMap can be updated without too much engineering overhead hence the approach taken.

    Thank you for your help!

    Regards,

    Edwin
    Attached Files Attached Files

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: TreeMap Quandary

    Please make a small program that compiles, executes and shows the problem and post it on the forum. Don't post the whole project which is sure to have lots of code that is not part of the problem.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: TreeMap Quandary

    Hello Norm,


    You are correct. The source code provided contains only what is required use the application specific to the question. The source code provided has been stripped of the fat I have locally.


    I hope this addresses your concern.


    Thank you you for your continued patience and assistance.


    Regards,
    Edwin

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: TreeMap Quandary

    Please post the code here in the thread, not as an attachment. It should be less than 300 lines total.
    Be sure to wrap the code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: TreeMap Quandary

    Hello Norm,

    I wrote the code as requested in a separate project. When I do everything works as expected. I appreciate your help but for me to post what you are asking will not help without using the source code already provided. I guess I will just have to continue working towards a solution on my end. Obviously I have a bug in my app that is difficult to figure out.

    Thanks again.

    Regards,
    Edwin

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,510
    Rep Power
    5

    Default Re: TreeMap Quandary

    Ugh! This is JavaFX. It should be posted under that forum.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  12. #12
    edwinvelez is offline Member
    Join Date
    Dec 2013
    Posts
    7
    Rep Power
    0

    Default Re: TreeMap Quandary

    Jim,

    You say this is JavaFX and you are correct. You probably opened the source code provided and came to the proper conclusion. Until then you would never have known otherwise. The original original question centered on the use of TreeMap and assigning a value to a BorderPane; the TreeMap object being available to JAVA and JavaFX and therefore free from breaking any "forum rules."

    Regardless, I have determined the problem and am now able to move on. The exercise that Norm asked me to do in writing a simple small program helped me to see where the error was.

    Thank you both for your patience and support.

    Regards,
    Edwin
    Last edited by edwinvelez; 12-29-2013 at 05:37 AM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: TreeMap Quandary

    Glad you found the problem.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,510
    Rep Power
    5

    Default Re: TreeMap Quandary

    You should still have posted it in the proper forum. Quite often, to help diagnose a problem, members of the forum will actually run the code. But depending on the IDE, the IDE may require additional capabilities to run JavaFX programs. Had you stated that originally or better still, put it in the proper forum, I would not have gone to the trouble of importing your code. I would have simply let someone set up to run JavaFX handle the question.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  15. #15
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: TreeMap Quandary

    In the future, if you crosspost (which is NOT a bad thing to do) post links to your other posts so people can follow them; this allows people to see what has already been answered elsewhere and not spend time posting duplicate information.

    https://community.oracle.com/thread/2616341
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. TreeMap problem
    By Tolls in forum Advanced Java
    Replies: 10
    Last Post: 08-31-2011, 02:58 PM
  2. TreeMap vs Map
    By alpdog14 in forum New To Java
    Replies: 5
    Last Post: 03-27-2011, 06:07 PM
  3. [JAVA] TreeMap
    By watle in forum Advanced Java
    Replies: 3
    Last Post: 03-16-2011, 05:39 PM
  4. Treemap's
    By Russo in forum New To Java
    Replies: 6
    Last Post: 10-11-2009, 01:13 AM
  5. How to use treemap
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-12-2008, 08:47 PM

Posting Permissions

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