@Override
	public boolean applyTo(Program program) {

		Listing listing = program.getListing();

		ProgramModule parentModule = listing.getModule(treeName, parentName);
		ProgramModule module = listing.getModule(treeName, folderName);

		if (parentModule == null || module == null) {
			return true; // ignore since the tree has changed since this command was scheduled
		}
		Group[] groups = module.getChildren();

		for (Group group : groups) {

			// first check to make sure that the parent module
			// does not alreay contain tree group

			String name = group.getName();
			ProgramModule m = listing.getModule(treeName, name);
			ProgramFragment f = null;
			try {
				if (m != null && parentModule.contains(m)) {
					module.removeChild(name);
					continue;
				}
				if (m == null) {
					f = listing.getFragment(treeName, name);
					if (parentModule.contains(f)) {
						module.removeChild(name);
						continue;
					}
				}

				parentModule.reparent(name, module);
			}
			catch (NotEmptyException e) {
				Msg.showError(this, null, "Error", "Error merging folder with its parent");
			}
			catch (NotFoundException e) {
				Msg.showError(this, null, "Error", "Error merging folder with its parent");
			}
		}
		// now remove the module from its parent...
		try {
			ProgramModule m = listing.getModule(treeName, folderName);
			ProgramModule[] parents = m.getParents();
			for (ProgramModule parent : parents) {
				parent.removeChild(folderName);
			}
			return true;
		}
		catch (NotEmptyException e) {
			errMsg = e.getMessage();
		}
		return false;
	}
Construct a new command.
@param treeName name of the tree that this command affects
@param folderName name of the folder (module) that is being merged in
with its parent
@param parentName name of the parent that will end up with children of
the folder named folderName
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/module/MergeFolderCmd.java