Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 18dd546

Browse files
committed
Add a unit test, minor renaming of internal constants
1 parent ff1626c commit 18dd546

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

src/main/java/com/fasterxml/jackson/dataformat/csv/CsvSchema.java

+26-26
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public class CsvSchema
7878
/**********************************************************************
7979
*/
8080

81-
protected final static int FEATURE_USE_HEADER = 0x0001;
82-
protected final static int FEATURE_SKIP_FIRST_DATA_ROW = 0x0002;
83-
protected final static int FEATURE_ALLOW_COMMENTS = 0x0004;
81+
protected final static int ENCODING_FEATURE_USE_HEADER = 0x0001;
82+
protected final static int ENCODING_FEATURE_SKIP_FIRST_DATA_ROW = 0x0002;
83+
protected final static int ENCODING_FEATURE_ALLOW_COMMENTS = 0x0004;
8484

85-
protected final static int DEFAULT_FEATURES = 0;
85+
protected final static int DEFAULT_ENCODING_FEATURES = 0;
8686

8787
/*
8888
/**********************************************************************
@@ -330,7 +330,7 @@ public static class Builder
330330
*
331331
* @since 2.5
332332
*/
333-
protected int _features = DEFAULT_FEATURES;
333+
protected int _encodingFeatures = DEFAULT_ENCODING_FEATURES;
334334

335335
protected char _columnSeparator = DEFAULT_COLUMN_SEPARATOR;
336336

@@ -349,7 +349,7 @@ public static class Builder
349349
* @since 2.5
350350
*/
351351
protected char[] _nullValue = DEFAULT_NULL_VALUE;
352-
352+
353353
public Builder() { }
354354

355355
/**
@@ -361,7 +361,7 @@ public Builder(CsvSchema src)
361361
for (Column col : src._columns) {
362362
_columns.add(col);
363363
}
364-
_features = src._features;
364+
_encodingFeatures = src._features;
365365
_columnSeparator = src._columnSeparator;
366366
_arrayElementSeparator = src._arrayElementSeparator;
367367
_quoteChar = src._quoteChar;
@@ -441,7 +441,7 @@ public Iterator<Column> getColumns() {
441441
* used for reading and writing or not.
442442
*/
443443
public Builder setUseHeader(boolean b) {
444-
_feature(FEATURE_USE_HEADER, b);
444+
_feature(ENCODING_FEATURE_USE_HEADER, b);
445445
return this;
446446
}
447447

