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

xxl.mathematica.list.SelectFirst Maven / Gradle / Ivy

package xxl.mathematica.list;

import xxl.mathematica.exception.ItemNotFoundException;

import java.util.List;
import java.util.function.Predicate;

/**
 * 选择第一个
 */

public class SelectFirst {
    /**
     * 给出第一个 Subscript[e, i],满足 crit[Subscript[e, i]] 是 True 或者找不到任何内容时抛出异常
     *
     * @param list
     * @param criteria
     * @param 
     * @return
     * @throws ItemNotFoundException
     */
    public static  T selectFirst(List list, Predicate criteria) throws ItemNotFoundException {
        return selectFirst(list, criteria, null);
    }

    /**
     * 给出 default,如果不存在满足 criteria 是 True 的 元素
     *
     * @param list
     * @param criteria
     * @param def
     * @param 
     * @return
     */
    public static  T selectFirst(List list, Predicate criteria, T def) {
        return io.vavr.collection.List.ofAll(list)
                .find(criteria)
                .getOrElse(def);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy