Created
January 22, 2014 21:14
-
-
Save robhinds/8567455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UnwelcomeVisitorIterator { | |
| static public traverse( data, visitor ){ | |
| if ( data instanceof Map ){ | |
| data.each{ entrySet -> | |
| entrySet.value = visitor.visitMap( entrySet.key, entrySet.value ) | |
| entrySet.value = traverse( entrySet.value, visitor ) | |
| } | |
| } else if ( data instanceof Collection ){ | |
| def processedList = [] | |
| data.each{ | |
| def visitedEntry = visitor.visitList( it ) | |
| processedList << traverse( visitedEntry, visitor ) | |
| } | |
| data = processedList | |
| } | |
| data | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment