统一工具类命名规则。
parent
09b5b1e0f3
commit
cc34af04c2
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
/**
|
||||
* NumberUtil
|
||||
* Numbers
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
|
@ -11,40 +11,40 @@ import org.junit.jupiter.api.Test;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class DateTimeUtilTests {
|
||||
class DateTimeToolsTests {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DateTimeUtilTests.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(DateTimeToolsTests.class);
|
||||
|
||||
@Test
|
||||
void testLocalNowStr() {
|
||||
log.info(DateTimeUtil.nowStr("yyyy/MM/dd HH:mm:ss.SSS"));
|
||||
log.info(DateTimeTools.nowStr("yyyy/MM/dd HH:mm:ss.SSS"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToJoda() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
log.info("now: {}", now);
|
||||
org.joda.time.LocalDateTime now2 = DateTimeUtil.toJodaLocalDateTime(now);
|
||||
org.joda.time.LocalDateTime now2 = DateTimeTools.toJodaLocalDateTime(now);
|
||||
log.info("now2: {}", now2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToInstant() {
|
||||
Instant now = DateTimeUtil.toInstant(System.currentTimeMillis());
|
||||
String str = DateTimeUtil.toString("yy-M-d HH:mm:ss.SSS", now);
|
||||
Instant now = DateTimeTools.toInstant(System.currentTimeMillis());
|
||||
String str = DateTimeTools.toString("yy-M-d HH:mm:ss.SSS", now);
|
||||
log.info(str);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToJodaDateTime() {
|
||||
DateTime jodaDateTime = DateTimeUtil.toJodaDateTime(Instant.now(), ZoneId.of("+08:00"));
|
||||
DateTime jodaDateTime = DateTimeTools.toJodaDateTime(Instant.now(), ZoneId.of("+08:00"));
|
||||
log.info("jodaDateTime: {}", jodaDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
Instant now = Instant.now();
|
||||
DateTime jodaDateTime = DateTimeUtil.toJodaDateTime(now, ZoneId.of("America/New_York"));
|
||||
DateTime jodaDateTime = DateTimeTools.toJodaDateTime(now, ZoneId.of("America/New_York"));
|
||||
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
log.info(formatter.print(jodaDateTime));
|
||||
log.info(jodaDateTime.getZone().toString());
|
||||
|
@ -52,7 +52,7 @@ class DateTimeUtilTests {
|
|||
log.info("==========================================");
|
||||
org.joda.time.Instant instant = new org.joda.time.Instant(System.currentTimeMillis() - 500000);
|
||||
log.info(instant.toString());
|
||||
log.info(DateTimeUtil.toJavaInstant(instant).toString());
|
||||
log.info(DateTimeUtil.toZonedDateTime(instant, DateTimeZone.forID("America/New_York")).toString());
|
||||
log.info(DateTimeTools.toJavaInstant(instant).toString());
|
||||
log.info(DateTimeTools.toZonedDateTime(instant, DateTimeZone.forID("America/New_York")).toString());
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
class NumberUtilTest {
|
||||
private static final Logger log = LoggerFactory.getLogger(NumberUtilTest.class);
|
||||
|
||||
@Test
|
||||
void testSum() {
|
||||
long result = 0;
|
||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||
result += Short.MAX_VALUE;
|
||||
}
|
||||
log.info("Integer.MAX_VALUE: {}", Integer.MAX_VALUE);
|
||||
log.info("result: {}", result);
|
||||
assertFalse(Integer.MAX_VALUE > result);
|
||||
|
||||
result = 0;
|
||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||
result += Short.MAX_VALUE;
|
||||
}
|
||||
log.info("Long.MAX_VALUE: {}", Long.MAX_VALUE);
|
||||
log.info("result: {}", result);
|
||||
assertTrue(Long.MAX_VALUE > result);
|
||||
|
||||
result = 0;
|
||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||
result += Integer.MAX_VALUE;
|
||||
}
|
||||
log.info("Long.MAX_VALUE: {}", Long.MAX_VALUE);
|
||||
log.info("result: {}", result);
|
||||
assertTrue(Long.MAX_VALUE > result);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue