code: public Map<String, SortedSet<ModuleElement>> groupModules(Set<ModuleElement> modules) {
          Map<String, SortedSet<ModuleElement>> groupModuleMap = new HashMap<>();
          String defaultGroupName =
              (elementNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())?
                  configuration.getResources().getText("doclet.Modules") :
                  configuration.getResources().getText("doclet.Other_Modules");
          // if the user has not used the default group name, add it
          if (!groupList.contains(defaultGroupName)) {
              groupList.add(defaultGroupName);
          }
          for (ModuleElement mdl : modules) {
              String moduleName = mdl.isUnnamed() ? null : mdl.getQualifiedName().toString();
              String groupName = mdl.isUnnamed() ? null : elementNameGroupMap.get(moduleName);
              // if this module is not explicitly assigned to a group,
              // try matching it to group specified by regular expression
              if (groupName == null) {
                  groupName = regExpGroupName(moduleName);
              }
              // if it is in neither group map, put it in the default
              // group
              if (groupName == null) {
                  groupName = defaultGroupName;
              }
              getModuleList(groupModuleMap, groupName).add(mdl);
          }
          return groupModuleMap;
      }
docs: Group the modules according the grouping information provided on the
  command line. Given a list of modules, search each module name in
  regular expression map as well as module name map to get the
  corresponding group name. Create another map with mapping of group name
  to the module list, which will fall under the specified group. If any
  module doesn't belong to any specified group on the command line, then
  a new group named "Other Modules" will be created for it. If there are
  no groups found, in other words if "-group" option is not at all used,
  then all the modules will be grouped under group "Modules".
  
  @param modules Specified modules.
  @return map of group names and set of module elements.