Java tree implementation using generic type