public <T extends ImmutableTerm> ImmutableSubstitution<T> prioritizeRenaming(
            ImmutableSubstitution<T> substitution, ImmutableSet<Variable> priorityVariables) {

        ImmutableMultimap<Variable, Variable> renamingMultimap = substitution.getImmutableMap().entrySet().stream()
                .filter(e -> priorityVariables.contains(e.getKey())
                        && (e.getValue() instanceof Variable)
                        && (!priorityVariables.contains(e.getValue())))
                .collect(ImmutableCollectors.toMultimap(
                        e -> (Variable) e.getValue(),
                        Map.Entry::getKey));

        if (renamingMultimap.isEmpty())
            return substitution;

        ImmutableMap<Variable, Variable> renamingMap = renamingMultimap.asMap().entrySet().stream()
                .collect(ImmutableCollectors.toMap(
                        Map.Entry::getKey,
                        e -> e.getValue().iterator().next()));
        InjectiveVar2VarSubstitution renamingSubstitution = substitutionFactory.getInjectiveVar2VarSubstitution(renamingMap);

        // TODO: refactor
        return (ImmutableSubstitution<T>) renamingSubstitution.composeWith(substitution);
    }
public < T extends ImmutableTerm > ImmutableSubstitution < T > prioritizeRenaming ( ImmutableSubstitution < T > substitution , ImmutableSet < Variable > priorityVariables ) { ImmutableMultimap < Variable , Variable > renamingMultimap = substitution . getImmutableMap ( ) . entrySet ( ) . stream ( ) . filter ( e -> priorityVariables . contains ( e . getKey ( ) ) && ( e . getValue ( ) instanceof Variable ) && ( ! priorityVariables . contains ( e . getValue ( ) ) ) ) . collect ( ImmutableCollectors . toMultimap ( e -> ( Variable ) e . getValue ( ) , Map . Entry :: getKey ) ) ; if ( renamingMultimap . isEmpty ( ) ) return substitution ; ImmutableMap < Variable , Variable > renamingMap = renamingMultimap . asMap ( ) . entrySet ( ) . stream ( ) . collect ( ImmutableCollectors . toMap ( Map . Entry :: getKey , e -> e . getValue ( ) . iterator ( ) . next ( ) ) ) ; InjectiveVar2VarSubstitution renamingSubstitution = substitutionFactory . getInjectiveVar2VarSubstitution ( renamingMap ) ; return ( ImmutableSubstitution < T > ) renamingSubstitution . composeWith ( substitution ) ; }
Prevents priority variables to be renamed into non-priority variables.

When applied to a MGU, it is expected to return another "equivalent" MGU.