All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.qdbp.jdbc.model.OmitStrategy Maven / Gradle / Ivy

package com.gitee.qdbp.jdbc.model;

import java.io.Serializable;
import com.gitee.qdbp.tools.utils.ConvertTools;
import com.gitee.qdbp.tools.utils.StringTools;

/**
 * 省略策略
 *
 * @author zhaohuihua
 * @version 20201005
 * @since 3.2.0
 */
public class OmitStrategy implements Serializable {

    /** serialVersionUID **/
    private static final long serialVersionUID = 1L;

    /** 至少超过多少项时启用省略 **/
    private final int minSize;
    /** 省略时首末各保留多少项 **/
    private final int keepSize;

    public OmitStrategy(int minSize, int keepSize) {
        this.minSize = minSize;
        this.keepSize = keepSize;
    }

    /** 至少超过多少项时启用省略 **/
    public int getMinSize() {
        return minSize;
    }

    /** 省略时首末各保留多少项 **/
    public int getKeepSize() {
        return keepSize;
    }

    /**
     * 解析省略策略字符串
* minSize:keepSize, 以冒号分隔; 如8:3, 表示超过8项启用省略, 前后各保留3项
* 如果只有一个数字, 那这个数字就是minSize, 此时keepSize=3
* * @param string 省略策略字符串 * @return 省略策略对象 */ public static OmitStrategy of(String string) { if (string == null || string.trim().length() == 0) { return new OmitStrategy(0, 0); } try { int minSize; int keepSize; if (string.indexOf(':') < 0) { minSize = ConvertTools.toInteger(string.trim()); keepSize = 3; } else { String[] array = StringTools.split(string.trim(), ':'); if (array.length != 2) { throw new IllegalArgumentException("OmitSizeFormatError: " + string); } minSize = ConvertTools.toInteger(array[0]); keepSize = ConvertTools.toInteger(array[1]); } if (minSize == 0) { return new OmitStrategy(0, 0); } if (minSize < 0 || keepSize <= 0) { throw new IllegalArgumentException("OmitSizeFormatError: " + string); } if (minSize < keepSize * 2 + 2) { minSize = keepSize * 2 + 2; } return new OmitStrategy(minSize, keepSize); } catch (NumberFormatException e) { throw new IllegalArgumentException("OmitSizeFormatError: " + string); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy