code: public Map<String, SortedSet<PackageElement>> groupPackages(Set<PackageElement> packages) {
          Map<String, SortedSet<PackageElement>> groupPackageMap = new HashMap<>();
          String defaultGroupName =
              (elementNameGroupMap.isEmpty() && regExpGroupMap.isEmpty())?
                  configuration.getResources().getText("doclet.Packages") :
                  configuration.getResources().getText("doclet.Other_Packages");
          // if the user has not used the default group name, add it
          if (!groupList.contains(defaultGroupName)) {
              groupList.add(defaultGroupName);
          }
          for (PackageElement pkg : packages) {
              String pkgName = pkg.isUnnamed() ? null : configuration.utils.getPackageName(pkg);
              String groupName = pkg.isUnnamed() ? null : elementNameGroupMap.get(pkgName);
              // if this package is not explicitly assigned to a group,
              // try matching it to group specified by regular expression
              if (groupName == null) {
                  groupName = regExpGroupName(pkgName);
              }
              // if it is in neither group map, put it in the default
              // group
              if (groupName == null) {
                  groupName = defaultGroupName;
              }
              getPkgList(groupPackageMap, groupName).add(pkg);
          }
          return groupPackageMap;
      }
docs: Group the packages according the grouping information provided on the
  command line. Given a list of packages, search each package name in
  regular expression map as well as package name map to get the
  corresponding group name. Create another map with mapping of group name
  to the package list, which will fall under the specified group. If any
  package doesn't belong to any specified group on the command line, then
  a new group named "Other Packages" 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 packages will be grouped under group "Packages".
  
  @param packages Packages specified on the command line.
  @return map of group names and set of package elements