Skip to content

Base Utils

Calvin Xiao edited this page Jan 25, 2017 · 2 revisions

防御式编程工具集

Spring, Common Lang, Guava都有提供校验参数的防御式编程API,选用Apache Commons Lang的Validate。

Spring的Assert,很容易和junit的Assert弄乱,而且校验函数没有返回输入参数的能力,而且出错信息也没有格式化字符串+自定义参数的能力。

Guava的Preconditions,一是名字太长了,二是Validate的方法更多,比如noNullElements()判断多个元素都不为空

MoreValidate主要参考Guava的MathPreconditions, 补充数字为正数或非负数的校验。

异常工具集

Springside-core自己感觉常用需求整理了Exceptions。

  • unchecked(), 将CheckedException转化为RuntimeException的方法
  • getStackTraceAsString(), 将整个Exception Stack所有消息转化为一个String
  • isCausedBy(), 判断异常是否由某些底层异常引起

系统设定工具集

Properties与SystemProperties工具集

Ojbect,Boolean 与 枚举工具集

自定义Annotations