This commit is contained in:
Looly
2025-06-25 11:23:36 +08:00
parent a7c5259d4b
commit 9d83869d85
36 changed files with 248 additions and 95 deletions

View File

@@ -35,6 +35,7 @@ import java.util.Map;
* @since 5.7.23
*/
public class AnnotationProxy<T extends Annotation> implements Annotation, InvocationHandler, Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**

View File

@@ -48,7 +48,7 @@ public class CacheObj<K, V> implements Serializable {
/**
* 访问次数
*/
protected AtomicLong accessCount = new AtomicLong();
protected final AtomicLong accessCount = new AtomicLong();
/**
* 对象存活时长0表示永久存活
*/

View File

@@ -21,6 +21,7 @@ import cn.hutool.v7.core.codec.Encoder;
import cn.hutool.v7.core.array.ArrayUtil;
import java.io.ByteArrayOutputStream;
import java.io.Serial;
import java.io.Serializable;
/**
@@ -31,6 +32,7 @@ import java.io.Serializable;
* @since 4.5.9
*/
public class Base62Codec implements Encoder<byte[], byte[]>, Decoder<byte[], byte[]>, Serializable {
@Serial
private static final long serialVersionUID = 1L;
private static final int STANDARD_BASE = 256;
@@ -39,7 +41,7 @@ public class Base62Codec implements Encoder<byte[], byte[]>, Decoder<byte[], byt
/**
* 单例
*/
public static Base62Codec INSTANCE = new Base62Codec();
public static final Base62Codec INSTANCE = new Base62Codec();
/**
* 编码指定消息bytes为Base62格式的bytes
@@ -124,11 +126,11 @@ public class Base62Codec implements Encoder<byte[], byte[]>, Decoder<byte[], byt
/**
* GMP风格编码器
*/
public static Base62Encoder GMP_ENCODER = new Base62Encoder(GMP);
public static final Base62Encoder GMP_ENCODER = new Base62Encoder(GMP);
/**
* 反转风格即将GMP风格中的大小写做转换编码器
*/
public static Base62Encoder INVERTED_ENCODER = new Base62Encoder(INVERTED);
public static final Base62Encoder INVERTED_ENCODER = new Base62Encoder(INVERTED);
private final byte[] alphabet;
@@ -158,11 +160,11 @@ public class Base62Codec implements Encoder<byte[], byte[]>, Decoder<byte[], byt
/**
* GMP风格解码器
*/
public static Base62Decoder GMP_DECODER = new Base62Decoder(Base62Encoder.GMP);
public static final Base62Decoder GMP_DECODER = new Base62Decoder(Base62Encoder.GMP);
/**
* 反转风格即将GMP风格中的大小写做转换解码器
*/
public static Base62Decoder INVERTED_DECODER = new Base62Decoder(Base62Encoder.INVERTED);
public static final Base62Decoder INVERTED_DECODER = new Base62Decoder(Base62Encoder.INVERTED);
private final byte[] lookupTable;

View File

@@ -20,6 +20,7 @@ import cn.hutool.v7.core.codec.Decoder;
import cn.hutool.v7.core.lang.mutable.MutableInt;
import cn.hutool.v7.core.array.ArrayUtil;
import java.io.Serial;
import java.io.Serializable;
/**
@@ -31,12 +32,13 @@ import java.io.Serializable;
*
*/
public class Base64Decoder implements Decoder<byte[], byte[]>, Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 单例对象
*/
public static Base64Decoder INSTANCE = new Base64Decoder();
public static final Base64Decoder INSTANCE = new Base64Decoder();
private static final byte PADDING = -2;

View File

@@ -36,7 +36,7 @@ public class CityHash implements Hash32<byte[]>, Hash64<byte[]>, Hash128<byte[]>
/**
* 单例
*/
public static CityHash INSTANCE = new CityHash();
public static final CityHash INSTANCE = new CityHash();
// Some primes between 2^63 and 2^64 for various uses.
private static final long k0 = 0xc3a5c85c97cb3127L;

View File

@@ -16,6 +16,7 @@
package cn.hutool.v7.core.codec.hash;
import java.io.Serial;
import java.io.Serializable;
import java.util.Collection;
import java.util.SortedMap;
@@ -30,6 +31,7 @@ import java.util.TreeMap;
* @author Looly
*/
public class ConsistentHash<T> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**

View File

@@ -29,6 +29,7 @@ import cn.hutool.v7.core.reflect.ConstructorUtil;
import cn.hutool.v7.core.reflect.TypeUtil;
import cn.hutool.v7.core.text.StrUtil;
import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Map;
@@ -45,12 +46,13 @@ import java.util.Map;
* @since 4.0.2
*/
public class BeanConverter implements Converter, Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 单例对象
*/
public static BeanConverter INSTANCE = new BeanConverter();
public static final BeanConverter INSTANCE = new BeanConverter();
private final CopyOptions copyOptions;

View File

@@ -20,6 +20,7 @@ import cn.hutool.v7.core.convert.AbstractConverter;
import cn.hutool.v7.core.classloader.ClassLoaderUtil;
import cn.hutool.v7.core.convert.MatcherConverter;
import java.io.Serial;
import java.lang.reflect.Type;
/**
@@ -29,12 +30,13 @@ import java.lang.reflect.Type;
* @author Looly
*/
public class ClassConverter extends AbstractConverter implements MatcherConverter {
@Serial
private static final long serialVersionUID = 1L;
/**
* 单例
*/
public static ClassConverter INSTANCE = new ClassConverter();
public static final ClassConverter INSTANCE = new ClassConverter();
private final boolean isInitialized;

View File

@@ -21,6 +21,7 @@ import cn.hutool.v7.core.convert.MatcherConverter;
import cn.hutool.v7.core.reflect.TypeReference;
import cn.hutool.v7.core.reflect.TypeUtil;
import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Collection;
@@ -32,12 +33,13 @@ import java.util.Collection;
* @since 3.0.8
*/
public class CollectionConverter implements MatcherConverter, Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 单例实体
*/
public static CollectionConverter INSTANCE = new CollectionConverter();
public static final CollectionConverter INSTANCE = new CollectionConverter();
@Override
public boolean match(final Type targetType, final Class<?> rawType, final Object value) {

View File

@@ -35,7 +35,7 @@ public class BlobStringer implements Function<Object, String> {
/**
* 单例
*/
public static ClobStringer INSTANCE = new ClobStringer();
public static final ClobStringer INSTANCE = new ClobStringer();
@Override

View File

@@ -34,7 +34,7 @@ public class ClobStringer implements Function<Object, String> {
/**
* 单例
*/
public static ClobStringer INSTANCE = new ClobStringer();
public static final ClobStringer INSTANCE = new ClobStringer();
@Override
public String apply(final Object o) {

View File

@@ -32,7 +32,7 @@ public class DefaultRegexDateParser implements PredicateDateParser {
/**
* 默认实例
*/
public static DefaultRegexDateParser INSTANCE = new DefaultRegexDateParser();
public static final DefaultRegexDateParser INSTANCE = new DefaultRegexDateParser();
private final RegexDateParser parser;

View File

@@ -34,7 +34,7 @@ public class DelVisitor extends SimpleFileVisitor<Path> {
/**
* 单例对象
*/
public static DelVisitor INSTANCE = new DelVisitor();
public static final DelVisitor INSTANCE = new DelVisitor();
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {

View File

@@ -17,7 +17,6 @@
package cn.hutool.v7.core.math;
import cn.hutool.v7.core.array.ArrayUtil;
import cn.hutool.v7.core.lang.Console;
import cn.hutool.v7.core.text.CharUtil;
import cn.hutool.v7.core.text.StrUtil;

View File

@@ -17,7 +17,6 @@
package cn.hutool.v7.core.net.url;
import cn.hutool.v7.core.convert.ConvertUtil;
import cn.hutool.v7.core.lang.Console;
import cn.hutool.v7.core.map.MapUtil;
import cn.hutool.v7.core.text.StrUtil;
import cn.hutool.v7.core.util.CharsetUtil;

View File

@@ -563,7 +563,7 @@ public class BeanUtilTest {
this.openid = openid;
}
public String name;
public final String name;
public int age;
public String openid;
}

View File

@@ -16,14 +16,14 @@
package cn.hutool.v7.core.func;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import cn.hutool.v7.core.collection.ListUtil;
import cn.hutool.v7.core.exception.ExceptionUtil;
import cn.hutool.v7.core.reflect.ConstructorUtil;
import cn.hutool.v7.core.reflect.lookup.LookupUtil;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -73,7 +73,7 @@ public class LambdaFactoryTest {
final BiConsumer<Something, String> set = LambdaFactory.build(BiConsumer.class, Something.class, "setName", String.class);
set.accept(something, name);
Assertions.assertEquals(something.getName(), name);
Assertions.assertEquals(name, something.getName());
}
@Data
@@ -87,7 +87,6 @@ public class LambdaFactoryTest {
*
* @author nasodaengineer
*/
@Disabled
public static class PerformanceTest {
public int count;

View File

@@ -16,7 +16,6 @@
package cn.hutool.v7.core.map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Map;

View File

@@ -17,6 +17,7 @@
package cn.hutool.v7.core.map;
import cn.hutool.v7.core.map.multi.DirectedWeightGraph;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -56,16 +57,8 @@ public class DirectedWeightGraphTest {
graph.removePoint("X");
System.out.println(graph);
Map<String, DirectedWeightGraph.Path<String>> map = null;
try {
map = graph.bestPathMap("A");
map.forEach((k, v) -> {
System.out.println(v);
});
} catch (final DirectedWeightGraph.NegativeRingException e) {
e.printStackTrace();
}
Assertions.assertThrows(DirectedWeightGraph.NegativeRingException.class, ()->{
graph.bestPathMap("A");
});
}
}

View File

@@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test;
/**
* @author 温良恭
* @Date 2024/8/21 22:04
*/
public class BitStatusUtilTest {
@@ -32,9 +31,9 @@ public class BitStatusUtilTest {
states = BitStatusUtil.add(states, 2); // 添加“已读”状态
states = BitStatusUtil.add(states, 4); // 添加“已写”状态
// 此时states 的值为 6二进制为 110这表示同时具有“已读”和“已写”状态
boolean hasRead = BitStatusUtil.has(states, 2); // 检查“已读”状态
boolean hasWrite = BitStatusUtil.has(states, 4); // 检查“已写”状态
Assertions.assertEquals(true, hasRead);
Assertions.assertEquals(true, hasWrite);
final boolean hasRead = BitStatusUtil.has(states, 2); // 检查“已读”状态
final boolean hasWrite = BitStatusUtil.has(states, 4); // 检查“已写”状态
Assertions.assertTrue(hasRead);
Assertions.assertTrue(hasWrite);
}
}

View File

@@ -31,7 +31,6 @@ import java.util.Objects;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class FieldUtilTest {
@Test

View File

@@ -16,7 +16,6 @@
package cn.hutool.v7.core.text.finder;
import cn.hutool.v7.core.lang.Console;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

View File

@@ -17,13 +17,12 @@
package cn.hutool.v7.core.util;
import cn.hutool.v7.core.collection.set.ConcurrentHashSet;
import cn.hutool.v7.core.data.id.UUID;
import cn.hutool.v7.core.data.id.IdUtil;
import cn.hutool.v7.core.data.id.Snowflake;
import cn.hutool.v7.core.date.DateUtil;
import cn.hutool.v7.core.date.StopWatch;
import cn.hutool.v7.core.exception.HutoolException;
import cn.hutool.v7.core.lang.Console;
import cn.hutool.v7.core.data.id.IdUtil;
import cn.hutool.v7.core.data.id.Snowflake;
import cn.hutool.v7.core.thread.ThreadUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
@@ -35,7 +34,6 @@ import java.util.Set;
import java.util.concurrent.CountDownLatch;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* {@link IdUtil} 单元测试
@@ -47,19 +45,19 @@ public class IdUtilTest {
@Test
public void randomUUIDTest() {
final String simpleUUID = IdUtil.simpleUUID();
Assertions.assertEquals(32, simpleUUID.length());
assertEquals(32, simpleUUID.length());
final String randomUUID = IdUtil.randomUUID();
Assertions.assertEquals(36, randomUUID.length());
assertEquals(36, randomUUID.length());
}
@Test
public void fastUUIDTest() {
final String simpleUUID = IdUtil.fastSimpleUUID();
Assertions.assertEquals(32, simpleUUID.length());
assertEquals(32, simpleUUID.length());
final String randomUUID = IdUtil.fastUUID();
Assertions.assertEquals(36, randomUUID.length());
assertEquals(36, randomUUID.length());
}
/**
@@ -88,14 +86,14 @@ public class IdUtilTest {
@Test
public void objectIdTest() {
final String id = IdUtil.objectId();
Assertions.assertEquals(24, id.length());
assertEquals(24, id.length());
}
@Test
public void getSnowflakeTest() {
final Snowflake snowflake = IdUtil.getSnowflake(1, 1);
final long id = snowflake.next();
Assertions.assertTrue(id > 0);
assertTrue(id > 0);
}
@Test
@@ -126,7 +124,7 @@ public class IdUtilTest {
} catch (final InterruptedException e) {
throw new HutoolException(e);
}
Assertions.assertEquals(threadCount * idCountPerThread, set.size());
assertEquals(threadCount * idCountPerThread, set.size());
}
@Test
@@ -156,14 +154,14 @@ public class IdUtilTest {
} catch (final InterruptedException e) {
throw new HutoolException(e);
}
Assertions.assertEquals(threadCount * idCountPerThread, set.size());
assertEquals(threadCount * idCountPerThread, set.size());
}
@Test
public void getDataCenterIdTest() {
//按照mac地址算法拼接的算法maxDatacenterId应该是0xffffffffL>>6-1此处暂时按照0x7fffffffffffffffL-1防止最后取模溢出
final long dataCenterId = IdUtil.getDataCenterId(Long.MAX_VALUE);
Assertions.assertTrue(dataCenterId >= 0);
assertTrue(dataCenterId >= 0);
}