Class MoreKit
java.lang.Object
com.iohao.net.common.kit.MoreKit
General-purpose utility methods.
- Author:
- 渔民小镇
- date:
- 2023-12-07
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidExecute the runnable on the given executor, or run it on the current thread if the executor is null.static <T> TfirstNonNull(T first, T second) Return the first non-null argument, or throw if both are null.static <K,T> T putIfAbsent(Map<K, T> map, K key, T value) Put the value into the map if the key is absent, and return the effective value.
-
Method Details
-
firstNonNull
public static <T> T firstNonNull(T first, T second) Return the first non-null argument, or throw if both are null.- Type Parameters:
T- the value type- Parameters:
first- the first candidatesecond- the second candidate- Returns:
- the first non-null value
- Throws:
NullPointerException- if both arguments are null
-
putIfAbsent
Put the value into the map if the key is absent, and return the effective value.If the key already exists, the existing value is returned; otherwise the newly inserted value is returned.
- Type Parameters:
K- the key typeT- the value type- Parameters:
map- the target mapkey- the key to checkvalue- the value to insert if absent- Returns:
- the existing value for the key, or
valueif newly inserted
-
execute
-