[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
Changes like this make the line longer than 100 characters, it appears. That's why it was wrapped.