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  
21  import org.supercsv.cellprocessor.ift.CellProcessor;
22  
23  /**
24   * Converts a String to a LocalDate.
25   *
26   * @author James Bassett
27   * @since 2.4.0
28   */
29  public class ParseLocalDate extends AbstractTemporalAccessorParsingProcessor<LocalDate> {
30  
31  	/**
32  	 * Constructs a new <tt>ParseLocalDate</tt> processor,
33  	 * which parses a String recognised by {@link LocalDate#parse(CharSequence)}
34  	 * as a LocalDate.
35  	 */
36  	public ParseLocalDate() {
37  	}
38  
39  	/**
40  	 * Constructs a new <tt>ParseLocalDate</tt> processor,
41  	 * which parses a String recognised by {@link LocalDate#parse(CharSequence)}
42  	 * as a LocalDate, then calls the next processor in the chain.
43  	 *
44  	 * @param next the next processor in the chain
45  	 * @throws NullPointerException if next is null
46  	 */
47  	public ParseLocalDate(final CellProcessor next) {
48  		super(next);
49  	}
50  
51  	/**
52  	 * Constructs a new <tt>ParseLocalDate</tt> processor, which parses a String
53  	 * as a LocalDate using the supplied formatter.
54  	 *
55  	 * @param formatter the formatter used for parsing
56  	 * @throws NullPointerException if formatter is null
57  	 */
58  	public ParseLocalDate(final DateTimeFormatter formatter) {
59  		super(formatter);
60  	}
61  
62  	/**
63  	 * Constructs a new <tt>ParseLocalDate</tt> processor, which parses a String
64  	 * as a LocalDate using the supplied formatter, then calls the next
65  	 * processor in the chain.
66  	 *
67  	 * @param formatter the formatter used for parsing
68  	 * @param next      the next processor in the chain
69  	 * @throws NullPointerException if formatter or next is null
70  	 */
71  	public ParseLocalDate(final DateTimeFormatter formatter, final CellProcessor next) {
72  		super(formatter, next);
73  	}
74  
75  	/**
76  	 * {@inheritDoc}
77  	 */
78  	@Override
79  	protected LocalDate parse(final String string) {
80  		return LocalDate.parse(string);
81  	}
82  
83  	/**
84  	 * {@inheritDoc}
85  	 */
86  	@Override
87  	protected LocalDate parse(final String string, final DateTimeFormatter formatter) {
88  		return LocalDate.parse(string, formatter);
89  	}
90  }