Skip to content

Commit

Permalink
refactor code to bring back immutability of config, simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 1, 2016
1 parent e188f09 commit 6f69605
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 241 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,16 @@ public JacksonJodaDateFormat(DateTimeFormatter defaultFormatter)
_adjustToContextTZOverride = null;
}

@Deprecated
public JacksonJodaDateFormat(JacksonJodaDateFormat base, Boolean useTimestamp)
public JacksonJodaDateFormat(JacksonJodaDateFormat base,
Boolean useTimestamp, Boolean adjustToContextTZOverride)
{
super(base, useTimestamp);
_formatter = base._formatter;
_jdkTimezone = base._jdkTimezone;
_explicitTimezone = base._explicitTimezone;
_adjustToContextTZOverride = base._adjustToContextTZOverride;
_adjustToContextTZOverride = adjustToContextTZOverride;
}

@Deprecated
public JacksonJodaDateFormat(JacksonJodaDateFormat base,
DateTimeFormatter formatter)
{
Expand All @@ -60,7 +59,6 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base,
_adjustToContextTZOverride = base._adjustToContextTZOverride;
}

@Deprecated
public JacksonJodaDateFormat(JacksonJodaDateFormat base, TimeZone jdkTimezone)
{
super(base, jdkTimezone);
Expand All @@ -70,7 +68,6 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, TimeZone jdkTimezone)
_adjustToContextTZOverride = base._adjustToContextTZOverride;
}

@Deprecated
public JacksonJodaDateFormat(JacksonJodaDateFormat base, Locale locale)
{
super(base, locale);
Expand All @@ -80,50 +77,17 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, Locale locale)
_adjustToContextTZOverride = base._adjustToContextTZOverride;
}

public JacksonJodaDateFormat(DateFormatSetup setup)
{
super(setup);
DateTimeFormatter formatter = setup.getFormatter();
if(_explicitLocale) {
formatter = formatter.withLocale(getLocale());
}
if(setup.getTimeZone() == null) {
_formatter = formatter;
DateTimeZone tz = _formatter.getZone();
_jdkTimezone = tz == null ? null : tz.toTimeZone();
_explicitTimezone = false;
} else {
_formatter = formatter.withZone(DateTimeZone.forTimeZone(setup.getTimeZone()));
_jdkTimezone = setup.getTimeZone();
_explicitTimezone = true;
}
_adjustToContextTZOverride = setup.getAdjustToContextTZOverride();
}

@Override
protected DateFormatSetup getSetup() {
DateFormatSetup setup = new DateFormatSetup(super.getSetup());
setup.setFormatter(_formatter);
if (_explicitTimezone) {
setup.setTimeZone(_jdkTimezone);
}
setup.setAdjustToContextTZOverride(_adjustToContextTZOverride);
return setup;
}

/*
/**********************************************************
/* Factory methods
/**********************************************************
*/

