package se.fnord.jamon;

import java.util.Arrays;

public class Path {
	private final Node[] path;

	private Path(Node[] path) {
		this.path = path;
    }


	}

	public Node root() {
		return path[0];
	}

	public Node leaf() {
		return path[path.length - 1];
	}

	public Path forChild(Node n) {
		if (!leaf().children().contains(n))
			throw new IllegalStateException("Provided node is not a child of the last node in the path");

		final Node[] newPath = Arrays.copyOf(path, path.length + 1);
		newPath[newPath.length - 1] = n;
		return new Path(newPath);
	}


	private static void checkPath(Node[] path) {
		if (path.length == 0)
			throw new IllegalStateException("Broken path");

		Node parent = path[0];
		for (int i = 1; i < path.length; i++) {
			Node current = path[i];
			if (!parent.children().contains(current))
				throw new IllegalStateException("Broken path");
			parent = current;
		}
	}

    public static Path path(Node ...nodes) {
    	nodes = nodes.clone();
    	checkPath(nodes);
    	return new Path(nodes);
    }
}

@@ -149,16 +149,495 @@
 %0A    %7D%0A%0A
+%09@Override%0A%09public boolean equals(Object obj) %7B%0A%09%09if (this == obj)%0A%09%09%09return true;%0A%09%09if (!(obj instanceof Path))%0A%09%09%09return false;%0A%09%09final Path other = (Path) obj;%0A%09%09if (path.length != other.path.length)%0A%09%09%09return false;%0A%09%09for (int i = 0; i %3C path.length; i++)%0A%09%09%09if (!path%5Bi%5D.shallowEquals(other.path%5Bi%5D))%0A%09%09%09%09return false;%0A%09%09return true;%0A%09%7D%0A%0A%09@Override%0A%09public int hashCode() %7B%0A%09%09int n = 0;%0A%09%09for (int i = 0; i %3C path.length; i++)%0A%09%09%09n = n + 31 * path%5Bi%5D.hashCode();%0A%09%09return n;
 %0A%09%7D%0A%0A%09pu
@@ -1033,16 +1033,137 @@
 h);%0A%09%7D%0A%0A
+%09public Path forParent() %7B%0A%09%09final Node%5B%5D newPath = Arrays.copyOf(path, path.length - 1);%0A%09%09return new Path(newPath);%0A%09%7D%0A
 %0A%09privat

Implement Path#equals(), Path#hashCode(), Path#forParent()