2121/**type:value
2222 * @author Lemon
2323 */
24- public class TypeValueKeyEntry extends Entry <String , String > {
24+ public class Pair extends Entry <String , String > {
2525
2626 private static Map <String , Class <?>> classMap ;
2727 static {
@@ -43,77 +43,87 @@ public class TypeValueKeyEntry extends Entry<String, String> {
4343 classMap .put (Collection .class .getSimpleName (), Collection .class );//不允许指定<T>
4444 classMap .put (Map .class .getSimpleName (), Map .class );//不允许指定<T>
4545 }
46-
47-
48- public TypeValueKeyEntry () {
46+
47+
48+ public Pair () {
4949 super ();
5050 }
51-
52-
51+
52+
5353 /**
5454 * @param <K>
55- * @param typeValue
55+ * @param pair
5656 * @return
5757 */
58- public static <K , V > boolean isCorrect (Entry <K , V > typeValue ) {
59- return typeValue != null && StringUtil .isNotEmpty (typeValue .getValue (), true );
58+ public static <K , V > boolean isCorrect (Entry <K , V > pair ) {
59+ return pair != null && StringUtil .isNotEmpty (pair .getValue (), true );
6060 }
6161
6262 /**
63- * @param typeValue
63+ * @param pair
6464 * @return
6565 */
66- public String toEntryString () {
67- return toEntryString (getKey (), getValue ());
66+ public String toPairString () {
67+ return toPairString (getKey (), getValue ());
6868 }
6969 /**
70- * @param typeValue
70+ * @param pair
7171 * @return
7272 */
73- public static String toEntryString (String typeKey , String valueKey ) {
73+ public static String toPairString (String typeKey , String valueKey ) {
7474 return (typeKey == null ? "" : typeKey + ":" ) + valueKey ;
7575 }
7676 /**
7777 * @param type
7878 * @param value
7979 * @return
8080 */
81- public static String toEntryString (Class <?> type , Object value ) {
82- return toEntryString (type == null ? null : type .getSimpleName (), StringUtil .getString (value ));
81+ public static String toPairString (Class <?> type , Object value ) {
82+ return toPairString (type == null ? null : type .getSimpleName (), StringUtil .getString (value ));
8383 }
84+
8485 /**
85- * @param typeValue
86+ * "key":null不应该出现?因为FastJSON内默认不存null
87+ * @param pair
88+ * @param defaultKey
8689 * @return
8790 */
88- public static Entry <String , String > parseKeyEntry (String typeValue ) {
89- typeValue = StringUtil .getString (typeValue );//让客户端去掉所有空格 getNoBlankString(typeValue );
90- if (typeValue .isEmpty ()) {
91+ public static Entry <String , String > parseEntry (String pair , String defaultKey ) {
92+ pair = StringUtil .getString (pair );//让客户端去掉所有空格 getNoBlankString(pair );
93+ if (pair .isEmpty ()) {
9194 return null ;
9295 }
93- int index = typeValue . contains ( ":" ) ? typeValue . indexOf (":" ) : - 1 ;
96+ int index = pair . indexOf (":" );
9497
9598 Entry <String , String > entry = new Entry <String , String >();
96- entry .setKey (index < 0 ? Object . class . getSimpleName () : typeValue .substring (0 , index ));
97- entry .setValue (typeValue .substring (index + 1 , typeValue .length ()));
99+ entry .setKey (index < 0 ? defaultKey : pair .substring (0 , index ));
100+ entry .setValue (pair .substring (index + 1 , pair .length ()));
98101
99102 return entry ;
100103 }
101104 /**
105+ * @param pair
106+ * @return
107+ */
108+ public static Entry <String , String > parseVariableEntry (String pair ) {
109+ return parseEntry (pair , Object .class .getSimpleName ());
110+ }
111+ /**
112+ * @param pair
102113 * @param valueMap
103- * @param typeValue
104114 * @return
105115 */
106- public static Entry <Class <?>, Object > parseEntry ( Map <String , Object > valueMap , String typeValue ) {
107- typeValue = StringUtil .getString (typeValue );//让客户端去掉所有空格 getNoBlankString(typeValue );
108- if (typeValue .isEmpty ()) {
116+ public static Entry <Class <?>, Object > parseVariableEntry ( String pair , Map <String , Object > valueMap ) {
117+ pair = StringUtil .getString (pair );//让客户端去掉所有空格 getNoBlankString(pair );
118+ if (pair .isEmpty ()) {
109119 return null ;
110120 }
111- int index = typeValue .contains (":" ) ? typeValue .indexOf (":" ) : -1 ;
112-
121+ int index = pair .contains (":" ) ? pair .indexOf (":" ) : -1 ;
122+
113123 Entry <Class <?>, Object > entry = new Entry <Class <?>, Object >();
114- entry .setKey (classMap .get (index < 0 ? Object .class .getSimpleName () : typeValue .substring (0 , index )));
115- entry .setValue (valueMap == null ? null : valueMap .get (typeValue .substring (index + 1 , typeValue .length ())));
116-
124+ entry .setKey (classMap .get (index < 0 ? Object .class .getSimpleName () : pair .substring (0 , index )));
125+ entry .setValue (valueMap == null ? null : valueMap .get (pair .substring (index + 1 , pair .length ())));
126+
117127 return entry ;
118128 }
119129}
0 commit comments