Skip to content

Commit 78f800c

Browse files
committed
Minor clean-up
1 parent 67e9651 commit 78f800c

File tree

3 files changed

+83
-100
lines changed

3 files changed

+83
-100
lines changed

.classpath

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<classpath>
3-
<classpathentry kind="src" output="target/classes" path="src/main/java">
4-
<attributes>
5-
<attribute name="optional" value="true"/>
6-
<attribute name="maven.pomderived" value="true"/>
7-
</attributes>
8-
</classpathentry>
9-
<classpathentry kind="src" output="target/classes" path="src/main/antlr3">
10-
<attributes>
11-
<attribute name="optional" value="true"/>
12-
<attribute name="maven.pomderived" value="true"/>
13-
</attributes>
14-
</classpathentry>
15-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
16-
<attributes>
17-
<attribute name="maven.pomderived" value="true"/>
18-
</attributes>
19-
</classpathentry>
20-
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java">
21-
<attributes>
22-
<attribute name="optional" value="true"/>
23-
<attribute name="maven.pomderived" value="true"/>
24-
</attributes>
25-
</classpathentry>
26-
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
27-
<attributes>
28-
<attribute name="maven.pomderived" value="true"/>
29-
</attributes>
30-
</classpathentry>
31-
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
32-
<attributes>
33-
<attribute name="maven.pomderived" value="true"/>
34-
</attributes>
35-
</classpathentry>
36-
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
37-
<attributes>
38-
<attribute name="maven.pomderived" value="true"/>
39-
</attributes>
40-
</classpathentry>
41-
<classpathentry kind="output" path="target/classes"/>
42-
</classpath>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/classes" path="src/main/antlr3">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java">
21+
<attributes>
22+
<attribute name="optional" value="true"/>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
27+
<attributes>
28+
<attribute name="maven.pomderived" value="true"/>
29+
</attributes>
30+
</classpathentry>
31+
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
32+
<attributes>
33+
<attribute name="maven.pomderived" value="true"/>
34+
</attributes>
35+
</classpathentry>
36+
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
37+
<attributes>
38+
<attribute name="maven.pomderived" value="true"/>
39+
</attributes>
40+
</classpathentry>
41+
<classpathentry kind="output" path="target/classes"/>
42+
</classpath>

src/main/java/org/culturegraph/mf/stream/converter/bib/PicaEncoder.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.culturegraph.mf.exceptions.FormatException;
2424
import org.culturegraph.mf.framework.DefaultStreamPipe;
25-
2625
import org.culturegraph.mf.framework.ObjectReceiver;
2726
import org.culturegraph.mf.framework.StreamReceiver;
2827
import org.culturegraph.mf.framework.annotations.Description;
@@ -32,22 +31,22 @@
3231

