您现在的位置是:首页 > 文章详情

feilong-core 2.1.0 发布,让 Java 开发更简便的工具包的副本

日期:2020-04-03点击:438

feilong-core 2.1.0 发布了,feilong-core 是一个让 Java 开发更简便的工具包。

  1. 让你从大量重复的底层代码中脱身,提高工作效率;
  2. 让你的代码更简炼,易写、易读、易于维护;

文档地址: http://feilong-core.mydoc.io/

单元测试数 增加至 2259 个, 单元测试覆盖率 增加至 91% ,javadoc 比率 83%

本次升级共有 10 处变更, 具体参见 2.1.0 milestone

[Feature] 🆕

#815 新建 DateUtil.nowTimestamp() 方法

在日常开发过程中,我们经常要生成文件/文件夹名字, 通常使用当前时间的 TIMESTAMP 命名

以前你需要写成 DateUtil.toString(new Date(), TIMESTAMP)

或者写成 DateUtil.nowString(TIMESTAMP) (since 1.14.0)

更或者 DateUtil.toString(Calendar.getInstance().getTime(), DatePattern.TIMESTAMP)

此时你可以写成, (使用静态导入 static import更精简): DateUtil.nowTimestamp() 即可,较少开发量


#809 Dateutil 新增日期字符串区间的比较

com.feilong.core.date.DateUtil.isInTime(String beginDateString,String endDateString,String datePattern)

com.feilong.core.date.DateUtil.isInTime(Date date,String beginDateString,String endDateString,String datePattern)

判断当前时间 是否在格式是pattern的 beginDate 和 endDate两个时间之间.

使用场景:

比如当日达,判断下单的时间是否是 08:00-16:00 之间, 超过这个时间段的订单不能下


#807 Dateutil 新增 将一个时间格式字符串转成另外时间格式字符串方法

com.feilong.core.date.DateUtil.toString(String dateString,String oldPattern,String newPattern)

将一个 oldPattern 格式日期 dateString 字符串 使用新格式 newPattern 转成新的字符串.

示例:

 DateUtil.toString("2020-01-06", "yyyy-MM-dd", "yyyy.MM.dd")="2020.01.06" DateUtil.toString("2020-01-06", "yyyy-MM-dd", "yyyy年MM月dd日")="2020年01月06日"

#816 新增 RandomUtil.createRandomString(int) 减少一步代码

Alphabet.DECIMAL_AND_LOWERCASE_LETTERS_DISTINGUISHABLE 随机抽取字符串,拼接成指定长度length的字符串.

说明:

  • 常用于生成验证码
  • 接口传参,比如微信需要 nonce_str ,不长于32位的随机字符串

示例:
RandomUtil.createRandomString(5)

生成的结果是可能是IFSMB


#813 新增 CollectionsUtil.find(Iterable, Map<String, ?>) 方法

找到 iterable中,第一个 propertyName属性名称和值是 propertyValue是 propertyNameAndPropertyValueMap 的对应元素.

示例:
场景: 从list中查找name是 关羽,且年龄是24 的User对象

 List<User> list = new ArrayList<>(); list.add(new User("张飞", 23)); list.add(new User("关羽", 24)); list.add(new User("刘备", 25)); list.add(new User("关羽", 50)); Map<String, ?> map = toMap("name", "关羽", "age", 24); LOGGER.info(JsonUtil.format(CollectionsUtil.find(list, map)));

返回:

 { "age": 24, "name": "关羽" }

说明:
返回第一个匹配对象


#808 CollectionsUtil 根据对象多个属性值去重

com.feilong.core.util.CollectionsUtil.removeDuplicate(Collection<O>, String...)

去重,返回指定属性 propertyNames 组合的值都不重复元素的新list (原集合对象不变).

比如下列user示例, 如果id相等,并且userInfo.age 属性值也相等 那么判定是重复对象

示例:

 User user1 = new User(1L); user1.setUserInfo(new UserInfo(15)); User user2 = new User(1L); user2.setUserInfo(new UserInfo(16)); User user3 = new User(1L); user3.setUserInfo(new UserInfo(15)); List<User> list = toList(user1, user2, user3); List<User> removeDuplicate = CollectionsUtil.removeDuplicate(list, "id", "userInfo.age"); assertThat(removeDuplicate, contains(user1, user2)); assertSame(2, removeDuplicate.size());

注意:

  • 如果原 objectCollection 是有序的,那么返回的结果参照原 objectCollection元素顺序
  • 原 objectCollection不变

[Update]

  • #818 基于sonar8 修复坏味道 坏味道

[版本升级]

  • none

[Javadoc]

  • #811 修改 AggregateUtil.sum(Iterable<O>, String...) javadoc
  • #810 修改 AggregateUtil.groupCount(Iterable<O>, String...) javadoc
  • #812 完善 DefaultRuntimeException(String, Object...) 注释

[Remove]

  • none

[Fix Bug] 

  • none
原文链接:https://www.oschina.net/news/114618/feilong-core-2-1-0-released
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章