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

com.github.cosycode.ext.hub.OnceExecClosureProxy Maven / Gradle / Ivy

Go to download

扩展模块, 用于存放一些非常用的工具或模块的扩展类, 例如在poi基础上扩展的excel的导入模块, 模拟按键模块

The newest version!
package com.github.cosycode.ext.hub;

import lombok.NonNull;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;

/**
 * Description : 
 * 

* created in 2021/4/6 * * @author CPF **/ public class OnceExecClosureProxy extends AbstractClosureProxy { private final Lock lock = new ReentrantLock(); private T skip; public OnceExecClosureProxy(@NonNull T then) { super(then); } public OnceExecClosureProxy(@NonNull T then, @NonNull BiFunction function) { super(then, function); } public OnceExecClosureProxy(@NonNull T then, @NonNull BiConsumer biConsumer) { super(then, biConsumer); } public static T of(T then) { return new OnceExecClosureProxy<>(then).proxy(); } public OnceExecClosureProxy skip(T skip) { this.skip = skip; return this; } @Override public R closureFunction(P params) { if (lock.tryLock()) { try { if (functional != null) { return biFunction.apply(functional, params); } } finally { lock.unlock(); } } else { if (skip != null) { return biFunction.apply(skip, params); } } return null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy