The code in this section demonstrates some scenarios with Group Tool.

##---------------------------------
## Execute $group.init() once in the script
#set( $void = $group.init())
## Add new entries to the group tool
#foreach($e in $elements)
#if($e.elementType == "class")
#set( $void = $group.put("class", $e) )
#elseif($e.elementType == "package")
#set( $void = $group.put("package", $e) )
#elseif($e.elementType == "interface")
#set( $void = $group.put("interface", $e) )
#end
#end
## Iterate over the groupTool instance
#foreach( $groupName in $group.groupNames() )
Grupp with name $groupName contains the following elements
#foreach( $e in $group.get($groupName) )
    Element: $e.name
#end
#end
---------------------------------
##set( $void = $group.init()) ## not use init group 
## Add new entries to the group tool
#foreach($e in $elements)
#if($e.elementType == "usecase")
#set( $void = $group.put("usecase", $e) )
#elseif($e.elementType == "stereotype")
#set( $void = $group.put("stereotype", $e) )
#end
#end
## Iterate over the groupTool instance
#foreach( $groupName in $group.groupNames() )
Grupp with name $groupName contains the following elements
#foreach( $e in $group.get($groupName) )
    Element: $e.name
#end
#end
---------------------------------
#set( $void = $group.init()) ## use init group
## Add new entries to the group tool
#foreach($e in $elements)
#if($e.elementType == "usecase")
#set( $void = $group.put("usecase", $e) )
#elseif($e.elementType == "stereotype")
#set( $void = $group.put("stereotype", $e) )
#end
#end
## Iterate over the groupTool instance
#foreach( $groupName in $group.groupNames() )
Grupp with name $groupName contains the following elements
#foreach( $e in $group.get($groupName) )
    Element: $e.name
#end
#end
##---------------------------------
## Create new group tool
#set( $newGroupTool = $group.create())
##set( $void = $newGroupTool.init()) ## no need to init at first time
## Add new entries to the group tool
#foreach($e in $elements)
#if($e.elementType == "class")
#set( $void = $newGroupTool.put("class", $e) )
#elseif($e.elementType == "interface")
#set( $void = $newGroupTool.put("interface", $e) )
#end
#end
==============================================================================
New Group
## Iterate over the groupTool instance
#foreach( $groupName in $newGroupTool.groupNames() )
Grupp with name $groupName contains the following elements
#foreach( $e in $newGroupTool.get($groupName) )
    Element: $e.name
#end
#end
OLD Group
## Iterate over the groupTool instance
#foreach( $groupName in $group.groupNames() )
Grupp with name $groupName contains the following elements
#foreach( $e in $group.get($groupName) )
    Element: $e.name
#end
#end
##---------------------------------