#120 Making built-in methods null-safe

This commit is contained in:
Gunnar Morling 2014-02-22 19:54:54 +01:00
parent 32f0bc0e22
commit bc5dda82f8
7 changed files with 35 additions and 6 deletions

View File

@ -19,6 +19,10 @@
-->
private XMLGregorianCalendar ${name}( Calendar cal ) {
if ( cal == null ) {
return null;
}
try {
GregorianCalendar gcal = new GregorianCalendar();
gcal.setTimeInMillis( cal.getTimeInMillis() );
@ -27,4 +31,4 @@ private XMLGregorianCalendar ${name}( Calendar cal ) {
catch ( DatatypeConfigurationException ex ) {
throw new RuntimeException( ex );
}
}
}

View File

@ -19,6 +19,10 @@
-->
private XMLGregorianCalendar ${name}( Date date ) {
if ( date == null ) {
return null;
}
try {
GregorianCalendar c = new GregorianCalendar();
c.setTime( date );
@ -27,4 +31,4 @@ private XMLGregorianCalendar ${name}( Date date ) {
catch ( DatatypeConfigurationException ex ) {
throw new RuntimeException( ex );
}
}
}

View File

@ -19,5 +19,9 @@
-->
private <T> T ${name}( JAXBElement <T> element ) {
if ( element == null ) {
return null;
}
return element.isNil() ? null : element.getValue();
}

View File

@ -19,6 +19,10 @@
-->
private XMLGregorianCalendar ${name}( String date, String dateFormat ) {
if ( date == null ) {
return null;
}
try {
DateFormat df = dateFormat != null ? new SimpleDateFormat( dateFormat ) : SimpleDateFormat.getInstance();
GregorianCalendar c = new GregorianCalendar();
@ -31,4 +35,4 @@ private XMLGregorianCalendar ${name}( String date, String dateFormat ) {
catch ( ParseException ex ) {
throw new RuntimeException( ex );
}
}
}

View File

@ -19,6 +19,10 @@
-->
private Calendar ${name}( XMLGregorianCalendar xcal ) {
if ( xcal == null ) {
return null;
}
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis( xcal.toGregorianCalendar().getTimeInMillis() );
return cal;

View File

@ -19,5 +19,9 @@
-->
private static Date ${name}( XMLGregorianCalendar xcal ) {
if ( xcal == null ) {
return null;
}
return xcal.toGregorianCalendar().getTime();
}
}

View File

@ -19,11 +19,16 @@
-->
private String ${name}( XMLGregorianCalendar xcal, String dateFormat ) {
if ( xcal == null ) {
return null;
}
if (dateFormat == null ) {
return xcal.toString();
} else {
}
else {
Date d = xcal.toGregorianCalendar().getTime();
SimpleDateFormat sdf = new SimpleDateFormat( dateFormat );
return sdf.format( d );
}
}
}