Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Use checkNotNull on DateTimeFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jodastephen committed Jun 7, 2009
1 parent f207f01 commit ee9d625
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, Stephen Colebourne & Michael Nascimento Santos
* Copyright (c) 2008-2009, Stephen Colebourne & Michael Nascimento Santos
*
* All rights reserved.
*
Expand Down Expand Up @@ -41,8 +41,8 @@

import javax.time.calendar.DateTimeFieldRule;
import javax.time.calendar.ISOChronology;
import javax.time.calendar.field.DayOfWeek;
import javax.time.calendar.field.AmPmOfDay;
import javax.time.calendar.field.DayOfWeek;
import javax.time.calendar.field.MonthOfYear;
import javax.time.calendar.format.DateTimeFormatterBuilder.TextStyle;

Expand Down Expand Up @@ -138,7 +138,7 @@ public static DateTimeFormatSymbols getInstance(Locale locale) {
// }
// }
//
FormatUtil.checkNotNull(locale, "locale");
DateTimeFormatter.checkNotNull(locale, "Locale must not be null");
DateFormatSymbols symbols = new DateFormatSymbols(locale);
return new DateTimeFormatSymbols(locale, symbols);
}
Expand All @@ -150,7 +150,7 @@ public static DateTimeFormatSymbols getInstance(Locale locale) {
* @param locale the locale, not null
*/
private DateTimeFormatSymbols(Locale locale) {
FormatUtil.checkNotNull(locale, "locale");
DateTimeFormatter.checkNotNull(locale, "Locale must not be null");
this.locale = locale;
textMap = new HashMap<String, Map<TextStyle, TextStore>>();
}
Expand All @@ -163,7 +163,7 @@ private DateTimeFormatSymbols(Locale locale) {
*/
private DateTimeFormatSymbols(Locale locale, DateFormatSymbols oldSymbols) {
this(locale);
FormatUtil.checkNotNull(oldSymbols, "symbols to convert");
DateTimeFormatter.checkNotNull(oldSymbols, "Symbols to convert must not be null");

Map<Integer, String> map = new HashMap<Integer, String>();
String[] array = null;
Expand Down Expand Up @@ -400,7 +400,7 @@ public Map<String, Integer> getFieldTextValueMap(DateTimeFieldRule fieldRule, Te
*/
public int[] matchFieldText(DateTimeFieldRule fieldRule, TextStyle textStyle, boolean ignoreCase, String searchText) {
TextStore store = getTextStore(fieldRule, textStyle);
FormatUtil.checkNotNull(searchText, "search text");
DateTimeFormatter.checkNotNull(searchText, "Search text must not be null");
if (store == null) {
return null;
}
Expand Down Expand Up @@ -442,8 +442,8 @@ public int[] matchFieldText(DateTimeFieldRule fieldRule, TextStyle textStyle, bo
* @return the text store, null if no text defined
*/
private TextStore getTextStore(DateTimeFieldRule fieldRule, TextStyle textStyle) {
FormatUtil.checkNotNull(fieldRule, "field rule");
FormatUtil.checkNotNull(textStyle, "text style");
DateTimeFormatter.checkNotNull(fieldRule, "DateTimeFieldRule must not be null");
DateTimeFormatter.checkNotNull(textStyle, "TextStyle must not be null");
String id = fieldRule.getID();
Map<TextStyle, TextStore> styleMap = textMap.get(id);
return styleMap == null ? null : styleMap.get(textStyle);
Expand Down Expand Up @@ -472,7 +472,7 @@ private class TextStore {
* @throws IllegalArgumentException if the map contains null or empty text
*/
private TextStore(Map<Integer, String> map) {
FormatUtil.checkNotNull(map, "text map");
DateTimeFormatter.checkNotNull(map, "Text map must not be null");
if (map.containsKey(null) || map.containsValue(null) || map.containsValue("")) {
throw new IllegalArgumentException("The map must not contain null or empty text");
}
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/javax/time/calendar/format/DateTimeFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ private DateTimeFormatter(
this.printerParser = printerParser;
}

//-----------------------------------------------------------------------
/**
* Validates that the input value is not null.
*
* @param object the object to check
* @param errorMessage the error to throw
* @throws NullPointerException if the object is null
*/
static void checkNotNull(Object object, String errorMessage) {
if (object == null) {
throw new NullPointerException(errorMessage);
}
}

//-----------------------------------------------------------------------
/**
* Gets the locale to be used during formatting.
Expand All @@ -112,7 +126,7 @@ public Locale getLocale() {
* @return a new DateTimeFormatter with the same format and the new locale, never null
*/
public DateTimeFormatter withLocale(Locale locale) {
FormatUtil.checkNotNull(locale, "locale");
DateTimeFormatter.checkNotNull(locale, "Locale must not be null");
if (locale.equals(this.getLocale())) {
return this;
}
Expand Down Expand Up @@ -173,8 +187,8 @@ public String print(CalendricalProvider calendrical) {
* @throws CalendricalFormatException if an error occurs during printing
*/
public void print(CalendricalProvider calendricalProvider, Appendable appendable) {
FormatUtil.checkNotNull(calendricalProvider, "calendrical provider");
FormatUtil.checkNotNull(appendable, "appendable");
DateTimeFormatter.checkNotNull(calendricalProvider, "CalendricalProvider must not be null");
DateTimeFormatter.checkNotNull(appendable, "Appendable must not be null");
Calendrical calendrical = calendricalProvider.toCalendrical();
try {
printerParser.print(calendrical, appendable, symbols);
Expand Down Expand Up @@ -259,8 +273,8 @@ public Calendrical parse(String text) {
* @throws IndexOutOfBoundsException if the position is invalid
*/
public Calendrical parse(String text, ParsePosition position) {
FormatUtil.checkNotNull(text, "text to parse");
FormatUtil.checkNotNull(position, "position to parse from");
DateTimeFormatter.checkNotNull(text, "Text must not be null");
DateTimeFormatter.checkNotNull(position, "ParsePosition must not be null");
DateTimeParseContext context = new DateTimeParseContext(symbols);
int pos = position.getIndex();
pos = printerParser.parse(context, text, pos);
Expand Down Expand Up @@ -325,9 +339,9 @@ private class ClassicFormat extends Format {
/** {@inheritDoc} */
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
FormatUtil.checkNotNull(obj, "object to be printed");
FormatUtil.checkNotNull(toAppendTo, "string buffer");
FormatUtil.checkNotNull(pos, "field position");
DateTimeFormatter.checkNotNull(obj, "Object to be printed must not be null");
DateTimeFormatter.checkNotNull(toAppendTo, "StringBuffer must not be null");
DateTimeFormatter.checkNotNull(pos, "FieldPosition must not be null");
Calendrical fdt = null;
if (obj instanceof CalendricalProvider) {
fdt = ((CalendricalProvider) obj).toCalendrical();
Expand Down

0 comments on commit ee9d625

Please sign in to comment.