统一工具类命名规则。

This commit is contained in:
2024-04-03 16:20:41 +08:00
parent 09b5b1e0f3
commit cc34af04c2
12 changed files with 37 additions and 74 deletions

View File

@@ -30,7 +30,7 @@ import javax.annotation.Nullable;
import com.google.common.annotations.Beta;
import xyz.zhouxy.plusone.commons.util.ConcurrentHashMapUtil;
import xyz.zhouxy.plusone.commons.util.ConcurrentHashMapTools;
@Beta
public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V, T>> {
@@ -130,7 +130,7 @@ public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V
public final V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
if (this.map instanceof ConcurrentHashMap) {
return ConcurrentHashMapUtil.computeIfAbsent(
return ConcurrentHashMapTools.computeIfAbsent(
(ConcurrentHashMap<K, V>) this.map, key, mappingFunction);
} else {
return this.map.computeIfAbsent(key, mappingFunction);

View File

@@ -23,7 +23,7 @@ import java.util.function.Function;
import javax.annotation.concurrent.ThreadSafe;
import xyz.zhouxy.plusone.commons.base.JRE;
import xyz.zhouxy.plusone.commons.util.ConcurrentHashMapUtil;
import xyz.zhouxy.plusone.commons.util.ConcurrentHashMapTools;
/**
* SafeConcurrentHashMap
@@ -35,7 +35,7 @@ import xyz.zhouxy.plusone.commons.util.ConcurrentHashMapUtil;
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* @since 1.0
* @see ConcurrentHashMap
* @see ConcurrentHashMapUtil#computeIfAbsentForJava8(ConcurrentHashMap, Object, Function)
* @see ConcurrentHashMapTools#computeIfAbsentForJava8(ConcurrentHashMap, Object, Function)
*/
@ThreadSafe
public class SafeConcurrentHashMap<K, V> extends ConcurrentHashMap<K, V> {
@@ -115,7 +115,7 @@ public class SafeConcurrentHashMap<K, V> extends ConcurrentHashMap<K, V> {
@Override
public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
return JRE.isJava8()
? ConcurrentHashMapUtil.computeIfAbsentForJava8(this, key, mappingFunction)
? ConcurrentHashMapTools.computeIfAbsentForJava8(this, key, mappingFunction)
: super.computeIfAbsent(key, mappingFunction);
}
}

View File

@@ -23,7 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.base.Preconditions;
import xyz.zhouxy.plusone.commons.util.RegexUtil;
import xyz.zhouxy.plusone.commons.util.RegexTools;
/**
* 带校验的字符串值对象
@@ -38,7 +38,7 @@ public abstract class ValidatableStringRecord
protected ValidatableStringRecord(String value, Pattern pattern) {
Preconditions.checkNotNull(pattern, "The pattern must not be null.");
Preconditions.checkArgument(StringUtils.isNotBlank(value), "The value must be has text.");
Preconditions.checkArgument(RegexUtil.matches(value, pattern));
Preconditions.checkArgument(RegexTools.matches(value, pattern));
this.value = value;
}

View File

@@ -24,7 +24,7 @@ import xyz.zhouxy.plusone.commons.base.JRE;
import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
/**
* ConcurrentHashMapUtil
* ConcurrentHashMapTools
*
* <p>
* Java 8 {@link ConcurrentHashMap#computeIfAbsent(Object, Function)} 方法有 bug
@@ -38,9 +38,10 @@ import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
* @see ConcurrentHashMap
* @see SafeConcurrentHashMap
*/
public class ConcurrentHashMapUtil {
public class ConcurrentHashMapTools {
public static <K, V> V computeIfAbsent(ConcurrentHashMap<K, V> map, final K key,
public static <K, V> V computeIfAbsent(
ConcurrentHashMap<K, V> map, final K key, // NOSONAR
final Function<? super K, ? extends V> mappingFunction) {
Objects.requireNonNull(map, "map");
return JRE.isJava8()
@@ -48,7 +49,8 @@ public class ConcurrentHashMapUtil {
: map.computeIfAbsent(key, mappingFunction);
}
public static <K, V> V computeIfAbsentForJava8(ConcurrentHashMap<K, V> map, final K key,
public static <K, V> V computeIfAbsentForJava8(
ConcurrentHashMap<K, V> map, final K key, // NOSONAR
final Function<? super K, ? extends V> mappingFunction) {
Objects.requireNonNull(key);
Objects.requireNonNull(mappingFunction);
@@ -66,7 +68,7 @@ public class ConcurrentHashMapUtil {
return v;
}
private ConcurrentHashMapUtil() {
private ConcurrentHashMapTools() {
throw new IllegalStateException("Utility class");
}
}

View File

@@ -20,7 +20,7 @@ import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
import xyz.zhouxy.plusone.commons.collection.MapWrapper;
public class DateTimeUtil {
public class DateTimeTools {
private static final MapWrapper<String, DateTimeFormatter> DATE_TIME_FORMATTER_CACHE = MapWrapper
.<String, DateTimeFormatter>wrap(new SafeConcurrentHashMap<>())
@@ -325,7 +325,7 @@ public class DateTimeUtil {
return org.joda.time.DateTimeZone.forID(zone.getId());
}
private DateTimeUtil() {
private DateTimeTools() {
throw new IllegalStateException("Utility class");
}
}

View File

@@ -27,9 +27,9 @@ import com.google.common.base.Preconditions;
*
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
*/
public final class EnumUtil {
public final class EnumTools {
private EnumUtil() {
private EnumTools() {
throw new IllegalStateException("Utility class");
}

View File

@@ -17,7 +17,7 @@
package xyz.zhouxy.plusone.commons.util;
/**
* NumberUtil
* Numbers
*
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
*/

View File

@@ -38,7 +38,7 @@ import com.google.common.annotations.Beta;
* @see OptionalLong
* @see OptionalDouble
*/
public class OptionalUtil {
public class OptionalTools {
/**
* 将包装类 {@link Integer} 转为 {@link OptionalInt}not null
@@ -149,7 +149,7 @@ public class OptionalUtil {
return optionalObj.isPresent() ? optionalObj.getAsDouble() : null;
}
private OptionalUtil() {
private OptionalTools() {
throw new IllegalStateException("Utility class");
}
}

View File

@@ -2,8 +2,8 @@ package xyz.zhouxy.plusone.commons.util;
import java.security.SecureRandom;
public final class RandomUtil {
private RandomUtil() {
public final class RandomTools {
private RandomTools() {
throw new IllegalStateException("Utility class");
}

View File

@@ -35,7 +35,7 @@ import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
* @author ZhouXY
*
*/
public final class RegexUtil {
public final class RegexTools {
private static final int DEFAULT_CACHE_INITIAL_CAPACITY = 64;
private static final int MAX_CACHE_SIZE = 256;
@@ -330,7 +330,7 @@ public final class RegexUtil {
@Nonnull
private static Pattern[] getAndCachePatternsInternal(@Nonnull final String[] patterns) {
return Arrays.stream(patterns)
.map(RegexUtil::getAndCachePatternInternal)
.map(RegexTools::getAndCachePatternInternal)
.toArray(Pattern[]::new);
}
@@ -344,7 +344,7 @@ public final class RegexUtil {
@Nonnull
private static Pattern[] getPatternsInternal(@Nonnull final String[] patterns) {
return Arrays.stream(patterns)
.map(RegexUtil::getPatternInternal)
.map(RegexTools::getPatternInternal)
.toArray(Pattern[]::new);
}
@@ -389,7 +389,7 @@ public final class RegexUtil {
return Arrays.stream(array).allMatch(Objects::nonNull);
}
private RegexUtil() {
private RegexTools() {
// 不允许实例化
throw new IllegalStateException("Utility class");
}