package org.diagbot.nlp.feature.extract;

import org.diagbot.nlp.feature.FeatureType;

/**
 * @Auther: fyeman
 * @Date: 2018/7/23/023 17:10
 * @Description:
 */
public class CaseTokenFactory {
    private static CaseTokenSymptom caseTokenSymptom = null;
    private static CaseTokenFeature caseTokenFeature = null;
    private static CaseTokenDiag caseTokenDiag = null;
    private static CaseTokenVital caseTokenVital = null;
    private static CaseTokenLIS caseTokenLis = null;
    private static CaseTokenPACS caseTokenPacs = null;

    public static CaseToken getInstance(FeatureType featureType) throws java.lang.InstantiationException, java.lang.IllegalAccessException {
        try {
            switch (featureType) {
                case SYMPTOM:
                    return (CaseTokenSymptom) create(caseTokenSymptom, CaseTokenSymptom.class);
                case FEATURE:
                    return (CaseTokenFeature) create(caseTokenFeature, CaseTokenFeature.class);
                case VITAL:
                    return (CaseTokenVital) create(caseTokenVital, CaseTokenVital.class);
                case PACS:
                    return (CaseTokenPACS) create(caseTokenPacs, CaseTokenPACS.class);
                case LIS:
                    return (CaseTokenLIS) create(caseTokenLis, CaseTokenLIS.class);
                case DIAG:
                    return (CaseTokenDiag) create(caseTokenDiag, CaseTokenDiag.class);
            }
        } catch (java.lang.InstantiationException inst) {
            throw inst;
        } catch (java.lang.IllegalAccessException ille) {
            throw ille;
        }
        return null;
    }

    private static Object create(CaseToken caseToken, Class cls) throws java.lang.InstantiationException, java.lang.IllegalAccessException {
        if (caseToken == null) {
            synchronized (cls) {
                return cls.newInstance();
            }
        }
        return caseToken;
    }
}
