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; 17 18 import org.supercsv.cellprocessor.ift.CellProcessor; 19 20 /** 21 * This processor is used to indicate that a cell is optional, and will avoid executing further processors if it 22 * encounters <tt>null</tt>. It is a simple customization of <tt>ConvertNullTo</tt>. 23 * <p> 24 * Prior to version 2.0.0, this processor returned <tt>null</tt> for empty String (""), but was updated because 25 * Tokenizer now reads empty columns as <tt>null</tt>. It also means that Optional can now be used when writing as well 26 * (instead of using {@code ConvertNullTo("")}). 27 * 28 * @author Kasper B. Graversen 29 * @author James Bassett 30 */ 31 public class Optional extends ConvertNullTo { 32 33 /** 34 * Constructs a new <tt>Optional</tt> processor, which when encountering <tt>null</tt> will return <tt>null</tt>, 35 * for all other values it will return the value unchanged. 36 */ 37 public Optional() { 38 super(null); 39 } 40 41 /** 42 * Constructs a new <tt>Optional</tt> processor, which when encountering <tt>null</tt> will return <tt>null</tt> , 43 * for all other values it will call the next processor in the chain. 44 * 45 * @param next 46 * the next CellProcessor in the chain 47 * @throws NullPointerException 48 * if next is null 49 */ 50 public Optional(final CellProcessor next) { 51 super(null, next); 52 } 53 54 }