private void doSort(ProgramModule parent, GroupComparator comparator, TaskMonitor monitor)
			throws NotFoundException, CancelledException {
		List<Group> list = new ArrayList<Group>();
		Group[] kids = parent.getChildren();

		monitor.initialize(kids.length);

		for (Group kid : kids) {
			monitor.checkCancelled();
			list.add(kid);
			if (kid instanceof ProgramModule) {
				doSort((ProgramModule) kid, comparator, monitor);
			}
			monitor.incrementProgress(1);
		}

		Collections.sort(list, comparator);

		monitor.initialize(list.size());
		for (int i = 0; i < list.size(); i++) {
			monitor.checkCancelled();

			Group group = list.get(i);
			monitor.setMessage("processing " + group.getName());
			parent.moveChild(group.getName(), i);
			monitor.incrementProgress(1);

			if (i % 10 == 0) {
				allowSwingThreadToPaintBetweenLongLocking();
			}

		}
	}
Plugin to sort Modules and Fragments within a selected Module.
Child Module folders are always name-sorted and placed
above child Fragments.  When sorting on address, the minimum
address for each fragment is used, while empty fragments are name-sorted
and placed at the bottom.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/module/ModuleSortPlugin.java