@@ -451,7 +451,7 @@ public Builder setUseHeader(boolean b) {
451451
* should be skipped in its entirety.
452452
*/
453453
public Builder setSkipFirstDataRow(boolean b) {
454-
_feature(FEATURE_SKIP_FIRST_DATA_ROW, b);
454+
_feature(ENCODING_FEATURE_SKIP_FIRST_DATA_ROW, b);
455455
return this;
456456
}
457457

@@ -463,12 +463,12 @@ public Builder setSkipFirstDataRow(boolean b) {
463463
* @since 2.5
464464
*/
465465
public Builder setAllowComments(boolean b) {
466-
_feature(FEATURE_ALLOW_COMMENTS, b);
466+
_feature(ENCODING_FEATURE_ALLOW_COMMENTS, b);
467467
return this;
468468
}
469469

470470
protected final void _feature(int feature, boolean state) {
471-
_features = state ? (_features | feature) : (_features & ~feature);
471+
_encodingFeatures = state ? (_encodingFeatures | feature) : (_encodingFeatures & ~feature);
472472
}
473473

474474
/**
@@ -556,7 +556,7 @@ public Builder setNullValue(char[] nvl) {
556556
public CsvSchema build()
557557
{
558558
Column[] cols = _columns.toArray(new Column[_columns.size()]);
559-
return new CsvSchema(cols, _features,
559+
return new CsvSchema(cols, _encodingFeatures,
560560
_columnSeparator, _quoteChar, _escapeChar,
561561
_lineSeparator, _arrayElementSeparator,
562562
_nullValue);
@@ -588,7 +588,7 @@ protected void _checkIndex(int index) {
588588
*
589589
* @since 2.5
590590
*/
591-
protected int _features = DEFAULT_FEATURES;
591+
protected int _features = DEFAULT_ENCODING_FEATURES;
592592

593593
protected final char _columnSeparator;
594594

@@ -612,7 +612,7 @@ public CsvSchema(Column[] columns,
612612
char[] lineSeparator)
613613
{
614614
this(columns,
615-
(useHeader ? FEATURE_USE_HEADER : 0) + (skipFirstDataRow ? FEATURE_SKIP_FIRST_DATA_ROW : 0),
615+
(useHeader ? ENCODING_FEATURE_USE_HEADER : 0) + (skipFirstDataRow ? ENCODING_FEATURE_SKIP_FIRST_DATA_ROW : 0),
616616
columnSeparator, quoteChar, escapeChar, lineSeparator,
617617
DEFAULT_ARRAY_ELEMENT_SEPARATOR, DEFAULT_NULL_VALUE);
618618
}
@@ -760,27 +760,27 @@ public Builder rebuild() {
760760
*/
761761

762762
public CsvSchema withUseHeader(boolean state) {
763-
return _withFeature(FEATURE_USE_HEADER, state);
763+
return _withFeature(ENCODING_FEATURE_USE_HEADER, state);
764764
}
765765

766766
/**
767767
* Helper method for constructing and returning schema instance that
768768
* is similar to this one, except that it will be using header line.
769769
*/
770770
public CsvSchema withHeader() {
771-
return _withFeature(FEATURE_USE_HEADER, true);
771+
return _withFeature(ENCODING_FEATURE_USE_HEADER, true);
772772
}
773773

774774
/**
775775
* Helper method for construcing and returning schema instance that
776776
* is similar to this one, except that it will not be using header line.
777777
*/
778778
public CsvSchema withoutHeader() {
779-
return _withFeature(FEATURE_USE_HEADER, false);
779+
return _withFeature(ENCODING_FEATURE_USE_HEADER, false);
780780
}
781781

782782
public CsvSchema withSkipFirstDataRow(boolean state) {
783-
return _withFeature(FEATURE_SKIP_FIRST_DATA_ROW, state);
783+
return _withFeature(ENCODING_FEATURE_SKIP_FIRST_DATA_ROW, state);
784784
}
785785

786786
/**
@@ -790,7 +790,7 @@ public CsvSchema withSkipFirstDataRow(boolean state) {
790790
* @since 2.5
791791
*/
792792
public CsvSchema withAllowComments(boolean state) {
793-
return _withFeature(FEATURE_ALLOW_COMMENTS, state);
793+
return _withFeature(ENCODING_FEATURE_ALLOW_COMMENTS, state);
794794
}
795795

796796
/**
@@ -800,7 +800,7 @@ public CsvSchema withAllowComments(boolean state) {
800800
* @since 2.5
801801
*/
802802
public CsvSchema withComments() {
803-
return _withFeature(FEATURE_ALLOW_COMMENTS, true);
803+
return _withFeature(ENCODING_FEATURE_ALLOW_COMMENTS, true);
804804
}
805805

806806
/**
@@ -810,7 +810,7 @@ public CsvSchema withComments() {
810810
* @since 2.5
811811
*/
812812
public CsvSchema withoutComments() {
813-
return _withFeature(FEATURE_ALLOW_COMMENTS, false);
813+
return _withFeature(ENCODING_FEATURE_ALLOW_COMMENTS, false);
814814
}
815815

816816
protected CsvSchema _withFeature(int feature, boolean state) {
@@ -956,21 +956,21 @@ public String getSchemaType() {
956956
/**********************************************************************
957957
*/
958958

959-
public boolean usesHeader() { return (_features & FEATURE_USE_HEADER) != 0; }
960-
public boolean skipsFirstDataRow() { return (_features & FEATURE_SKIP_FIRST_DATA_ROW) != 0; }
961-
public boolean allowsComments() { return (_features & FEATURE_ALLOW_COMMENTS) != 0; }
959+
public boolean usesHeader() { return (_features & ENCODING_FEATURE_USE_HEADER) != 0; }
960+
public boolean skipsFirstDataRow() { return (_features & ENCODING_FEATURE_SKIP_FIRST_DATA_ROW) != 0; }
961+
public boolean allowsComments() { return (_features & ENCODING_FEATURE_ALLOW_COMMENTS) != 0; }
962962

963963
/**
964964
* @deprecated Use {@link #usesHeader()} instead
965965
*/
966966
@Deprecated // since 2.5
967-
public boolean useHeader() { return (_features & FEATURE_USE_HEADER) != 0; }
967+
public boolean useHeader() { return (_features & ENCODING_FEATURE_USE_HEADER) != 0; }
968968

969969
/**
970970
* @deprecated Use {@link #skipsFirstDataRow()} instead
971971
*/
972972
@Deprecated // since 2.5
973-
public boolean skipFirstDataRow() { return (_features & FEATURE_SKIP_FIRST_DATA_ROW) != 0; }
973+
public boolean skipFirstDataRow() { return (_features & ENCODING_FEATURE_SKIP_FIRST_DATA_ROW) != 0; }
974974

975975
public char getColumnSeparator() { return _columnSeparator; }
976976
public int getArrayElementSeparator() { return _arrayElementSeparator; }

src/test/java/com/fasterxml/jackson/dataformat/csv/deser/TestParserNoSchema.java

+27
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ public void testUntypedAsStringArray() throws Exception
108108
assertEquals("", row[1]);
109109
}
110110

111+
public void testUntypedViaReadValues() throws Exception
112+
{
113+
CsvMapper mapper = mapperForCsv();
114+
mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY);
115+
MappingIterator<String[]> it = mapper.readerFor(String[].class)
116+
.readValues("1,\"xyz\"\n\ntrue,\n");
117+
assertTrue(it.hasNextValue());
118+
String[] row = it.nextValue();
119+
assertEquals(2, row.length);
120+
assertEquals("1",row[0]);
121+
assertEquals("xyz", row[1]);
122+
123+
assertTrue(it.hasNextValue());
124+
row = it.nextValue();
125+
assertEquals(1, row.length);
126+
assertEquals("", row[0]);
127+
128+
assertTrue(it.hasNextValue());
129+
row = it.nextValue();
130+
assertEquals(2, row.length);
131+
assertEquals("true", row[0]);
132+
assertEquals("", row[1]);
133+
134+
assertFalse(it.hasNextValue());
135+
it.close();
136+
}
137+
111138
public void testUntypedWithHeaderAsMap() throws Exception
112139
{
113140
CsvMapper mapper = mapperForCsv();

0 commit comments

Comments
 (0)