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

com.github.houbb.chinese.idiom.util.ChinesePhraseHelper Maven / Gradle / Ivy

The newest version!
package com.github.houbb.chinese.idiom.util;

import com.github.houbb.chinese.common.api.IChineseInfo;
import com.github.houbb.chinese.common.constant.ChineseConst;
import com.github.houbb.chinese.common.support.handler.IChineseInfoHandler;
import com.github.houbb.chinese.common.support.handler.impl.ChineseInfoHandlers;
import com.github.houbb.chinese.idiom.bs.ChineseIdiomBs;
import com.github.houbb.chinese.idiom.constant.enums.IdiomChineseNum;
import com.github.houbb.chinese.idiom.constant.enums.IdiomChineseStyle;
import com.github.houbb.heaven.util.common.ArgUtil;

import java.util.List;

/**
 * @author binbin.hou
 * @since 0.0.1
 */
public final class ChinesePhraseHelper {

    private ChinesePhraseHelper(){}

    /**
     * 包含指定文字的词语
     * @param text 文本
     * @return 结果列表
     * @since 0.0.2
     */
    public static IChineseInfo equals(final String text) {
        return ChineseIdiomBs.newInstance().equals(text);
    }

    /**
     * 包含指定文字的词语
     * @param text 文本
     * @return 结果列表
     * @since 0.0.1
     */
    public static List contains(final String text) {
        List chineseInfos = ChineseIdiomBs.newInstance().contains(text, ChineseConst.DEFAULT_LIMIT);
        return resultHandler(chineseInfos, ChineseInfoHandlers.defaults());
    }

    /**
     * 以指定文字开始的词语
     * @param text 文本
     * @return 结果列表
     * @since 0.0.1
     */
    public static List startWith(final String text) {
        List chineseInfos =  ChineseIdiomBs.newInstance().startWith(text, ChineseConst.DEFAULT_LIMIT);
        return resultHandler(chineseInfos, ChineseInfoHandlers.defaults());
    }

    /**
     * 以指定文字结束的词语
     * @param text 文本
     * @return 结果列表
     * @since 0.0.1
     */
    public static List endWith(final String text) {
        List chineseInfos = ChineseIdiomBs.newInstance().endWith(text, ChineseConst.DEFAULT_LIMIT);
        return resultHandler(chineseInfos, ChineseInfoHandlers.defaults());
    }

    /**
     * 以指定文字个数的词语
     * @param num 成语字数
     * @return 结果列表
     * @since 0.0.1
     */
    public static List withNum(final IdiomChineseNum num) {
        List chineseInfos = ChineseIdiomBs.newInstance().withNum(num.num(), ChineseConst.DEFAULT_LIMIT);
        return resultHandler(chineseInfos, ChineseInfoHandlers.defaults());
    }

    /**
     * 以指定文字个数的词语
     * @param style 成语样式
     * @return 结果列表
     * @since 0.0.1
     */
    public static List withStyle(final IdiomChineseStyle style) {
        List chineseInfos = ChineseIdiomBs.newInstance().withStyle(style.style(), ChineseConst.DEFAULT_LIMIT);

        return resultHandler(chineseInfos, ChineseInfoHandlers.defaults());
    }


    /**
     * 结果处理
     * @param list 原始列表
     * @param handler 限制类
     * @param  泛型
     * @return 处理后的结果列表
     * @since 0.0.1
     */
    private static  R resultHandler(final List list, final IChineseInfoHandler handler) {
        ArgUtil.notNull(handler, "handler");

        return handler.handler(list);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy