package com.fufan.mtsaas.tools;

import lombok.Data;

import java.util.function.Predicate;

public class PredicateEvaluator {

    public static boolean evaluate(Object obj, Predicate<Object> predicate) {
        return predicate.test(obj);
    }

    public static void main(String[] args) {
        Product product = new Product("Laptop", 999.99, true);

        // 定义动态判断条件
        Predicate<Object> isExpensive = o -> ((Product) o).getPrice() > 500;
        Predicate<Object> isAvailable = o -> ((Product) o).isInStock();

        System.out.println("Is expensive: " + evaluate(product, isExpensive)); // true
        System.out.println("Is available: " + evaluate(product, isAvailable)); // true
    }
}

@Data
class Product {
    private String name;
    private double price;
    private boolean inStock;

    // 构造方法和getter/setter省略...
    public Product(String name, double price, boolean inStock) {
        this.name = name;
        this.price = price;
        this.inStock = inStock;
    }
}