转载

feilong-core 1.14.3 发布啦,让 Java 开发更简便的工具包

本次升级共有 3 处变更, 具体参见  1.14.3 milestone

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

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

[Feature] :new:

  • #788  sort util 封装数组或者集合 固定的排序方法

com.feilong.core.util.SortUtil
新增  sortListByFixedOrderArray(List<T>, T...) 和  sortListByFixedOrderList(List<T>, List<T>) 方法

对 集合 list 按照指定的固定顺序 fixedOrderItemList 进行排序.

说明:

默认使用的是 UnknownObjectBehavior.AFTER ,不在指定固定顺序的元素将排在后面

示例:

assertThat(
                 sortListByFixedOrderList(toList("张飞", "关羽", "刘备"), toList("刘备", "张飞", "关羽")), //
                 contains("刘备", "张飞", "关羽"));

重构:

对于以下代码:

try{
    Collections.sort(
        list,
        new FixedOrderComparator<>(
            StoPropertyConstants.PRPT_ITEM_HYPELAUNCH,
            StoPropertyConstants.PRPT_ITEM_MIADIDAS_VALUE_EN,
            StoPropertyConstants.PRPT_ITEM_PRESONALLZATION_CODE,
            StoPropertyConstants.PRPT_ITEM_PERSALES_CODE,
            StoPropertyConstants.PRPT_ITEM_VIP_CODE,
            StoPropertyConstants.PRPT_ITEM_COMINGSOON_CODE,
            StoPropertyConstants.PRPT_ITEM_DISCOUNT_CODE,
            StoPropertyConstants.PRPT_ITEM_NORMAL_CODE,
            StoPropertyConstants.PRPT_ITEM_NOSALE));
 }catch (Exception e){
     LOGGER.error("itemType sort error:{},itemType:{}", e, JsonUtil.format(itemType));
 }

可以重构成:

com.feilong.core.util.SortUtil.sortListByFixedOrderList(
    list,
    toList(
            StoPropertyConstants.PRPT_ITEM_HYPELAUNCH,
            StoPropertyConstants.PRPT_ITEM_MIADIDAS_VALUE_EN,
            StoPropertyConstants.PRPT_ITEM_PRESONALLZATION_CODE,
            StoPropertyConstants.PRPT_ITEM_PERSALES_CODE,
            StoPropertyConstants.PRPT_ITEM_VIP_CODE,
            StoPropertyConstants.PRPT_ITEM_COMINGSOON_CODE,
            StoPropertyConstants.PRPT_ITEM_DISCOUNT_CODE,
            StoPropertyConstants.PRPT_ITEM_NORMAL_CODE,
            StoPropertyConstants.PRPT_ITEM_NOSALE));
  • #789 新建  ComparatorUtil

  • #791 新建  ContainsStringPredicate

使用场景,参考

<bean class="com.feilong.context.converter.IfStringToBeanConverter">

        <property name="predicate">
            <bean class="com.feilong.core.util.predicate.ContainsStringPredicate" p:searchCharSequence="TRADE_NOT_EXIST" />
        </property>

        <property name="trueStringToBeanConverter">
            <bean class="com.feilong.netpay.alipay.query.AlipayTradeNotExistStringToBeanConverter" />
        </property>

        <property name="falseStringToBeanConverter">
            <bean class="com.feilong.context.converter.XMLMapBuilderStringToBeanConverter">
                <property name="beanClass" value="com.feilong.netpay.alipay.query.AlipaySingleQueryResultCommand" />

                <property name="nameAndValueMapBuilder">
                    <bean class="com.feilong.context.converter.builder.XmlNodeNameAndValueMapBuilder" p:xpathExpression="/alipay/response/trade/*" />
                </property>

                <property name="beanBuilder">
                    <bean class="com.feilong.context.converter.builder.AliasBeanBuilder" />
                </property>
            </bean>
        </property>
    </bean>

[Update]

  • none

[版本升级]

  • none

[Remove]

  • none

[Fix Bug] :bug:

  • none

[Javadoc]

  • none

[Junit Test]

  • none
原文  https://www.oschina.net/news/109422/feilong-core-1-14-3-released
正文到此结束
Loading...