Revision 3a676b7a
Added by Andreas Müller over 6 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmImportBase.java | ||
---|---|---|
1443 | 1443 |
} |
1444 | 1444 |
|
1445 | 1445 |
|
1446 |
/** |
|
1447 |
* Converts a given string into an integer. If this is not possible |
|
1448 |
* an error is logged in the import result with record location and attribute name. |
|
1449 |
* |
|
1450 |
* @param state |
|
1451 |
* @param strToConvert |
|
1452 |
* @param recordLocation |
|
1453 |
* @param attributeName |
|
1454 |
* @return the converted integer |
|
1455 |
*/ |
|
1456 |
protected Integer intFromString(STATE state, |
|
1457 |
String strToConvert, |
|
1458 |
String recordLocation, |
|
1459 |
String attributeName) { |
|
1460 |
|
|
1461 |
if (strToConvert == null){ |
|
1462 |
return null; |
|
1463 |
} |
|
1464 |
try { |
|
1465 |
Integer result = Integer.valueOf(strToConvert); |
|
1466 |
return result; |
|
1467 |
} catch (NumberFormatException e) { |
|
1468 |
String message = "Text '%s' could not be transformed into integer number for attribute %s"; |
|
1469 |
message = String.format(message, strToConvert, attributeName); |
|
1470 |
state.getResult().addError(message, e, null, recordLocation); |
|
1471 |
} |
|
1472 |
return null; |
|
1473 |
} |
|
1474 |
|
|
1475 |
/** |
|
1476 |
* Converts a given string into a {@link Double}. If this is not possible |
|
1477 |
* an error is logged in the import result with record location and attribute name. |
|
1478 |
* |
|
1479 |
* @param state |
|
1480 |
* @param strToConvert |
|
1481 |
* @param recordLocation |
|
1482 |
* @param attributeName |
|
1483 |
* @return the converted integer |
|
1484 |
*/ |
|
1485 |
protected Double doubleFromString(STATE state, |
|
1486 |
String strToConvert, |
|
1487 |
String recordLocation, |
|
1488 |
String attributeName) { |
|
1489 |
|
|
1490 |
if (strToConvert == null){ |
|
1491 |
return null; |
|
1492 |
} |
|
1493 |
try { |
|
1494 |
Double result = Double.valueOf(strToConvert); |
|
1495 |
return result; |
|
1496 |
} catch (NumberFormatException e) { |
|
1497 |
String message = "Text '%s' could not be transformed into number of type Double for attribute %s"; |
|
1498 |
message = String.format(message, strToConvert, attributeName); |
|
1499 |
state.getResult().addError(message, e, null, recordLocation); |
|
1500 |
} |
|
1501 |
return null; |
|
1502 |
} |
|
1503 |
|
|
1504 |
|
|
1446 | 1505 |
/** |
1447 | 1506 |
* Returns <code>null</code> for all blank strings. Identity function otherwise. |
1448 | 1507 |
* @param str |
Also available in: Unified diff
ref #6606 changes in cdmlib for bogota specimen import