class SocialNetworkNavigation {
/*
* Assuming non-null destination.
* Return values:
* -1 = Go back one in the hierarchy
* 0 = Invalid destination
* 1 = Go Forward one in the hierarchy to destination
* 2 = Go Home
*/
public static int validDestination(String[] currentPath, String destination) {
if (destination.trim().equals("..")) {
return -1;
}
if (destination.trim().toLowerCase().equals("home") || destination.trim().equals("/")) {
return 2;
}
//first case covers being in a regular board's post
//second case covers being in the freeforall board's post
if (currentPath[currentPath.length-1] != null ||
(currentPath[0] != null && ("freeforall").equals(currentPath[0])
&& currentPath[1] != null)) {
return 0;
}
else { //actual destination and can advance.
return 1;
}
}
}