/** * Create a {@link Node} that resembles the parent of this. */ private Node<E> describeParent() { int pathLength = pathLength(); // this is a root node, it has no parent if(pathLength == 1) return null; // return a node describing the parent path return new Node<E>(true, new ArrayList<E>(path.subList(0, pathLength - 1))); }
/** * Create a {@link Node} that resembles the parent of this. */ private Node<E> describeParent() { int pathLength = pathLength(); // this is a root node, it has no parent if(pathLength == 1) return null; // return a node describing the parent path return new Node<E>(true, new ArrayList<E>(path.subList(0, pathLength - 1))); }
/** * Create a {@link Node} that resembles the parent of this. */ private Node<E> describeParent() { int pathLength = pathLength(); // this is a root node, it has no parent if(pathLength == 1) return null; // return a node describing the parent path return new Node<E>(true, new ArrayList<E>(path.subList(0, pathLength - 1))); }
/** * Lookup the ancestor of this node whose path length is the length * specified. For example, the ancestor of path length 2 of the node * <code>/Users/jessewilson/Desktop/yarbo.mp4</code> is the node * <code>/Users/jessewilson</code>. * * <p>If the ancestor path length is the same as this node's path length, * then this node will be returned. */ private Node<E> ancestorWithPathLength(int ancestorPathLength) { assert(pathLength() >= ancestorPathLength); Node<E> ancestor = this; while(ancestor.pathLength() > ancestorPathLength) { ancestor = ancestor.parent; if(ancestor == null) { throw new IllegalStateException(); } } return ancestor; }
/** * Lookup the ancestor of this node whose path length is the length * specified. For example, the ancestor of path length 2 of the node * <code>/Users/jessewilson/Desktop/yarbo.mp4</code> is the node * <code>/Users/jessewilson</code>. * * <p>If the ancestor path length is the same as this node's path length, * then this node will be returned. */ private Node<E> ancestorWithPathLength(int ancestorPathLength) { assert(pathLength() >= ancestorPathLength); Node<E> ancestor = this; while(ancestor.pathLength() > ancestorPathLength) { ancestor = ancestor.parent; if(ancestor == null) { throw new IllegalStateException(); } } return ancestor; }
/** * Lookup the ancestor of this node whose path length is the length * specified. For example, the ancestor of path length 2 of the node * <code>/Users/jessewilson/Desktop/yarbo.mp4</code> is the node * <code>/Users/jessewilson</code>. * * <p>If the ancestor path length is the same as this node's path length, * then this node will be returned. */ private Node<E> ancestorWithPathLength(int ancestorPathLength) { assert(pathLength() >= ancestorPathLength); Node<E> ancestor = this; while(ancestor.pathLength() > ancestorPathLength) { ancestor = ancestor.parent; if(ancestor == null) { throw new IllegalStateException(); } } return ancestor; }