[SPARK-3781] code format and little improvement

1. use scala recommended usage
2. method body's left bracket
3. parameter list format
4. explicit mutable collection, such as "new mutable.HashMap"
5. others
Changing this indentation makes the start of the code body less apparent. Moving the `{` seems reasonable but not enough to justify a change IMHO.