Refactoring java code (data processing)