Skip to content

Commit 21f4f58

Browse files
committed
Sort methods in AB order.
1 parent abd7de4 commit 21f4f58

5 files changed

Lines changed: 258 additions & 258 deletions

File tree

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@ public void remove() {
184184
}
185185
}
186186

187+
/**
188+
* Header information based on name and position.
189+
*/
190+
private static final class Headers {
191+
/**
192+
* Header column positions (0-based)
193+
*/
194+
final Map<String, Integer> headerMap;
195+
196+
/**
197+
* Header names in column order
198+
*/
199+
final List<String> headerNames;
200+
201+
Headers(final Map<String, Integer> headerMap, final List<String> headerNames) {
202+
this.headerMap = headerMap;
203+
this.headerNames = headerNames;
204+
}
205+
}
206+
187207
/**
188208
* Creates a parser for the given {@link File}.
189209
*
@@ -281,6 +301,8 @@ public static CSVParser parse(final Reader reader, final CSVFormat format) throw
281301
return new CSVParser(reader, format);
282302
}
283303

304+
// the following objects are shared to reduce garbage
305+
284306
/**
285307
* Creates a parser for the given {@link String}.
286308
*
@@ -301,8 +323,6 @@ public static CSVParser parse(final String string, final CSVFormat format) throw
301323
return new CSVParser(new StringReader(string), format);
302324
}
303325

304-
// the following objects are shared to reduce garbage
305-
306326
/**
307327
* Creates and returns a parser for the given URL, which the caller MUST close.
308328
*
@@ -448,26 +468,6 @@ private Map<String, Integer> createEmptyHeaderMap() {
448468
new LinkedHashMap<>();
449469
}
450470

451-
/**
452-
* Header information based on name and position.
453-
*/
454-
private static final class Headers {
455-
/**
456-
* Header column positions (0-based)
457-
*/
458-
final Map<String, Integer> headerMap;
459-
460-
/**
461-
* Header names in column order
462-
*/
463-
final List<String> headerNames;
464-
465-
Headers(final Map<String, Integer> headerMap, final List<String> headerNames) {
466-
this.headerMap = headerMap;
467-
this.headerNames = headerNames;
468-
}
469-
}
470-
471471
/**
472472
* Creates the name to index mapping if the format defines a header.
473473
*

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,6 @@ public boolean isMapped(final String name) {
228228
return headerMap != null && headerMap.containsKey(name);
229229
}
230230

231-
/**
232-
* Checks whether a given columns is mapped and has a value.
233-
*
234-
* @param name
235-
* the name of the column to be retrieved.
236-
* @return whether a given columns is mapped and has a value
237-
*/
238-
public boolean isSet(final String name) {
239-
return isMapped(name) && getHeaderMapRaw().get(name).intValue() < values.length;
240-
}
241-
242231
/**
243232
* Checks whether a column with given index has a value.
244233
*
@@ -250,6 +239,17 @@ public boolean isSet(final int index) {
250239
return 0 <= index && index < values.length;
251240
}
252241

242+
/**
243+
* Checks whether a given columns is mapped and has a value.
244+
*
245+
* @param name
246+
* the name of the column to be retrieved.
247+
* @return whether a given columns is mapped and has a value
248+
*/
249+
public boolean isSet(final String name) {
250+
return isMapped(name) && getHeaderMapRaw().get(name).intValue() < values.length;
251+
}
252+
253253
/**
254254
* Returns an iterator over the values of this record.
255255
*

src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,31 @@ final class ExtendedBufferedReader extends BufferedReader {
5353
super(reader);
5454
}
5555

56+
/**
57+
* Closes the stream.
58+
*
59+
* @throws IOException
60+
* If an I/O error occurs
61+
*/
5662
@Override
57-
public int read() throws IOException {
58-
final int current = super.read();
59-
if (current == CR || current == LF && lastChar != CR) {
60-
eolCounter++;
63+
public void close() throws IOException {
64+
// Set ivars before calling super close() in case close() throws an IOException.
65+
closed = true;
66+
lastChar = END_OF_STREAM;
67+
super.close();
68+
}
69+
70+
/**
71+
* Returns the current line number
72+
*
73+
* @return the current line number
74+
*/
75+
long getCurrentLineNumber() {
76+
// Check if we are at EOL or EOF or just starting
77+
if (lastChar == CR || lastChar == LF || lastChar == UNDEFINED || lastChar == END_OF_STREAM) {
78+
return eolCounter; // counter is accurate
6179
}
62-
lastChar = current;
63-
this.position++;
64-
return lastChar;
80+
return eolCounter + 1; // Allow for counter being incremented only at EOL
6581
}
6682

6783
/**
@@ -76,6 +92,47 @@ int getLastChar() {
7692
return lastChar;
7793
}
7894

95+
/**
96+
* Gets the character position in the reader.
97+
*
98+
* @return the current position in the reader (counting characters, not bytes since this is a Reader)
99+
*/
100+
long getPosition() {
101+
return this.position;
102+
}
103+
104+
public boolean isClosed() {
105+
return closed;
106+
}
107+
108+
/**
109+
* Returns the next character in the current reader without consuming it. So the next call to {@link #read()} will
110+
* still return this value. Does not affect line number or last character.
111+
*
112+
* @return the next character
113+
*
114+
* @throws IOException
115+
* if there is an error in reading
116+
*/
117+
int lookAhead() throws IOException {
118+
super.mark(1);
119+
final int c = super.read();
120+
super.reset();
121+
122+
return c;
123+
}
124+
125+
@Override
126+
public int read() throws IOException {
127+
final int current = super.read();
128+
if (current == CR || current == LF && lastChar != CR) {
129+
eolCounter++;
130+
}
131+
lastChar = current;
132+
this.position++;
133+
return lastChar;
134+
}
135+
79136
@Override
80137
public int read(final char[] buf, final int offset, final int length) throws IOException {
81138
if (length == 0) {
@@ -131,61 +188,4 @@ public String readLine() throws IOException {
131188
return line;
132189
}
133190

134-
/**
135-
* Returns the next character in the current reader without consuming it. So the next call to {@link #read()} will
136-
* still return this value. Does not affect line number or last character.
137-
*
138-
* @return the next character
139-
*
140-
* @throws IOException
141-
* if there is an error in reading
142-
*/
143-
int lookAhead() throws IOException {
144-
super.mark(1);
145-
final int c = super.read();
146-
super.reset();
147-
148-
return c;
149-
}
150-
151-
/**
152-
* Returns the current line number
153-
*
154-
* @return the current line number
155-
*/
156-
long getCurrentLineNumber() {
157-
// Check if we are at EOL or EOF or just starting
158-
if (lastChar == CR || lastChar == LF || lastChar == UNDEFINED || lastChar == END_OF_STREAM) {
159-
return eolCounter; // counter is accurate
160-
}
161-
return eolCounter + 1; // Allow for counter being incremented only at EOL
162-
}
163-
164-
/**
165-
* Gets the character position in the reader.
166-
*
167-
* @return the current position in the reader (counting characters, not bytes since this is a Reader)
168-
*/
169-
long getPosition() {
170-
return this.position;
171-
}
172-
173-
public boolean isClosed() {
174-
return closed;
175-
}
176-
177-
/**
178-
* Closes the stream.
179-
*
180-
* @throws IOException
181-
* If an I/O error occurs
182-
*/
183-
@Override
184-
public void close() throws IOException {
185-
// Set ivars before calling super close() in case close() throws an IOException.
186-
closed = true;
187-
lastChar = END_OF_STREAM;
188-
super.close();
189-
}
190-
191191
}

0 commit comments

Comments
 (0)