Skip to content

Commit 4956554

Browse files
committed
metafacture-formeta/ (main): Fix Checkstyle violations.
1 parent ee5d3c9 commit 4956554

26 files changed

+255
-191
lines changed

metafacture-formeta/src/main/java/org/metafacture/formeta/Formeta.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta;
1718

1819
/**

metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaDecoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta;
1718

1819
import org.metafacture.formeta.parser.Emitter;

metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaEncoder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta;
1718

1819
import org.metafacture.formeta.formatter.Formatter;
@@ -35,12 +36,14 @@
3536
@In(StreamReceiver.class)
3637
@Out(String.class)
3738
@FluxCommand("encode-formeta")
38-
public final class FormetaEncoder extends
39-
DefaultStreamPipe<ObjectReceiver<String>> {
39+
public final class FormetaEncoder extends DefaultStreamPipe<ObjectReceiver<String>> {
4040

4141
private FormatterStyle style = FormatterStyle.CONCISE;
4242
private Formatter formatter = style.createFormatter();
4343

44+
public FormetaEncoder() {
45+
}
46+
4447
public FormatterStyle getStyle() {
4548
return style;
4649
}
@@ -50,7 +53,6 @@ public void setStyle(final FormatterStyle formatterStyle) {
5053
formatter = formatterStyle.createFormatter();
5154
}
5255

53-
5456
@Override
5557
public void startRecord(final String identifier) {
5658
formatter.reset();

metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.metafacture.formeta;
1716

18-
import java.io.IOException;
19-
import java.io.Reader;
17+
package org.metafacture.formeta;
2018

2119
import org.metafacture.framework.FluxCommand;
2220
import org.metafacture.framework.MetafactureException;
@@ -26,6 +24,9 @@
2624
import org.metafacture.framework.annotations.Out;
2725
import org.metafacture.framework.helpers.DefaultObjectPipe;
2826

27+
import java.io.IOException;
28+
import java.io.Reader;
29+
2930
/**
3031
* Reads a stream of formeta data and splits between each top-level element.
3132
*
@@ -36,15 +37,17 @@
3637
@Out(String.class)
3738
@Description("Reads a stream of formeta data and splits between each top-level element")
3839
@FluxCommand("as-formeta-records")
39-
public final class FormetaRecordsReader extends
40-
DefaultObjectPipe<Reader, ObjectReceiver<String>> {
40+
public final class FormetaRecordsReader extends DefaultObjectPipe<Reader, ObjectReceiver<String>> {
4141

4242
private static final int BUFFER_SIZE = 1024 * 1024 * 16;
4343

4444
private final StringBuilder builder = new StringBuilder();
4545
private final char[] buffer = new char[BUFFER_SIZE];
4646

47-
@Override
47+
public FormetaRecordsReader() {
48+
}
49+
50+
@Override // checkstyle-disable-line CyclomaticComplexity
4851
public void process(final Reader reader) {
4952
assert !isClosed();
5053

@@ -58,29 +61,32 @@ public void process(final Reader reader) {
5861
int offset = 0;
5962
for (int i = 0; i < size; ++i) {
6063
switch (buffer[i]) {
61-
case Formeta.ESCAPE_CHAR:
62-
i += 1; // Skip next character
63-
break;
64-
case Formeta.GROUP_START:
65-
if (!inQuotedText) {
66-
groupLevel += 1;
67-
}
68-
break;
69-
case Formeta.GROUP_END:
70-
if (!inQuotedText) {
71-
groupLevel -= 1;
72-
}
73-
// Fall through
74-
case Formeta.ITEM_SEPARATOR:
75-
if (!inQuotedText && groupLevel == 0) {
76-
builder.append(buffer, offset, i - offset + 1);
77-
offset = i + 1;
78-
emitRecord();
79-
}
80-
break;
81-
case Formeta.QUOT_CHAR:
82-
inQuotedText = !inQuotedText;
83-
break;
64+
case Formeta.ESCAPE_CHAR:
65+
// Skip next character
66+
i += 1; // checkstyle-disable-line ModifiedControlVariable
67+
break;
68+
case Formeta.GROUP_START:
69+
if (!inQuotedText) {
70+
groupLevel += 1;
71+
}
72+
break;
73+
case Formeta.GROUP_END:
74+
if (!inQuotedText) {
75+
groupLevel -= 1;
76+
}
77+
// fall through
78+
case Formeta.ITEM_SEPARATOR:
79+
if (!inQuotedText && groupLevel == 0) {
80+
builder.append(buffer, offset, i - offset + 1);
81+
offset = i + 1;
82+
emitRecord();
83+
}
84+
break;
85+
case Formeta.QUOT_CHAR:
86+
inQuotedText = !inQuotedText;
87+
break;
88+
default:
89+
// ignore
8490
}
8591
}
8692
builder.append(buffer, offset, size - offset);
@@ -89,7 +95,8 @@ public void process(final Reader reader) {
8995
emitRecord();
9096
}
9197

92-
} catch (final IOException e) {
98+
}
99+
catch (final IOException e) {
93100
throw new MetafactureException(e);
94101
}
95102
}

metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/AbstractFormatter.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta.formatter;
1718

1819
import org.metafacture.commons.StringUtil;
@@ -26,15 +27,15 @@
2627
*/
2728
public abstract class AbstractFormatter implements Formatter {
2829

29-
public static final String CHARS_TO_ESCAPE_QUOTED = "\n\r"
30-
+ Formeta.QUOT_CHAR
31-
+ Formeta.ESCAPE_CHAR;
30+
public static final String CHARS_TO_ESCAPE_QUOTED = "\n\r" +
31+
Formeta.QUOT_CHAR +
32+
Formeta.ESCAPE_CHAR;
3233

33-
public static final String CHARS_TO_ESCAPE = CHARS_TO_ESCAPE_QUOTED
34-
+ Formeta.GROUP_START
35-
+ Formeta.GROUP_END
36-
+ Formeta.ITEM_SEPARATOR
37-
+ Formeta.NAME_VALUE_SEPARATOR;
34+
public static final String CHARS_TO_ESCAPE = CHARS_TO_ESCAPE_QUOTED +
35+
Formeta.GROUP_START +
36+
Formeta.GROUP_END +
37+
Formeta.ITEM_SEPARATOR +
38+
Formeta.NAME_VALUE_SEPARATOR;
3839

3940
protected static final int BUFFER_SIZE = 1024;
4041

@@ -73,16 +74,17 @@ protected final void escapeAndAppend(final String str) {
7374
escapeAndAppendChar(buffer[i], CHARS_TO_ESCAPE_QUOTED);
7475
}
7576
builder.append(Formeta.QUOT_CHAR);
76-
} else {
77+
}
78+
else {
7779
if (bufferLen > 0) {
7880
escapeAndAppendChar(buffer[0],
7981
CHARS_TO_ESCAPE + Formeta.WHITESPACE);
8082
}
81-
for (int i = 1; i < bufferLen-1; ++i) {
83+
for (int i = 1; i < bufferLen - 1; ++i) {
8284
escapeAndAppendChar(buffer[i], CHARS_TO_ESCAPE);
8385
}
8486
if (bufferLen > 1) {
85-
escapeAndAppendChar(buffer[bufferLen-1],
87+
escapeAndAppendChar(buffer[bufferLen - 1],
8688
CHARS_TO_ESCAPE + Formeta.WHITESPACE);
8789
}
8890
}
@@ -92,27 +94,28 @@ protected void onReset() {
9294
// Default implementation does nothing
9395
}
9496

95-
protected abstract boolean shouldQuoteText(final char[] buffer, final int len);
97+
protected abstract boolean shouldQuoteText(char[] currentBuffer, int len);
9698

9799
private void escapeAndAppendChar(final char ch, final String charsToEscape) {
98100
if (charsToEscape.indexOf(ch) > -1) {
99101
appendEscapedChar(ch);
100-
} else {
102+
}
103+
else {
101104
builder.append(ch);
102105
}
103106
}
104107

105108
private void appendEscapedChar(final char ch) {
106109
builder.append(Formeta.ESCAPE_CHAR);
107110
switch (ch) {
108-
case '\n':
109-
builder.append(Formeta.NEWLINE_ESC_SEQ);
110-
break;
111-
case '\r':
112-
builder.append(Formeta.CARRIAGE_RETURN_ESC_SEQ);
113-
break;
114-
default:
115-
builder.append(ch);
111+
case '\n':
112+
builder.append(Formeta.NEWLINE_ESC_SEQ);
113+
break;
114+
case '\r':
115+
builder.append(Formeta.CARRIAGE_RETURN_ESC_SEQ);
116+
break;
117+
default:
118+
builder.append(ch);
116119
}
117120
}
118121

metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/ConciseFormatter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta.formatter;
1718

1819
import org.metafacture.formeta.Formeta;
@@ -27,6 +28,9 @@ public final class ConciseFormatter extends AbstractFormatter {
2728

2829
private boolean appendItemSeparator;
2930

31+
public ConciseFormatter() {
32+
}
33+
3034
@Override
3135
public void startGroup(final String name) {
3236
if (appendItemSeparator) {

metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/Formatter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta.formatter;
1718

1819
/**
@@ -25,10 +26,10 @@ public interface Formatter {
2526

2627
void reset();
2728

28-
void startGroup(final String name);
29+
void startGroup(String name);
2930

3031
void endGroup();
3132

32-
void literal(final String name, final String value);
33+
void literal(String name, String value);
3334

3435
}

metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/FormatterStyle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta.formatter;
1718

1819
/**

metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/MultilineFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta.formatter;
1718

1819
import org.metafacture.formeta.Formeta;
@@ -36,7 +37,6 @@ public final class MultilineFormatter extends AbstractFormatter {
3637
private boolean firstItem;
3738

3839
public MultilineFormatter() {
39-
super();
4040
onReset();
4141
}
4242

metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/VerboseFormatter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.metafacture.formeta.formatter;
1718

1819
import org.metafacture.formeta.Formeta;
@@ -32,6 +33,9 @@ public final class VerboseFormatter extends AbstractFormatter {
3233

3334
private boolean appendItemSeparator;
3435

36+
public VerboseFormatter() {
37+
}
38+
3539
@Override
3640
public void startGroup(final String name) {
3741
if (appendItemSeparator) {

0 commit comments

Comments
 (0)