You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB
Java

3 years ago
package cokr.xit.foundation.component;
2 weeks ago
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import cokr.xit.foundation.AbstractObject;
import cokr.xit.foundation.data.DataObject;
3 years ago
/** .<br />
* .<br />
* .
* @author mjkhan
*/
2 weeks ago
public class ServiceResponse extends AbstractObject {
private List<ExecInfo> results;
private DataObject info;
2 weeks ago
public List<ExecInfo> getResults() {
return ifEmpty(results, Collections::emptyList);
}
2 weeks ago
public ServiceResponse setResults(List<ExecInfo> results) {
this.results = results;
return this;
}
2 weeks ago
public ServiceResponse add(ExecInfo result) {
if (results == null)
results = new ArrayList<>();
else if (!(results instanceof ArrayList)) {
List<ExecInfo> tmp = results;
results = new ArrayList<>(tmp);
}
2 weeks ago
results.add(result);
return this;
}
/** .
* @return
*/
public DataObject getInfo() {
return info;
}
/** .
* @return
*/
2 weeks ago
private DataObject info() {
return ifEmpty(info, () -> info = new DataObject());
}
/** .
* @param <T>
* @param key
* @param val
* @return
*/
public ServiceResponse info(String key, Object val) {
info().put(key, val);
return this;
}
2 weeks ago
/** .
* @return
*/
2 weeks ago
public int getAffected() {
return ExecInfo.getAffected(results);
}
2 weeks ago
/** .
* @return
*/
2 weeks ago
public boolean isSuccess() {
return ExecInfo.isSuccess(results);
}
3 years ago
}