This commit is contained in:
@@ -18,7 +18,7 @@ import static java.lang.annotation.RetentionPolicy.*;
|
|||||||
@Documented
|
@Documented
|
||||||
@Target({METHOD, FIELD})
|
@Target({METHOD, FIELD})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
@Repeatable(ConvertColumns.class)
|
//@Repeatable(ConvertColumns.class)
|
||||||
public @interface ConvertColumn {
|
public @interface ConvertColumn {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -128,7 +128,8 @@ public abstract class Factory<R extends Reader, W extends Writer> {
|
|||||||
ConvertColumnEntry en = this.columnEntrys.get(field);
|
ConvertColumnEntry en = this.columnEntrys.get(field);
|
||||||
if (en != null) return en;
|
if (en != null) return en;
|
||||||
final ConvertType ct = this.getConvertType();
|
final ConvertType ct = this.getConvertType();
|
||||||
for (ConvertColumn ref : field.getAnnotationsByType(ConvertColumn.class)) {
|
ConvertColumn ref = field.getAnnotation(ConvertColumn.class);
|
||||||
|
if (ref != null) {
|
||||||
if (ref.type().contains(ct)) {
|
if (ref.type().contains(ct)) {
|
||||||
ConvertColumnEntry entry = new ConvertColumnEntry(ref);
|
ConvertColumnEntry entry = new ConvertColumnEntry(ref);
|
||||||
if (skipAllIgnore) {
|
if (skipAllIgnore) {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package com.wentch.redkale.util;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import static java.lang.annotation.ElementType.CONSTRUCTOR;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
@Documented @Target(CONSTRUCTOR) @Retention(RUNTIME)
|
||||||
|
public @interface ConstructorProperties {
|
||||||
|
/**
|
||||||
|
<p>The getter names.</p>
|
||||||
|
@return the getter names corresponding to the parameters in the
|
||||||
|
annotated constructor.
|
||||||
|
*/
|
||||||
|
String[] value();
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.wentch.redkale.util;
|
package com.wentch.redkale.util;
|
||||||
|
|
||||||
import java.beans.ConstructorProperties;
|
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
@@ -110,7 +109,7 @@ public interface Creator<T> {
|
|||||||
}
|
}
|
||||||
Constructor<T> constructor = null;
|
Constructor<T> constructor = null;
|
||||||
for (Constructor c : clazz.getConstructors()) {
|
for (Constructor c : clazz.getConstructors()) {
|
||||||
if (c.getParameterCount() == 0) {
|
if (c.getParameterTypes().length == 0) {
|
||||||
constructor = c;
|
constructor = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -154,8 +153,9 @@ public interface Creator<T> {
|
|||||||
mv.visitTypeInsn(NEW, interName);
|
mv.visitTypeInsn(NEW, interName);
|
||||||
mv.visitInsn(DUP);
|
mv.visitInsn(DUP);
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
|
final Class[] params = constructor.getParameterTypes();
|
||||||
{
|
{
|
||||||
Parameter[] params = constructor.getParameters();
|
|
||||||
final int[] iconsts = {ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5};
|
final int[] iconsts = {ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5};
|
||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
mv.visitVarInsn(ALOAD, 1);
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
@@ -165,7 +165,7 @@ public interface Creator<T> {
|
|||||||
mv.visitIntInsn(BIPUSH, i);
|
mv.visitIntInsn(BIPUSH, i);
|
||||||
}
|
}
|
||||||
mv.visitInsn(AALOAD);
|
mv.visitInsn(AALOAD);
|
||||||
Class ct = params[i].getType();
|
Class ct = params[i];
|
||||||
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(ct));
|
mv.visitTypeInsn(CHECKCAST, Type.getInternalName(ct));
|
||||||
if (ct.isPrimitive()) {
|
if (ct.isPrimitive()) {
|
||||||
Class fct = Array.get(Array.newInstance(ct, 1), 0).getClass();
|
Class fct = Array.get(Array.newInstance(ct, 1), 0).getClass();
|
||||||
@@ -181,7 +181,7 @@ public interface Creator<T> {
|
|||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
mv.visitMethodInsn(INVOKESPECIAL, interName, "<init>", Type.getConstructorDescriptor(constructor), false);
|
mv.visitMethodInsn(INVOKESPECIAL, interName, "<init>", Type.getConstructorDescriptor(constructor), false);
|
||||||
mv.visitInsn(ARETURN);
|
mv.visitInsn(ARETURN);
|
||||||
mv.visitMaxs((constructor.getParameterCount() > 0 ? (constructor.getParameterCount() + 3) : 2), 2);
|
mv.visitMaxs((params.length > 0 ? (params.length + 3) : 2), 2);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
{ //虚拟 create 方法
|
{ //虚拟 create 方法
|
||||||
|
|||||||
@@ -5,11 +5,9 @@
|
|||||||
package com.wentch.redkale.util;
|
package com.wentch.redkale.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
import java.time.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
|
|
||||||
@@ -25,25 +23,9 @@ public final class Utility {
|
|||||||
|
|
||||||
private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
|
||||||
private static final sun.misc.Unsafe UNSAFE;
|
|
||||||
|
|
||||||
private static final long strvaloffset;
|
|
||||||
|
|
||||||
private static final javax.net.ssl.SSLContext DEFAULTSSL_CONTEXT;
|
private static final javax.net.ssl.SSLContext DEFAULTSSL_CONTEXT;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
sun.misc.Unsafe usafe = null;
|
|
||||||
long fd = 0L;
|
|
||||||
try {
|
|
||||||
Field safeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
|
||||||
safeField.setAccessible(true);
|
|
||||||
usafe = (sun.misc.Unsafe) safeField.get(null);
|
|
||||||
fd = usafe.objectFieldOffset(String.class.getDeclaredField("value"));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e); //不可能会发生
|
|
||||||
}
|
|
||||||
UNSAFE = usafe;
|
|
||||||
strvaloffset = fd;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DEFAULTSSL_CONTEXT = javax.net.ssl.SSLContext.getInstance("SSL");
|
DEFAULTSSL_CONTEXT = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||||
@@ -123,37 +105,6 @@ public final class Utility {
|
|||||||
return back;
|
return back;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int today() {
|
|
||||||
java.time.LocalDate today = java.time.LocalDate.now();
|
|
||||||
return today.getYear() * 10000 + today.getMonthValue() * 100 + today.getDayOfMonth();
|
|
||||||
}
|
|
||||||
|
|
||||||
//时间点所在星期的周一
|
|
||||||
public static long monday(long time) {
|
|
||||||
ZoneId zid = ZoneId.systemDefault();
|
|
||||||
Instant instant = Instant.ofEpochMilli(time);
|
|
||||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
|
||||||
ld = ld.minusDays(ld.getDayOfWeek().getValue() - 1);
|
|
||||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
//时间点所在星期的周日
|
|
||||||
public static long sunday(long time) {
|
|
||||||
ZoneId zid = ZoneId.systemDefault();
|
|
||||||
Instant instant = Instant.ofEpochMilli(time);
|
|
||||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
|
||||||
ld = ld.plusDays(7 - ld.getDayOfWeek().getValue());
|
|
||||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
//时间点所在月份的1号
|
|
||||||
public static long monthFirstDay(long time) {
|
|
||||||
ZoneId zid = ZoneId.systemDefault();
|
|
||||||
Instant instant = Instant.ofEpochMilli(time);
|
|
||||||
LocalDate ld = instant.atZone(zid).toLocalDate().withDayOfMonth(1);
|
|
||||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String binToHexString(byte[] bytes) {
|
public static String binToHexString(byte[] bytes) {
|
||||||
return new String(binToHex(bytes));
|
return new String(binToHex(bytes));
|
||||||
}
|
}
|
||||||
@@ -260,7 +211,7 @@ public final class Utility {
|
|||||||
|
|
||||||
public static byte[] encodeUTF8(final String value) {
|
public static byte[] encodeUTF8(final String value) {
|
||||||
if (value == null) return new byte[0];
|
if (value == null) return new byte[0];
|
||||||
return encodeUTF8((char[]) UNSAFE.getObject(value, strvaloffset));
|
return encodeUTF8(value.toCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] encodeUTF8(final char[] array) {
|
public static byte[] encodeUTF8(final char[] array) {
|
||||||
@@ -301,7 +252,7 @@ public final class Utility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static char[] charArray(String value) {
|
public static char[] charArray(String value) {
|
||||||
return value == null ? null : (char[]) UNSAFE.getObject(value, strvaloffset);
|
return value == null ? null : value.toCharArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ByteBuffer encodeUTF8(final ByteBuffer buffer, final char[] array) {
|
public static ByteBuffer encodeUTF8(final ByteBuffer buffer, final char[] array) {
|
||||||
@@ -314,7 +265,7 @@ public final class Utility {
|
|||||||
|
|
||||||
public static int encodeUTF8Length(String value) {
|
public static int encodeUTF8Length(String value) {
|
||||||
if (value == null) return -1;
|
if (value == null) return -1;
|
||||||
return encodeUTF8Length((char[]) UNSAFE.getObject(value, strvaloffset));
|
return encodeUTF8Length(value.toCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int encodeUTF8Length(final char[] text) {
|
public static int encodeUTF8Length(final char[] text) {
|
||||||
|
|||||||
Reference in New Issue
Block a user