Result.java
5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package com.diligrp.website.util.domain;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Map;
/**
* <B>Description</B> 检测账户状态 <br />
* <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
* 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
* <B>Company</B> 地利集团
* @createTime May 12, 2014 12:29:10 PM
* @author wujianjun
*/
public class Result implements Serializable {
private static final long serialVersionUID = 1L;
private static final int INIT_MAP_SIZE = 5;
/**
* 默认的处理结果常量,为true
*/
public static final boolean DEFAULT_STATUS_SUCCESS = true;
/**
* 附加值的默认key
*/
public static final String RESULT_KEY_DEFAULT_VALUE = "model";
/**
* 默认消息KEY
*/
public static final String RESULT_KEY_MSG = "msg";
/**
* 处理结果: true成功, false失败,默认为true
*/
private boolean success;
private int code;
private Map<String, Object> result;
private Result() {
}
/**
* 创建一个Result对象,,默认为成功结果
* @return Result对象
* @createTime May 13, 2014 11:05:18 AM
* @author wujianjun
*/
public static Result create() {
return create(DEFAULT_STATUS_SUCCESS);
}
/**
* 创建一个Result对象
* @param isSuccess 指示是否成功的操作结果
* @return Result对象
* @createTime May 13, 2014 11:05:54 AM
* @author wujianjun
*/
public static Result create(boolean isSuccess) {
return create(isSuccess, null);
}
/**
* set value of Result.code
* @param code the code
* @return this instance
* @createTime 2014年5月15日 下午12:11:16
* @author Wang22
*/
public Result setCode(int code) {
this.code = code;
return this;
}
/**
* get value of Result.code
* @return the code
* @createTime 2014年5月15日 下午12:11:37
* @author Wang22
*/
public int getCode() {
return code;
}
/**
* 创建一个Result对象
* @param isSuccess 指示是否成功的操作结果
* @param resultInfo Result对象附加结果
* @return Result对象
* @createTime May 13, 2014 11:06:25 AM
* @author wujianjun
*/
public static Result create(boolean isSuccess,
Map<String, Object> resultInfo) {
return new Result().setSuccess(isSuccess).addResult(resultInfo);
}
/**
* 创建一个Result对象
* @param isSuccess 指示是否成功的操作结果
* @param value Result对象附加结果
* @return Result对象
* @createTime May 13, 2014 11:06:25 AM
* @author wujianjun
*/
public static Result create(boolean isSuccess, Object value) {
return new Result().setSuccess(isSuccess).addResult(RESULT_KEY_DEFAULT_VALUE,
value);
}
/**
* 创建一个Result对象
* @param value 默认为成功的操作,结果对象
* @return Result对象
* @createTime May 13, 2014 11:06:25 AM
* @author wujianjun
*/
public static Result create(Object value ) {
return new Result().setSuccess(DEFAULT_STATUS_SUCCESS).addResult(
RESULT_KEY_DEFAULT_VALUE, value);
}
/**
* get value of Result.success
* @return the success
* @createTime May 13, 2014 10:30:39 AM
* @author wujianjun
*/
public boolean isSuccess() {
return success;
}
/**
* set value of Result.success
* @param success the success to set
* @return this result object
* @createTime May 13, 2014 10:30:39 AM
* @author wujianjun
*/
public Result setSuccess(boolean success) {
this.success = success;
return this;
}
/**
* get value of Result.result
* @return the result
* @createTime May 13, 2014 10:30:39 AM
* @author wujianjun
*/
public Map<String, Object> getAllResult() {
return result;
}
/**
* 获取消息
* @return
*/
public String getMsg() {
Object val = getResult(RESULT_KEY_MSG);
return val == null ? "" : val.toString();
}
/**
* 设置消息
* @param msg
* @return this object
*/
public Result setMsg(String msg) {
addResult(RESULT_KEY_MSG, msg);
return this;
}
/**
* add value of Result.result
* @param resultInfo the value
* @return this result object
* @createTime May 13, 2014 10:30:39 AM
* @author wujianjun
*/
public Result addResult(Map<String, Object> resultInfo) {
if (resultInfo == null) {
return this;
}
if (this.result == null) {
this.result = new Hashtable<String, Object>(5);
}
this.result.putAll(resultInfo);
return this;
}
/**
* add value of Result.result
* @param key the value of key
* @param value the object value
* @return this result object
* @createTime May 13, 2014 10:30:39 AM
* @author wujianjun
*/
public Result addResult(String key, Object value) {
if (this.result == null) {
this.result = new Hashtable<String, Object>(INIT_MAP_SIZE);
}
if (value != null) {
this.result.put(key, value);
}
return this;
}
/**
* get value by key
* @see Result.RESULT_KEY_DEFAULT_VALUE
* @return the value
* @createTime May 13, 2014 10:33:30 AM
* @author wujianjun
*/
public Object getResult() {
return getResult(RESULT_KEY_DEFAULT_VALUE);
}
/**
* get value by key
* @param key Need to get the value of the key
* @return the value
* @createTime May 13, 2014 10:33:30 AM
* @author wujianjun
*/
public Object getResult(String key) {
return this.result == null ? null : this.result.get(key);
}
}