美文网首页
函数式编程之Predicate

函数式编程之Predicate

作者: hehehehe | 来源:发表于2020-11-27 16:47 被阅读0次
String qVal = tempString.split("\\s+")[valueIndex];
if (predicate.test(qVal)) {
    linkedList.add(tempString);
} else {
    if (linkedList.size() > continueMaxTimes * 100) {
        createRecord(linkedList, exceptPoint, exceptLas);
    }
    linkedList.clear();
}
static Predicate<String> getPredicate(JsonNode thresholdValue, String thresholdType) {
        Predicate<String> predicate = null;
        if (thresholdValue.isInt()) {
            if (">".equals(thresholdType)) {
                predicate = x -> Integer.parseInt(x) > thresholdValue.intValue();
            } else if ("<".equals(thresholdType)) {
                predicate = x -> Integer.parseInt(x) < thresholdValue.intValue();
            } else if (">=".equals(thresholdType)) {
                predicate = x -> Integer.parseInt(x) >= thresholdValue.intValue();
            } else if ("<=".equals(thresholdType)) {
                predicate = x -> Integer.parseInt(x) <= thresholdValue.intValue();
            }
        } else if (thresholdValue.isDouble()) {
            if (">".equals(thresholdType)) {
                predicate = x -> Float.parseFloat(x) > thresholdValue.floatValue();
            } else if ("<".equals(thresholdType)) {
                predicate = x -> Float.parseFloat(x) < thresholdValue.floatValue();
            } else if (">=".equals(thresholdType)) {
                predicate = x -> Float.parseFloat(x) >= thresholdValue.floatValue();
            } else if ("<=".equals(thresholdType)) {
                predicate = x -> Float.parseFloat(x) <= thresholdValue.floatValue();
            }
        } else if (thresholdValue.isTextual()) {
            predicate = x -> x.equals(thresholdValue.textValue());
        }

        return predicate;
    }

相关文章

网友评论

      本文标题:函数式编程之Predicate

      本文链接:https://www.haomeiwen.com/subject/nkgxwktx.html