解除lang3依赖

master
剑器近 2020-11-12 16:52:41 +08:00
parent 6e2afe8111
commit e02a71d32d
3 changed files with 98 additions and 9 deletions

10
pom.xml
View File

@ -44,7 +44,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
@ -62,12 +62,8 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.1.51.Final</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
<version>4.1.54.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -1,8 +1,8 @@
package io.github.yezhihao.protostar.field;
import io.github.yezhihao.protostar.annotation.Field;
import io.github.yezhihao.protostar.util.StrUtils;
import io.netty.buffer.ByteBuf;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -44,7 +44,7 @@ public abstract class BasicField<T> implements Comparable<BasicField<T>> {
public void println(int index, String desc, String hex, Object value) {
if (value != null)
System.out.println(index + "\t" + "[" + hex + "] " + desc + ": " + (value.getClass().isArray() ? ArrayUtils.toString(value) : value));
System.out.println(index + "\t" + "[" + hex + "] " + desc + ": " + StrUtils.toString(value));
}
public int index() {

View File

@ -0,0 +1,93 @@
package io.github.yezhihao.protostar.util;
/**
* @author yezhihao
* home https://gitee.com/yezhihao/jt808-server
*/
public class StrUtils {
public static String toString(Object value) {
if (!value.getClass().isArray())
return value.toString();
StringBuilder root = new StringBuilder(32);
toString(value, root);
return root.toString();
}
public static StringBuilder toString(Object value, StringBuilder builder) {
if (value == null)
return builder;
builder.append('[');
int start = builder.length();
if (value instanceof long[]) {
long[] array = (long[]) value;
for (long t : array)
builder.append(t).append(',');
} else if (value instanceof int[]) {
int[] array = (int[]) value;
for (int t : array)
builder.append(t).append(',');
} else if (value instanceof short[]) {
short[] array = (short[]) value;
for (short t : array)
builder.append(t).append(',');
} else if (value instanceof byte[]) {
byte[] array = (byte[]) value;
for (byte t : array)
builder.append(t).append(',');
} else if (value instanceof char[]) {
char[] array = (char[]) value;
for (char t : array)
builder.append(t).append(',');
} else if (value instanceof double[]) {
double[] array = (double[]) value;
for (double t : array)
builder.append(t).append(',');
} else if (value instanceof float[]) {
float[] array = (float[]) value;
for (float t : array)
builder.append(t).append(',');
} else if (value instanceof boolean[]) {
boolean[] array = (boolean[]) value;
for (boolean t : array)
builder.append(t).append(',');
} else if (value instanceof String[]) {
String[] array = (String[]) value;
for (String t : array)
builder.append(t).append(',');
} else if (isArray(value)) {
Object[] array = (Object[]) value;
for (Object t : array)
toString(t, builder).append(',');
} else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
for (Object t : array)
builder.append(t).append(',');
}
int end = builder.length();
if (end <= start) builder.append(']');
else builder.setCharAt(end - 1, ']');
return builder;
}
private static boolean isArray(Object value) {
Class<?> componentType = value.getClass().getComponentType();
if (componentType == null)
return false;
return componentType.isArray();
}
}