From fcc0d15c7b541191f14b0861d945cbbeba770d10 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Thu, 1 Aug 2013 02:04:27 +0000 Subject: [PATCH] - Remove trailing spaces. - Add missing final keywords. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1509069 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/csv/CSVFormat.java | 28 ++++----- .../java/org/apache/commons/csv/CSVLexer.java | 4 +- .../org/apache/commons/csv/CSVParser.java | 60 +++++++++---------- .../org/apache/commons/csv/Constants.java | 2 +- .../commons/csv/ExtendedBufferedReader.java | 4 +- .../java/org/apache/commons/csv/Lexer.java | 4 +- .../java/org/apache/commons/csv/Token.java | 2 +- .../apache/commons/csv/CSVFileParserTest.java | 4 +- .../org/apache/commons/csv/CSVFormatTest.java | 24 ++++---- .../org/apache/commons/csv/CSVLexerTest.java | 6 +- .../org/apache/commons/csv/CSVParserTest.java | 2 +- .../apache/commons/csv/CSVPrinterTest.java | 4 +- .../org/apache/commons/csv/CSVRecordTest.java | 4 +- .../org/apache/commons/csv/TokenMatchers.java | 3 +- 14 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index b4c9ee1e..baa36dc0 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -53,7 +53,7 @@ import java.util.Set; public class CSVFormat implements Serializable { private static final long serialVersionUID = 1L; - + /** * Returns true if the given character is a line break character. * @@ -66,7 +66,7 @@ public class CSVFormat implements Serializable { static boolean isLineBreak(final Character c) { return c != null && isLineBreak(c.charValue()); } - + private final char delimiter; private final Character quoteChar; private final Quote quotePolicy; @@ -324,8 +324,8 @@ public class CSVFormat implements Serializable { } /** - * Returns a copy of the header array. - * + * Returns a copy of the header array. + * * @return a copy of the header array */ public String[] getHeader() { @@ -362,7 +362,7 @@ public class CSVFormat implements Serializable { *
  • * Writing: Writes {@code null} as the given {@code nullString} when writing records.
  • * - * + * * @return the String to convert to and from {@code null}. No substitution occurs if {@code null} */ public String getNullString() { @@ -454,11 +454,11 @@ public class CSVFormat implements Serializable { /** * Parses the specified content. - * + * *

    * See also the various static parse methods on {@link CSVParser}. *

    - * + * * @param in * the input stream * @return a parser over a stream of {@link #CSVRecord}s. @@ -528,9 +528,9 @@ public class CSVFormat implements Serializable { if (escape == null && quotePolicy == Quote.NONE) { throw new IllegalStateException("No quotes mode set but no escape character is set"); } - + if (header != null) { - Set set = new HashSet(header.length); + final Set set = new HashSet(header.length); set.addAll(Arrays.asList(header)); if (set.size() != header.length) { throw new IllegalStateException("The header contains duplicate names: " + Arrays.toString(header)); @@ -621,18 +621,18 @@ public class CSVFormat implements Serializable { /** * Sets the header of the format. The header can either be parsed automatically from the input file with: - * + * *
          * CSVFormat format = aformat.withHeader();
    - * + * * or specified manually with: - * + * *
          * CSVFormat format = aformat.withHeader("name", "email", "phone");
    - * + * * @param header * the header, null if disabled, empty if parsed automatically, user specified otherwise. - * + * * @return A new CSVFormat that is equal to this but with the specified header * @see #withSkipHeaderRecord(boolean) */ diff --git a/src/main/java/org/apache/commons/csv/CSVLexer.java b/src/main/java/org/apache/commons/csv/CSVLexer.java index 81fa7dc5..c45322b1 100644 --- a/src/main/java/org/apache/commons/csv/CSVLexer.java +++ b/src/main/java/org/apache/commons/csv/CSVLexer.java @@ -86,11 +86,11 @@ final class CSVLexer extends Lexer { } if (isStartOfLine(lastChar) && isCommentStart(c)) { - String line = in.readLine(); + final String line = in.readLine(); if (line == null) { token.type = EOF; // don't set token.isReady here because no content - return token; + return token; } final String comment = line.trim(); token.content.append(comment); diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index cf181513..5de74148 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -37,15 +37,15 @@ import java.util.NoSuchElementException; /** * Parses CSV files according to the specified configuration. - * + * * Because CSV appears in many different dialects, the parser supports many configuration settings by allowing the * specification of a {@link CSVFormat}. - * + * *

    * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, and comments * starting with '#', you write: *

    - * + * *
      * Reader in = new StringReader("a\tb\nc\td");
      * Iterable<CSVRecord> parser = CSVFormat.DEFAULT
    @@ -56,11 +56,11 @@ import java.util.NoSuchElementException;
      *     ...
      *  }
      * 
    - * + * *

    * To parse CSV input in a given format like Excel, you write: *

    - * + * *
      * Reader in = new StringReader("a;b\nc;d");
      * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in);
    @@ -71,7 +71,7 @@ import java.util.NoSuchElementException;
      * 

    * You may also get a List of records: *

    - * + * *
      * Reader in = new StringReader("a;b\nc;d");
      * CSVParser parser = new CSVParser(in, CSVFormat.EXCEL);
    @@ -83,18 +83,18 @@ import java.util.NoSuchElementException;
      * 

    * Internal parser state is completely covered by the format and the reader-state. *

    - * + * *

    * see package documentation for more details *

    - * + * * @version $Id$ */ public class CSVParser implements Iterable, Closeable { /** * Creates a parser for the given {@link File}. - * + * * @param file * a CSV file * @param format @@ -109,11 +109,11 @@ public class CSVParser implements Iterable, Closeable { /** * Creates a parser for the given resource. - * + * *

    * If you do not read all records from the given source, you should call {@link #close()} on the parser. *

    - * + * * @param resource * a resource path * @param charset @@ -128,7 +128,7 @@ public class CSVParser implements Iterable, Closeable { */ public static CSVParser parseResource(String resource, Charset charset, ClassLoader classLoader, final CSVFormat format) throws IOException { - URL url = classLoader.getResource(resource); + final URL url = classLoader.getResource(resource); if (url == null) { throw new IllegalArgumentException("Resource cannot be found: " + resource); } @@ -137,11 +137,11 @@ public class CSVParser implements Iterable, Closeable { /** * Creates a parser for the given resource. - * + * *

    * If you do not read all records from the given source, you should call {@link #close()} on the parser. *

    - * + * * @param resource * a resource path * @param charset @@ -153,7 +153,7 @@ public class CSVParser implements Iterable, Closeable { * If an I/O error occurs */ public static CSVParser parseResource(String resource, Charset charset, final CSVFormat format) throws IOException { - URL url = ClassLoader.getSystemResource(resource); + final URL url = ClassLoader.getSystemResource(resource); if (url == null) { throw new IllegalArgumentException("System resource cannot be found: " + resource); } @@ -162,7 +162,7 @@ public class CSVParser implements Iterable, Closeable { /** * Creates a parser for the given {@link String} using the default format {@link CSVFormat#DEFAULT}. - * + * * @param string * a CSV string * @return a new parser @@ -175,7 +175,7 @@ public class CSVParser implements Iterable, Closeable { /** * Creates a parser for the given {@link String}. - * + * * @param string * a CSV string * @param format @@ -190,12 +190,12 @@ public class CSVParser implements Iterable, Closeable { /** * Creates a parser for the given URL. - * + * *

    * If you do not read all records from the given {@code url}, you should call {@link #close()} on the parser, unless * you close the {@code url}. *

    - * + * * @param url * a URL * @param charset @@ -230,12 +230,12 @@ public class CSVParser implements Iterable, Closeable { /** * CSV parser using the default format {@link CSVFormat#DEFAULT}. - * + * *

    * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser, * unless you close the {@code reader}. *

    - * + * * @param input * a Reader containing "csv-formatted" input * @throws IllegalArgumentException @@ -249,12 +249,12 @@ public class CSVParser implements Iterable, Closeable { /** * Customized CSV parser using the given {@link CSVFormat} - * + * *

    * If you do not read all records from the given {@code reader}, you should call {@link #close()} on the parser, * unless you close the {@code reader}. *

    - * + * * @param reader * a Reader containing CSV-formatted input * @param format @@ -283,7 +283,7 @@ public class CSVParser implements Iterable, Closeable { /** * Closes resources. - * + * * @throws IOException * If an I/O error occurs */ @@ -297,7 +297,7 @@ public class CSVParser implements Iterable, Closeable { * Returns the current line number in the input stream. *

    * ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to the record number. - * + * * @return current line number */ public long getCurrentLineNumber() { @@ -308,7 +308,7 @@ public class CSVParser implements Iterable, Closeable { * Returns a copy of the header map that iterates in column order. *

    * The map keys are column names. The map values are 0-based indices. - * + * * @return a copy of the header map that iterates in column order. */ public Map getHeaderMap() { @@ -319,7 +319,7 @@ public class CSVParser implements Iterable, Closeable { * Returns the current record number in the input stream. *

    * ATTENTION: If your CSV input has multi-line values, the returned number does not correspond to the line number. - * + * * @return current line number */ public long getRecordNumber() { @@ -331,7 +331,7 @@ public class CSVParser implements Iterable, Closeable { * entries. *

    * The returned content starts at the current parse-position in the stream. - * + * * @return list of {@link CSVRecord} entries, may be empty * @throws IOException * on parse error or input read-failure @@ -350,7 +350,7 @@ public class CSVParser implements Iterable, Closeable { */ private Map initializeHeader() throws IOException { Map hdrMap = null; - String[] formatHeader = this.format.getHeader(); + final String[] formatHeader = this.format.getHeader(); if (formatHeader != null) { hdrMap = new LinkedHashMap(); @@ -436,7 +436,7 @@ public class CSVParser implements Iterable, Closeable { /** * Parses the next record from the current point in the stream. - * + * * @return the record as an array of values, or null if the end of the stream has been reached * @throws IOException * on parse error or input read-failure diff --git a/src/main/java/org/apache/commons/csv/Constants.java b/src/main/java/org/apache/commons/csv/Constants.java index 254d1985..d92bd8c2 100644 --- a/src/main/java/org/apache/commons/csv/Constants.java +++ b/src/main/java/org/apache/commons/csv/Constants.java @@ -49,7 +49,7 @@ final class Constants { /** According to RFC 4180, line breaks are delimited by CRLF */ static final String CRLF = "\r\n"; - + /** * Unicode line separator. */ diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java index d6614dd3..9b220529 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -41,7 +41,7 @@ final class ExtendedBufferedReader extends BufferedReader { /** The count of EOLs (CR/LF/CRLF) seen so far */ private long eolCounter = 0; - + private boolean closed; /** @@ -163,7 +163,7 @@ final class ExtendedBufferedReader extends BufferedReader { /** * Closes the stream. - * + * * @throws IOException * If an I/O error occurs */ diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java index aaf633fb..8fb3ab6f 100644 --- a/src/main/java/org/apache/commons/csv/Lexer.java +++ b/src/main/java/org/apache/commons/csv/Lexer.java @@ -151,7 +151,7 @@ abstract class Lexer implements Closeable { boolean isClosed() { return in.isClosed(); } - + /** * @return true if the given char is a whitespace character */ @@ -201,7 +201,7 @@ abstract class Lexer implements Closeable { /** * Closes resources. - * + * * @throws IOException * If an I/O error occurs */ diff --git a/src/main/java/org/apache/commons/csv/Token.java b/src/main/java/org/apache/commons/csv/Token.java index c1efc2c1..26f3508d 100644 --- a/src/main/java/org/apache/commons/csv/Token.java +++ b/src/main/java/org/apache/commons/csv/Token.java @@ -65,7 +65,7 @@ final class Token { /** * Eases IDE debugging. - * + * * @return a string helpful for debugging. */ @Override diff --git a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java index 5ecdd87b..1d90d937 100644 --- a/src/test/java/org/apache/commons/csv/CSVFileParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFileParserTest.java @@ -111,7 +111,7 @@ public class CSVFileParserTest { // Now parse the file and compare against the expected results // We use a buffered reader internally so no need to create one here. - CSVParser parser = CSVParser.parseFile(new File(BASE, split[0]), format); + final CSVParser parser = CSVParser.parseFile(new File(BASE, split[0]), format); for(final CSVRecord record : parser) { String parsed = record.toString(); if (checkComments) { @@ -153,7 +153,7 @@ public class CSVFileParserTest { assertEquals(testName + " Expected format ", line, format.toString()); // Now parse the file and compare against the expected results - CSVParser parser = CSVParser.parseResource("CSVFileParser/" + split[0], Charset.forName("UTF-8"), + final CSVParser parser = CSVParser.parseResource("CSVFileParser/" + split[0], Charset.forName("UTF-8"), this.getClass().getClassLoader(), format); for (final CSVRecord record : parser) { String parsed = record.toString(); diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index 277aa7f3..0e081f15 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -214,10 +214,10 @@ public class CSVFormatTest { @Test public void testGetHeader() throws Exception { - String[] header = new String[]{"one", "two", "three"}; - CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header); + final String[] header = new String[]{"one", "two", "three"}; + final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header); // getHeader() makes a copy of the header array. - String[] headerCopy = formatWithHeader.getHeader(); + final String[] headerCopy = formatWithHeader.getHeader(); headerCopy[0] = "A"; headerCopy[1] = "B"; headerCopy[2] = "C"; @@ -282,7 +282,7 @@ public class CSVFormatTest { @Test public void testWithCommentStart() throws Exception { - CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentStart('#'); + final CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentStart('#'); assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentStart()); } @@ -293,7 +293,7 @@ public class CSVFormatTest { @Test public void testWithDelimiter() throws Exception { - CSVFormat formatWithDelimiter = CSVFormat.DEFAULT.withDelimiter('!'); + final CSVFormat formatWithDelimiter = CSVFormat.DEFAULT.withDelimiter('!'); assertEquals('!', formatWithDelimiter.getDelimiter()); } @@ -304,7 +304,7 @@ public class CSVFormatTest { @Test public void testWithEscape() throws Exception { - CSVFormat formatWithEscape = CSVFormat.DEFAULT.withEscape('&'); + final CSVFormat formatWithEscape = CSVFormat.DEFAULT.withEscape('&'); assertEquals(Character.valueOf('&'), formatWithEscape.getEscape()); } @@ -315,9 +315,9 @@ public class CSVFormatTest { @Test public void testWithHeader() throws Exception { - String[] header = new String[]{"one", "two", "three"}; + final String[] header = new String[]{"one", "two", "three"}; // withHeader() makes a copy of the header array. - CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header); + final CSVFormat formatWithHeader = CSVFormat.DEFAULT.withHeader(header); assertArrayEquals(header, formatWithHeader.getHeader()); assertNotSame(header, formatWithHeader.getHeader()); header[0] = "A"; @@ -340,13 +340,13 @@ public class CSVFormatTest { @Test public void testWithNullString() throws Exception { - CSVFormat formatWithNullString = CSVFormat.DEFAULT.withNullString("null"); + final CSVFormat formatWithNullString = CSVFormat.DEFAULT.withNullString("null"); assertEquals("null", formatWithNullString.getNullString()); } @Test public void testWithQuoteChar() throws Exception { - CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuoteChar('"'); + final CSVFormat formatWithQuoteChar = CSVFormat.DEFAULT.withQuoteChar('"'); assertEquals(Character.valueOf('"'), formatWithQuoteChar.getQuoteChar()); } @@ -357,13 +357,13 @@ public class CSVFormatTest { @Test public void testWithQuotePolicy() throws Exception { - CSVFormat formatWithQuotePolicy = CSVFormat.DEFAULT.withQuotePolicy(Quote.ALL); + final CSVFormat formatWithQuotePolicy = CSVFormat.DEFAULT.withQuotePolicy(Quote.ALL); assertEquals(Quote.ALL, formatWithQuotePolicy.getQuotePolicy()); } @Test public void testWithRecordSeparator() throws Exception { - CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator('!'); + final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withRecordSeparator('!'); assertEquals("!", formatWithRecordSeparator.getRecordSeparator()); } diff --git a/src/test/java/org/apache/commons/csv/CSVLexerTest.java b/src/test/java/org/apache/commons/csv/CSVLexerTest.java index b13bdfa6..f93bdb73 100644 --- a/src/test/java/org/apache/commons/csv/CSVLexerTest.java +++ b/src/test/java/org/apache/commons/csv/CSVLexerTest.java @@ -26,11 +26,11 @@ import static org.apache.commons.csv.Token.Type.COMMENT; import static org.apache.commons.csv.Token.Type.EOF; import static org.apache.commons.csv.Token.Type.EORECORD; import static org.apache.commons.csv.Token.Type.TOKEN; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertThat; import static org.apache.commons.csv.TokenMatchers.hasContent; import static org.apache.commons.csv.TokenMatchers.matches; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringReader; diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index a4f08c2e..b2caf9f6 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -472,7 +472,7 @@ public class CSVParserTest { iterator.remove(); fail("expected UnsupportedOperationException"); } catch (final UnsupportedOperationException expected) { - // expected + // expected } assertArrayEquals(new String[]{"a", "b", "c"}, iterator.next().values()); assertArrayEquals(new String[]{"1", "2", "3"}, iterator.next().values()); diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java index 09bb2d80..5616372c 100644 --- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java +++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java @@ -327,7 +327,7 @@ public class CSVPrinterTest { final CSVPrinter printer = new CSVPrinter(sw, format); printer.printRecord("a", null, "b"); printer.close(); - String csvString = sw.toString(); + final String csvString = sw.toString(); assertEquals("a,NULL,b" + recordSeparator, csvString); final Iterable iterable = format.parse(new StringReader(csvString)); final Iterator iterator = iterable.iterator(); @@ -486,7 +486,7 @@ public class CSVPrinterTest { @Test(expected = IllegalArgumentException.class) public void testInvalidFormat() throws Exception { - CSVFormat invalidFormat = CSVFormat.DEFAULT.withDelimiter(CR); + final CSVFormat invalidFormat = CSVFormat.DEFAULT.withDelimiter(CR); new CSVPrinter(null, invalidFormat); } } diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java index 6becc874..0bf7dddd 100644 --- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java +++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java @@ -22,7 +22,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import org.junit.Before; @@ -101,8 +100,7 @@ public class CSVRecordTest { @Test public void testIterator() { int i = 0; - for (final Iterator itr = record.iterator(); itr.hasNext();) { - final String value = itr.next(); + for (String value : record) { assertEquals(values[i], value); i++; } diff --git a/src/test/java/org/apache/commons/csv/TokenMatchers.java b/src/test/java/org/apache/commons/csv/TokenMatchers.java index e6a8e479..ba39c4c8 100644 --- a/src/test/java/org/apache/commons/csv/TokenMatchers.java +++ b/src/test/java/org/apache/commons/csv/TokenMatchers.java @@ -16,10 +16,11 @@ */ package org.apache.commons.csv; +import static org.hamcrest.core.AllOf.allOf; + import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; -import static org.hamcrest.core.AllOf.allOf; /** * Collection of matchers for asserting the type and content of tokens.