
net.sf.weixinmp.http.dialog.base.support.Operations Maven / Gradle / Ivy
The newest version!
package net.sf.weixinmp.http.dialog.base.support;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class Operations implements Runnable {
private final List> operations = new ArrayList>();
private final Map context = new HashMap();
public final static Operations buid(Operation extends Object> op) {
Operations ops = new Operations();
ops.add(op);
return ops;
}
public final void clear() {
operations.clear();
}
public final void add(Operation extends Object> operation) {
if (operation == null)
return;
operations.add(operation);
operation.setContext(context);
}
public final int size() {
return operations.size();
}
@SuppressWarnings("unchecked")
public final T getFirstResult() {
T opRst = null;
if (size() > 0) {
Operation extends Object> op = operations.get(0);
opRst = (T) op.getResult();
}
return opRst;
}
public final List> getAll() {
return operations;
}
public final Object getContext(String key) {
return context.get(key);
}
public void run() {
for (int i = 0, j = operations.size(); i < j; i++) {
Operation> op = operations.get(i);
try {
op.run();
} catch (Exception e) {
if (op.isContinueWhenError()) {
continue;
} else {
throw new RuntimeException(e);
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy