package core.operation.utils;

import error.GExcptFormat;
import gdms.Configuration;
import gdms.Mode;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public interface Utils {
    Map<String,String> fileTableField = new HashMap<>() {
        {
            put("announcement","annex_url");
            put("graduation_design_finished_product","graduation_design_url");
            put("graduation_design_opening_report","report_url");
        }};
    static String stringOptionsFormat(String options){
        return options.replaceAll(" {2,}", " ") ;
    }
    static Map<String, Object> string2MapOptions(String sOptions) throws GExcptFormat {
        sOptions = stringOptionsFormat(sOptions);
        Map<String, Object> options = new HashMap<>();
        String[] sOpts = sOptions.split(" ");
        for(int i=0;i<sOpts.length;i++){
            if(Mode.strict==1){
                if(sOpts[i].indexOf(0)=='-')
                    throw new GExcptFormat("options format error");
            }
            options.put(sOpts[i].substring(1),sOpts[++i]);
        }
        return options;
    }
    static String getFileField(String table){
        return fileTableField.get(table);
    }
}