3332
/**
3433
* Encodes an event stream in pica+ format.
35-
*
34+
*
3635
* <strong>Special handling of subfield 'S':</strong> the code of
3736
* "control subfields" (subfield name='S') will be appended to the fieldName.
3837
* E.g.: 041A $Saxx would be mapped to the fieldName 041Aa, and xx will be
3938
* ignored. A recovery of such field to original is not implemented. So the
40-
* encoder cannot identify an S-field.
39+
* encoder cannot identify an S-field.
4140
* The S-field special processing can be turned on if the decoder is called
4241
* with the option: (appendcontrolsubfield="true")
4342
* The default value of this option is set to "false".
44-
*
43+
*
4544
* @see PicaDecoder
46-
*
45+
*
4746
* @author Yining Li
48-
*
47+
*
4948
*/
50-
@Description("Encodes a stream in pica+ Format")
49+
@Description("Encodes a stream in pica+ format")
5150
@In(StreamReceiver.class)
5251
@Out(String.class)
5352
public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>> {
@@ -63,16 +62,14 @@ public final class PicaEncoder extends DefaultStreamPipe<ObjectReceiver<String>>
6362
private boolean entityOpen; //Flag to inform whether an entity is opened.
6463
private boolean idnControlSubField; //Flag to inform whether it is the 003@ field.
6564
private boolean ignoreRecordId; //Flag to decide whether the record Id is checked.
66-
67-
private String id;
6865

69-
66+
private String id;
7067

7168
@Override
7269
public void startRecord(final String recordId) {
7370
// the name is a idn, which should be found in the encoded data under 003@.
7471
//any rest of the previous record is cleared before the new begins.
75-
builder.setLength(0);
72+
builder.setLength(0);
7673
this.id = recordId;
7774
//Now an entity can be opened. But no literal is allowed.
7875
this.entityOpen = false;
@@ -81,15 +78,15 @@ public void startRecord(final String recordId) {
8178
public void setIgnoreRecordId(final boolean ignoreRecordId) {
8279
this.ignoreRecordId = ignoreRecordId;
8380
}
84-
81+
8582
public boolean getIgnoreRecordId() {
8683
return this.ignoreRecordId;
8784
}
88-
85+
8986
@Override
9087
public void startEntity(final String name) {
91-
// Here begins a field (i.e. "028A ", which is given in the name.
92-
// It is unknown, whether there are any subfields in the field.
88+
// Here begins a field (i.e. "028A ", which is given in the name.
89+
// It is unknown, whether there are any subfields in the field.
9390
final Matcher fieldNameMatcher = FIELD_NAME_PATTERN.matcher(name);
9491
if (!fieldNameMatcher.matches()) {
9592
throw new FormatException(name);
@@ -107,14 +104,14 @@ public void startEntity(final String name) {
107104
@Override
108105
public void literal(final String name, final String value) {
109106
//A Subfield has one character or digit exactly.
110-
if (name.length()!=1){
107+
if (name.length() != 1) {
111108
throw new FormatException(name);
112109
}
113-
if (!entityOpen){
110+
if (!entityOpen) {
114111
throw new FormatException(name); //new exceptions definition for literal out of entity
115112
}
116113
final String valueNew = Normalizer.normalize(value, Form.NFD);
117-
if (idnControlSubField){
114+
if (idnControlSubField) {
118115
// it is a 003@ field, the same record id delivered with record should follow
119116
if (!this.id.equals(value)) {
120117
throw new MissingIdException(value);
@@ -139,6 +136,7 @@ public void endRecord() {
139136
//No literal is allowed.
140137
this.entityOpen = false;
141138
}
139+
142140
@Override
143141
protected void onResetStream() {
144142
builder.setLength(0);

src/test/java/org/culturegraph/mf/stream/converter/bib/PicaEncoderTest.java

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,30 @@
2626
import org.mockito.MockitoAnnotations;
2727

2828
/**
29-
* Tests for {@link PicaEncoder}
30-
*
31-
* @author li
29+
* Tests for {@link PicaEncoder}.
30+
*
31+
* @author Yining Li
3232
*
3333
*/
3434
public final class PicaEncoderTest {
3535

3636
private PicaEncoder picaEncoder;
37-
37+
3838
@Mock
3939
private ObjectReceiver<String> receiver;
40-
40+
4141
@Before
4242
public void setup() {
4343
MockitoAnnotations.initMocks(this);
4444
picaEncoder = new PicaEncoder();
4545
picaEncoder.setReceiver(receiver);
4646
}
47-
47+
4848
@After
4949
public void cleanup() {
5050
picaEncoder.closeStream();
5151
}
52-
52+
5353
@Test
5454
public void testShouldWriteFieldAndSubfield() {
5555
picaEncoder.startRecord("17709958X");
@@ -62,7 +62,7 @@ public void testShouldWriteFieldAndSubfield() {
6262
picaEncoder.literal("l", "Bapst");
6363
picaEncoder.endEntity();
6464
picaEncoder.endRecord();
65-
65+
6666
verify(receiver).process("003@ \u001f017709958X\u001e028@ \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
6767
}
6868

@@ -78,12 +78,12 @@ public void testShouldWriteFieldAndSubfield2() {
7878
picaEncoder.literal("l", "Bapst");
7979
picaEncoder.endEntity();
8080
picaEncoder.endRecord();
81-
81+
8282
verify(receiver).process("003@ \u001f017709958X\u001e028@/30 \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
8383
}
8484

8585
@Test(expected=FormatException.class)
86-
public void testShouldFailOnIlligalFieldName() {
86+
public void testShouldFailOnInvalidFieldName() {
8787
picaEncoder.startRecord("17709958X");
8888
picaEncoder.startEntity("003@");
8989
picaEncoder.literal("0", "17709958X");
@@ -94,12 +94,12 @@ public void testShouldFailOnIlligalFieldName() {
9494
picaEncoder.literal("l", "Bapst");
9595
picaEncoder.endEntity();
9696
picaEncoder.endRecord();
97-
97+
9898
verify(receiver).process("003@ \u001f017709958X\u001e@028 \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
9999
}
100-
100+
101101
@Test(expected=FormatException.class)
102-
public void testShouldFailOnIlligalFieldName2() {
102+
public void testShouldFailOnInvalidFieldName2() {
103103
picaEncoder.startRecord("17709958X");
104104
picaEncoder.startEntity("003@");
105105
picaEncoder.literal("0", "17709958X");
@@ -110,58 +110,42 @@ public void testShouldFailOnIlligalFieldName2() {
110110
picaEncoder.literal("l", "Bapst");
111111
picaEncoder.endEntity();
112112
picaEncoder.endRecord();
113-
113+
114114
verify(receiver).process("003@ \u001f017709958X\u001e@028 \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
115115
}
116116

117117
@Test(expected=FormatException.class)
118-
public void testShouldFailOnIlligalSubfieldName() {
118+
public void testShouldFailOnInvalidSubfieldName() {
119119
picaEncoder.startRecord("17709958X");
120120
picaEncoder.startEntity("003@");
121121
picaEncoder.literal("0", "17709958X");
122122
picaEncoder.endEntity();
123-
picaEncoder.startEntity("028@");
123+
picaEncoder.startEntity("028@");
124124
picaEncoder.literal("Pp", "Abläöübolo");//the subfieldname pattern not match!
125125
picaEncoder.literal("n", "VIX");
126126
picaEncoder.literal("l", "Bapst");
127127
picaEncoder.endEntity();
128128
picaEncoder.endRecord();
129-
129+
130130
verify(receiver).process("003@ \u001f017709958X\u001e@028 \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
131131
}
132-
132+
133133
@Test(expected=FormatException.class)
134-
public void testShouldFailOnLiteralOutofEntity() {
134+
public void testShouldFailOnLiteralOutOfEntity() {
135135
picaEncoder.startRecord("17709958X");
136136
picaEncoder.startEntity("003@");
137137
picaEncoder.literal("0", "17709958X");
138138
picaEncoder.endEntity();
139139
picaEncoder.literal("P", "Abläöübolo");//the subfieldname out of entity!
140-
picaEncoder.startEntity("028@");
141-
picaEncoder.literal("n", "VIX");
142-
picaEncoder.literal("l", "Bapst");
143-
picaEncoder.endEntity();
144-
picaEncoder.endRecord();
145-
146-
verify(receiver).process("003@ \u001f017709958X\u001e@028 \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
147-
}
148-
149-
@Test(expected=FormatException.class)
150-
public void testShouldFailOnEntityOutOfRecord() {
151-
picaEncoder.startEntity("003@"); //the Entity out of record!
152-
picaEncoder.startRecord("17709958X");
153-
picaEncoder.startEntity("003@");
154-
picaEncoder.literal("0", "17709958X");
155-
picaEncoder.endEntity();
156-
picaEncoder.literal("P", "Abläöübolo");
157-
picaEncoder.startEntity("028@");
140+
picaEncoder.startEntity("028@");
158141
picaEncoder.literal("n", "VIX");
159142
picaEncoder.literal("l", "Bapst");
160143
picaEncoder.endEntity();
161144
picaEncoder.endRecord();
162-
145+
163146
verify(receiver).process("003@ \u001f017709958X\u001e@028 \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
164147
}
148+
165149
@Test (expected=MissingIdException.class)
166150
public void testShouldFailOnWrongRecordId() {
167151
picaEncoder.startRecord("17709958");
@@ -174,7 +158,7 @@ public void testShouldFailOnWrongRecordId() {
174158
picaEncoder.literal("l", "Bapst");
175159
picaEncoder.endEntity();
176160
picaEncoder.endRecord();
177-
161+
178162
verify(receiver).process("003@ \u001f017709958X\u001e028@ \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
179163
}
180164

@@ -191,7 +175,8 @@ public void testShouldIgnoreRecordId() {
191175
picaEncoder.literal("l", "Bapst");
192176
picaEncoder.endEntity();
193177
picaEncoder.endRecord();
194-
178+
195179
verify(receiver).process("003@ \u001f017709958X\u001e028@ \u001fPAbla\u0308o\u0308u\u0308bolo\u001fnVIX\u001flBapst\u001e");
196180
}
181+
197182
}

0 commit comments

Comments
 (0)