This commit is contained in:
redkale
2024-08-07 21:16:52 +08:00
parent 2733cbcc62
commit c6fa2a688c
16 changed files with 64 additions and 57 deletions

View File

@@ -571,7 +571,7 @@ public abstract class NodeServer {
return cf;
}
AnyValue[] proplist = this.serverConf.getAnyValues(properties);
if (proplist == null || proplist.length < 1) {
if (Utility.isEmpty(proplist)) {
cf.setRefused(true);
return cf;
}

View File

@@ -726,7 +726,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
}
ConvertFactory columnFactory(Type type, ConvertCoder[] coders, boolean encode) {
if (coders == null || coders.length < 1) {
if (Utility.isEmpty(coders)) {
return this;
}
final ConvertType ct = this.getConvertType();

View File

@@ -182,7 +182,7 @@ public class BsonConvert extends BinaryConvert<BsonReader, BsonWriter> {
@Override
@SuppressWarnings("unchecked")
public <T> T convertFrom(final Type type, final ByteBuffer... buffers) {
if (type == null || buffers.length < 1) {
if (type == null || Utility.isEmpty(buffers)) {
return null;
}
return (T) factory.loadDecoder(type).convertFrom(new BsonByteBufferReader(buffers));

View File

@@ -10,6 +10,7 @@ import java.lang.reflect.*;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.function.*;
import org.redkale.annotation.Nullable;
import org.redkale.convert.*;
import org.redkale.convert.ext.StringArraySimpledCoder;
import org.redkale.util.*;
@@ -28,12 +29,14 @@ public class ProtobufConvert extends BinaryConvert<ProtobufReader, ProtobufWrite
private final ThreadLocal<ProtobufWriter> writerPool = Utility.withInitialThreadLocal(ProtobufWriter::new);
private final Consumer<ProtobufWriter> writerConsumer = w -> offerWriter(w);
private final Consumer<ProtobufWriter> writerConsumer = this::offerWriter;
private final ThreadLocal<ProtobufReader> readerPool = Utility.withInitialThreadLocal(ProtobufReader::new);
@Nullable
private Encodeable lastConvertEncodeable;
@Nullable
private Decodeable lastConvertDecodeable;
protected ProtobufConvert(ConvertFactory<ProtobufReader, ProtobufWriter> factory, int features) {
@@ -634,7 +637,7 @@ public class ProtobufConvert extends BinaryConvert<ProtobufReader, ProtobufWrite
if (true) {
throw new ConvertException(this.getClass().getSimpleName() + " not supported convertFrom ByteBuffer");
}
if (type == null || buffers.length < 1) {
if (type == null || Utility.isEmpty(buffers)) {
return null;
}
Decodeable decoder = this.lastConvertDecodeable;

View File

@@ -3,7 +3,24 @@
*/
package org.redkale.mq.spi;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.redkale.asm.AnnotationVisitor;
import org.redkale.asm.AsmMethodBean;
import org.redkale.asm.AsmMethodBoost;
import org.redkale.asm.Asms;
import org.redkale.asm.ClassWriter;
import static org.redkale.asm.ClassWriter.COMPUTE_FRAMES;
import org.redkale.asm.FieldVisitor;
import org.redkale.asm.Label;
import org.redkale.asm.MethodVisitor;
import org.redkale.asm.Opcodes;
import static org.redkale.asm.Opcodes.ACC_BRIDGE;
import static org.redkale.asm.Opcodes.ACC_PRIVATE;
import static org.redkale.asm.Opcodes.ACC_PUBLIC;
@@ -24,24 +41,6 @@ import static org.redkale.asm.Opcodes.POP;
import static org.redkale.asm.Opcodes.PUTFIELD;
import static org.redkale.asm.Opcodes.RETURN;
import static org.redkale.asm.Opcodes.V11;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.redkale.asm.AnnotationVisitor;
import org.redkale.asm.AsmMethodBean;
import org.redkale.asm.AsmMethodBoost;
import org.redkale.asm.Asms;
import org.redkale.asm.ClassWriter;
import org.redkale.asm.FieldVisitor;
import org.redkale.asm.Label;
import org.redkale.asm.MethodVisitor;
import org.redkale.asm.Opcodes;
import org.redkale.convert.ConvertFactory;
import org.redkale.inject.ResourceFactory;
import org.redkale.mq.MessageConext;
@@ -322,7 +321,7 @@ public class MessageAsmMethodBoost extends AsmMethodBoost {
@Override
public void doInstance(ResourceFactory resourceFactory, Object service) {
DynForMessage[] dyns = service.getClass().getAnnotationsByType(DynForMessage.class);
if (dyns.length < 1) {
if (Utility.isEmpty(dyns)) {
return;
}
try {

View File

@@ -2560,7 +2560,7 @@ public class HttpRequest extends Request<HttpContext> {
*/
public String getParametersToString(String prefix) {
byte[] rbs = queryBytes;
if (rbs == null || rbs.length < 1) {
if (Utility.isEmpty(rbs)) {
return "";
}
Charset charset = this.context.getCharset();

View File

@@ -114,7 +114,7 @@ public final class Rest {
}
public static JsonFactory createJsonFactory(int features, RestConvert[] converts, RestConvertCoder[] coders) {
if ((converts == null || converts.length < 1) && (coders == null || coders.length < 1)) {
if (Utility.isEmpty(converts) && Utility.isEmpty(coders)) {
return JsonFactory.root();
}
final JsonFactory childFactory = JsonFactory.create();

View File

@@ -5,9 +5,6 @@
*/
package org.redkale.net.http;
import static org.redkale.boot.Application.RESNAME_APP_NODEID;
import static org.redkale.net.http.WebSocket.RETCODE_GROUP_EMPTY;
import java.io.Serializable;
import java.net.InetSocketAddress;
import java.util.*;
@@ -17,9 +14,11 @@ import java.util.stream.*;
import org.redkale.annotation.*;
import org.redkale.annotation.Comment;
import org.redkale.boot.Application;
import static org.redkale.boot.Application.RESNAME_APP_NODEID;
import org.redkale.convert.*;
import org.redkale.convert.json.JsonConvert;
import org.redkale.mq.spi.MessageAgent;
import static org.redkale.net.http.WebSocket.RETCODE_GROUP_EMPTY;
import org.redkale.net.sncp.Sncp;
import org.redkale.service.*;
import org.redkale.source.CacheSource;
@@ -659,7 +658,7 @@ public abstract class WebSocketNode implements Service {
@Local
public CompletableFuture<Integer> sendMessage(
final Convert convert, final Object message0, final boolean last, final Serializable... userids) {
if (userids == null || userids.length < 1) {
if (Utility.isEmpty(userids)) {
return CompletableFuture.completedFuture(RETCODE_GROUP_EMPTY);
}
if (userids[0] instanceof WebSocketUserAddress) {
@@ -748,7 +747,7 @@ public abstract class WebSocketNode implements Service {
@Local
public CompletableFuture<Integer> sendMessage(
Convert convert, Object message0, boolean last, WebSocketUserAddress... useraddrs) {
if (useraddrs == null || useraddrs.length < 1) {
if (Utility.isEmpty(useraddrs)) {
return CompletableFuture.completedFuture(RETCODE_GROUP_EMPTY);
}
if (message0 instanceof CompletableFuture) {
@@ -1102,7 +1101,7 @@ public abstract class WebSocketNode implements Service {
*/
@Local
public CompletableFuture<Integer> sendAction(final WebSocketAction action, final Serializable... userids) {
if (userids == null || userids.length < 1) {
if (Utility.isEmpty(userids)) {
return CompletableFuture.completedFuture(RETCODE_GROUP_EMPTY);
}
if (userids[0] instanceof WebSocketUserAddress) {
@@ -1175,7 +1174,7 @@ public abstract class WebSocketNode implements Service {
@Local
public CompletableFuture<Integer> sendAction(
final WebSocketAction action, final WebSocketUserAddress... useraddrs) {
if (useraddrs == null || useraddrs.length < 1) {
if (Utility.isEmpty(useraddrs)) {
return CompletableFuture.completedFuture(RETCODE_GROUP_EMPTY);
}
if (this.localEngine != null && this.source == null) { // 本地模式且没有分布式

View File

@@ -667,7 +667,7 @@ public class CronExpression {
}
public static CronField compose(CronField[] fields, CronType type, String value) {
if (fields == null || fields.length < 1) {
if (Utility.isEmpty(fields)) {
throw new RedkaleException("Fields must not be empty");
}
if (Utility.isBlank(value)) {

View File

@@ -9,6 +9,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import org.redkale.util.Utility;
/**
* 错误码加载器
@@ -67,7 +68,7 @@ public abstract class RetCodes {
if (retcode == 0) {
return RetResult.success();
}
if (args == null || args.length < 1) {
if (Utility.isEmpty(args)) {
return new RetResult(retcode, retInfo(retcode));
}
String info = MessageFormat.format(retInfo(retcode), args);
@@ -78,7 +79,7 @@ public abstract class RetCodes {
if (retcode == 0) {
return RetResult.success();
}
if (args == null || args.length < 1) {
if (Utility.isEmpty(args)) {
return new RetResult(retcode, retInfo(locale, retcode));
}
String info = MessageFormat.format(retInfo(locale, retcode), args);
@@ -105,7 +106,7 @@ public abstract class RetCodes {
if (retcode == 0) {
return result.retcode(0).retinfo("");
}
if (args == null || args.length < 1) {
if (Utility.isEmpty(args)) {
return result.retcode(retcode).retinfo(retInfo(retcode));
}
String info = MessageFormat.format(retInfo(retcode), args);
@@ -116,7 +117,7 @@ public abstract class RetCodes {
if (retcode == 0) {
return result.retcode(0).retinfo("");
}
if (args == null || args.length < 1) {
if (Utility.isEmpty(args)) {
return result.retcode(retcode).retinfo(retInfo(locale, retcode));
}
String info = MessageFormat.format(retInfo(locale, retcode), args);

View File

@@ -283,7 +283,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
@Override
@ResourceChanged
public void onResourceChange(ResourceEvent[] events) {
if (events == null || events.length < 1) {
if (Utility.isEmpty(events)) {
return;
}
// 不支持读写分离模式的动态切换
@@ -643,7 +643,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
|| column.getType() == java.util.Date.class
|| "java.sql.Date".equals(column.getType().getName())) {
sqltype = "DATE";
} else if (column.getType() == java.time.LocalTime.class || "java.sql.Time".equals(column.getType().getName())) {
} else if (column.getType() == java.time.LocalTime.class
|| "java.sql.Time".equals(column.getType().getName())) {
sqltype = "TIME";
} else if (column.getType() == java.time.LocalDateTime.class
|| "java.sql.Timestamp".equals(column.getType().getName())) {
@@ -797,7 +798,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
|| column.getType() == java.util.Date.class
|| "java.sql.Date".equals(column.getType().getName())) {
sqltype = "DATE";
} else if (column.getType() == java.time.LocalTime.class || "java.sql.Time".equals(column.getType().getName())) {
} else if (column.getType() == java.time.LocalTime.class
|| "java.sql.Time".equals(column.getType().getName())) {
sqltype = "TIME";
} else if (column.getType() == java.time.LocalDateTime.class
|| "java.sql.Timestamp".equals(column.getType().getName())) {
@@ -2084,7 +2086,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
*/
@Override
public <T> int updateColumn(final Class<T> clazz, final Serializable pk, final ColumnValue... values) {
if (values == null || values.length < 1) {
if (Utility.isEmpty(values)) {
return -1;
}
final EntityInfo<T> info = loadEntityInfo(clazz);
@@ -2107,7 +2109,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
@Override
public <T> CompletableFuture<Integer> updateColumnAsync(
final Class<T> clazz, Serializable pk, ColumnValue... values) {
if (values == null || values.length < 1) {
if (Utility.isEmpty(values)) {
return CompletableFuture.completedFuture(-1);
}
final EntityInfo<T> info = loadEntityInfo(clazz);
@@ -2172,7 +2174,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
@Override
public <T> int updateColumn(
final Class<T> clazz, final FilterNode node, final Flipper flipper, final ColumnValue... values) {
if (values == null || values.length < 1) {
if (Utility.isEmpty(values)) {
return -1;
}
final EntityInfo<T> info = loadEntityInfo(clazz);
@@ -2194,7 +2196,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
@Override
public <T> CompletableFuture<Integer> updateColumnAsync(
Class<T> clazz, FilterNode node, Flipper flipper, ColumnValue... values) {
if (values == null || values.length < 1) {
if (Utility.isEmpty(values)) {
return CompletableFuture.completedFuture(-1);
}
final EntityInfo<T> info = loadEntityInfo(clazz);

View File

@@ -256,7 +256,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
@Override
public CompletableFuture<Void> subscribeAsync(CacheEventListener<byte[]> listener, String... topics) {
Objects.requireNonNull(listener);
if (topics == null || topics.length < 1) {
if (Utility.isEmpty(topics)) {
throw new RedkaleException("topics is empty");
}
for (String topic : topics) {
@@ -271,7 +271,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
public CompletableFuture<Integer> unsubscribeAsync(CacheEventListener listener, String... topics) {
int c = 0;
if (listener == null) {
if (topics == null || topics.length < 1) { // 清空所有订阅者
if (Utility.isEmpty(topics)) { // 清空所有订阅者
for (Set<CacheEventListener<byte[]>> listeners : pubsubListeners.values()) {
c += listeners != null ? listeners.size() : 0;
}
@@ -283,7 +283,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
}
}
} else {
if (topics == null || topics.length < 1) {
if (Utility.isEmpty(topics)) {
for (Set<CacheEventListener<byte[]>> listeners : pubsubListeners.values()) {
c += listeners != null && listeners.remove(listener) ? 1 : 0;
}
@@ -1291,7 +1291,8 @@ public final class CacheMemorySource extends AbstractCacheSource {
.collect(Collectors.toMap(
Map.Entry::getKey, en -> CacheEntry.serialToObj(convert, type, en.getValue())));
} else {
Predicate<String> regex = Pattern.compile(pattern.replace("*", ".*")).asPredicate();
Predicate<String> regex =
Pattern.compile(pattern.replace("*", ".*")).asPredicate();
Set<Map.Entry<String, Serializable>> set = entry.mapValue.entrySet();
return set.stream()
.filter(en -> regex.test(en.getKey()))
@@ -2356,7 +2357,8 @@ public final class CacheMemorySource extends AbstractCacheSource {
if (Utility.isEmpty(pattern)) {
return sets.stream().collect(Collectors.toList());
} else {
Predicate<String> regex = Pattern.compile(pattern.replace("*", ".*")).asPredicate();
Predicate<String> regex =
Pattern.compile(pattern.replace("*", ".*")).asPredicate();
return sets.stream().filter(en -> regex.test(en.getValue())).collect(Collectors.toList());
}
}

View File

@@ -1313,11 +1313,11 @@ public final class EntityInfo<T> {
if (tableStrategy == null) {
return new String[] {table};
}
String[] t = tableStrategy.getTables(table, node);
if (t == null || t.length < 1) {
String[] ts = tableStrategy.getTables(table, node);
if (Utility.isEmpty(ts)) {
throw new SourceException(table + " tableStrategy.getTable is empty, filter=" + node);
}
return t;
return ts;
}
/**

View File

@@ -8,6 +8,7 @@ package org.redkale.source;
import java.util.*;
import org.redkale.convert.*;
import org.redkale.convert.json.JsonConvert;
import org.redkale.util.Utility;
/**
* SearchQuery用于构建搜索过滤条件<br>
@@ -138,7 +139,7 @@ public interface SearchQuery extends java.io.Serializable {
public SearchSimpleQuery(String keyword, String... fields) {
this.keyword = keyword;
this.fields = fields;
if (fields == null || fields.length < 1) {
if (Utility.isEmpty(fields)) {
throw new IllegalArgumentException("fields is empty");
}
}
@@ -154,7 +155,7 @@ public interface SearchQuery extends java.io.Serializable {
}
public SearchSimpleQuery fields(String... fields) {
if (fields == null || fields.length < 1) {
if (Utility.isEmpty(fields)) {
throw new IllegalArgumentException("fields is empty");
}
this.fields = fields;

View File

@@ -193,7 +193,7 @@ public class AnyValueWriter extends AnyValue {
continue;
}
Entry<AnyValue>[] ns = getAnyValueEntrys(en.name);
if (ns == null || ns.length < 1) {
if (Utility.isEmpty(ns)) {
addValue(en.name, en.value);
} else {
boolean ok = false;

View File

@@ -5093,7 +5093,7 @@ public final class Utility {
final StringBuilder sb = new StringBuilder();
java.lang.reflect.Type[] us = wt.getUpperBounds();
java.lang.reflect.Type[] ls = wt.getLowerBounds();
if (ls.length < 1) {
if (isEmpty(ls)) {
if (us.length == 1 && us[0] == Object.class) {
sb.append('*');
} else {