Exemplo n.º 1
0
  public boolean canDescendPath(ArrayList<T> path) {
    if (path == null) return false;
    if (path.size() == 0) return containsDescendables();
    Descendable desc = descend(path.get(0));
    if (desc == null) return false;
    if (path.size() == 1) {
      return true;
    }
    ArrayList<T> rest = new ArrayList<>(path);

    rest.remove(0);
    return desc.canDescendPath(rest);
  }
Exemplo n.º 2
0
  public Descendable descendPath(ArrayList<T> path, T item) {
    if (path == null || path.size() == 0) {
      if (item == null) {
        return this;
      }
      return descend(item);
    }
    T nextItem = path.get(0);
    ArrayList<T> rest = new ArrayList<>(path);

    rest.remove(0);
    Descendable desc = descend(nextItem);
    if (desc == null) return null;
    return desc.descendPath(rest, item);
  }