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!