@@ -48,8 +48,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
4848 /** The values of the record */
4949 private final String [] values ;
5050
51- CSVRecord (final String [] values , final Map <String , Integer > mapping ,
52- final String comment , final long recordNumber ) {
51+ CSVRecord (final String [] values , final Map <String , Integer > mapping , final String comment , final long recordNumber ) {
5352 this .recordNumber = recordNumber ;
5453 this .values = values != null ? values : EMPTY_STRING_ARRAY ;
5554 this .mapping = mapping ;
@@ -94,27 +93,26 @@ public String get(final int i) {
9493 public String get (final String name ) {
9594 if (mapping == null ) {
9695 throw new IllegalStateException (
97- "No header mapping was specified, the record values can't be accessed by name" );
96+ "No header mapping was specified, the record values can't be accessed by name" );
9897 }
9998 final Integer index = mapping .get (name );
10099 if (index == null ) {
101100 throw new IllegalArgumentException (String .format ("Mapping for %s not found, expected one of %s" , name ,
102- mapping .keySet ()));
101+ mapping .keySet ()));
103102 }
104103 try {
105104 return values [index .intValue ()];
106105 } catch (final ArrayIndexOutOfBoundsException e ) {
107106 throw new IllegalArgumentException (String .format (
108- "Index for header '%s' is %d but CSVRecord only has %d values!" , name , index ,
109- Integer .valueOf (values .length )));
107+ "Index for header '%s' is %d but CSVRecord only has %d values!" , name , index ,
108+ Integer .valueOf (values .length )));
110109 }
111110 }
112111
113112 /**
114113 * Returns the comment for this record, if any.
115114 *
116- * @return the comment for this record, or null if no comment for this
117- * record is available.
115+ * @return the comment for this record, or null if no comment for this record is available.
118116 */
119117 public String getComment () {
120118 return comment ;
@@ -176,14 +174,16 @@ public boolean isSet(final String name) {
176174 *
177175 * @return an iterator over the values of this record.
178176 */
177+ @ Override
179178 public Iterator <String > iterator () {
180179 return toList ().iterator ();
181180 }
182181
183182 /**
184183 * Puts all values of this record into the given Map.
185184 *
186- * @param map The Map to populate.
185+ * @param map
186+ * The Map to populate.
187187 * @return the given map.
188188 */
189189 <M extends Map <String , String >> M putIn (final M map ) {
@@ -212,6 +212,7 @@ public int size() {
212212 * Converts the values to a List.
213213 *
214214 * TODO: Maybe make this public?
215+ *
215216 * @return a new List
216217 */
217218 private List <String > toList () {
@@ -227,7 +228,6 @@ public Map<String, String> toMap() {
227228 return putIn (new HashMap <String , String >(values .length ));
228229 }
229230
230-
231231 /**
232232 * Returns a string representation of the contents of this record. The result is constructed by comment, mapping,
233233 * recordNumber and by passing the internal values array to {@link Arrays#toString(Object[])}.
@@ -236,14 +236,16 @@ public Map<String, String> toMap() {
236236 */
237237 @ Override
238238 public String toString () {
239- return "CSVRecord [comment=" + comment + ", mapping=" + mapping +
240- ", recordNumber=" + recordNumber + ", values=" +
241- Arrays .toString (values ) + "]" ;
239+ StringBuilder sb = new StringBuilder ();
240+ sb .append ("CSVRecord [comment=" ).append (comment );
241+ sb .append (", mapping=" ).append (mapping );
242+ sb .append (", recordNumber=" ).append (recordNumber );
243+ sb .append (", values=" ).append (Arrays .toString (values )).append (']' );
244+ return sb .toString ();
242245 }
243246
244247 String [] values () {
245248 return values ;
246249 }
247250
248-
249251}
0 commit comments