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;
    private static CaseTokenTime caseTokenTime = null;

    public static CaseToken getInstance(FeatureType featureType) throws java.lang.InstantiationException, java.lang.IllegalAccessException {
        try {
            switch (featureType) {
                case SYMPTOM:
                    if (caseTokenSymptom == null) {
                        caseTokenSymptom = new CaseTokenSymptom();
                    }
                    return caseTokenSymptom;
                case FEATURE:
                    if (caseTokenFeature == null) {
                        caseTokenFeature = new CaseTokenFeature();
                    }
                    return caseTokenFeature;
                case VITAL:
                    if (caseTokenVital == null) {
                        caseTokenVital = new CaseTokenVital();
                    }
                    return caseTokenVital;
                case PACS:
                    if (caseTokenPacs == null) {
                        caseTokenPacs = new CaseTokenPACS();
                    }
                    return caseTokenPacs;
                case LIS:
                    if (caseTokenLis == null) {
                        caseTokenLis = new CaseTokenLIS();
                    }
                    return caseTokenLis;
                case DIAG:
                    if (caseTokenDiag == null) {
                        caseTokenDiag = new CaseTokenDiag();
                    }
                    return caseTokenDiag;
                case TIME:
                    if (caseTokenTime == null) {
                        caseTokenTime = new CaseTokenTime();
                    }
                    return caseTokenTime;
            }
        }catch (Exception 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;
    }
}
