code: public void removeUnchangedTopLevelResources(ResourceMap publishRelatedResources, ResourceMap reachability) {
  
          Set<CmsResource> unchangedParents = Sets.newHashSet();
          Set<CmsResource> childrenOfUnchangedParents = Sets.newHashSet();
          Set<CmsResource> other = Sets.newHashSet();
          for (CmsResource parent : publishRelatedResources.keySet()) {
              if (isUnchangedAndShouldBeRemoved(parent)) {
                  unchangedParents.add(parent);
                  childrenOfUnchangedParents.addAll(publishRelatedResources.get(parent));
              } else {
                  other.add(parent);
                  other.addAll(publishRelatedResources.get(parent));
              }
          }
  
          // we want the resources which *only* occur as children of unchanged parents
          childrenOfUnchangedParents.removeAll(other);
  
          for (CmsResource parent : unchangedParents) {
              publishRelatedResources.remove(parent);
          }
  
          // Try to find hierarchical relationships in childrenOfUnchangedParents
          while (findAndMoveParentWithChildren(childrenOfUnchangedParents, reachability, publishRelatedResources)) {
              // do nothing
          }
          // only the resources with no 'children' are left, transfer them to the target map
          for (CmsResource remainingResource : childrenOfUnchangedParents) {
              publishRelatedResources.get(remainingResource);
          }
      }
docs: Removes unchanged resources from the top level, and if they have children which do not occur anywhere else,
  moves these children to the top level.<p>
  
  @param publishRelatedResources the resource map to modify
  @param reachability the reachability map