app/src/main/java/org/jgrapht/alg/util/UnionFind.java
public T find(T element)
    {
        if (!parentMap.containsKey(element)) {
            throw new IllegalArgumentException(
                "elements must be contained in given set");
        }

        T parent = parentMap.get(element);
        if (parent.equals(element)) {
            return element;
        }

        T newParent = find(parent);
        parentMap.put(element, newParent);
        return newParent;
    }
/**
     * Returns the representative element of the set that element is in.
     *
     * @param element The element to find.
     *
     * @return The element representing the set the element is in.
     */
Returns the representative element of the set that element is in.
@param element The element to find.

@return The element representing the set the element is in.
Returns the representative element of the set that element is in . @param element The element to find . @return The element representing the set the element is in .
public T find(T element)
    {
        if (!parentMap.containsKey(element)) {
            throw new IllegalArgumentException(
                "elements must be contained in given set");
        }
        T parent = parentMap.get(element);
        if (parent.equals(element)) {
            return element;
        }
        T newParent = find(parent);
        parentMap.put(element, newParent);
        return newParent;
    }
public T find ( T element ) { if ( ! parentMap . containsKey ( element ) ) { throw new IllegalArgumentException ( "elements must be contained in given set" ) ; } T parent = parentMap . get ( element ) ; if ( parent . equals ( element ) ) { return element ; } T newParent = find ( parent ) ; parentMap . put ( element , newParent ) ; return newParent ; }
Returns the representative element of the set that element is in.
Returns the representative element of the set that element is in .