IDEA配置
IDEA插件
google-java-format
1.7.0.6 锁死版本。新版风格应该不一样。
以下是1.7.0.6的下载地址。
https://plugins.jetbrains.com/plugin/8527-google-java-format/versions/stable/115957
选择AOSP
Save Actions
保存自动格式化。
IDEA配置文件修改
.editerconfig 参考Apache Flink源码中的配置
Maven配置
spotless
这个插件的作用是代码不符合规范 maven validate不通过,不给编译。
https://github.com/diffplug/spotless/tree/main/plugin-maven
<plugin><groupId>com.diffplug.spotless</groupId><artifactId>spotless-maven-plugin</artifactId><version>2.4.2</version><configuration><java><googleJavaFormat><version>1.7</version><style>AOSP</style></googleJavaFormat><!-- \# refers to the static imports --><importOrder><order>org.apache.flink,org.apache.flink.shaded,,javax,java,scala,\#</order></importOrder><removeUnusedImports /></java></configuration><executions><execution><id>spotless-check</id><phase>validate</phase><goals><goal>check</goal></goals></execution></executions></plugin>
字符串分隔
split问题
https://www.cnblogs.com/yxmfighting/p/7383013.html
Apache Common StringUtils.split优点
1、已经帮助用户判空。
2、不是正则性能好。
3、当传入””空串的时候,原生的返回数组里有一个元素。而StringUtils返回0个。
Apache Common问题
1、和原生split功能其实是不一样的。具体如下文。
https://blog.csdn.net/lewky_liu/article/details/89166506
配置读取
String filepath = "vertx.properties";Properties props = new Properties();InputStream inputStream = Entry.class.getClassLoader().getResourceAsStream(filepath);props.load(inputStream);String key = props.getProperty("username");
异常管理
Catch中打印堆栈信息
//goodtry {//......} catch (Exeception e) {LOG.info("foo" + e);}//bad 不可控try {//......} catch (Exeception e) {e.printStackTrace();}
返利
泛型
// goodArrayList<String> bar = new ArrayList<>();// badArrayList<String> foo = new ArrayList<String>();
流编程模型的使用
https://google.github.io/styleguide/
参考文献
[1] Apache Flink Code Style and Quality Guide https://flink.apache.org/contributing/code-style-and-quality-common.html
[2] Google Java Style Guide https://google.github.io/styleguide/javaguide.html
