package com.moral.api.util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Method { public static Map getDataStore(String data) { data = data.replaceFirst("&&",";"); Map dataStore = new HashMap<>(); String[] commands = data.split(";"); List commandList = Arrays.asList(commands); commandList.forEach(command -> { String[] cmds = command.split("="); String key = cmds[0]; String value = cmds.length > 1 ? cmds[1] : ""; dataStore.put(key, value); }); return dataStore; } public static Map getCpDataStore(String cp) { String[] dataItems = cp.split(";"); // [array] Map dataStore = new HashMap<>(); List dataItemList = Arrays.asList(dataItems); dataItemList.forEach(dataItem -> { String[] itemArr= dataItem.split(";"); List itemList = Arrays.asList(itemArr); itemList.forEach(item -> { String[] item1Arr = item.split(","); List item1List = Arrays.asList(item1Arr); item1List.forEach(itemChild -> { String[] items = itemChild.split("="); String item1 = items[0]; String item2 = items[1]; if(item1.endsWith("-Rtd")) { String key = item1.replace("-Rtd", ""); dataStore.put(key, item2); }else{ String k = item1; dataStore.put(k, item2); } }); }); }); return dataStore; } public static long getTimeStamp(String time, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (!"".equals(format)) { simpleDateFormat = new SimpleDateFormat(format); } long timeStemp = 0; try { Date date = simpleDateFormat.parse(time); timeStemp = date.getTime(); } catch (ParseException e) { e.printStackTrace(); } return timeStemp; } }