View Javadoc
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.time;
17  
18  import java.time.LocalDate;
19  import java.time.format.DateTimeFormatter;
20  import java.time.format.DateTimeFormatterBuilder;
21  
22  import org.supercsv.cellprocessor.ift.CellProcessor;
23  
24  /**
25   * Converts a LocalDate to a String.
26   * For constructors using DateTimeFormatter, refer to the following
27   * classes:
28   * <ul>
29   * <li>{@link DateTimeFormatter} - formats by pattern and style</li>
30   * <li>{@link DateTimeFormatter} - ISO 8601 formats</li>
31   * <li>{@link DateTimeFormatterBuilder} - complex formats created via method
32   * calls</li>
33   * </ul>
34   *
35   * @author Ludovico Fischer
36   * @since 2.4.0
37   */
38  public class FmtLocalDate extends AbstractTemporalAccessorFormattingProcessor<LocalDate> {
39  	/**
40  	 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a
41  	 * LocalDate as a String, with the same output as {@link LocalDate#toString()}
42  	 */
43  	public FmtLocalDate() {
44  		super();
45  	}
46  
47  	/**
48  	 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a
49  	 * LocalDate as a String, then calls the next processor in the chain.
50  	 *
51  	 * @param next next processor in the chain
52  	 * @throws NullPointerException if next is null
53  	 * @see FmtLocalDate()
54  	 */
55  	public FmtLocalDate(final CellProcessor next) {
56  		super(next);
57  	}
58  
59  	/**
60  	 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a
61  	 * LocalDate as a String using the supplied formatter.
62  	 *
63  	 * @param formatter the formatter to use
64  	 * @throws NullPointerException if formatter is null
65  	 */
66  	public FmtLocalDate(final DateTimeFormatter formatter) {
67  		super(formatter);
68  	}
69  
70  	/**
71  	 * Constructs a new <tt>FmtLocalDate</tt> processor, which formats a
72  	 * LocalDate as a String using the supplied formatter, then calls the next
73  	 * processor in the chain.
74  	 *
75  	 * @param formatter the formatter to use
76  	 * @param next      the next processor in the chain
77  	 * @throws NullPointerException if formatter or next is null
78  	 */
79  	public FmtLocalDate(final DateTimeFormatter formatter, final CellProcessor next) {
80  		super(formatter, next);
81  	}
82  
83  	@Override
84  	protected Class<LocalDate> getType() {
85  		return LocalDate.class;
86  	}
87  }