BeanFieldJoinStringIndex.java

  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. import org.apache.commons.collections4.MultiValuedMap;

  18. import java.lang.reflect.Field;
  19. import java.util.Locale;

  20. /**
  21.  * Implements a {@link BeanFieldJoin} with a {@link java.lang.String} for an
  22.  * index.
  23.  *
  24.  * @param <T> The type of the bean being populated
  25.  *
  26.  * @author Andrew Rucker Jones
  27.  * @since 4.2
  28.  */
  29. public class BeanFieldJoinStringIndex<T> extends BeanFieldJoin<T, String> {

  30.     /**
  31.      * Creates a new instance.
  32.      *
  33.      * @param type The type of the class in which this field is found. This is
  34.      *             the type as instantiated by opencsv, and not necessarily the
  35.      *             type in which the field is declared in the case of
  36.      *             inheritance.
  37.      * @param field       The bean field this object represents
  38.      * @param required    Whether or not a value is always required for this field
  39.      * @param errorLocale The locale to use for error messages
  40.      * @param converter   The converter to be used for performing the data
  41.      *                    conversion on reading or writing
  42.      * @param mapType     The type of the
  43.      *                    {@link org.apache.commons.collections4.MultiValuedMap} that should be
  44.      *                    instantiated for the bean field being populated
  45.      * @param capture     See {@link CsvBindAndJoinByName#capture()}
  46.      * @param format      The format string used for packaging values to be written.
  47.      *                    If {@code null} or empty, it is ignored.
  48.      */
  49.     public BeanFieldJoinStringIndex(
  50.             Class<?> type, Field field, boolean required, Locale errorLocale,
  51.             CsvConverter converter, Class<? extends MultiValuedMap> mapType,
  52.             String capture, String format) {
  53.         super(type, field, required, errorLocale, converter, mapType, capture, format);
  54.     }

  55.     @Override
  56.     protected Object putNewValue(MultiValuedMap<String, Object> map, String index, Object newValue) {
  57.         return map.put(index, newValue);
  58.     }
  59. }