mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#75 JavaDoc
This commit is contained in:
parent
ac01dda742
commit
d6a6cb25b6
@ -28,7 +28,9 @@ import org.mapstruct.ap.util.Strings;
|
||||
import static org.mapstruct.ap.util.Collections.asSet;
|
||||
|
||||
/**
|
||||
* Base class for conversions between Joda-Time types and String.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public abstract class AbstractJodaTypeToStringConversion extends SimpleConversion {
|
||||
|
||||
@ -83,11 +85,17 @@ public abstract class AbstractJodaTypeToStringConversion extends SimpleConversio
|
||||
return conversionString.toString();
|
||||
}
|
||||
|
||||
public String defaultDateFormatPattern() {
|
||||
private String defaultDateFormatPattern() {
|
||||
return "DateTimeFormat.patternForStyle( \"" + formatStyle() + "\", Locale.getDefault() )";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default format style to be applied if non is given explicitly.
|
||||
*/
|
||||
protected abstract String formatStyle();
|
||||
|
||||
/**
|
||||
* Returns the name of the parse method for converting a String into a specific Joda-Time type.
|
||||
*/
|
||||
protected abstract String parseMethod();
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class Conversions {
|
||||
register( BigInteger.class, String.class, new BigIntegerToStringConversion() );
|
||||
register( BigDecimal.class, String.class, new BigDecimalToStringConversion() );
|
||||
|
||||
registerJoda();
|
||||
registerJodaConversions();
|
||||
|
||||
//misc.
|
||||
register( Enum.class, String.class, new EnumStringConversion() );
|
||||
@ -187,7 +187,7 @@ public class Conversions {
|
||||
register( BigDecimal.class, BigInteger.class, new BigDecimalToBigIntegerConversion() );
|
||||
}
|
||||
|
||||
private void registerJoda() {
|
||||
private void registerJodaConversions() {
|
||||
if ( !isJodaTimeAvailable() ) {
|
||||
return;
|
||||
}
|
||||
@ -235,7 +235,7 @@ public class Conversions {
|
||||
register(
|
||||
getClass( JodaTimeConstants.DATE_TIME_FQN ),
|
||||
Calendar.class,
|
||||
new JodaTimeToCalendarConversion()
|
||||
new JodaDateTimeToCalendarConversion()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
@ -27,9 +28,11 @@ import org.mapstruct.ap.model.common.Type;
|
||||
import static org.mapstruct.ap.util.Collections.asSet;
|
||||
|
||||
/**
|
||||
* Conversion between {@code DateTime} and {@link Calendar}.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public class JodaTimeToCalendarConversion extends SimpleConversion {
|
||||
public class JodaDateTimeToCalendarConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
protected String getToExpression(ConversionContext conversionContext) {
|
@ -19,7 +19,9 @@
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
/**
|
||||
* Conversion between {@code DateTime} and {@code String}.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public class JodaDateTimeToStringConversion extends AbstractJodaTypeToStringConversion {
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
/**
|
||||
* Conversion between {@code LocalDateTime} and {@code String}.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public class JodaLocalDateTimeToStringConversion extends AbstractJodaTypeToStringConversion {
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
/**
|
||||
* Conversion between {@code LocalDate} and {@code String}.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public class JodaLocalDateToStringConversion extends AbstractJodaTypeToStringConversion {
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
/**
|
||||
* Conversion between {@code LocalTime} and {@code String}.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public class JodaLocalTimeToStringConversion extends AbstractJodaTypeToStringConversion {
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
/**
|
||||
* Helper holding constants for working with joda time
|
||||
* Helper holding constants for working with Joda-Time.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public final class JodaTimeConstants {
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.mapstruct.ap.conversion;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mapstruct.ap.model.common.ConversionContext;
|
||||
@ -26,14 +27,14 @@ import org.mapstruct.ap.model.common.Type;
|
||||
import static org.mapstruct.ap.util.Collections.asSet;
|
||||
|
||||
/**
|
||||
* Implementation of {@link org.mapstruct.ap.conversion.ConversionProvider} mapping Joda Types
|
||||
* Conversion between the following Joda types and {@link Date}:
|
||||
* <ul>
|
||||
* <li>org.joda.time.DateTime</li>
|
||||
* <li>org.joda.time.LocalDateTime</li>
|
||||
* <li>org.joda.time.LocalDate</li>
|
||||
* </ul>
|
||||
* to java.util.Date by invoking org.joda.time.base.AbstractInstant#toDate().
|
||||
* Backward conversion is done.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
public class JodaTimeToDateConversion extends SimpleConversion {
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.conversion.jodatime;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDate;
|
||||
@ -29,13 +32,12 @@ import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests the conversion between Joda-Time types and String/Date/Calendar.
|
||||
*
|
||||
* @author Timo Eckhardt
|
||||
*/
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
|
||||
@ -110,7 +112,7 @@ public class JodaConversionTest {
|
||||
Target target = new Target();
|
||||
target.setDateTime( dateTimeAsString );
|
||||
DateTime sourceDateTime =
|
||||
new DateTime( 2014, 1, 1, 0, 0, 0, DateTimeZone.UTC );
|
||||
new DateTime( 2014, 1, 1, 0, 0, 0, DateTimeZone.UTC );
|
||||
|
||||
Source src = SourceTargetMapper.INSTANCE.targetToSourceDateTimeMapped( target );
|
||||
assertThat( src ).isNotNull();
|
||||
@ -123,7 +125,7 @@ public class JodaConversionTest {
|
||||
Target target = new Target();
|
||||
target.setLocalDateTime( dateTimeAsString );
|
||||
LocalDateTime sourceDateTime =
|
||||
new LocalDateTime( 2014, 1, 1, 0, 0, 0 );
|
||||
new LocalDateTime( 2014, 1, 1, 0, 0, 0 );
|
||||
|
||||
Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalDateTimeMapped( target );
|
||||
assertThat( src ).isNotNull();
|
||||
@ -136,7 +138,7 @@ public class JodaConversionTest {
|
||||
Target target = new Target();
|
||||
target.setLocalDate( dateTimeAsString );
|
||||
LocalDate sourceDate =
|
||||
new LocalDate( 2014, 1, 1 );
|
||||
new LocalDate( 2014, 1, 1 );
|
||||
|
||||
Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalDateMapped( target );
|
||||
assertThat( src ).isNotNull();
|
||||
@ -149,7 +151,7 @@ public class JodaConversionTest {
|
||||
Target target = new Target();
|
||||
target.setLocalTime( dateTimeAsString );
|
||||
LocalTime sourceTime =
|
||||
new LocalTime( 0, 0 );
|
||||
new LocalTime( 0, 0 );
|
||||
|
||||
Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalTimeMapped( target );
|
||||
assertThat( src ).isNotNull();
|
||||
@ -199,6 +201,5 @@ public class JodaConversionTest {
|
||||
Source mappedSource = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||
assertThat( mappedSource ).isNotNull();
|
||||
assertThat( mappedSource.getDateTimeForCalendarConversion() ).isEqualTo( dateTimeWithCalendar );
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,6 @@ import org.joda.time.LocalDate;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.joda.time.LocalTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Source {
|
||||
|
||||
private DateTime dateTime;
|
||||
|
@ -23,9 +23,6 @@ import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Mapper
|
||||
public interface SourceTargetMapper {
|
||||
|
||||
@ -39,43 +36,47 @@ public interface SourceTargetMapper {
|
||||
|
||||
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||
|
||||
@Mappings({ @Mapping( source = "dateTime", dateFormat = DATE_TIME_FORMAT ),
|
||||
@Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
|
||||
@Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
|
||||
@Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT ) })
|
||||
@Mappings({
|
||||
@Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT),
|
||||
@Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT),
|
||||
@Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT),
|
||||
@Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
|
||||
})
|
||||
Target sourceToTarget(Source source);
|
||||
|
||||
Target sourceToTargetDefaultMapping(Source source);
|
||||
|
||||
@Mapping( source = "dateTime", dateFormat = DATE_TIME_FORMAT )
|
||||
@Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT)
|
||||
Target sourceToTargetDateTimeMapped(Source source);
|
||||
|
||||
@Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT )
|
||||
@Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT)
|
||||
Target sourceToTargetLocalDateTimeMapped(Source source);
|
||||
|
||||
@Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT )
|
||||
@Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT)
|
||||
Target sourceToTargetLocalDateMapped(Source source);
|
||||
|
||||
@Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT )
|
||||
@Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
|
||||
Target sourceToTargetLocalTimeMapped(Source source);
|
||||
|
||||
|
||||
@Mappings({ @Mapping( source = "dateTime", dateFormat = DATE_TIME_FORMAT ),
|
||||
@Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
|
||||
@Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
|
||||
@Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT ) })
|
||||
@Mappings({
|
||||
@Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT),
|
||||
@Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT),
|
||||
@Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT),
|
||||
@Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
|
||||
})
|
||||
Source targetToSource(Target target);
|
||||
|
||||
@Mapping( source = "dateTime", dateFormat = DATE_TIME_FORMAT )
|
||||
@Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT)
|
||||
Source targetToSourceDateTimeMapped(Target target);
|
||||
|
||||
@Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT )
|
||||
@Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT)
|
||||
Source targetToSourceLocalDateTimeMapped(Target target);
|
||||
|
||||
@Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT )
|
||||
@Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT)
|
||||
Source targetToSourceLocalDateMapped(Target target);
|
||||
|
||||
@Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT )
|
||||
@Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
|
||||
Source targetToSourceLocalTimeMapped(Target target);
|
||||
|
||||
Source targetToSourceDefaultMapping(Target target);
|
||||
|
@ -21,9 +21,6 @@ package org.mapstruct.ap.test.conversion.jodatime;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Target {
|
||||
|
||||
private String dateTime;
|
||||
|
Loading…
x
Reference in New Issue
Block a user