View Javadoc
1   /*
2    * Copyright 2018 Andrew Rucker Jones.
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 com.opencsv.bean;
17  
18  import java.util.Locale;
19  import org.apache.commons.lang3.ObjectUtils;
20  
21  /**
22   * Collects common aspects of a {@link ComplexFieldMapEntry}.
23   * 
24   * @param <I> The initializer type used to build the many-to-one mapping
25   * @param <K> The type of the key used for indexing
26   * @param <T> The type of the bean being converted
27   *
28   * @author Andrew Rucker Jones
29   * @since 4.2
30   */
31  abstract public class AbstractFieldMapEntry<I, K extends Comparable<K>, T> implements ComplexFieldMapEntry<I, K, T> {
32      
33      /** The {@link BeanField} that is the target of this mapping. */
34      protected final BeanField<T, K> field;
35      
36      /** The locale to be used for error messages. */
37      protected Locale errorLocale;
38      
39      /**
40       * The only constructor, and it must be called by all derived classes.
41       * 
42       * @param field The BeanField being mapped to
43       * @param errorLocale The locale to be used for error messages
44       */
45      protected AbstractFieldMapEntry(final BeanField<T, K> field, final Locale errorLocale) {
46          this.field = field;
47          this.errorLocale = ObjectUtils.defaultIfNull(errorLocale, Locale.getDefault());
48      }
49      
50      @Override
51      public BeanField<T, K> getBeanField() {
52          return field;
53      }
54      
55      @Override
56      public void setErrorLocale(final Locale errorLocale) {
57          this.errorLocale = ObjectUtils.defaultIfNull(errorLocale, Locale.getDefault());
58      }
59  }