所需工具库

  1. Guava
  2. commons-lang

测试所需工具库

  1. junit-jupiter-api
  2. junit-platform-commons
  3. junit-platform-launcher
  4. junit-platform-engine

常用代码片段

分割大的列表变成小的列表

1
Lists.partition(bigList, splitSize);

将 String 变成 List

1
2
3
4
5
6
public static List<String> splitStringToList(String text, String separator) {
if (Strings.isNullOrEmpty(text)) {
return Lists.newArrayList();
}
return Lists.newArrayList(text.split(separator));
}

判断是否开启了 Debug 模式

1
2
3
4
5
6
7
8
private static final String AGENTLIB_JDWP = "-agentlib:jdwp";

public static boolean isDebugMode() {
final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
return runtimeMXBean.getInputArguments()
.stream()
.anyMatch(arg -> arg.contains(AGENTLIB_JDWP));
}

快乐 Guava

未完待续