in src/main/java/org/apache/sling/serviceusermapping/impl/ServiceUserMapperImpl.java [363:398]
    RegistrationSet updateServiceRegistrations(final Mapping[] newMappings) {
        RegistrationSet result = new RegistrationSet();
        final SortedSet<Mapping> orderedNewMappings = new TreeSet<>(Arrays.asList(newMappings));
        final SortedMap<Mapping, Registration> newRegistrations = new TreeMap<>();
        // keep those that are still mapped
        for (Map.Entry<Mapping, Registration> registrationEntry: activeRegistrations.entrySet()) {
            boolean keepEntry = true;
            if (!orderedNewMappings.contains(registrationEntry.getKey())) {
                Registration registration = registrationEntry.getValue();
                result.removed.add(registration);
                keepEntry = false;
            }
            if (keepEntry) {
                newRegistrations.put(registrationEntry.getKey(), registrationEntry.getValue());
            }
        }
        // add those that are new
        for (final Mapping mapping: orderedNewMappings) {
            if (!newRegistrations.containsKey(mapping)) {
                Registration registration = new Registration(mapping);
                newRegistrations.put(mapping, registration);
                result.added.add(registration);
            }
        }
        activeRegistrations = newRegistrations;
        return result;
    }