/*
 * Decompiled with CFR 0.152.
 */
package com.hst.framework.util;

import com.hst.framework.util.HstReflectUtil;
import java.util.HashMap;
import java.util.Map;

public class HstArray2MapUtil {
    private static HstArray2MapUtil HstArray2MapUtil;

    private HstArray2MapUtil() {
    }

    public static HstArray2MapUtil getInstance() {
        if (HstArray2MapUtil == null) {
            HstArray2MapUtil = new HstArray2MapUtil();
        }
        return HstArray2MapUtil;
    }

    public Map getMap(Object[] objects) throws Exception {
        return this.getMap(objects, null, null);
    }

    public Map getMap(Object[] objects, String field) throws Exception {
        return this.getMap(objects, new String[]{field}, null);
    }

    public Map getMap(Object[] objects, String[] fields) throws Exception {
        return this.getMap(objects, fields, null);
    }

    public Map getMap(Object[] objects, String[] fields, String split) throws Exception {
        HashMap<Object, Object> map = new HashMap<Object, Object>();
        if (objects != null) {
            int i = 0;
            while (i < objects.length) {
                if (fields != null) {
                    String keyValue = this.getKeyValue(objects[i], fields, split);
                    map.put(keyValue, objects[i]);
                } else {
                    map.put(objects[i], objects[i]);
                }
                ++i;
            }
        }
        return map;
    }

    private String getKeyValue(Object object, String[] fields, String split) throws Exception {
        String value = "";
        int i = 0;
        while (i < fields.length) {
            value = String.valueOf(value) + (split == null ? "" : split) + HstReflectUtil.getFieldValue(object, fields[i]);
            ++i;
        }
        return value;
    }
}
