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 org.apache.commons.collections4.MultiValuedMap;
19  
20  import java.lang.reflect.Field;
21  import java.util.Locale;
22  
23  /**
24   * Implements a {@link BeanFieldJoin} with a {@link java.lang.Integer} for an
25   * index.
26   * 
27   * @param <T> The type of the bean being populated
28   * 
29   * @author Andrew Rucker Jones
30   * @since 4.2
31   */
32  public class BeanFieldJoinIntegerIndex<T> extends BeanFieldJoin<T, Integer> {
33  
34      /**
35       * Creates a new instance.
36       *
37       * @param type The type of the class in which this field is found. This is
38       *             the type as instantiated by opencsv, and not necessarily the
39       *             type in which the field is declared in the case of
40       *             inheritance.
41       * @param field       The bean field this object represents
42       * @param required    Whether or not a value is always required for this field
43       * @param errorLocale The locale to use for error messages
44       * @param converter   The converter to be used for performing the data
45       *                    conversion on reading or writing
46       * @param mapType     The type of the
47       *                    {@link org.apache.commons.collections4.MultiValuedMap} that should be
48       *                    instantiated for the bean field being populated
49       * @param capture     See {@link CsvBindAndJoinByName#capture()}
50       * @param format      The format string used for packaging values to be written.
51       *                    If {@code null} or empty, it is ignored.
52       */
53      public BeanFieldJoinIntegerIndex(
54              Class<?> type, Field field, boolean required, Locale errorLocale,
55              CsvConverter converter, Class<? extends MultiValuedMap> mapType,
56              String capture, String format) {
57          super(type, field, required, errorLocale, converter, mapType, capture, format);
58      }
59  
60      @Override
61      protected Object putNewValue(MultiValuedMap<Integer, Object> map, String index, Object newValue) {
62          return map.put(Integer.valueOf(index), newValue);
63      }
64  }