View Javadoc
1   /*
2    * Copyright 2017 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  /**
19   * Represents one entry in {@link FieldMapByName}.
20   * Note: This is not used in the internal structure of {@link FieldMapByName}, but
21   * rather when representing its contents to the outside world.
22   * @param <T> The type of the bean being converted
23   *
24   * @author Andrew Rucker Jones
25   * @since 4.2
26   */
27  public class FieldMapByNameEntry<T> {
28      
29      /**
30       * The name of the header or a regular expression pattern matching possible
31       * names for the header.
32       */
33      private final String name;
34      
35      /** The {@link BeanField} associated with this header or these headers. */
36      private final BeanField<T, String> field;
37      
38      /**
39       * Whether {@link #name} is a header name or a regular expression pattern
40       * that is meant to match header names.
41       */
42      private final boolean regexPattern;
43      
44      /**
45       * Initializes the entry.
46       * 
47       * @param name The name or regular expression pattern representing the header(s)
48       * @param field The field associated with the header(s)
49       * @param regexPattern Whether or not {@code name} is a regular expression pattern
50       */
51      public FieldMapByNameEntry(String name, BeanField<T, String> field, boolean regexPattern) {
52          this.name = name;
53          this.field = field;
54          this.regexPattern = regexPattern;
55      }
56  
57      /**
58       * @return The name of the header or a regular expression pattern
59       *   matching all possible header names
60       */
61      public String getName() {
62          return name;
63      }
64  
65      /**
66       * @return The {@link BeanField} associated with this header or these headers
67       */
68      public BeanField<T, String> getField() {
69          return field;
70      }
71  
72      /**
73       * @return Whether the string returned by {@link #getName()} is a header name
74       *   or a regular expression pattern to match header names
75       */
76      public boolean isRegexPattern() {
77          return regexPattern;
78      }
79  }