Java Code refatoring