Skip to content

Commit

Permalink
Merge branch 'master' into rxsocks
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Mar 25, 2024
2 parents 50e4d5a + 7c0dae3 commit 7b825de
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 40 deletions.
3 changes: 2 additions & 1 deletion rxlib-x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lombok.version>1.18.30</lombok.version>
<mysql.version>5.1.49</mysql.version>
</properties>

<dependencies>
Expand All @@ -27,7 +28,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
Expand Down
16 changes: 8 additions & 8 deletions rxlib/src/main/java/org/rx/bean/DataRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public <T> T get(int ordinal) {
return get(table.getColumn(ordinal));
}

public void set(int ordinal, Object item) {
set(table.getColumn(ordinal), item);
public void set(int ordinal, Object cell) {
set(table.getColumn(ordinal), cell);
}

public <T> T get(String columnName) {
return get(table.getColumn(columnName));
}

public void set(String columnName, Object item) {
set(table.getColumn(columnName), item);
public void set(String columnName, Object cell) {
set(table.getColumn(columnName), cell);
}

public <T> T get(@NonNull DataColumn<T> column) {
Expand All @@ -76,16 +76,16 @@ public <T> T get(@NonNull DataColumn<T> column) {
return (T) items.get(column.ordinal);
}

public <T> void set(@NonNull DataColumn<T> column, T item) {
public <T> void set(@NonNull DataColumn<T> column, T cell) {
require(column, column.getTable() == table);

if (column.dataType != null && !Reflects.isInstance(item, column.dataType)) {
if (column.dataType != null && !Reflects.isInstance(cell, column.dataType)) {
throw new InvalidException("Item type error");
}
if (column.ordinal < items.size()) {
items.set(column.ordinal, item);
items.set(column.ordinal, cell);
} else {
items.add(column.ordinal, item);
items.add(column.ordinal, cell);
}
}
}
12 changes: 6 additions & 6 deletions rxlib/src/main/java/org/rx/bean/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public <T> List<T> toList(@NonNull Type type) {
return list;
}

public DataRow addRow(Object... items) {
DataRow row = newRow(items);
public DataRow addRow(Object... cells) {
DataRow row = newRow(cells);
rows.add(row);
return row;
}
Expand All @@ -201,10 +201,10 @@ public DataRow removeRow(DataRow row) {
return row;
}

public DataRow newRow(Object... items) {
public DataRow newRow(Object... cells) {
DataRow row = new DataRow(this);
if (!Arrays.isEmpty(items)) {
row.setArray(items);
if (!Arrays.isEmpty(cells)) {
row.setArray(cells);
}
return row;
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public <T> DataColumn<T> getColumn(int ordinal) {
}

public <T> DataColumn<T> getColumn(String columnName) {
return Linq.from(columns).first(p -> eq(p.columnName, columnName));
return Linq.from(columns).first(p -> Strings.hashEquals(p.columnName, columnName));
}

<T> void setOrdinal(DataColumn<T> column, int ordinal) {
Expand Down
15 changes: 10 additions & 5 deletions rxlib/src/main/java/org/rx/core/StringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import lombok.SneakyThrows;
import org.rx.util.function.TripleAction;

import java.io.IOException;
import java.io.Serializable;
import java.text.MessageFormat;

@Getter
public final class StringBuilder implements Appendable, CharSequence, Serializable {
Expand Down Expand Up @@ -172,10 +172,6 @@ public StringBuilder append(String str) {
return this;
}

public StringBuilder append(String format, Object... args) {
return append(String.format(format, args));
}

@Override
public StringBuilder append(CharSequence csq, int start, int end) {
buffer.append(csq, start, end);
Expand Down Expand Up @@ -224,6 +220,15 @@ public StringBuilder appendLine(Object obj) {
return appendLine();
}

public StringBuilder appendFormat(String format, Object... args) {
return append(String.format(format, args));
}

public StringBuilder appendMessageFormat(String format, Object... args) {
buffer.append(MessageFormat.format(format, args));
return this;
}

public StringBuilder appendLine(String format, Object... args) {
return appendLine(String.format(format, args));
}
Expand Down
24 changes: 24 additions & 0 deletions rxlib/src/main/java/org/rx/core/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ public static int compareVersion(@NonNull String version1, @NonNull String versi
return 0;
}

public static boolean isStrongPwd(String input) {
//^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}
//^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9~!@#$%^&*]{8,16}$
int len = input.length();
if (len < 8) {
return false;
}
int strength = 0, f = 1 | 2 | 4;
for (int i = 0; i < len; i++) {
char c = input.charAt(i);
if (Character.isLowerCase(c)) {
strength |= 1;
} else if (Character.isUpperCase(c)) {
strength |= 2;
} else if (Character.isDigit(c)) {
strength |= 4;
}
if ((strength & f) == f) {
return true;
}
}
return false;
}

public static String maskPrivacy(String str) {
if (isEmpty(str)) {
return EMPTY;
Expand Down
4 changes: 1 addition & 3 deletions rxlib/src/main/java/org/rx/core/Sys.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.SystemUtils;
import org.rx.annotation.Subscribe;
import org.rx.bean.DynamicProxyBean;
import org.rx.bean.LogStrategy;
import org.rx.bean.ProceedEventArgs;
import org.rx.bean.Tuple;
import org.rx.codec.CodecUtil;
import org.rx.exception.InvalidException;
import org.rx.exception.TraceHandler;
Expand Down Expand Up @@ -402,7 +400,7 @@ public static void log(@NonNull ProceedEventArgs eventArgs, @NonNull BiAction<St
msg.append("MDC:\t");
first = false;
}
msg.append("%s=%s ", entry.getKey(), entry.getValue());
msg.appendFormat("%s=%s ", entry.getKey(), entry.getValue());
}
if (!first) {
msg.appendLine();
Expand Down
2 changes: 1 addition & 1 deletion rxlib/src/main/java/org/rx/core/ThreadEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public String toString(int maxFrames) {
if (inNative) {
sb.append(" (in native)");
}
sb.append(" BlockedTime=%s WaitedTime=%s UserTime=%s CpuTime=%s",
sb.appendFormat(" BlockedTime=%s WaitedTime=%s UserTime=%s CpuTime=%s",
Sys.formatNanosElapsed(blockedTime, 2), Sys.formatNanosElapsed(waitedTime, 2),
Sys.formatNanosElapsed(userNanos), Sys.formatNanosElapsed(cpuNanos));
sb.append('\n');
Expand Down
9 changes: 8 additions & 1 deletion rxlib/src/main/java/org/rx/exception/TraceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.rx.bean.ProceedEventArgs;
import org.rx.codec.CodecUtil;
import org.rx.core.*;
import org.rx.core.StringBuilder;
import org.rx.io.EntityDatabase;
import org.rx.io.EntityQueryLambda;
import org.slf4j.helpers.FormattingTuple;
Expand Down Expand Up @@ -233,7 +234,13 @@ public void saveExceptionTrace(Thread t, String msg, Throwable e) {
if (queue.size() > conf.getErrorMessageSize()) {
queue.poll();
}
queue.offer(String.format("%s\t%s\nMDC:\t%s", DateTime.now().toDateTimeString(), msg, Sys.getMDCCtxMap()));
StringBuilder b = new StringBuilder();
b.appendMessageFormat("{}\t{}", DateTime.now().toDateTimeString(), msg);
Map<String, String> ctxMap = Sys.getMDCCtxMap();
if (!ctxMap.isEmpty()) {
b.appendMessageFormat("\nMDC:\t{}", ctxMap);
}
queue.offer(b.toString());
entity.occurCount++;
entity.setAppName(RxConfig.INSTANCE.getId());
entity.setThreadName(t.getName());
Expand Down
8 changes: 4 additions & 4 deletions rxlib/src/main/java/org/rx/io/EntityDatabaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public <T> void save(T entity, boolean doInsert) {
continue;
}

cols.append("`%s`=?,", col.getKey());
cols.appendFormat("`%s`=?,", col.getKey());
params.add(val);
}
cols.setLength(cols.length() - 1);
Expand Down Expand Up @@ -301,7 +301,7 @@ public <T> long delete(EntityQueryLambda<T> query) {
List<Object> params = new ArrayList<>();
appendClause(subSql, query, params);

sql.append(" IN(%s)", subSql);
sql.appendFormat(" IN(%s)", subSql);
String execSql = sql.toString();

long total = 0;
Expand Down Expand Up @@ -489,7 +489,7 @@ public void createMapping(Class<?>... entityTypes) {
for (Class<?> entityType : entityTypes) {
createCols.setLength(0);
String tableName = tableName(entityType);
insert.setLength(0).append("INSERT INTO %s VALUES (", tableName);
insert.setLength(0).appendFormat("INSERT INTO %s VALUES (", tableName);

String pkName = null;
Map<String, Tuple<Field, DbColumn>> columns = new LinkedHashMap<>();
Expand Down Expand Up @@ -628,7 +628,7 @@ public static DataTable sharding(List<DataTable> queryResults, String querySql)
String tableName = template.getTableName();
StringBuilder createCols = new StringBuilder();
StringBuilder insert = new StringBuilder();
insert.append("INSERT INTO %s VALUES (", tableName);
insert.appendFormat("INSERT INTO %s VALUES (", tableName);

int len = template.getColumns().size();
List<Class<?>> colTypes = new ArrayList<>(len);
Expand Down
14 changes: 7 additions & 7 deletions rxlib/src/main/java/org/rx/io/EntityQueryLambda.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum Order {
static final String FUNC_RAND = "RAND()";

static void pkClaus(StringBuilder sql, String pk) {
sql.append(WHERE).append(Operator.EQ.format, pk, PARAM_HOLD);
sql.append(WHERE).appendFormat(Operator.EQ.format, pk, PARAM_HOLD);
}

final Class<T> entityType;
Expand Down Expand Up @@ -234,7 +234,7 @@ static <T> String resolve(ArrayList<BiTuple<Serializable, Operator, ?>> conditio
} else {
valHold = toValueString(condition.right);
}
b.append(op.format, colName, valHold);
b.appendFormat(op.format, colName, valHold);
}
break;
case IN:
Expand All @@ -250,7 +250,7 @@ static <T> String resolve(ArrayList<BiTuple<Serializable, Operator, ?>> conditio
} else {
valHold = Linq.from((Object[]) condition.right).toJoinString(",", EntityQueryLambda::toValueString);
}
b.append(op.format, colName, valHold);
b.appendFormat(op.format, colName, valHold);
}
break;
case BETWEEN:
Expand All @@ -270,7 +270,7 @@ static <T> String resolve(ArrayList<BiTuple<Serializable, Operator, ?>> conditio
valHold0 = toValueString(p[0]);
valHold1 = toValueString(p[1]);
}
b.append(op.format, colName, valHold0, valHold1);
b.appendFormat(op.format, colName, valHold0, valHold1);
}
break;
case AND:
Expand All @@ -280,7 +280,7 @@ static <T> String resolve(ArrayList<BiTuple<Serializable, Operator, ?>> conditio
if (!b.isEmpty()) {
b.append(OP_AND);
}
b.append(op.format, resolve(l, params, null, orderByRand, autoUnderscoreColumnName, limit, offset), r.toString(params));
b.appendFormat(op.format, resolve(l, params, null, orderByRand, autoUnderscoreColumnName, limit, offset), r.toString(params));
break;
}
}
Expand All @@ -291,15 +291,15 @@ static <T> String resolve(ArrayList<BiTuple<Serializable, Operator, ?>> conditio
b.append(ORDER_BY);
for (Tuple<BiFunc<T, ?>, Order> bi : orders) {
String colName = resolveColumnName(bi.left, autoUnderscoreColumnName);
b.append("%s %s,", colName, bi.right);
b.appendFormat("%s %s,", colName, bi.right);
}
b.setLength(b.length() - 1);
}

if (limit != null) {
b.append(LIMIT);
if (offset != null) {
b.append("%s,", offset);
b.appendFormat("%s,", offset);
}
b.append(limit);
// b.append(LIMIT).append(limit);
Expand Down
4 changes: 2 additions & 2 deletions rxlib/src/main/java/org/rx/net/AuthenticEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public String toString() {
s.append(username);
}
if (!Strings.isEmpty(password)) {
s.append(":%s", password);
s.appendFormat(":%s", password);
}
s.append("@%s", Sockets.toString(endpoint));
s.appendFormat("@%s", Sockets.toString(endpoint));
if (!MapUtils.isEmpty(parameters)) {
s.append(HttpClient.buildUrl(null, (Map) parameters));
}
Expand Down
2 changes: 1 addition & 1 deletion rxlib/src/main/java/org/rx/net/http/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static <T> T facade(Class<T> contract, String serverPrefixUrl, BiFunc<Str
msg.appendLine("GET:\t%s", reqUrl);
}
msg.appendLine("Request:\t%s", toJsonString(args.getParameters()));
msg.append("Response:\t%s", args.getReturnValue());
msg.appendFormat("Response:\t%s", args.getReturnValue());
});
}
if (m.getReturnType().equals(Void.class)) {
Expand Down
2 changes: 1 addition & 1 deletion rxlib/src/main/java/org/rx/net/transport/TcpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public String dumpClients() {
StringBuilder buf = new StringBuilder();
int i = 1;
for (TcpClient client : Linq.from(clients.values()).orderBy(p -> p.remoteEndpoint)) {
buf.append("\t%s", client.getRemoteEndpoint());
buf.appendFormat("\t%s", client.getRemoteEndpoint());
if (i++ % 3 == 0) {
buf.appendLine();
}
Expand Down

0 comments on commit 7b825de

Please sign in to comment.