0

I'm really new to Java and recursive functions in general. I'm a bit lost on a couple things. Why for some reason am I getting duplicate output. It only seems to be when I traverse up in the content. I have an idea why this is happening because it seems like my "isPageParent" function is returning false and running through the function multiple times. But I can't figure out why? I've been spending hours on this and absolutely stuck. I'm a newbie so code samples are greatly appreciated.

public static String generateTest(Page page, Page rootPage, String bc) {

Page parent = page.getParent();

String bread = ""; 
bread += (parent != null) ? "<li><a href=" + parent.getPath() + ">" + parent.getTitle() + "</a>" : "";
bread += "<li>" + "<a href=" + page.getPath() + ">" + page.getTitle() + "</a></li>" + bc;
return (ifPageRoot(parent , rootPage)) ? breadcrumb : generateTest(parent, rootPage, bread);

}

public static boolean ifPageRoot(Page page, Page root) {
return (page == null || root.getPath().equals(page.getPath()));
}

Thanks!

Delmon Young
  • 2,013
  • 5
  • 39
  • 51
  • 1
    It looks like on the first pass it will add the content from the parent variable. On the second pass the parent is now the page variable so it will add the exact same content to the string as the page variable. You might want to just remove the first string concatenation. – Nathanial Apr 10 '13 at 01:13
  • What is `breadcrumb`? btw. really ugly code. No wonder you are "a bit lost in here" – drzymala Apr 10 '13 at 02:03
  • Thanks @Nathanial that seemed to be the problem. Thanks for the help! – Delmon Young Apr 10 '13 at 12:41

0 Answers0