This commit is contained in:
Looly
2023-04-22 21:53:58 +08:00
parent 2d9febc7fb
commit 6a04ef4a3a
12 changed files with 422 additions and 299 deletions

View File

@@ -1,4 +1,16 @@
package org.dromara.hutool.core.lang.func;
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.core.func;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.date.DateUtil;

View File

@@ -1,12 +1,22 @@
package org.dromara.hutool.core.lang.func;
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.core.func;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.dromara.hutool.core.collection.ListUtil;
import org.dromara.hutool.core.func.LambdaFactory;
import org.dromara.hutool.core.func.SerSupplier;
import org.dromara.hutool.core.reflect.ConstructorUtil;
import org.dromara.hutool.core.reflect.lookup.LookupUtil;
import org.junit.jupiter.api.Assertions;

View File

@@ -1,20 +1,30 @@
package org.dromara.hutool.core.lang.func;
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.core.func;
import org.dromara.hutool.core.func.*;
import org.dromara.hutool.core.lang.tuple.Tuple;
import org.dromara.hutool.core.reflect.MethodUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldNameConstants;
import org.dromara.hutool.core.lang.tuple.Tuple;
import org.dromara.hutool.core.reflect.MethodUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.*;
import java.util.stream.Stream;
public class LambdaUtilTest {
@@ -307,4 +317,30 @@ public class LambdaUtilTest {
return func.getClass().getName();
}
}
@Test
void getInvokeMethodTest() {
Method invokeMethod = LambdaUtil.getInvokeMethod(Predicate.class);
Assertions.assertEquals("test", invokeMethod.getName());
invokeMethod = LambdaUtil.getInvokeMethod(Consumer.class);
Assertions.assertEquals("accept", invokeMethod.getName());
invokeMethod = LambdaUtil.getInvokeMethod(Runnable.class);
Assertions.assertEquals("run", invokeMethod.getName());
invokeMethod = LambdaUtil.getInvokeMethod(SerFunction.class);
Assertions.assertEquals("applying", invokeMethod.getName());
invokeMethod = LambdaUtil.getInvokeMethod(Function.class);
Assertions.assertEquals("apply", invokeMethod.getName());
}
@Test
void getInvokeMethodErrorTest() {
// 非函数接口返回异常
Assertions.assertThrows(IllegalArgumentException.class, ()->{
LambdaUtil.getInvokeMethod(LambdaUtilTest.class);
});
}
}

View File

@@ -1,4 +1,16 @@
package org.dromara.hutool.core.lang.func;
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.core.func;
import org.dromara.hutool.core.collection.set.SetUtil;
import org.dromara.hutool.core.func.PredicateUtil;