public static int distance(Category category1, Category category2) {
		// The path to the root is computed for category1 and category2.
		Collection<Category> pathToRoot1 = category1.pathToRoot();	
		Collection<Category> pathToRoot2 = category2.pathToRoot();
		
		int distanceToCommonAncestor1 = 0;
		int distanceToCommonAncestor2 = 0;
		
		boolean commonAncestorFound = false;
		// Iteration on the categories located on the path between category1
		// and root.
		Iterator<Category> pathToRootIterator1 = pathToRoot1.iterator();
	    while (!commonAncestorFound && pathToRootIterator1.hasNext()){
	    	Category pathToRootCategory1 = pathToRootIterator1.next();
	    	distanceToCommonAncestor2 = 0;
	    	
	    	// Iteration on the categories located on the path between
	    	// category2 and root.
	    	Iterator<Category> pathToRootIterator2 = pathToRoot2.iterator();
	    	while (!commonAncestorFound && pathToRootIterator2.hasNext()) {
	    		Category pathToRootCategory2 = pathToRootIterator2.next();
	    		
	    		if (pathToRootCategory1.equals(pathToRootCategory2)) {
	    			// The pathes to root for category1 and category2 are
	    			// intersecting: the lowest common ancestor is found.
	    			commonAncestorFound = true;
	    		} else {
	    			// The lowest common ancestor has not been found yet: the
	    			// distance is incremented and the iteration on the path
	    			// between category2 and root continues.
	    			distanceToCommonAncestor2++;
	    		}
	    	}
	    	
	    	if (!commonAncestorFound) {
	    		// The lowest common ancestor has not been found yet: the
    			// distance is incremented and the iteration on the path
    			// between category1 and root continues.
	    		distanceToCommonAncestor1++;
	    	}
	    }
		
	    // The distance between category1 and category2 is equal to the
	    // distance between category1 and their lowest common ancestor added to
	    // the distance between category2 and their common ancestor.
	    return distanceToCommonAncestor1 + distanceToCommonAncestor2;
	}