Java refactor