Java code refactoring