com.paymentwall.java.WidgetBuilder Maven / Gradle / Ivy
package com.paymentwall.java;
import java.util.ArrayList;
import java.util.HashMap;
public class WidgetBuilder {
String userId;
String widgetCode;
ArrayList products = new ArrayList();
HashMap extraParams = new HashMap();
private UserProfile userProfile;
public void setUserProfile(UserProfile userProfile) {
this.userProfile = userProfile;
}
public WidgetBuilder(String userId_, String widgetCode_) {
userId = userId_;
widgetCode = widgetCode_;
}
public Widget build() {
if(userProfile == null) {
return new Widget(userId, widgetCode, products, extraParams);
} else {
HashMap allParams = new HashMap();
allParams.putAll(extraParams);
allParams.putAll(userProfile.toParameters());
return new Widget(userId, widgetCode, products, allParams);
}
}
public void setProducts(ArrayList products_) { products = products_; }
public void setProduct(final Product products_) { products = new ArrayList(){{add(products_);}}; }
public void setExtraParams(HashMap extraParams_) { extraParams = extraParams_; }
}