-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding XML serialization for PICA #232
- Loading branch information
Showing
5 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/de/gwdg/metadataqa/marc/utils/pica/PicaDataField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.gwdg.metadataqa.marc.utils.pica; | ||
|
||
import org.marc4j.marc.Subfield; | ||
import org.marc4j.marc.impl.DataFieldImpl; | ||
|
||
public class PicaDataField extends DataFieldImpl { | ||
|
||
private String occurrence; | ||
|
||
/** | ||
* Creates a new <code>DataField</code> and sets the tag name and the first and second indicator. | ||
* | ||
* @param tag The tag name | ||
*/ | ||
public PicaDataField(String tag) { | ||
super(tag, ' ', ' '); | ||
} | ||
|
||
public PicaDataField(String tag, String occurrence) { | ||
this(tag); | ||
this.occurrence = occurrence; | ||
} | ||
|
||
public String getOccurrence() { | ||
return occurrence; | ||
} | ||
|
||
public void setOccurrence(String occurrence) { | ||
this.occurrence = occurrence; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder(); | ||
sb.append(getTag()); | ||
if (occurrence != null) | ||
sb.append("/" + getOccurrence()); | ||
if (!getSubfields().isEmpty()) | ||
sb.append(' '); | ||
// sb.append(getIndicator1()); | ||
// sb.append(getIndicator2()); | ||
|
||
for (final Subfield sf : getSubfields()) { | ||
sb.append(sf.toString()); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/de/gwdg/metadataqa/marc/utils/pica/PicaDataFieldTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package de.gwdg.metadataqa.marc.utils.pica; | ||
|
||
import org.junit.Test; | ||
import org.marc4j.marc.impl.SubfieldImpl; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class PicaDataFieldTest { | ||
|
||
@Test | ||
public void constructor_withTag() { | ||
PicaDataField dataField = new PicaDataField("029F"); | ||
assertEquals("029F", dataField.getTag()); | ||
assertEquals(null, dataField.getOccurrence()); | ||
assertEquals("029F", dataField.toString()); | ||
} | ||
|
||
@Test | ||
public void constructor_withTagAndOccurence() { | ||
PicaDataField dataField = new PicaDataField("029F", "01"); | ||
assertEquals("029F", dataField.getTag()); | ||
assertEquals("01", dataField.getOccurrence()); | ||
assertEquals("029F/01", dataField.toString()); | ||
} | ||
|
||
@Test | ||
public void addSubfields() { | ||
PicaDataField dataField = new PicaDataField("029F", "01"); | ||
dataField.addSubfield(new SubfieldImpl('a', "something")); | ||
assertEquals("029F", dataField.getTag()); | ||
assertEquals("01", dataField.getOccurrence()); | ||
assertEquals("029F/01 $asomething", dataField.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters