From 276cb4da92534f1b6c630c2541cbe472b9b99c38 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Thu, 15 Jun 2017 08:08:38 +0800 Subject: [PATCH] --- src/org/redkale/convert/ConvertColumn.java | 7 ++++++ .../redkale/convert/ConvertColumnEntry.java | 24 +++++++++++++++++-- src/org/redkale/convert/ConvertFactory.java | 6 ++++- src/org/redkale/convert/DeMember.java | 7 ++++++ src/org/redkale/convert/EnMember.java | 7 ++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/org/redkale/convert/ConvertColumn.java b/src/org/redkale/convert/ConvertColumn.java index 6f6afbd8a..6769e0cf7 100644 --- a/src/org/redkale/convert/ConvertColumn.java +++ b/src/org/redkale/convert/ConvertColumn.java @@ -31,6 +31,13 @@ public @interface ConvertColumn { */ String name() default ""; + /** + * 给字段取个序号ID,值小靠前 + * + * @return 字段排序ID + */ + int index() default 0; + /** * 解析/序列化时是否屏蔽该字段 * diff --git a/src/org/redkale/convert/ConvertColumnEntry.java b/src/org/redkale/convert/ConvertColumnEntry.java index b713c5854..c73a2c17e 100644 --- a/src/org/redkale/convert/ConvertColumnEntry.java +++ b/src/org/redkale/convert/ConvertColumnEntry.java @@ -8,11 +8,15 @@ package org.redkale.convert; /** * ConvertColumn 对应的实体类 * - *

详情见: https://redkale.org + *

+ * 详情见: https://redkale.org + * * @author zhangjx */ public final class ConvertColumnEntry { + private int index; + private String name = ""; private boolean ignore; @@ -25,6 +29,7 @@ public final class ConvertColumnEntry { public ConvertColumnEntry(ConvertColumn column) { if (column == null) return; this.name = column.name(); + this.index = column.index(); this.ignore = column.ignore(); this.convertType = column.type(); } @@ -32,7 +37,7 @@ public final class ConvertColumnEntry { public ConvertColumnEntry(String name) { this(name, false); } - + public ConvertColumnEntry(String name, boolean ignore) { this.name = name; this.ignore = ignore; @@ -45,6 +50,13 @@ public final class ConvertColumnEntry { this.convertType = convertType; } + public ConvertColumnEntry(String name, int index, boolean ignore, ConvertType convertType) { + this.name = name; + this.index = index; + this.ignore = ignore; + this.convertType = convertType; + } + public String name() { return name == null ? "" : name; } @@ -69,4 +81,12 @@ public final class ConvertColumnEntry { this.convertType = convertType; } + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + } diff --git a/src/org/redkale/convert/ConvertFactory.java b/src/org/redkale/convert/ConvertFactory.java index 3b4e67cc4..1ddfa87af 100644 --- a/src/org/redkale/convert/ConvertFactory.java +++ b/src/org/redkale/convert/ConvertFactory.java @@ -129,12 +129,16 @@ public abstract class ConvertFactory { public abstract ConvertType getConvertType(); - public abstract boolean isReversible(); + public abstract boolean isReversible(); //是否可逆的 public abstract ConvertFactory createChild(); public abstract ConvertFactory createChild(boolean tiny); + public boolean isIndexSort() { //是否使用@ConvertColumn.index排序 + return false; + } + public Convert getConvert() { return convert; } diff --git a/src/org/redkale/convert/DeMember.java b/src/org/redkale/convert/DeMember.java index 8732595c1..ee31e9ef8 100644 --- a/src/org/redkale/convert/DeMember.java +++ b/src/org/redkale/convert/DeMember.java @@ -22,6 +22,8 @@ import org.redkale.util.Attribute; @SuppressWarnings("unchecked") public final class DeMember implements Comparable> { + protected int index; + protected final Attribute attribute; protected Decodeable decoder; @@ -68,9 +70,14 @@ public final class DeMember implements Comparable o) { if (o == null) return 1; + if (this.index != o.index) return this.index - o.index; return this.attribute.field().compareTo(o.attribute.field()); } diff --git a/src/org/redkale/convert/EnMember.java b/src/org/redkale/convert/EnMember.java index 7f5739e31..c3c5da6c5 100644 --- a/src/org/redkale/convert/EnMember.java +++ b/src/org/redkale/convert/EnMember.java @@ -31,6 +31,8 @@ public final class EnMember implements Comparable attribute, Encodeable encoder) { this.attribute = attribute; this.encoder = encoder; @@ -61,9 +63,14 @@ public final class EnMember implements Comparable o) { if (o == null) return 1; + if (this.index != o.index) return this.index - o.index; return this.attribute.field().compareTo(o.attribute.field()); }