AbstractMerger.java 1.93 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.sling.commons.json.JSONArray
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.JSONObject
 */
package com.day.cq.analytics.sitecatalyst.rsmerger;

import com.day.cq.analytics.sitecatalyst.rsmerger.MergedVariable;
import com.day.cq.analytics.sitecatalyst.rsmerger.Merger;
import com.day.cq.analytics.sitecatalyst.rsmerger.ReportSuiteVariable;
import com.day.cq.analytics.sitecatalyst.rsmerger.Variable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.sling.commons.json.JSONArray;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;

@Deprecated
public abstract class AbstractMerger
implements Merger {
    protected JSONObject jsonObj;
    protected Map<Integer, MergedVariable> varMap;

    public AbstractMerger(JSONArray variables) throws JSONException {
        this.jsonObj = variables.length() > 0 ? variables.getJSONObject(0) : new JSONObject();
        this.varMap = new TreeMap<Integer, MergedVariable>();
    }

    protected void intertwine(ReportSuiteVariable rsvar) {
        int index = 0;
        for (Variable var : rsvar.getVariables()) {
            MergedVariable mVar = this.varMap.get(index);
            if (mVar == null) {
                mVar = new MergedVariable(var.getJSONObject());
                this.varMap.put(index, mVar);
            }
            mVar.put(var.getName(), rsvar.getRsid());
            ++index;
        }
    }

    protected JSONArray getVariables() throws JSONException {
        JSONArray jsonArray = new JSONArray();
        for (Map.Entry<Integer, MergedVariable> entry : this.varMap.entrySet()) {
            JSONObject jsonVar = this.mergeVariable(entry.getKey(), entry.getValue());
            jsonArray.put((Object)jsonVar);
        }
        return jsonArray;
    }
}