package com.qianwen.core.tool.script.engine;
|
|
import java.util.function.Supplier;
|
import javax.script.ScriptException;
|
|
public class ExecuteResult {
|
private boolean success;
|
private Object result;
|
private String message;
|
private transient Exception exception;
|
private long useTime;
|
|
public boolean isSuccess() {
|
return this.success;
|
}
|
|
public void setSuccess(boolean success) {
|
this.success = success;
|
}
|
|
@Deprecated
|
public Object getResult() {
|
return this.result;
|
}
|
|
public void setResult(Object result) {
|
this.result = result;
|
}
|
|
public String getMessage() {
|
if (this.message == null && this.exception != null) {
|
this.message = this.exception.getMessage();
|
}
|
return this.message;
|
}
|
|
public void setMessage(String message) {
|
this.message = message;
|
}
|
|
public Exception getException() {
|
return this.exception;
|
}
|
|
public void setException(Exception exception) {
|
this.exception = exception;
|
}
|
|
public long getUseTime() {
|
return this.useTime;
|
}
|
|
public void setUseTime(long useTime) {
|
this.useTime = useTime;
|
}
|
|
public String toString() {
|
return String.valueOf(getResult());
|
}
|
|
public Object get() {
|
return this.result;
|
}
|
|
public Object getIfSuccess() throws Exception {
|
if (!this.success) {
|
if (this.exception != null) {
|
throw this.exception;
|
}
|
throw new ScriptException(this.message);
|
}
|
return this.result;
|
}
|
|
public Object getIfSuccess(Object defaultValue) {
|
if (!this.success) {
|
return defaultValue;
|
}
|
return this.result;
|
}
|
|
public Object getIfSuccess(Supplier<?> supplier) {
|
if (!this.success) {
|
return supplier.get();
|
}
|
return this.result;
|
}
|
}
|