package org.adaptlab.chpir.android.survey.Rules;

import java.util.ArrayList;

import org.adaptlab.chpir.android.survey.Rules.RuleCallback;

import android.content.Context;
import android.widget.Toast;

public class RuleBuilder {
    private Context mContext;
    private ArrayList<PassableRule> mRules;
    private RuleCallback mRuleCallback;
    private boolean mShowToastOnFailure;
    private boolean mPassesRules;
    
    public RuleBuilder(Context context) {
        mContext = context;
        mRules = new ArrayList<PassableRule>();
        mShowToastOnFailure = false;
        mPassesRules = false;
    }
    
    public RuleBuilder addRule(PassableRule rule) {
        this.mRules.add(rule);
        return this;
    }

    public RuleBuilder setCallbacks(RuleCallback ruleCallback) {
        this.mRuleCallback = ruleCallback;
        return this;
    }
    
    public RuleBuilder showToastOnFailure(boolean showToast) {
        this.mShowToastOnFailure = showToast;
        return this;
    }
    
    public RuleBuilder checkRules() {
        if (mRuleCallback == null) {
            throw new IllegalStateException("You must set success and failure callbacks for rule checking!");
        }
        
        for (PassableRule rule : mRules) {
            if (!rule.passesRule()) {
                if (mShowToastOnFailure) Toast.makeText(mContext, rule.getFailureMessage(), Toast.LENGTH_LONG).show();
                mRuleCallback.onRulesFail();
                mPassesRules = false;
                return this;
            }
        }
        
        mRuleCallback.onRulesPass(); 
        mPassesRules = true;
        return this;
    }
    
    public boolean getResult() {
        return mPassesRules;
    }
}

@@ -1047,174 +1047,8 @@
 ) %7B%0A
-        if (mRuleCallback == null) %7B%0A            throw new IllegalStateException(%22You must set success and failure callbacks for rule checking!%22);%0A        %7D%0A        %0A
     
@@ -1082,24 +1082,24 @@
 : mRules) %7B%0A
+
             
@@ -1254,24 +1254,51 @@
             
+ if (mRuleCallback != null)
  mRuleCallba
@@ -1415,23 +1415,50 @@
        %0A
-
        
+ if (mRuleCallback != null)
  mRuleCa

Make RuleBuilder work without requiring callbacks