public JacksonJodaDateFormat withUseTimestamp(Boolean useTimestamp) {
if (_useTimestamp != null && _useTimestamp.equals(useTimestamp)) {
if ((_useTimestamp != null) && _useTimestamp.equals(useTimestamp)) {
return this;
}
DateFormatSetup setup = getSetup();
setup.setUseTimeStamp(useTimestamp);
return new JacksonJodaDateFormat(setup);
return new JacksonJodaDateFormat(this, useTimestamp, _adjustToContextTZOverride);
}

public JacksonJodaDateFormat withFormat(String format) {
Expand All @@ -140,39 +104,29 @@ public JacksonJodaDateFormat withFormat(String format) {
if (_locale != null) {
formatter = formatter.withLocale(_locale);
}
// copy TimeZone from previous formatter
formatter = formatter.withZone(_formatter.getZone());
DateFormatSetup setup = getSetup();
setup.setFormatter(formatter);
return new JacksonJodaDateFormat(setup);
return new JacksonJodaDateFormat(this, formatter);
}

public JacksonJodaDateFormat withTimeZone(TimeZone tz) {
if ((tz == null) || (_jdkTimezone != null && _jdkTimezone.equals(tz))) {
return this;
}
DateFormatSetup setup = getSetup();
setup.setTimeZone(tz);
return new JacksonJodaDateFormat(setup);
return new JacksonJodaDateFormat(this, tz);
}

public JacksonJodaDateFormat withLocale(Locale locale) {
if ((locale == null) || (_locale != null && _locale.equals(locale))) {
return this;
}
DateFormatSetup setup = getSetup();
setup.setLocale(locale);
return new JacksonJodaDateFormat(setup);
return new JacksonJodaDateFormat(this, locale);
}

public JacksonJodaDateFormat withAdjustToContextTZOverride(Boolean adjustToContextTZOverride) {
if ((adjustToContextTZOverride == null) ||
(_adjustToContextTZOverride != null && _adjustToContextTZOverride.equals(adjustToContextTZOverride))) {
// minor efficiency check to avoid recreation if no change:
if (adjustToContextTZOverride == _adjustToContextTZOverride) {
return this;
}
DateFormatSetup setup = getSetup();
setup.setAdjustToContextTZOverride(adjustToContextTZOverride);
return new JacksonJodaDateFormat(setup);
return new JacksonJodaDateFormat(this, _useTimestamp, adjustToContextTZOverride);
}

/*
Expand Down Expand Up @@ -260,7 +214,7 @@ public DateTimeFormatter createParser(DeserializationContext ctxt)
}

private boolean isAdjustDatesToContextTimeZone(DeserializationContext ctxt) {
return _adjustToContextTZOverride != null ? _adjustToContextTZOverride :
return (_adjustToContextTZOverride != null) ? _adjustToContextTZOverride :
ctxt.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,65 +26,52 @@ abstract class JacksonJodaFormatBase

protected final boolean _explicitLocale;

@Deprecated
protected JacksonJodaFormatBase(Boolean useTimestamp,
Locale locale, boolean explicitLocale) {
_useTimestamp = useTimestamp;
_locale = locale;
_explicitLocale = explicitLocale;
}

protected JacksonJodaFormatBase() {
_useTimestamp = null;
_locale = DEFAULT_LOCALE;
_explicitLocale = false;
}

@Deprecated
protected JacksonJodaFormatBase(JacksonJodaFormatBase base)
{
_useTimestamp = base._useTimestamp;
_locale = base._locale;
_explicitLocale = base._explicitLocale;
}

@Deprecated
protected JacksonJodaFormatBase(JacksonJodaFormatBase base, Boolean useTimestamp)
{
_useTimestamp = useTimestamp;
_locale = base._locale;
_explicitLocale = base._explicitLocale;
}

@Deprecated
protected JacksonJodaFormatBase(JacksonJodaFormatBase base, TimeZone jdkTimezone)
{
_useTimestamp = base._useTimestamp;
_locale = base._locale;
_explicitLocale = base._explicitLocale;
}

@Deprecated
protected JacksonJodaFormatBase(JacksonJodaFormatBase base, Locale locale)
{
_useTimestamp = base._useTimestamp;
_locale = locale;
_explicitLocale = true;
}

protected JacksonJodaFormatBase(BaseFormatSetup setup) {
_useTimestamp = setup.isUseTimestamp();
if (setup.getLocale() != null) {
_locale = setup.getLocale();
_explicitLocale = true;
} else {
if (locale == null) {
_locale = DEFAULT_LOCALE;
_explicitLocale = false;
} else {
_locale = locale;
_explicitLocale = true;
}
}

protected BaseFormatSetup getSetup() {
BaseFormatSetup setup = new BaseFormatSetup();
setup.setUseTimeStamp(_useTimestamp);
if (_explicitLocale) {
setup.setLocale(_locale);
}
return setup;
}

/*
/**********************************************************
/* Other public methods
Expand Down
Loading

0 comments on commit 6f69605

Please sign in to comment.