
org.unique.support.upload.BaseState Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unique-support-upload Show documentation
Show all versions of unique-support-upload Show documentation
unique-web is a lightweight Java Web Framework
The newest version!
package org.unique.support.upload;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* upload state
* @author:biezhi
* @version:1.0
*/
public class BaseState implements State {
private boolean state = false;
private String info = null;
private Map infoMap = new HashMap();
private Map formParamMap = new HashMap();
public BaseState() {
this.state = true;
}
public BaseState(boolean state) {
this.setState(state);
}
public BaseState(boolean state, String info) {
this.setState(state);
this.info = info;
}
public BaseState(boolean state, int infoCode) {
this.setState(state);
this.info = StateInfo.getStateInfo(infoCode);
}
@Override
public boolean isSuccess() {
return this.state;
}
@Override
public void putInfo(String name, String val) {
this.infoMap.put(name, val);
}
@Override
public void putInfo(String name, long val) {
this.putInfo(name, val + "");
}
@Override
public String toJSONString() {
return this.toString();
}
public boolean isState() {
return state;
}
public void setState(boolean state) {
this.state = state;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
@Override
public String toString() {
String key = null;
String stateVal = this.isSuccess() ? StateInfo
.getStateInfo(StateInfo.SUCCESS) : this.info;
StringBuilder builder = new StringBuilder();
builder.append("{\"state\": \"" + stateVal + "\"");
Iterator iterator = this.infoMap.keySet().iterator();
while (iterator.hasNext()) {
key = iterator.next();
builder.append(",\"" + key + "\": \"" + this.infoMap.get(key)
+ "\"");
}
builder.append("}");
return builder.toString();
}
@Override
public Map getFormParams() {
return this.formParamMap;
}
@Override
public void putFormParams(Map formParams) {
this.formParamMap = formParams;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy