DomainParameterParser { public static Entry<String, Object> generateParameterEntry(final String parameter) { final String key; final Object value; log.debug("parsing: " + parameter); final String[] firstSplit = parameter.split(Pattern.quote("("), 2); key = firstSplit[0].trim(); log.debug("got key: " + key); final String tempString = firstSplit[1]; log.debug("parsing second part: " + tempString); final String[] secondSplit = tempString.split(Pattern.quote(")"), 2); final String type = secondSplit[0].trim(); log.debug("got type: " + type); final String tempSecondString = secondSplit[1]; log.debug("parsing third part:" + tempSecondString); final String[] thirdSplit = tempSecondString.split("=", 2); final String valueString = thirdSplit[1]; log.debug("got value: " + valueString); value = createValueInstance(type, valueString); return new AbstractMap.SimpleEntry<>(key, value); } private  DomainParameterParser(); static String parseParameterMapToString(final Map<String, Object> parametersMap); static void parseParameterEntryToString(final StringBuilder stringBuilder, final Entry<String, Object> entry); static JobParameters parseParametersToJobParameters(final String parameters); static Map<String, Object> parseParameters(final String parameters); static String parseJobParametersToString(final JobParameters jobParameters); static Entry<String, Object> generateParameterEntry(final String parameter); static Object createValueInstance(final String type, final String valueString); static Date parseDate(final String dateString); static String parseDate(final Date date); static final String DATE_FORMAT_WITH_TIMESTAMP; static final String DATE_FORMAT; }
@Test public void generateParameterStringEntryTest() { final String parameter = "test(String)=56788"; final Entry<String, Object> entry = DomainParameterParser .generateParameterEntry(parameter); assertThat(entry.getKey()).isEqualTo("test"); assertThat(entry.getValue()).isEqualTo("56788"); }
@Test public void generateParameterLongEntryTest() { final String parameter = "test(Long)=56"; final Entry<String, Object> entry = DomainParameterParser .generateParameterEntry(parameter); assertThat(entry.getKey()).isEqualTo("test"); assertThat(entry.getValue()).isEqualTo(56L); }
@Test public void generateParameterDateEntryTest() { final SimpleDateFormat simpleDateFormat = new SimpleDateFormat( DomainParameterParser.DATE_FORMAT_WITH_TIMESTAMP); final String parameter = "test(date)=2015/03/27 23:19:24:120"; final Entry<String, Object> entry = DomainParameterParser .generateParameterEntry(parameter); assertThat(entry.getKey()).isEqualTo("test"); assertThat(simpleDateFormat.format(entry.getValue())).isEqualTo( "2015/03/27 23:19:24:120"); }
@Test public void generateParameterDoubleEntryTest() { final String parameter = "test(Double)=5.2212"; final Entry<String, Object> entry = DomainParameterParser.generateParameterEntry(parameter); assertThat(entry.getKey()).isEqualTo("test"); assertThat(entry.getValue()).isEqualTo(5.2212); }