public class OrderOption implements Serializable {
private static final long serialVersionUID = 476097616410824547L;
private Vendor vendor;
private Boolean allowPriceZero;
/** 缺省供应商 */
public Vendor getVendor() {
return vendor;
}
public OrderOption setVendor(Vendor vendor) {
this.vendor = vendor;
return this;
}
/**
* 包装成符合选项的存储格式
*
* @return
*/
public Map<String, String> encode() {
Map<String, String> map = new HashMap<String, String>();
map.put(Diralcs.DEFAULTVENDOR, this.vendor == null ? null : this.vendor.getCode());
map.put(Diralcs.ALLOWPRICEZERO, this.allowPriceZero ? "是" : "否");
return map;
}
public OrderOption decode(Map<String, String> options) {
try {
return this
.setAllowPriceZero(OptionUtil.parseBooleanValue(options.get(Diralcs.ALLOWPRICEZERO)))
} catch (Exception e) {
throw new RuntimeException();
}
private static final long serialVersionUID = 476097616410824547L;
private Vendor vendor;
private Boolean allowPriceZero;
/** 缺省供应商 */
public Vendor getVendor() {
return vendor;
}
public OrderOption setVendor(Vendor vendor) {
this.vendor = vendor;
return this;
}
/**
* 包装成符合选项的存储格式
*
* @return
*/
public Map<String, String> encode() {
Map<String, String> map = new HashMap<String, String>();
map.put(Diralcs.DEFAULTVENDOR, this.vendor == null ? null : this.vendor.getCode());
map.put(Diralcs.ALLOWPRICEZERO, this.allowPriceZero ? "是" : "否");
return map;
}
public OrderOption decode(Map<String, String> options) {
try {
return this
.setAllowPriceZero(OptionUtil.parseBooleanValue(options.get(Diralcs.ALLOWPRICEZERO)))
} catch (Exception e) {
throw new RuntimeException();
}
}
注意这种set的写法,主要在decode的方法中,要return 出this对象,好需要赋值。可以一直.set往里面赋值。
本文介绍了一个名为OrderOption的Java类,该类实现了Serializable接口,并包含了供应商设置和价格为零的选项处理。文中详细展示了如何使用set和get方法来操作属性,并提供了将对象状态编码为Map及从Map解码的方法。
2950

被折叠的 条评论
为什么被折叠?



