Revision e2ffb1fd
Added by Andreas Müller almost 6 years ago
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/TimePeriodParser.java | ||
---|---|---|
410 | 410 |
|
411 | 411 |
public static VerbatimTimePeriod parseStringVerbatim(String strPeriod) { |
412 | 412 |
VerbatimTimePeriod timePeriod = VerbatimTimePeriod.NewVerbatimInstance(); |
413 |
strPeriod = parseVerbatimPart(timePeriod, strPeriod); |
|
413 | 414 |
return parseString(timePeriod, strPeriod); |
414 | 415 |
} |
415 | 416 |
|
416 | 417 |
|
417 | 418 |
|
418 |
protected static Partial parseSingleDate(String singleDateString) throws IllegalArgumentException{ |
|
419 |
/** |
|
420 |
* @param timePeriod |
|
421 |
* @param strPeriod |
|
422 |
* @return |
|
423 |
*/ |
|
424 |
private static String parseVerbatimPart(VerbatimTimePeriod timePeriod, String strPeriod) { |
|
425 |
//very first implementation, only for years and following 1 format |
|
426 |
String regEx = "(.*)(\\[\"\\d{4}\"\\])"; |
|
427 |
Pattern pattern = Pattern.compile(regEx); |
|
428 |
Matcher matcher = pattern.matcher(strPeriod); |
|
429 |
if (matcher.matches()){ |
|
430 |
String verbatimDate = matcher.group(2).substring(2, 6); |
|
431 |
timePeriod.setVerbatimDate(verbatimDate); |
|
432 |
strPeriod = matcher.group(1).trim(); |
|
433 |
} |
|
434 |
return strPeriod; |
|
435 |
} |
|
436 |
|
|
437 |
protected static Partial parseSingleDate(String singleDateString) throws IllegalArgumentException{ |
|
419 | 438 |
//FIXME until now only quick and dirty and incomplete |
420 | 439 |
Partial partial = new Partial(); |
421 | 440 |
singleDateString = singleDateString.trim(); |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/strategy/parser/TimePeriodParserTest.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import eu.etaxonomy.cdm.common.UTF8; |
28 | 28 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
29 |
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod; |
|
29 | 30 |
|
30 | 31 |
/** |
31 | 32 |
* @author a.mueller |
... | ... | |
268 | 269 |
} |
269 | 270 |
|
270 | 271 |
|
272 |
@Test |
|
273 |
public void testParseVerbatim() { |
|
274 |
String strDate = "1957 [\"1958\"]"; |
|
275 |
VerbatimTimePeriod tp = TimePeriodParser.parseStringVerbatim(strDate); |
|
276 |
assertNotNull(tp); |
|
277 |
Assert.assertEquals(strDate, tp.toString()); |
|
278 |
Assert.assertEquals("1957", tp.getYear()); |
|
279 |
Assert.assertEquals(Integer.valueOf(1957), tp.getStartYear()); |
|
280 |
// Assert.assertEquals(Integer.valueOf(8), tp.getStartMonth()); |
|
281 |
// Assert.assertEquals(Integer.valueOf(24), tp.getStartDay()); |
|
282 |
Assert.assertEquals("1958", tp.getVerbatimDate()); |
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
|
|
287 |
|
|
271 | 288 |
} |
Also available in: Unified diff
ref #6752 first implementation of VerbatimTimePeriod parser