1 /*
2 * Copyright 2007 Kasper B. Graversen
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.supercsv.cellprocessor.joda;
17
18 import java.util.Locale;
19
20 import org.joda.time.LocalDate;
21 import org.joda.time.format.DateTimeFormat;
22 import org.joda.time.format.DateTimeFormatter;
23 import org.joda.time.format.DateTimeFormatterBuilder;
24 import org.joda.time.format.ISODateTimeFormat;
25 import org.supercsv.cellprocessor.ift.CellProcessor;
26
27 /**
28 * Converts a Joda LocalDate to a String.
29 *
30 * <p>
31 * For constructors using DateTimeFormatter, refer to the following Joda
32 * classes:
33 * <ul>
34 * <li>{@link DateTimeFormat} - formats by pattern and style</li>
35 * <li>{@link ISODateTimeFormat} - ISO8601 formats</li>
36 * <li>{@link DateTimeFormatterBuilder} - complex formats created via method
37 * calls</li>
38 * </ul>
39 * <p>
40 * For constructors using date format Strings, refer to {@link DateTimeFormat}
41 * for example formats.
42 *
43 * @since 2.3.0
44 * @author James Bassett
45 */
46 public class FmtLocalDate extends AbstractJodaFormattingProcessor<LocalDate> {
47
48 private static final Class<LocalDate> JODA_CLASS = LocalDate.class;
49
50 /**
51 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
52 * LocalDate as a String.
53 */
54 public FmtLocalDate() {
55 super(JODA_CLASS);
56 }
57
58 /**
59 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
60 * LocalDate as a String, then calls the next processor in the chain.
61 *
62 * @param next
63 * next processor in the chain
64 * @throws NullPointerException
65 * if next is null
66 */
67 public FmtLocalDate(final CellProcessor next) {
68 super(JODA_CLASS, next);
69 }
70
71 /**
72 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
73 * LocalDate as a String using the supplied formatter.
74 *
75 * @param formatter
76 * the formatter to use
77 * @throws NullPointerException
78 * if formatter is null
79 */
80 public FmtLocalDate(final DateTimeFormatter formatter) {
81 super(JODA_CLASS, formatter);
82 }
83
84 /**
85 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
86 * LocalDate as a String using the supplied formatter, then calls the next
87 * processor in the chain.
88 *
89 * @param formatter
90 * the formatter to use
91 * @param next
92 * the next processor in the chain
93 * @throws NullPointerException
94 * if formatter or next is null
95 */
96 public FmtLocalDate(final DateTimeFormatter formatter,
97 final CellProcessor next) {
98 super(JODA_CLASS, formatter, next);
99 }
100
101 /**
102 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
103 * LocalDate as a String using the supplied pattern and the default locale.
104 *
105 * @param pattern
106 * the pattern to use
107 * @throws NullPointerException
108 * if pattern is null
109 */
110 public FmtLocalDate(final String pattern) {
111 super(JODA_CLASS, pattern);
112 }
113
114 /**
115 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
116 * LocalDate as a String using the supplied pattern and the default locale,
117 * then calls the next processor in the chain.
118 *
119 * @param pattern
120 * the pattern to use
121 * @param next
122 * the next processor in the chain
123 * @throws NullPointerException
124 * if pattern or next is null
125 */
126 public FmtLocalDate(final String pattern, final CellProcessor next) {
127 super(JODA_CLASS, pattern, next);
128 }
129
130 /**
131 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
132 * LocalDate as a String using the supplied pattern and the locale.
133 *
134 * @param pattern
135 * the pattern to use
136 * @param locale
137 * the locale to use (default used if <tt>null</tt>)
138 * @throws NullPointerException
139 * if pattern is null
140 */
141 public FmtLocalDate(final String pattern, final Locale locale) {
142 super(JODA_CLASS, pattern, locale);
143 }
144
145 /**
146 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a Joda
147 * LocalDate as a String using the supplied pattern and the locale, then
148 * calls the next processor in the chain.
149 *
150 * @param pattern
151 * the pattern to use
152 * @param locale
153 * the locale to use (default used if <tt>null</tt>)
154 * @param next
155 * the next processor in the chain
156 * @throws NullPointerException
157 * if pattern or next is null
158 */
159 public FmtLocalDate(final String pattern, final Locale locale,
160 final CellProcessor next) {
161 super(JODA_CLASS, pattern, locale, next);
162 }
163
164 /**
165 * {@inheritDoc}
166 */
167 @Override
168 protected String format(final LocalDate jodaType,
169 final DateTimeFormatter formatter) {
170 return jodaType.toString(formatter);
171 }
172
173 /**
174 * {@inheritDoc}
175 */
176 @Override
177 protected String format(final LocalDate jodaType, final String pattern,
178 final Locale locale) {
179 return jodaType.toString(pattern, locale);
180 }
181
182 /**
183 * {@inheritDoc}
184 */
185 @Override
186 protected String format(final LocalDate jodaType) {
187 return jodaType.toString();
188 }
189
190 }