From 3c04232a799ead816c94034a9d8078aa66e67aba Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sat, 4 Sep 2021 15:14:16 +0200 Subject: [PATCH 01/30] Add Checkstyle config. Based on https://github.com/metafacture/metafacture-fix/blob/master/config/checkstyle/checkstyle.xml. --- build.gradle | 5 + config/checkstyle/checkstyle.xml | 163 +++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 config/checkstyle/checkstyle.xml diff --git a/build.gradle b/build.gradle index 1b552802c..428d80192 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,7 @@ subprojects { apply plugin: 'signing' apply plugin: 'maven' apply plugin: 'jacoco' + apply plugin: 'checkstyle' check.dependsOn(editorconfigCheck) @@ -85,6 +86,10 @@ subprojects { archives javadocJar } + checkstyle { + toolVersion '8.30' + } + signing { required { scmInfo.isRelease() && gradle.taskGraph.hasTask(tasks.uploadArchives) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..1693187d0 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0bef5fbd58240ad0baa21e99826e6496f830cc37 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 12:13:59 +0200 Subject: [PATCH 02/30] Disable Checkstyle runs against test sources. --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 428d80192..7e3d1e00c 100644 --- a/build.gradle +++ b/build.gradle @@ -88,6 +88,7 @@ subprojects { checkstyle { toolVersion '8.30' + checkstyleTest.enabled = false } signing { From 56c78b0b0032721f80926f35b54937774957709d Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sat, 4 Sep 2021 20:23:33 +0200 Subject: [PATCH 03/30] metafacture-biblio/ (main): Fix Checkstyle violations. --- .../biblio/AlephMabXmlHandler.java | 32 ++- .../org/metafacture/biblio/AseqDecoder.java | 24 +- .../metafacture/biblio/ComarcXmlHandler.java | 88 ++++--- .../org/metafacture/biblio/MabDecoder.java | 25 +- .../org/metafacture/biblio/OaiPmhOpener.java | 207 ++++++++-------- .../biblio/iso2709/DirectoryBuilder.java | 19 +- .../biblio/iso2709/DirectoryEntry.java | 22 +- .../biblio/iso2709/FieldHandler.java | 1 + .../biblio/iso2709/FieldsBuilder.java | 14 +- .../biblio/iso2709/Iso2709Constants.java | 1 + .../biblio/iso2709/Iso646ByteBuffer.java | 9 +- .../biblio/iso2709/Iso646Constants.java | 1 + .../org/metafacture/biblio/iso2709/Label.java | 44 ++-- .../biblio/iso2709/LabelBuilder.java | 78 +++--- .../metafacture/biblio/iso2709/Record.java | 35 ++- .../biblio/iso2709/RecordBuilder.java | 105 ++++---- .../biblio/iso2709/RecordFormat.java | 70 +++--- .../biblio/marc21/Marc21Constants.java | 71 +++--- .../biblio/marc21/Marc21Decoder.java | 51 ++-- .../biblio/marc21/Marc21Encoder.java | 29 +-- .../biblio/marc21/Marc21EventNames.java | 225 +++++++++--------- .../biblio/marc21/MarcXmlEncoder.java | 48 ++-- .../biblio/marc21/MarcXmlHandler.java | 57 +++-- .../biblio/pica/PicaConstants.java | 46 ++-- .../metafacture/biblio/pica/PicaDecoder.java | 37 ++- .../metafacture/biblio/pica/PicaEncoder.java | 17 +- .../biblio/pica/PicaMultiscriptRemodeler.java | 108 +++++---- .../biblio/pica/PicaParserContext.java | 10 +- .../biblio/pica/PicaParserState.java | 92 +++---- .../biblio/pica/PicaXmlHandler.java | 24 +- .../biblio/AlephMabXmlHandlerTest.java | 1 + .../metafacture/biblio/AseqDecoderTest.java | 1 + .../biblio/ComarcXmlHandlerTest.java | 1 + .../metafacture/biblio/MabDecoderTest.java | 1 + .../biblio/iso2709/DirectoryEntryTest.java | 1 + .../biblio/iso2709/Iso646ByteBufferTest.java | 1 + .../metafacture/biblio/iso2709/LabelTest.java | 1 + .../biblio/iso2709/RecordBuilderTest.java | 4 +- .../biblio/iso2709/RecordFormatTest.java | 1 + .../biblio/iso2709/RecordTest.java | 1 + .../biblio/marc21/Marc21DecoderTest.java | 1 + .../biblio/marc21/Marc21EncoderTest.java | 1 + .../biblio/marc21/MarcXmlHandlerTest.java | 1 + .../biblio/pica/PicaEncoderTest.java | 1 + .../pica/PicaMultiscriptRemodelerTest.java | 4 +- 45 files changed, 852 insertions(+), 759 deletions(-) diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/AlephMabXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/AlephMabXmlHandler.java index e1911dbe5..3904ed3a6 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/AlephMabXmlHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/AlephMabXmlHandler.java @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio; import org.metafacture.framework.FluxCommand; @@ -21,6 +22,7 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -48,6 +50,9 @@ public final class AlephMabXmlHandler extends DefaultXmlPipe { private String currentTag = ""; private StringBuilder builder = new StringBuilder(); + public AlephMabXmlHandler() { + } + @Override public void characters(final char[] chars, final int start, final int length) throws SAXException { @@ -60,11 +65,14 @@ public void endElement(final String uri, final String localName, final String qN if (AlephMabXmlHandler.CONTROLLFIELD.equals(localName)) { getReceiver().literal(this.currentTag, this.builder.toString().trim()); getReceiver().endEntity(); - } else if (AlephMabXmlHandler.SUBFIELD.equals(localName)) { + } + else if (AlephMabXmlHandler.SUBFIELD.equals(localName)) { getReceiver().literal(this.currentTag, this.builder.toString().trim()); - } else if (AlephMabXmlHandler.DATAFIELD.equals(localName)) { + } + else if (AlephMabXmlHandler.DATAFIELD.equals(localName)) { getReceiver().endEntity(); - } else if (AlephMabXmlHandler.RECORD.equals(localName)) { + } + else if (AlephMabXmlHandler.RECORD.equals(localName)) { getReceiver().endRecord(); } } @@ -76,16 +84,20 @@ public void startElement(final String uri, final String localName, final String this.builder = new StringBuilder(); this.currentTag = ""; getReceiver().startEntity(attributes.getValue(AlephMabXmlHandler.DATAFIELD_ATTRIBUTE)); - } else if (AlephMabXmlHandler.SUBFIELD.equals(localName)) { + } + else if (AlephMabXmlHandler.SUBFIELD.equals(localName)) { this.builder = new StringBuilder(); this.currentTag = attributes.getValue(AlephMabXmlHandler.SUBFIELD_ATTRIBUTE); - } else if (AlephMabXmlHandler.DATAFIELD.equals(localName)) { - getReceiver().startEntity(attributes.getValue(AlephMabXmlHandler.DATAFIELD_ATTRIBUTE) - + attributes.getValue(AlephMabXmlHandler.INDICATOR1) - + attributes.getValue(AlephMabXmlHandler.INDICATOR2)); - } else if (AlephMabXmlHandler.RECORD.equals(localName)) { + } + else if (AlephMabXmlHandler.DATAFIELD.equals(localName)) { + getReceiver().startEntity(attributes.getValue(AlephMabXmlHandler.DATAFIELD_ATTRIBUTE) + + attributes.getValue(AlephMabXmlHandler.INDICATOR1) + + attributes.getValue(AlephMabXmlHandler.INDICATOR2)); + } + else if (AlephMabXmlHandler.RECORD.equals(localName)) { getReceiver().startRecord(""); - } else if (AlephMabXmlHandler.LEADER.equals(localName)) { + } + else if (AlephMabXmlHandler.LEADER.equals(localName)) { this.builder = new StringBuilder(); this.currentTag = AlephMabXmlHandler.LEADER; } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/AseqDecoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/AseqDecoder.java index 5ebdb18b8..9c5d37977 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/AseqDecoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/AseqDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio; import org.metafacture.framework.FluxCommand; @@ -31,11 +32,19 @@ @In(String.class) @Out(StreamReceiver.class) @FluxCommand("decode-aseq") -public final class AseqDecoder - extends DefaultObjectPipe { +public final class AseqDecoder extends DefaultObjectPipe { private static final String FIELD_DELIMITER = "\n"; + private static final int CATEGORY_BEGIN = 10; + private static final int CATEGORY_END = 15; + private static final int FIELD_CONTENT_BEGIN = 18; + private static final int RECORD_IDENTIFIER_BEGIN = 0; + private static final int RECORD_IDENTIFIER_END = 9; + + public AseqDecoder() { + } + @Override public void process(final String record) { assert !isClosed(); @@ -44,16 +53,17 @@ public void process(final String record) { return; } final String[] lines = trimedRecord.split(FIELD_DELIMITER); - for (int i = 0; i < lines.length; i++) { + for (int i = 0; i < lines.length; ++i) { final String field = lines[i]; if (i == 0) { - getReceiver().startRecord(field.substring(0, 9)); + getReceiver().startRecord(field.substring(RECORD_IDENTIFIER_BEGIN, RECORD_IDENTIFIER_END)); } - final String category = field.substring(10, 15).trim(); - final String fieldContent = field.substring(18).trim(); + final String category = field.substring(CATEGORY_BEGIN, CATEGORY_END).trim(); + final String fieldContent = field.substring(FIELD_CONTENT_BEGIN).trim(); if (!fieldContent.startsWith("$$")) { getReceiver().literal(category, fieldContent); - } else { + } + else { getReceiver().startEntity(category); final String[] subfields = fieldContent.split("\\$\\$"); for (final String subfield : subfields) { diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/ComarcXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/ComarcXmlHandler.java index 15edf729c..625300a8d 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/ComarcXmlHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/ComarcXmlHandler.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio; -import java.util.ArrayList; -import java.util.List; +package org.metafacture.biblio; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamReceiver; @@ -25,9 +23,13 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import java.util.ArrayList; +import java.util.List; + /** * A class handling ComarcXML. Comarc is the MARC version used by the National * Library of Slovenia. It does not have a leader, instead most (all?) the @@ -61,14 +63,7 @@ public class ComarcXmlHandler extends DefaultXmlPipe { private String currentTag = ""; private StringBuilder builder = new StringBuilder(); - private class Entry { - String key; - String value; - - Entry(final String key, final String value) { - this.key = key; - this.value = value; - } + public ComarcXmlHandler() { } @Override @@ -78,12 +73,14 @@ public void startElement(final String uri, final String localName, if (SUBFIELD.equals(localName)) { this.builder = new StringBuilder(); this.currentTag = attributes.getValue("code"); - } else if (DATAFIELD.equals(localName) - && this.state == RECORD_INITIALISED) { + } + else if (DATAFIELD.equals(localName) && this.state == RECORD_INITIALISED) { getReceiver().startEntity( - attributes.getValue("tag") + attributes.getValue("ind1") - + attributes.getValue("ind2")); - } else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { + attributes.getValue("tag") + + attributes.getValue("ind1") + + attributes.getValue("ind2")); + } + else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { this.state = RECORD_NOT_INITIALISED; } } @@ -94,26 +91,27 @@ public void endElement(final String uri, final String localName, if (SUBFIELD.equals(localName)) { this.subfieldValues.add(new Entry(this.currentTag, this.builder .toString().trim())); - } else if (DATAFIELD.equals(localName)) { + } + else if (DATAFIELD.equals(localName)) { switch (this.state) { - case RECORD_NOT_INITIALISED: - super.getReceiver().startRecord(getFirstSubfield("x")); - super.getReceiver().startEntity("000 "); - this.state = RECORD_INITIALISED; - // this should fall through so that the entity 000 is properly - // ended - case RECORD_INITIALISED: - for (final Entry entry : this.subfieldValues) { - super.getReceiver().literal(entry.key, entry.value); - } - super.getReceiver().endEntity(); - this.subfieldValues.clear(); - break; - default: - throw new SAXException( - "State was not one of initialised or not initialised"); + case RECORD_NOT_INITIALISED: + super.getReceiver().startRecord(getFirstSubfield("x")); + super.getReceiver().startEntity("000 "); + this.state = RECORD_INITIALISED; + // fall through so that the entity 000 is properly ended + case RECORD_INITIALISED: + for (final Entry entry : this.subfieldValues) { + super.getReceiver().literal(entry.getKey(), entry.getValue()); + } + super.getReceiver().endEntity(); + this.subfieldValues.clear(); + break; + default: + throw new SAXException( + "State was not one of initialised or not initialised"); } - } else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { + } + else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { getReceiver().endRecord(); } } @@ -127,12 +125,30 @@ public void characters(final char[] chars, final int start, final int length) private String getFirstSubfield(final String subfieldCode) { String ret = null; for (final Entry entry : this.subfieldValues) { - if (subfieldCode.equals(entry.key)) { - ret = entry.value; + if (subfieldCode.equals(entry.getKey())) { + ret = entry.getValue(); break; } } return ret; } + private class Entry { + private final String key; + private final String value; + + Entry(final String key, final String value) { + this.key = key; + this.value = value; + } + + private String getKey() { + return key; + } + + private String getValue() { + return value; + } + } + } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/MabDecoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/MabDecoder.java index 62169f664..4804199b8 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/MabDecoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/MabDecoder.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio; -import java.util.regex.Pattern; +package org.metafacture.biblio; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.FormatException; @@ -26,6 +25,7 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.regex.Pattern; /** * Parses a raw Mab2 stream (utf-8 encoding assumed). Events are handled by a @@ -40,8 +40,7 @@ @In(String.class) @Out(StreamReceiver.class) @FluxCommand("decode-mab") -public final class MabDecoder - extends DefaultObjectPipe { +public final class MabDecoder extends DefaultObjectPipe { private static final String FIELD_END = "\u001e"; private static final Pattern FIELD_PATTERN = @@ -58,6 +57,9 @@ public final class MabDecoder private static final String ID_TAG = "001 "; private static final int TAG_LENGTH = 4; + public MabDecoder() { + } + @Override public void process(final String record) { assert !isClosed(); @@ -70,7 +72,7 @@ public void process(final String record) { try { getReceiver().literal(LEADER, record.substring(0, HEADER_SIZE)); - getReceiver().literal(TYPE, String.valueOf(record.charAt(HEADER_SIZE-1))); + getReceiver().literal(TYPE, String.valueOf(record.charAt(HEADER_SIZE - 1))); final String content = record.substring(HEADER_SIZE); for (final String part : FIELD_PATTERN.split(content)) { if (!part.startsWith(RECORD_END)) { @@ -80,7 +82,8 @@ public void process(final String record) { if (subFields.length == 1) { getReceiver().literal(fieldName, subFields[0]); - } else { + } + else { getReceiver().startEntity(fieldName); for (int i = 1; i < subFields.length; ++i) { @@ -92,7 +95,8 @@ public void process(final String record) { } } } - } catch (final IndexOutOfBoundsException e) { + } + catch (final IndexOutOfBoundsException e) { throw new FormatException("[" + record + "]", e); } @@ -100,13 +104,14 @@ public void process(final String record) { } private String extractIdFromRecord(final String record) { - try{ + try { final int fieldEnd = record.indexOf(FIELD_END, HEADER_SIZE); - if(record.substring(HEADER_SIZE, HEADER_SIZE + TAG_LENGTH).equals(ID_TAG)){ + if (record.substring(HEADER_SIZE, HEADER_SIZE + TAG_LENGTH).equals(ID_TAG)) { return record.substring(HEADER_SIZE + TAG_LENGTH, fieldEnd); } throw new MissingIdException(record); - } catch (IndexOutOfBoundsException e) { + } + catch (final IndexOutOfBoundsException e) { throw new FormatException(INVALID_FORMAT + record, e); } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/OaiPmhOpener.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/OaiPmhOpener.java index 3c7110bae..fd98f3470 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/OaiPmhOpener.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/OaiPmhOpener.java @@ -3,24 +3,23 @@ package org.metafacture.biblio; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; - import org.metafacture.framework.MetafactureException; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.annotations.Description; import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; -import org.xml.sax.SAXException; import ORG.oclc.oai.harvester2.app.RawWrite; +import org.xml.sax.SAXException; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; /** * Opens an OAI-PMH stream and passes a reader to the receiver. @@ -31,97 +30,99 @@ @Description("Opens an OAI-PMH stream and passes a reader to the receiver. Mandatory arguments are: BASE_URL, DATE_FROM, DATE_UNTIL, METADATA_PREFIX, SET_SPEC .") @In(String.class) @Out(java.io.Reader.class) -public final class OaiPmhOpener extends - DefaultObjectPipe> { - - private String encoding = "UTF-8"; - - final ByteArrayOutputStream OUTPUT_STREAM = new ByteArrayOutputStream(); - - private String dateFrom; - - private String dateUntil; - - private String setSpec; - - private String metadataPrefix; - - /** - * Default constructor - */ - public OaiPmhOpener() { - - } - - /** - * Sets the encoding to use. The default setting is UTF-8. - * - * @param encoding new default encoding - */ - public void setEncoding(final String encoding) { - this.encoding = encoding; - } - - /** - * Sets the beginning of the retrieving of updated data. The form is - * YYYY-MM-DD . - * - * @param dateFrom The form is YYYY-MM-DD . - */ - public void setDateFrom(final String dateFrom) { - this.dateFrom = dateFrom; - } - - /** - * Sets the end of the retrieving of updated data. The form is YYYY-MM-DD . - * - * @param dateUntil The form is YYYY-MM-DD . - */ - public void setDateUntil(final String dateUntil) { - this.dateUntil = dateUntil; - } - - /** - * Sets the OAI-PM metadata prefix . - * - * @param metadataPrefix the OAI-PM metadata prefix - */ - public void setMetadataPrefix(final String metadataPrefix) { - this.metadataPrefix = metadataPrefix; - } - - /** - * Sets the OAI-PM set specification . - * - * @param setSpec th OAI-PM set specification - */ - public void setSetSpec(final String setSpec) { - this.setSpec = setSpec; - } - - @Override - public void process(final String baseUrl) { - - try { - RawWrite.run(baseUrl, this.dateFrom, this.dateUntil, this.metadataPrefix, - this.setSpec, OUTPUT_STREAM); - } catch (IOException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (TransformerException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } - try { - getReceiver().process( - new InputStreamReader(new ByteArrayInputStream(OUTPUT_STREAM - .toByteArray()), encoding)); - } catch (IOException e) { - throw new MetafactureException(e); - } - } +public final class OaiPmhOpener extends DefaultObjectPipe> { + + private String encoding = "UTF-8"; + + private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + + private String dateFrom; + + private String dateUntil; + + private String setSpec; + + private String metadataPrefix; + + /** + * Default constructor + */ + public OaiPmhOpener() { + } + + /** + * Sets the encoding to use. The default setting is UTF-8. + * + * @param encoding new default encoding + */ + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + + /** + * Sets the beginning of the retrieving of updated data. The form is + * YYYY-MM-DD . + * + * @param dateFrom The form is YYYY-MM-DD . + */ + public void setDateFrom(final String dateFrom) { + this.dateFrom = dateFrom; + } + + /** + * Sets the end of the retrieving of updated data. The form is YYYY-MM-DD . + * + * @param dateUntil The form is YYYY-MM-DD . + */ + public void setDateUntil(final String dateUntil) { + this.dateUntil = dateUntil; + } + + /** + * Sets the OAI-PM metadata prefix . + * + * @param metadataPrefix the OAI-PM metadata prefix + */ + public void setMetadataPrefix(final String metadataPrefix) { + this.metadataPrefix = metadataPrefix; + } + + /** + * Sets the OAI-PM set specification . + * + * @param setSpec th OAI-PM set specification + */ + public void setSetSpec(final String setSpec) { + this.setSpec = setSpec; + } + + @Override + public void process(final String baseUrl) { + + try { + RawWrite.run(baseUrl, this.dateFrom, this.dateUntil, this.metadataPrefix, this.setSpec, outputStream); + } + catch (final IOException e) { + e.printStackTrace(); + } + catch (final ParserConfigurationException e) { + e.printStackTrace(); + } + catch (final SAXException e) { + e.printStackTrace(); + } + catch (final TransformerException e) { + e.printStackTrace(); + } + catch (final NoSuchFieldException e) { + e.printStackTrace(); + } + try { + getReceiver().process( + new InputStreamReader(new ByteArrayInputStream(outputStream.toByteArray()), encoding)); + } + catch (final IOException e) { + throw new MetafactureException(e); + } + } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryBuilder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryBuilder.java index f168e44fc..1ea6deb66 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryBuilder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryBuilder.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_SEPARATOR; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MAX_PAYLOAD_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.TAG_LENGTH; +package org.metafacture.biblio.iso2709; import org.metafacture.framework.FormatException; @@ -31,6 +28,8 @@ */ final class DirectoryBuilder { + private static final int RADIX = 10; + private final Iso646ByteBuffer buffer; private final int fieldStartLength; @@ -41,11 +40,11 @@ final class DirectoryBuilder { private final int maxFieldLength; DirectoryBuilder(final RecordFormat format) { - buffer = new Iso646ByteBuffer(MAX_PAYLOAD_LENGTH); + buffer = new Iso646ByteBuffer(Iso2709Constants.MAX_PAYLOAD_LENGTH); fieldStartLength = format.getFieldStartLength(); fieldLengthLength = format.getFieldLengthLength(); implDefinedPartLength = format.getImplDefinedPartLength(); - entryLength = TAG_LENGTH + fieldStartLength + fieldLengthLength + + entryLength = Iso2709Constants.TAG_LENGTH + fieldStartLength + fieldLengthLength + implDefinedPartLength; maxFieldStart = calculateMaxValue(fieldStartLength); maxFieldLength = calculateMaxValue(fieldLengthLength); @@ -54,15 +53,15 @@ final class DirectoryBuilder { private int calculateMaxValue(final int digits) { assert digits >= 0; int maxValue = 1; - for (int i = 0; i < digits; i++) { - maxValue *= 10; + for (int i = 0; i < digits; ++i) { + maxValue *= RADIX; } return maxValue - 1; } void addEntries(final char[] tag, final char[] implDefinedPart, final int fieldStart, final int fieldEnd) { - assert tag.length == TAG_LENGTH; + assert tag.length == Iso2709Constants.TAG_LENGTH; assert implDefinedPart.length == implDefinedPartLength; assert fieldStart >= 0; assert fieldEnd >= fieldStart; @@ -125,7 +124,7 @@ void copyToBuffer(final byte[] destBuffer, final int fromIndex) { System.arraycopy(buffer.getByteArray(), 0, destBuffer, fromIndex, directoryLength); final int directoryEnd = fromIndex + directoryLength; - destBuffer[directoryEnd] = FIELD_SEPARATOR; + destBuffer[directoryEnd] = Iso2709Constants.FIELD_SEPARATOR; } @Override diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryEntry.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryEntry.java index 99709d964..b6ff9b1ed 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryEntry.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/DirectoryEntry.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MAX_BASE_ADDRESS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MIN_BASE_ADDRESS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LABEL_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.TAG_LENGTH; +package org.metafacture.biblio.iso2709; /** * Provides access to a directory entry. A {@code DirectoryEntry} works like @@ -43,21 +39,21 @@ class DirectoryEntry { DirectoryEntry(final Iso646ByteBuffer buffer, final RecordFormat recordFormat, final int baseAddress) { assert buffer != null; - assert baseAddress >= MIN_BASE_ADDRESS; - assert baseAddress <= MAX_BASE_ADDRESS; + assert baseAddress >= Iso2709Constants.MIN_BASE_ADDRESS; + assert baseAddress <= Iso2709Constants.MAX_BASE_ADDRESS; this.buffer = buffer; directoryEnd = baseAddress - Byte.BYTES; fieldLengthLength = recordFormat.getFieldLengthLength(); fieldStartLength = recordFormat.getFieldStartLength(); implDefinedPartLength = recordFormat.getImplDefinedPartLength(); - entryLength = TAG_LENGTH + fieldLengthLength + fieldStartLength + + entryLength = Iso2709Constants.TAG_LENGTH + fieldLengthLength + fieldStartLength + implDefinedPartLength; rewind(); } void rewind() { - currentPosition = RECORD_LABEL_LENGTH; + currentPosition = Iso2709Constants.RECORD_LABEL_LENGTH; } void gotoNext() { @@ -71,25 +67,25 @@ boolean endOfDirectoryReached() { char[] getTag() { assert currentPosition < directoryEnd; - return buffer.charsAt(currentPosition, TAG_LENGTH); + return buffer.charsAt(currentPosition, Iso2709Constants.TAG_LENGTH); } int getFieldLength() { assert currentPosition < directoryEnd; - final int fieldLengthStart = currentPosition + TAG_LENGTH; + final int fieldLengthStart = currentPosition + Iso2709Constants.TAG_LENGTH; return buffer.parseIntAt(fieldLengthStart, fieldLengthLength); } int getFieldStart() { assert currentPosition < directoryEnd; - final int fieldStartStart = currentPosition + TAG_LENGTH + + final int fieldStartStart = currentPosition + Iso2709Constants.TAG_LENGTH + fieldLengthLength; return buffer.parseIntAt(fieldStartStart, fieldStartLength); } char[] getImplDefinedPart() { assert currentPosition < directoryEnd; - final int implDefinedPartStart = currentPosition + TAG_LENGTH + + final int implDefinedPartStart = currentPosition + Iso2709Constants.TAG_LENGTH + fieldLengthLength + fieldStartLength; return buffer.charsAt(implDefinedPartStart, implDefinedPartLength); } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldHandler.java index 59ffb4787..35c82f2ee 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; /** diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldsBuilder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldsBuilder.java index a5ac854fe..038a87f80 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldsBuilder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/FieldsBuilder.java @@ -13,17 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_SEPARATOR; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IDENTIFIER_MARKER; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_SEPARATOR; +import org.metafacture.framework.FormatException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import org.metafacture.framework.FormatException; - /** * Builds a list of fields in ISO 2709:2008 format. * @@ -43,7 +40,6 @@ final class FieldsBuilder { private int undoMarker = NO_MARKER_SET; private boolean inField; - FieldsBuilder(final RecordFormat format, final int maxSize) { buffer = new Iso646ByteBuffer(maxSize); identifierLength = format.getIdentifierLength(); @@ -75,7 +71,7 @@ int endField() { assert inField; checkCapacity(Byte.BYTES); inField = false; - buffer.writeByte(FIELD_SEPARATOR); + buffer.writeByte(Iso2709Constants.FIELD_SEPARATOR); return buffer.getWritePosition(); } @@ -91,7 +87,7 @@ void appendSubfield(final char[] identifier, final String value) { final byte[] bytes = value.getBytes(charset); checkCapacity(bytes.length + identifierLength + Byte.BYTES); if (identifierLength > 0) { - buffer.writeByte(IDENTIFIER_MARKER); + buffer.writeByte(Iso2709Constants.IDENTIFIER_MARKER); buffer.writeChars(identifier); } buffer.writeBytes(bytes); @@ -126,7 +122,7 @@ void copyToBuffer(final byte[] destBuffer, final int fromIndex) { System.arraycopy(buffer.getByteArray(), 0, destBuffer, fromIndex, fieldLength); final int fieldsEnd = fromIndex + fieldLength; - destBuffer[fieldsEnd] = RECORD_SEPARATOR; + destBuffer[fieldsEnd] = Iso2709Constants.RECORD_SEPARATOR; } @Override diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso2709Constants.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso2709Constants.java index 8ed53f989..ebe9475c8 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso2709Constants.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso2709Constants.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; /** diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646ByteBuffer.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646ByteBuffer.java index 3586f96dd..ed603257e 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646ByteBuffer.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646ByteBuffer.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.iso2709; -import java.nio.charset.Charset; +package org.metafacture.biblio.iso2709; import org.metafacture.framework.FormatException; +import java.nio.charset.Charset; + /** * Provides methods for reading and writing strings and integers in a byte * array. @@ -255,7 +256,7 @@ void writeBytes(final byte[] array) { } void writeInt(final int value) { - assert 0 <= value && value < 10; + assert 0 <= value && value < RADIX; byteArray[writePosition] = (byte) (Iso646Constants.ZERO + value); writePosition += 1; } @@ -265,7 +266,7 @@ void writeInt(final int value, final int digits) { assert digits >= 0; assert (writePosition + digits) <= byteArray.length; int head = value; - for (int i = writePosition + digits - 1; i >= writePosition; i--) { + for (int i = writePosition + digits - 1; i >= writePosition; --i) { byteArray[i] = (byte) (Iso646Constants.ZERO + head % RADIX); head /= RADIX; } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646Constants.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646Constants.java index f90794bd9..eee706496 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646Constants.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Iso646Constants.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import java.nio.charset.Charset; diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Label.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Label.java index 166fa36c7..51de1fd2b 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Label.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Label.java @@ -13,24 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.BASE_ADDRESS_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.BASE_ADDRESS_START; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_LENGTH_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_START_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IDENTIFIER_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_CODES_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_CODES_START; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_DEFINED_PART_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.INDICATOR_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LABEL_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LENGTH_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LENGTH_START; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_STATUS_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RESERVED_CHAR_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.SYSTEM_CHARS_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.SYSTEM_CHARS_START; +package org.metafacture.biblio.iso2709; /** * Provides read access to the record label of a ISO 2709:2008 formatted @@ -46,7 +30,7 @@ class Label { Label(final Iso646ByteBuffer buffer) { final int bufferLength = buffer.getLength(); - assert bufferLength >= RECORD_LABEL_LENGTH; + assert bufferLength >= Iso2709Constants.RECORD_LABEL_LENGTH; this.buffer = buffer; } @@ -61,52 +45,52 @@ RecordFormat getRecordFormat() { } int getRecordLength() { - return buffer.parseIntAt(RECORD_LENGTH_START, RECORD_LENGTH_LENGTH); + return buffer.parseIntAt(Iso2709Constants.RECORD_LENGTH_START, Iso2709Constants.RECORD_LENGTH_LENGTH); } char getRecordStatus() { - return buffer.charAt(RECORD_STATUS_POS); + return buffer.charAt(Iso2709Constants.RECORD_STATUS_POS); } char[] getImplCodes() { - return buffer.charsAt(IMPL_CODES_START, IMPL_CODES_LENGTH); + return buffer.charsAt(Iso2709Constants.IMPL_CODES_START, Iso2709Constants.IMPL_CODES_LENGTH); } int getIndicatorLength() { - return buffer.parseIntAt(INDICATOR_LENGTH_POS); + return buffer.parseIntAt(Iso2709Constants.INDICATOR_LENGTH_POS); } int getIdentifierLength() { - return buffer.parseIntAt(IDENTIFIER_LENGTH_POS); + return buffer.parseIntAt(Iso2709Constants.IDENTIFIER_LENGTH_POS); } int getBaseAddress() { - return buffer.parseIntAt(BASE_ADDRESS_START, BASE_ADDRESS_LENGTH); + return buffer.parseIntAt(Iso2709Constants.BASE_ADDRESS_START, Iso2709Constants.BASE_ADDRESS_LENGTH); } char[] getSystemChars() { - return buffer.charsAt(SYSTEM_CHARS_START, SYSTEM_CHARS_LENGTH); + return buffer.charsAt(Iso2709Constants.SYSTEM_CHARS_START, Iso2709Constants.SYSTEM_CHARS_LENGTH); } int getFieldLengthLength() { - return buffer.parseIntAt(FIELD_LENGTH_LENGTH_POS); + return buffer.parseIntAt(Iso2709Constants.FIELD_LENGTH_LENGTH_POS); } int getFieldStartLength() { - return buffer.parseIntAt(FIELD_START_LENGTH_POS); + return buffer.parseIntAt(Iso2709Constants.FIELD_START_LENGTH_POS); } int getImplDefinedPartLength() { - return buffer.parseIntAt(IMPL_DEFINED_PART_LENGTH_POS); + return buffer.parseIntAt(Iso2709Constants.IMPL_DEFINED_PART_LENGTH_POS); } char getReservedChar() { - return buffer.charAt(RESERVED_CHAR_POS); + return buffer.charAt(Iso2709Constants.RESERVED_CHAR_POS); } @Override public String toString() { - return buffer.stringAt(0, RECORD_LABEL_LENGTH, Iso646Constants.CHARSET); + return buffer.stringAt(0, Iso2709Constants.RECORD_LABEL_LENGTH, Iso646Constants.CHARSET); } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/LabelBuilder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/LabelBuilder.java index f8572fdca..270d59f66 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/LabelBuilder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/LabelBuilder.java @@ -13,28 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.BASE_ADDRESS_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.BASE_ADDRESS_START; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_LENGTH_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_START_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IDENTIFIER_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_CODES_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_CODES_START; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_DEFINED_PART_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.INDICATOR_LENGTH_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MAX_BASE_ADDRESS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MAX_RECORD_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MIN_BASE_ADDRESS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MIN_RECORD_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LABEL_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LENGTH_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LENGTH_START; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_STATUS_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RESERVED_CHAR_POS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.SYSTEM_CHARS_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.SYSTEM_CHARS_START; +package org.metafacture.biblio.iso2709; import java.util.Arrays; @@ -49,87 +29,87 @@ class LabelBuilder { private static final char DEFAULT_RECORD_STATUS = ' '; - private static final char[] DEFAULT_IMPL_CODES = { ' ', ' ', ' ', ' ' }; - private static final char[] DEFAULT_SYSTEM_CHARS = { ' ', ' ', ' ' }; + private static final char[] DEFAULT_IMPL_CODES = {' ', ' ', ' ', ' '}; + private static final char[] DEFAULT_SYSTEM_CHARS = {' ', ' ', ' '}; private static final char DEFAULT_RESERVED_CHAR = ' '; private final Iso646ByteBuffer buffer; private final byte[] defaultLabel; LabelBuilder(final RecordFormat recordFormat) { - buffer = new Iso646ByteBuffer(RECORD_LABEL_LENGTH); + buffer = new Iso646ByteBuffer(Iso2709Constants.RECORD_LABEL_LENGTH); defaultLabel = buildDefaultLabel(recordFormat); } private byte[] buildDefaultLabel(final RecordFormat recordFormat) { writeRecordFormatToLabel(recordFormat); - setRecordLength(MIN_RECORD_LENGTH); + setRecordLength(Iso2709Constants.MIN_RECORD_LENGTH); setRecordStatus(DEFAULT_RECORD_STATUS); setImplCodes(DEFAULT_IMPL_CODES); - setBaseAddress(MIN_BASE_ADDRESS); + setBaseAddress(Iso2709Constants.MIN_BASE_ADDRESS); setSystemChars(DEFAULT_SYSTEM_CHARS); setReservedChar(DEFAULT_RESERVED_CHAR); return Arrays.copyOf(buffer.getByteArray(), buffer.getLength()); } private void writeRecordFormatToLabel(final RecordFormat recordFormat) { - buffer.setWritePosition(INDICATOR_LENGTH_POS); + buffer.setWritePosition(Iso2709Constants.INDICATOR_LENGTH_POS); buffer.writeInt(recordFormat.getIndicatorLength()); - buffer.setWritePosition(IDENTIFIER_LENGTH_POS); + buffer.setWritePosition(Iso2709Constants.IDENTIFIER_LENGTH_POS); buffer.writeInt(recordFormat.getIdentifierLength()); - buffer.setWritePosition(FIELD_LENGTH_LENGTH_POS); + buffer.setWritePosition(Iso2709Constants.FIELD_LENGTH_LENGTH_POS); buffer.writeInt(recordFormat.getFieldLengthLength()); - buffer.setWritePosition(FIELD_START_LENGTH_POS); + buffer.setWritePosition(Iso2709Constants.FIELD_START_LENGTH_POS); buffer.writeInt(recordFormat.getFieldStartLength()); - buffer.setWritePosition(IMPL_DEFINED_PART_LENGTH_POS); + buffer.setWritePosition(Iso2709Constants.IMPL_DEFINED_PART_LENGTH_POS); buffer.writeInt(recordFormat.getImplDefinedPartLength()); } void setRecordLength(final int recordLength) { - assert recordLength >= MIN_RECORD_LENGTH; - assert recordLength <= MAX_RECORD_LENGTH; - buffer.setWritePosition(RECORD_LENGTH_START); - buffer.writeInt(recordLength, RECORD_LENGTH_LENGTH); + assert recordLength >= Iso2709Constants.MIN_RECORD_LENGTH; + assert recordLength <= Iso2709Constants.MAX_RECORD_LENGTH; + buffer.setWritePosition(Iso2709Constants.RECORD_LENGTH_START); + buffer.writeInt(recordLength, Iso2709Constants.RECORD_LENGTH_LENGTH); } void setRecordStatus(final char recordStatus) { - buffer.setWritePosition(RECORD_STATUS_POS); + buffer.setWritePosition(Iso2709Constants.RECORD_STATUS_POS); buffer.writeChar(recordStatus); } void setImplCodes(final char[] implCodes) { - assert implCodes.length == IMPL_CODES_LENGTH; - buffer.setWritePosition(IMPL_CODES_START); + assert implCodes.length == Iso2709Constants.IMPL_CODES_LENGTH; + buffer.setWritePosition(Iso2709Constants.IMPL_CODES_START); buffer.writeChars(implCodes); } void setImplCode(final int index, final char value) { - assert 0 <= index && index < IMPL_CODES_LENGTH; - buffer.setWritePosition(IMPL_CODES_START + index); + assert 0 <= index && index < Iso2709Constants.IMPL_CODES_LENGTH; + buffer.setWritePosition(Iso2709Constants.IMPL_CODES_START + index); buffer.writeChar(value); } void setBaseAddress(final int baseAddress) { - assert baseAddress >= MIN_BASE_ADDRESS; - assert baseAddress <= MAX_BASE_ADDRESS; - buffer.setWritePosition(BASE_ADDRESS_START); - buffer.writeInt(baseAddress, BASE_ADDRESS_LENGTH); + assert baseAddress >= Iso2709Constants.MIN_BASE_ADDRESS; + assert baseAddress <= Iso2709Constants.MAX_BASE_ADDRESS; + buffer.setWritePosition(Iso2709Constants.BASE_ADDRESS_START); + buffer.writeInt(baseAddress, Iso2709Constants.BASE_ADDRESS_LENGTH); } void setSystemChars(final char[] systemChars) { - assert systemChars.length == SYSTEM_CHARS_LENGTH; - buffer.setWritePosition(SYSTEM_CHARS_START); + assert systemChars.length == Iso2709Constants.SYSTEM_CHARS_LENGTH; + buffer.setWritePosition(Iso2709Constants.SYSTEM_CHARS_START); buffer.writeChars(systemChars); } void setSystemChar(final int index, final char value) { - assert 0 <= index && index < SYSTEM_CHARS_LENGTH; - buffer.setWritePosition(SYSTEM_CHARS_START + index); + assert 0 <= index && index < Iso2709Constants.SYSTEM_CHARS_LENGTH; + buffer.setWritePosition(Iso2709Constants.SYSTEM_CHARS_START + index); buffer.writeChar(value); } void setReservedChar(final char reservedChar) { - buffer.setWritePosition(RESERVED_CHAR_POS); + buffer.setWritePosition(Iso2709Constants.RESERVED_CHAR_POS); buffer.writeChar(reservedChar); } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Record.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Record.java index 38ba469be..c72b5b4e4 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Record.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/Record.java @@ -13,19 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.FIELD_SEPARATOR; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IDENTIFIER_MARKER; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MIN_BASE_ADDRESS; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MIN_RECORD_LENGTH; +import org.metafacture.commons.Require; +import org.metafacture.framework.FormatException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import org.metafacture.commons.Require; -import org.metafacture.framework.FormatException; - /** * Reads a record in ISO 2709:2008 format from a byte array. * @@ -36,7 +32,7 @@ public final class Record { private static final int RECORD_ID_MISSING = -1; private static final char[] EMPTY_IDENTIFIER = new char[0]; private static final byte[] DATA_SEPARATORS = { - FIELD_SEPARATOR, IDENTIFIER_MARKER + Iso2709Constants.FIELD_SEPARATOR, Iso2709Constants.IDENTIFIER_MARKER }; private final Iso646ByteBuffer buffer; @@ -73,13 +69,13 @@ public Record(final byte[] recordData) { } private void checkRecordDataLength(final byte[] recordData) { - if (recordData.length < MIN_RECORD_LENGTH) { + if (recordData.length < Iso2709Constants.MIN_RECORD_LENGTH) { throw new FormatException("record is too short"); } } private void checkBaseAddress() { - if (baseAddress < MIN_BASE_ADDRESS || baseAddress > buffer.getLength() - 1) { + if (baseAddress < Iso2709Constants.MIN_BASE_ADDRESS || baseAddress > buffer.getLength() - 1) { throw new FormatException("base address is out of range"); } } @@ -164,40 +160,43 @@ public String getRecordId() { public String getLabel() { return label.toString(); } + /** * Iterates through all fields in the record and calls the appropriate method * on the supplied {@link FieldHandler} instance. * - * @param fieldHandler instance of field handler. Must not be null. + * @param currentFieldHandler instance of field handler. Must not be null. */ - public void processFields(final FieldHandler fieldHandler) { - this.fieldHandler = Require.notNull(fieldHandler); + public void processFields(final FieldHandler currentFieldHandler) { + fieldHandler = Require.notNull(currentFieldHandler); boolean continuedField = false; directoryEntry.rewind(); while (!directoryEntry.endOfDirectoryReached()) { if (continuedField) { fieldHandler.additionalImplDefinedPart( directoryEntry.getImplDefinedPart()); - } else { + } + else { processField(); } continuedField = directoryEntry.isContinuedField(); directoryEntry.gotoNext(); } - this.fieldHandler = null; + fieldHandler = null; } private void processField() { if (directoryEntry.isReferenceField()) { processReferenceField(); - } else { + } + else { processDataField(); } } private void processReferenceField() { final int fieldStart = baseAddress + directoryEntry.getFieldStart(); - final int fieldLength = buffer.distanceTo(FIELD_SEPARATOR, fieldStart); + final int fieldLength = buffer.distanceTo(Iso2709Constants.FIELD_SEPARATOR, fieldStart); final String value = buffer.stringAt(fieldStart, fieldLength, charset); fieldHandler.referenceField(directoryEntry.getTag(), directoryEntry.getImplDefinedPart(), value); @@ -214,7 +213,7 @@ private void processDataField() { private void processDataValues(final int fromIndex) { int start = fromIndex; - while (buffer.byteAt(start) != FIELD_SEPARATOR) { + while (buffer.byteAt(start) != Iso2709Constants.FIELD_SEPARATOR) { start = processDataValue(start); } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordBuilder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordBuilder.java index f4b9deb54..5c47701c9 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordBuilder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordBuilder.java @@ -13,21 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; -import static org.metafacture.biblio.iso2709.Iso2709Constants.IMPL_CODES_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.MAX_PAYLOAD_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.RECORD_LABEL_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.SYSTEM_CHARS_LENGTH; -import static org.metafacture.biblio.iso2709.Iso2709Constants.TAG_LENGTH; +import org.metafacture.commons.Require; +import org.metafacture.framework.FormatException; import java.nio.charset.Charset; import java.util.Arrays; import java.util.regex.Pattern; -import org.metafacture.commons.Require; -import org.metafacture.framework.FormatException; - /** * Builds records in ISO2709:2008 format. * @@ -37,7 +32,7 @@ public final class RecordBuilder { private static final char[] EMPTY_IDENTIFIER = new char[0]; - private static final char[] ID_FIELD_TAG = { '0', '0', '1' }; + private static final char[] ID_FIELD_TAG = {'0', '0', '1'}; private static final Pattern REFERENCE_FIELD_TAG_PATTERN = Pattern.compile( "^00[1-9a-zA-Z]$"); private static final Pattern DATA_FIELD_TAG_PATTERN = Pattern.compile( @@ -55,7 +50,7 @@ public final class RecordBuilder { private final char[] defaultIndicators; private final char[] defaultIdentifier; - private final char[] tag = new char[TAG_LENGTH]; + private final char[] tag = new char[Iso2709Constants.TAG_LENGTH]; private final char[] implDefinedPart; private AppendState appendState; @@ -65,7 +60,7 @@ public RecordBuilder(final RecordFormat recordFormat) { Require.notNull(recordFormat); label = new LabelBuilder(recordFormat); directory = new DirectoryBuilder(recordFormat); - fields = new FieldsBuilder(recordFormat, MAX_PAYLOAD_LENGTH); + fields = new FieldsBuilder(recordFormat, Iso2709Constants.MAX_PAYLOAD_LENGTH); indicatorLength = recordFormat.getIndicatorLength(); identifierLength = recordFormat.getIdentifierLength(); implDefinedPartLength = recordFormat.getImplDefinedPartLength(); @@ -73,7 +68,8 @@ public RecordBuilder(final RecordFormat recordFormat) { defaultIndicators = arrayOfNSpaceChars(indicatorLength); if (identifierLength > 1) { defaultIdentifier = arrayOfNSpaceChars(identifierLength - 1); - } else { + } + else { defaultIdentifier = EMPTY_IDENTIFIER; } implDefinedPart = new char[implDefinedPartLength]; @@ -101,26 +97,26 @@ public void setRecordStatus(final char recordStatus) { public void setImplCodes(final char[] implCodes) { Require.notNull(implCodes); - Require.that(implCodes.length == IMPL_CODES_LENGTH); + Require.that(implCodes.length == Iso2709Constants.IMPL_CODES_LENGTH); require7BitAscii(implCodes); label.setImplCodes(implCodes); } public void setImplCode(final int index, final char implCode) { - Require.that(0 <= index && index < IMPL_CODES_LENGTH); + Require.that(0 <= index && index < Iso2709Constants.IMPL_CODES_LENGTH); require7BitAscii(implCode); label.setImplCode(index, implCode); } public void setSystemChars(final char[] systemChars) { Require.notNull(systemChars); - Require.that(systemChars.length == SYSTEM_CHARS_LENGTH); + Require.that(systemChars.length == Iso2709Constants.SYSTEM_CHARS_LENGTH); require7BitAscii(systemChars); label.setSystemChars(systemChars); } public void setSystemChar(final int index, final char systemChar) { - Require.that(0 <= index && index < SYSTEM_CHARS_LENGTH); + Require.that(0 <= index && index < Iso2709Constants.SYSTEM_CHARS_LENGTH); require7BitAscii(systemChar); label.setSystemChar(index, systemChar); } @@ -131,81 +127,79 @@ public void setReservedChar(final char reservedChar) { } public void appendIdentifierField(final String value) { - appendIdentifierField(defaultImplDefinedPart,value); + appendIdentifierField(defaultImplDefinedPart, value); } - public void appendIdentifierField(final char[] implDefinedPart, - final String value) { + public void appendIdentifierField(final char[] currentImplDefinedPart, final String value) { requireNotInDataField(); requireNotAppendingReferenceFields(); requireNotAppendingDataFields(); if (appendState != AppendState.ID_FIELD) { throw new IllegalStateException("no id field allowed"); } - appendReferenceField(ID_FIELD_TAG, implDefinedPart, value); + appendReferenceField(ID_FIELD_TAG, currentImplDefinedPart, value); } - public void appendReferenceField(final char[] tag, final String value) { - appendReferenceField(tag, defaultImplDefinedPart, value); + public void appendReferenceField(final char[] currentTag, final String value) { + appendReferenceField(currentTag, defaultImplDefinedPart, value); } - public void appendReferenceField(final char[] tag, - final char[] implDefinedPart, final String value) { + public void appendReferenceField(final char[] currentTag, final char[] currentImplDefinedPart, final String value) { requireNotInDataField(); requireNotAppendingDataFields(); - Require.notNull(tag); - Require.notNull(implDefinedPart); - Require.that(implDefinedPart.length == implDefinedPartLength); - require7BitAscii(implDefinedPart); + Require.notNull(currentTag); + Require.notNull(currentImplDefinedPart); + Require.that(currentImplDefinedPart.length == implDefinedPartLength); + require7BitAscii(currentImplDefinedPart); Require.notNull(value); - checkValidReferenceFieldTag(tag); - final int fieldStart = fields.startField(); + checkValidReferenceFieldTag(currentTag); + final int currentFieldStart = fields.startField(); fields.appendValue(value); final int fieldEnd = fields.endField(); try { - directory.addEntries(tag, implDefinedPart, fieldStart, fieldEnd); - } catch (final FormatException e) { + directory.addEntries(currentTag, currentImplDefinedPart, currentFieldStart, fieldEnd); + } + catch (final FormatException e) { fields.undoLastField(); throw e; } appendState = AppendState.REFERENCE_FIELD; } - private void checkValidReferenceFieldTag(final char[] tag) { - if (!REFERENCE_FIELD_TAG_PATTERN.matcher(String.valueOf(tag)).matches()) { + private void checkValidReferenceFieldTag(final char[] currentTag) { + if (!REFERENCE_FIELD_TAG_PATTERN.matcher(String.valueOf(currentTag)).matches()) { throw new FormatException("invalid tag format for reference field"); } } - public void startDataField(final char[] tag) { - startDataField(tag, defaultIndicators); + public void startDataField(final char[] currentTag) { + startDataField(currentTag, defaultIndicators); } - public void startDataField(final char[] tag, final char[] indicators) { - startDataField(tag, indicators, defaultImplDefinedPart); + public void startDataField(final char[] currentTag, final char[] indicators) { + startDataField(currentTag, indicators, defaultImplDefinedPart); } - public void startDataField(final char[] tag, final char[] indicators, - final char[] implDefinedPart) { + public void startDataField(final char[] currentTag, final char[] indicators, final char[] currentImplDefinedPart) { requireNotInDataField(); - Require.notNull(tag); + Require.notNull(currentTag); Require.notNull(indicators); Require.that(indicators.length == indicatorLength); require7BitAscii(indicators); - Require.notNull(implDefinedPart); - Require.that(implDefinedPart.length == implDefinedPartLength); - require7BitAscii(implDefinedPart); + Require.notNull(currentImplDefinedPart); + Require.that(currentImplDefinedPart.length == implDefinedPartLength); + require7BitAscii(currentImplDefinedPart); - checkValidDataFieldTag(tag); - copyArray(tag, this.tag); - copyArray(implDefinedPart, this.implDefinedPart); + checkValidDataFieldTag(currentTag); + copyArray(currentTag, tag); + copyArray(currentImplDefinedPart, implDefinedPart); fieldStart = fields.startField(indicators); appendState = AppendState.IN_DATA_FIELD; } - private void checkValidDataFieldTag(final char[] tag) { - if (!DATA_FIELD_TAG_PATTERN.matcher(String.valueOf(tag)).matches()) { + private void checkValidDataFieldTag(final char[] currentTag) { + if (!DATA_FIELD_TAG_PATTERN.matcher(String.valueOf(currentTag)).matches()) { throw new FormatException("invalid tag format for data field"); } } @@ -220,7 +214,8 @@ public void endDataField() { appendState = AppendState.DATA_FIELD; try { directory.addEntries(tag, implDefinedPart, fieldStart, fieldEnd); - } catch (final FormatException e) { + } + catch (final FormatException e) { fields.undoLastField(); throw e; } @@ -243,13 +238,13 @@ public void appendSubfield(final char[] identifier, final String value) { public byte[] build() { requireNotInDataField(); - final int baseAddress = RECORD_LABEL_LENGTH + directory.length(); + final int baseAddress = Iso2709Constants.RECORD_LABEL_LENGTH + directory.length(); final int recordLength = baseAddress + fields.length(); label.setBaseAddress(baseAddress); label.setRecordLength(recordLength); final byte[] recordBuffer = new byte[recordLength]; label.copyToBuffer(recordBuffer); - directory.copyToBuffer(recordBuffer, RECORD_LABEL_LENGTH); + directory.copyToBuffer(recordBuffer, Iso2709Constants.RECORD_LABEL_LENGTH); fields.copyToBuffer(recordBuffer, baseAddress); return recordBuffer; } @@ -300,9 +295,9 @@ public void reset() { @Override public String toString() { - return "label: " + label.toString() + "\n" - + "directory: " + directory.toString() + "\n" - + "fields: " + fields.toString(); + return "label: " + label.toString() + "\n" + + "directory: " + directory.toString() + "\n" + + "fields: " + fields.toString(); } private enum AppendState { diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordFormat.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordFormat.java index cd7ecb202..0fe9756cf 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordFormat.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/iso2709/RecordFormat.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.iso2709; -import java.util.Arrays; +package org.metafacture.biblio.iso2709; import org.metafacture.commons.Require; +import java.util.Arrays; + /** * Holds the configuration of an instance of the ISO2709:2008 format. * @@ -30,19 +31,19 @@ public final class RecordFormat { /** * The number of characters in the field tags. */ - public final int TAG_LENGTH = Iso2709Constants.TAG_LENGTH; + public static final int TAG_LENGTH = Iso2709Constants.TAG_LENGTH; /** * The number of characters in the implementation codes element of the * record leader. */ - public final int IMPL_CODES_LENGTH = Iso2709Constants.IMPL_CODES_LENGTH; + public static final int IMPL_CODES_LENGTH = Iso2709Constants.IMPL_CODES_LENGTH; /** * The number of characters in the system characters element of the * record leader. */ - public final int SYSTEM_CHARS_LENGTH = Iso2709Constants.SYSTEM_CHARS_LENGTH; + public static final int SYSTEM_CHARS_LENGTH = Iso2709Constants.SYSTEM_CHARS_LENGTH; private final int indicatorLength; private final int identifierLength; @@ -110,19 +111,19 @@ public boolean equals(final Object obj) { } if (obj instanceof RecordFormat) { final RecordFormat other = (RecordFormat) obj; - return indicatorLength == other.indicatorLength - && identifierLength == other.identifierLength - && fieldLengthLength == other.fieldLengthLength - && fieldStartLength == other.fieldStartLength - && implDefinedPartLength == other.implDefinedPartLength; + return indicatorLength == other.indicatorLength && + identifierLength == other.identifierLength && + fieldLengthLength == other.fieldLengthLength && + fieldStartLength == other.fieldStartLength && + implDefinedPartLength == other.implDefinedPartLength; } return false; } @Override public int hashCode() { - final int[] items = { indicatorLength, identifierLength, fieldLengthLength, - fieldStartLength, implDefinedPartLength }; + final int[] items = {indicatorLength, identifierLength, fieldLengthLength, + fieldStartLength, implDefinedPartLength}; return Arrays.hashCode(items); } @@ -137,44 +138,49 @@ public String toString() { public static class Builder { + private static final int RADIX = 10; + private int indicatorLength; private int identifierLength; private int fieldLengthLength; private int fieldStartLength; private int implDefinedPartLength; - public Builder withIndicatorLength(final int indicatorLength) { - Require.notNegative(indicatorLength); - Require.that(indicatorLength <= 9); - this.indicatorLength = indicatorLength; + Builder() { + } + + public Builder withIndicatorLength(final int currentIndicatorLength) { + Require.notNegative(currentIndicatorLength); + Require.that(currentIndicatorLength < RADIX); + indicatorLength = currentIndicatorLength; return this; } - public Builder withIdentifierLength(final int identifierLength) { - Require.notNegative(identifierLength); - Require.that(identifierLength <= 9); - this.identifierLength = identifierLength; + public Builder withIdentifierLength(final int currentIdentifierLength) { + Require.notNegative(currentIdentifierLength); + Require.that(currentIdentifierLength < RADIX); + identifierLength = currentIdentifierLength; return this; } - public Builder withFieldLengthLength(final int fieldLengthLength) { - Require.that(fieldLengthLength > 0); - Require.that(fieldLengthLength <= 9); - this.fieldLengthLength = fieldLengthLength; + public Builder withFieldLengthLength(final int currentFieldLengthLength) { + Require.that(currentFieldLengthLength > 0); + Require.that(currentFieldLengthLength < RADIX); + fieldLengthLength = currentFieldLengthLength; return this; } - public Builder withFieldStartLength(final int fieldStartLength) { - Require.that(fieldStartLength > 0); - Require.that(fieldStartLength <= 9); - this.fieldStartLength = fieldStartLength; + public Builder withFieldStartLength(final int currentFieldStartLength) { + Require.that(currentFieldStartLength > 0); + Require.that(currentFieldStartLength < RADIX); + fieldStartLength = currentFieldStartLength; return this; } - public Builder withImplDefinedPartLength(final int implDefinedPartLength) { - Require.notNegative(implDefinedPartLength); - Require.that(implDefinedPartLength <= 9); - this.implDefinedPartLength = implDefinedPartLength; + public Builder withImplDefinedPartLength(final int currentImplDefinedPartLength) { + Require.notNegative(currentImplDefinedPartLength); + Require.that(currentImplDefinedPartLength < RADIX); + implDefinedPartLength = currentImplDefinedPartLength; return this; } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Constants.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Constants.java index f729ff513..a8cd083ce 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Constants.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Constants.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; +import org.metafacture.biblio.iso2709.RecordFormat; + import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import org.metafacture.biblio.iso2709.RecordFormat; - /** * Useful constants for the MARC 21 format. * @@ -27,43 +28,43 @@ */ final class Marc21Constants { - static final RecordFormat MARC21_FORMAT = RecordFormat.create() - .withIndicatorLength(2) - .withIdentifierLength(2) - .withFieldLengthLength(4) - .withFieldStartLength(5) - .withImplDefinedPartLength(0) - .build(); + static final RecordFormat MARC21_FORMAT = RecordFormat.create() + .withIndicatorLength(2) + .withIdentifierLength(2) + .withFieldLengthLength(4) // checkstyle-disable-line MagicNumber + .withFieldStartLength(5) // checkstyle-disable-line MagicNumber + .withImplDefinedPartLength(0) + .build(); - static final Charset MARC21_CHARSET = StandardCharsets.UTF_8; + static final Charset MARC21_CHARSET = StandardCharsets.UTF_8; - static final int RECORD_TYPE_INDEX = 0; - static final int BIBLIOGRAPHIC_LEVEL_INDEX = 1; - static final int TYPE_OF_CONTROL_INDEX = 2; - static final int CHARACTER_CODING_INDEX = 3; - static final int ENCODING_LEVEL_INDEX = 0; - static final int CATALOGING_FORM_INDEX = 1; - static final int MULTIPART_LEVEL_INDEX = 2; + static final int RECORD_TYPE_INDEX = 0; + static final int BIBLIOGRAPHIC_LEVEL_INDEX = 1; + static final int TYPE_OF_CONTROL_INDEX = 2; + static final int CHARACTER_CODING_INDEX = 3; + static final int ENCODING_LEVEL_INDEX = 0; + static final int CATALOGING_FORM_INDEX = 1; + static final int MULTIPART_LEVEL_INDEX = 2; - static final char[] RECORD_STATUS_CODES = { 'a', 'c', 'd', 'n', 'p' }; - static final char[] RECORD_TYPE_CODES = { - 'a', 'c', 'd', 'e', 'f', 'g', 'i', 'j', 'k', 'm', 'o', 'p', 'r', 't' - }; - static final char[] BIBLIOGRAPHIC_LEVEL_CODES = { - 'a', 'b', 'c', 'd', 'i', 'm', 's' - }; - static final char[] TYPE_OF_CONTROL_CODES = { ' ', 'a' }; - static final char[] CHARACTER_CODING_CODES = { 'a' }; - static final char[] ENCODING_LEVEL_CODES = { - ' ', '1', '2', '3', '4', '5', '7', '8', 'u', 'z' - }; - static final char[] CATALOGING_FORM_CODES = { ' ', 'a', 'c', 'i', 'u' }; - static final char[] MULTIPART_LEVEL_CODES = { ' ', 'a', 'b', 'c' }; + static final char[] RECORD_STATUS_CODES = {'a', 'c', 'd', 'n', 'p'}; + static final char[] RECORD_TYPE_CODES = { + 'a', 'c', 'd', 'e', 'f', 'g', 'i', 'j', 'k', 'm', 'o', 'p', 'r', 't' + }; + static final char[] BIBLIOGRAPHIC_LEVEL_CODES = { + 'a', 'b', 'c', 'd', 'i', 'm', 's' + }; + static final char[] TYPE_OF_CONTROL_CODES = {' ', 'a'}; + static final char[] CHARACTER_CODING_CODES = {'a'}; + static final char[] ENCODING_LEVEL_CODES = { + ' ', '1', '2', '3', '4', '5', '7', '8', 'u', 'z' + }; + static final char[] CATALOGING_FORM_CODES = {' ', 'a', 'c', 'i', 'u'}; + static final char[] MULTIPART_LEVEL_CODES = {' ', 'a', 'b', 'c'}; - static final char RESERVED_CHAR = '0'; + static final char RESERVED_CHAR = '0'; - private Marc21Constants() { - throw new AssertionError("class should not be instantiated"); - } + private Marc21Constants() { + throw new AssertionError("class should not be instantiated"); + } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Decoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Decoder.java index e52b54e4e..29080313c 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Decoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Decoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; import org.metafacture.biblio.iso2709.FieldHandler; @@ -134,14 +135,16 @@ @Out(StreamReceiver.class) @Description("Decodes MARC 21 records") @FluxCommand("decode-marc21") -public final class Marc21Decoder - extends DefaultObjectPipe { +public final class Marc21Decoder extends DefaultObjectPipe { private final FieldHandler fieldHandler = new Marc21Handler(); private boolean ignoreMissingId; private boolean emitLeaderAsWhole; + public Marc21Decoder() { + } + /** * Controls whether the decoder aborts processing if a record has no * identifier. A {@link MissingIdException} is thrown in these cases. @@ -227,27 +230,28 @@ private String tryGetRecordId(final Record record) { private void emitLeader(final Record record) { getReceiver().startEntity(Marc21EventNames.LEADER_ENTITY); - if (emitLeaderAsWhole){ + if (emitLeaderAsWhole) { getReceiver().literal(Marc21EventNames.LEADER_ENTITY, record.getLabel()); - }else { - final char[] implCodes = record.getImplCodes(); - final char[] systemChars = record.getSystemChars(); - getReceiver().literal(Marc21EventNames.RECORD_STATUS_LITERAL, String.valueOf( - record.getRecordStatus())); - getReceiver().literal(Marc21EventNames.RECORD_TYPE_LITERAL, String.valueOf( - implCodes[Marc21Constants.RECORD_TYPE_INDEX])); - getReceiver().literal(Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL, String.valueOf( - implCodes[Marc21Constants.BIBLIOGRAPHIC_LEVEL_INDEX])); - getReceiver().literal(Marc21EventNames.TYPE_OF_CONTROL_LITERAL, String.valueOf( - implCodes[Marc21Constants.TYPE_OF_CONTROL_INDEX])); - getReceiver().literal(Marc21EventNames.CHARACTER_CODING_LITERAL, String.valueOf( - implCodes[Marc21Constants.CHARACTER_CODING_INDEX])); - getReceiver().literal(Marc21EventNames.ENCODING_LEVEL_LITERAL, String.valueOf( - systemChars[Marc21Constants.ENCODING_LEVEL_INDEX])); - getReceiver().literal(Marc21EventNames.CATALOGING_FORM_LITERAL, String.valueOf( - systemChars[Marc21Constants.CATALOGING_FORM_INDEX])); - getReceiver().literal(Marc21EventNames.MULTIPART_LEVEL_LITERAL, String.valueOf( - systemChars[Marc21Constants.MULTIPART_LEVEL_INDEX])); + } + else { + final char[] implCodes = record.getImplCodes(); + final char[] systemChars = record.getSystemChars(); + getReceiver().literal(Marc21EventNames.RECORD_STATUS_LITERAL, String.valueOf( + record.getRecordStatus())); + getReceiver().literal(Marc21EventNames.RECORD_TYPE_LITERAL, String.valueOf( + implCodes[Marc21Constants.RECORD_TYPE_INDEX])); + getReceiver().literal(Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL, String.valueOf( + implCodes[Marc21Constants.BIBLIOGRAPHIC_LEVEL_INDEX])); + getReceiver().literal(Marc21EventNames.TYPE_OF_CONTROL_LITERAL, String.valueOf( + implCodes[Marc21Constants.TYPE_OF_CONTROL_INDEX])); + getReceiver().literal(Marc21EventNames.CHARACTER_CODING_LITERAL, String.valueOf( + implCodes[Marc21Constants.CHARACTER_CODING_INDEX])); + getReceiver().literal(Marc21EventNames.ENCODING_LEVEL_LITERAL, String.valueOf( + systemChars[Marc21Constants.ENCODING_LEVEL_INDEX])); + getReceiver().literal(Marc21EventNames.CATALOGING_FORM_LITERAL, String.valueOf( + systemChars[Marc21Constants.CATALOGING_FORM_INDEX])); + getReceiver().literal(Marc21EventNames.MULTIPART_LEVEL_LITERAL, String.valueOf( + systemChars[Marc21Constants.MULTIPART_LEVEL_INDEX])); } getReceiver().endEntity(); } @@ -257,6 +261,9 @@ private void emitLeader(final Record record) { */ private final class Marc21Handler implements FieldHandler { + Marc21Handler() { + } + @Override public void referenceField(final char[] tag, final char[] implDefinedPart, final String value) { diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java index db0839de8..5bf3643fc 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21Encoder.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.marc21; -import java.util.Arrays; +package org.metafacture.biblio.marc21; import org.metafacture.biblio.iso2709.RecordBuilder; import org.metafacture.framework.FluxCommand; @@ -27,6 +26,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.util.Arrays; + /** * Encodes a stream in MARC21 format. *

@@ -83,6 +84,7 @@ public Marc21Encoder() { builder = new RecordBuilder(Marc21Constants.MARC21_FORMAT); builder.setCharset(Marc21Constants.MARC21_CHARSET); } + /** * Controls whether the record identifier field ("001") is * generated from the record id in the start-record event. If id field @@ -117,8 +119,8 @@ public void startRecord(final String identifier) { private void initLeader() { builder.setRecordStatus(' '); - builder.setImplCodes(new char[]{ ' ', ' ', ' ', ' ' }); - builder.setSystemChars(new char[]{ ' ', ' ', ' ' }); + builder.setImplCodes(new char[]{' ', ' ', ' ', ' '}); + builder.setSystemChars(new char[]{' ', ' ', ' '}); builder.setReservedChar(Marc21Constants.RESERVED_CHAR); } @@ -136,7 +138,8 @@ public void startEntity(final String name) { } if (Marc21EventNames.LEADER_ENTITY.equals(name)) { state = State.IN_LEADER_ENTITY; - } else { + } + else { startField(name); state = State.IN_FIELD_ENTITY; } @@ -153,7 +156,6 @@ private void startField(final String name) { builder.startDataField(tag, indicators); } - @Override public void endEntity() { if (state.equals(State.IN_FIELD_ENTITY)) { @@ -229,18 +231,17 @@ private void requireValidCode(final char code, final char[] validCodes) { return; } } - throw new FormatException("invalid code '" + code + "'; allowed codes are: " - + Arrays.toString(validCodes)); + throw new FormatException("invalid code '" + code + "'; allowed codes are: " + Arrays.toString(validCodes)); } private void processTopLevelLiteral(final String name, final String value) { - if (Marc21EventNames.MARCXML_TYPE_LITERAL.equals(name)) { - // MarcXmlHandler may output `type` literals. The - // information in these literals is not included in - // marc21 records. Therefore, we need to ignore - // these literals here. + if (Marc21EventNames.MARCXML_TYPE_LITERAL.equals(name)) { + // MarcXmlHandler may output `type` literals. The + // information in these literals is not included in + // marc21 records. Therefore, we need to ignore + // these literals here. return; - } + } builder.appendReferenceField(name.toCharArray(), value); } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21EventNames.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21EventNames.java index 1b0e6e1aa..fa842b137 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21EventNames.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/Marc21EventNames.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; /** @@ -22,127 +23,127 @@ */ public final class Marc21EventNames { - /** - * Name of the literal event which contains the value of the - * type attribute of the record element. - */ - public static final String MARCXML_TYPE_LITERAL = "type"; + /** + * Name of the literal event which contains the value of the + * type attribute of the record element. + */ + public static final String MARCXML_TYPE_LITERAL = "type"; - /** - * Name of the entity event which contains the bibliographic - * information in the record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String LEADER_ENTITY = "leader"; + /** + * Name of the entity event which contains the bibliographic + * information in the record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String LEADER_ENTITY = "leader"; - /** - * Name of the literal event emitted for the record status field. - *

- * The name of the literal is "{@value #RECORD_STATUS_LITERAL}". - *

- * The record status is specified at position 5 in the record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String RECORD_STATUS_LITERAL = "status"; + /** + * Name of the literal event emitted for the record status field. + *

+ * The name of the literal is "{@value #RECORD_STATUS_LITERAL}". + *

+ * The record status is specified at position 5 in the record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String RECORD_STATUS_LITERAL = "status"; - /** - * Name of the literal event emitted for the bibliographic level - * field. - *

- * The name of the literal is - * "{@value #BIBLIOGRAPHIC_LEVEL_LITERAL}". - *

- * The bibliographic level is specified at position 7 in the record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String BIBLIOGRAPHIC_LEVEL_LITERAL = "bibliographicLevel"; + /** + * Name of the literal event emitted for the bibliographic level + * field. + *

+ * The name of the literal is + * "{@value #BIBLIOGRAPHIC_LEVEL_LITERAL}". + *

+ * The bibliographic level is specified at position 7 in the record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String BIBLIOGRAPHIC_LEVEL_LITERAL = "bibliographicLevel"; - /** - * Name of the literal event emitted for the type of control field. - *

- * The name of the literal is "{@value #TYPE_OF_CONTROL_LITERAL}". - *

- * The type of control is specified at position 8 in the record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String TYPE_OF_CONTROL_LITERAL = "typeOfControl"; + /** + * Name of the literal event emitted for the type of control field. + *

+ * The name of the literal is "{@value #TYPE_OF_CONTROL_LITERAL}". + *

+ * The type of control is specified at position 8 in the record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String TYPE_OF_CONTROL_LITERAL = "typeOfControl"; - /** - * Name of the literal event emitted for the character coding scheme - * field. - *

- * The name of the literal is "{@value #CHARACTER_CODING_LITERAL}". - *

- * The character coding scheme is specified at position 9 in the record - * leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String CHARACTER_CODING_LITERAL = "characterCodingScheme"; + /** + * Name of the literal event emitted for the character coding scheme + * field. + *

+ * The name of the literal is "{@value #CHARACTER_CODING_LITERAL}". + *

+ * The character coding scheme is specified at position 9 in the record + * leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String CHARACTER_CODING_LITERAL = "characterCodingScheme"; - /** - * Name of the literal event emitted for the encoding level field. - *

- * The name of the literal is "{@value #ENCODING_LEVEL_LITERAL}". - *

- * The encoding level is specified at position 17 in the record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String ENCODING_LEVEL_LITERAL = "encodingLevel"; + /** + * Name of the literal event emitted for the encoding level field. + *

+ * The name of the literal is "{@value #ENCODING_LEVEL_LITERAL}". + *

+ * The encoding level is specified at position 17 in the record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String ENCODING_LEVEL_LITERAL = "encodingLevel"; - /** - * Name of the literal event emitted for the descriptive cataloging - * form field. - *

- * The name of the literal is "{@value #CATALOGING_FORM_LITERAL}". - *

- * The descriptive cataloging form is specified at position 18 in the record - * leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String CATALOGING_FORM_LITERAL = "catalogingForm"; + /** + * Name of the literal event emitted for the descriptive cataloging + * form field. + *

+ * The name of the literal is "{@value #CATALOGING_FORM_LITERAL}". + *

+ * The descriptive cataloging form is specified at position 18 in the record + * leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String CATALOGING_FORM_LITERAL = "catalogingForm"; - /** - * Name of the literal event emitted for the multipart resource - * record level field. - *

- * The name of the literal is "{@value #MULTIPART_LEVEL_LITERAL}". - *

- * The multipart resource record level is specified at position 19 in the - * record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String MULTIPART_LEVEL_LITERAL = "multipartLevel"; + /** + * Name of the literal event emitted for the multipart resource + * record level field. + *

+ * The name of the literal is "{@value #MULTIPART_LEVEL_LITERAL}". + *

+ * The multipart resource record level is specified at position 19 in the + * record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String MULTIPART_LEVEL_LITERAL = "multipartLevel"; - /** - * Name of the literal event emitted for the type of record field. - *

- * The name of the literal is "{@value #RECORD_TYPE_LITERAL}". - *

- * The type of record is specified at position 6 in the record leader. - * - * @see MARC 21 - * Standard: Record Leader - */ - public static final String RECORD_TYPE_LITERAL = "type"; + /** + * Name of the literal event emitted for the type of record field. + *

+ * The name of the literal is "{@value #RECORD_TYPE_LITERAL}". + *

+ * The type of record is specified at position 6 in the record leader. + * + * @see MARC 21 + * Standard: Record Leader + */ + public static final String RECORD_TYPE_LITERAL = "type"; - private Marc21EventNames() { - throw new AssertionError("class should not be instantiated"); - } + private Marc21EventNames() { + throw new AssertionError("class should not be instantiated"); + } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java index 84b4d8aa6..43df44e5f 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java @@ -15,8 +15,6 @@ package org.metafacture.biblio.marc21; -import java.util.Collections; - import org.metafacture.commons.XmlUtil; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -27,6 +25,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.util.Collections; + /** * Encodes a stream into MARCXML. * @@ -62,6 +62,15 @@ public final class MarcXmlEncoder extends DefaultStreamPipe"; + private static final int LEADER_ENTITY_LENGTH = 5; + + private static final int IND1_BEGIN = 3; + private static final int IND1_END = 4; + private static final int IND2_BEGIN = 4; + private static final int IND2_END = 5; + private static final int TAG_BEGIN = 0; + private static final int TAG_END = 3; + private final StringBuilder builder; private boolean atStreamStart; @@ -88,15 +97,15 @@ public MarcXmlEncoder() { this.formatted = true; } - public void omitXmlDeclaration(boolean omitXmlDeclaration) { - this.omitXmlDeclaration = omitXmlDeclaration; + public void omitXmlDeclaration(final boolean currentOmitXmlDeclaration) { + omitXmlDeclaration = currentOmitXmlDeclaration; } - public void setXmlVersion(String xmlVersion) { + public void setXmlVersion(final String xmlVersion) { this.xmlVersion = xmlVersion; } - public void setXmlEncoding(String xmlEncoding) { + public void setXmlEncoding(final String xmlEncoding) { this.xmlEncoding = xmlEncoding; } @@ -106,7 +115,7 @@ public void setXmlEncoding(String xmlEncoding) { * @param formatted * True, if formatting is activated. */ - public void setFormatted(boolean formatted) { + public void setFormatted(final boolean formatted) { this.formatted = formatted; } @@ -143,15 +152,15 @@ public void endRecord() { public void startEntity(final String name) { currentEntity = name; if (!name.equals(Marc21EventNames.LEADER_ENTITY)) { - if (name.length() != 5) { - String message = String.format("Entity too short." + "Got a string ('%s') of length %d." - + "Expected a length of 5 (field + indicators).", name, name.length()); + if (name.length() != LEADER_ENTITY_LENGTH) { + final String message = String.format("Entity too short." + "Got a string ('%s') of length %d." + + "Expected a length of " + LEADER_ENTITY_LENGTH + " (field + indicators).", name, name.length()); throw new MetafactureException(message); } - String tag = name.substring(0, 3); - String ind1 = name.substring(3, 4); - String ind2 = name.substring(4, 5); + final String tag = name.substring(TAG_BEGIN, TAG_END); + final String ind1 = name.substring(IND1_BEGIN, IND1_END); + final String ind2 = name.substring(IND2_BEGIN, IND2_END); prettyPrintIndentation(); writeRaw(String.format(DATAFIELD_OPEN_TEMPLATE, tag, ind1, ind2)); prettyPrintNewLine(); @@ -172,20 +181,23 @@ public void endEntity() { @Override public void literal(final String name, final String value) { - if (currentEntity.equals("")) { + if ("".equals(currentEntity)) { prettyPrintIndentation(); writeRaw(String.format(CONTROLFIELD_OPEN_TEMPLATE, name)); - if (value != null) + if (value != null) { writeEscaped(value.trim()); + } writeRaw(CONTROLFIELD_CLOSE); prettyPrintNewLine(); - } else if (!currentEntity.equals(Marc21EventNames.LEADER_ENTITY)) { + } + else if (!currentEntity.equals(Marc21EventNames.LEADER_ENTITY)) { prettyPrintIndentation(); writeRaw(String.format(SUBFIELD_OPEN_TEMPLATE, name)); writeEscaped(value.trim()); writeRaw(SUBFIELD_CLOSE); prettyPrintNewLine(); - } else { + } + else { if (name.equals(Marc21EventNames.LEADER_ENTITY)) { prettyPrintIndentation(); writeRaw(LEADER_OPEN_TEMPLATE + value + LEADER_CLOSE_TEMPLATE); @@ -242,7 +254,7 @@ private void writeEscaped(final String str) { private void prettyPrintIndentation() { if (formatted) { - String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT)); + final String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT)); builder.append(prefix); } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java index 6f1264140..7de7fb1ef 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; import org.metafacture.framework.FluxCommand; @@ -22,10 +23,10 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; - /** * A marc xml reader. * @author Markus Michael Geipel @@ -48,6 +49,9 @@ public final class MarcXmlHandler extends DefaultXmlPipe { private String namespace = NAMESPACE; private StringBuilder builder = new StringBuilder(); + public MarcXmlHandler() { + } + public void setNamespace(final String namespace) { this.namespace = namespace; } @@ -57,39 +61,46 @@ private boolean checkNamespace(final String uri) { } @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) - throws SAXException { - if(SUBFIELD.equals(localName)){ - builder = new StringBuilder(); - currentTag = attributes.getValue("code"); - }else if(DATAFIELD.equals(localName)){ - getReceiver().startEntity(attributes.getValue("tag") + attributes.getValue("ind1") + attributes.getValue("ind2")); - }else if(CONTROLFIELD.equals(localName)){ - builder = new StringBuilder(); - currentTag = attributes.getValue("tag"); - }else if(RECORD.equals(localName) && checkNamespace(uri)){ - getReceiver().startRecord(""); - getReceiver().literal(TYPE, attributes.getValue(TYPE)); - }else if(LEADER.equals(localName)){ - builder = new StringBuilder(); - currentTag = LEADER; - } + public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { + if (SUBFIELD.equals(localName)) { + builder = new StringBuilder(); + currentTag = attributes.getValue("code"); + } + else if (DATAFIELD.equals(localName)) { + getReceiver().startEntity(attributes.getValue("tag") + attributes.getValue("ind1") + attributes.getValue("ind2")); + } + else if (CONTROLFIELD.equals(localName)) { + builder = new StringBuilder(); + currentTag = attributes.getValue("tag"); + } + else if (RECORD.equals(localName) && checkNamespace(uri)) { + getReceiver().startRecord(""); + getReceiver().literal(TYPE, attributes.getValue(TYPE)); + } + else if (LEADER.equals(localName)) { + builder = new StringBuilder(); + currentTag = LEADER; + } } @Override public void endElement(final String uri, final String localName, final String qName) throws SAXException { - if(SUBFIELD.equals(localName)){ + if (SUBFIELD.equals(localName)) { getReceiver().literal(currentTag, builder.toString().trim()); - }else if(DATAFIELD.equals(localName)){ + } + else if (DATAFIELD.equals(localName)) { getReceiver().endEntity(); - }else if(CONTROLFIELD.equals(localName)){ + } + else if (CONTROLFIELD.equals(localName)) { getReceiver().literal(currentTag, builder.toString().trim()); - }else if(RECORD.equals(localName) && checkNamespace(uri)){ + } + else if (RECORD.equals(localName) && checkNamespace(uri)) { getReceiver().endRecord(); - }else if(LEADER.equals(localName)){ + } + else if (LEADER.equals(localName)) { getReceiver().literal(currentTag, builder.toString()); } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaConstants.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaConstants.java index 92ffd2a7e..e36a4be3a 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaConstants.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaConstants.java @@ -26,31 +26,31 @@ * */ enum PicaConstants { - // We use '\0' for null/empty - RECORD_MARKER('\u001d', '\n'), // - FIELD_MARKER('\u001e', '\0'), // - SUBFIELD_MARKER('\u001f', '$'), // - FIELD_END_MARKER('\n', '\n'), // - NO_MARKER('\0', '\0'); + // We use '\0' for null/empty + RECORD_MARKER('\u001d', '\n'), // + FIELD_MARKER('\u001e', '\0'), // + SUBFIELD_MARKER('\u001f', '$'), // + FIELD_END_MARKER('\n', '\n'), // + NO_MARKER('\0', '\0'); - char normalized; - char nonNormalized; + private final char normalized; + private final char nonNormalized; - PicaConstants(char normalized, char nonNormalized) { - this.normalized = normalized; - this.nonNormalized = nonNormalized; - } + PicaConstants(final char normalized, final char nonNormalized) { + this.normalized = normalized; + this.nonNormalized = nonNormalized; + } - public char get(boolean isNormalized) { - return isNormalized ? normalized : nonNormalized; - } + public char get(final boolean isNormalized) { + return isNormalized ? normalized : nonNormalized; + } - public static PicaConstants from(boolean isNormalized, char ch) { - for (PicaConstants value : values()) { - if (ch == (isNormalized ? value.normalized : value.nonNormalized)) { - return value; - } - } - return NO_MARKER; - } + public static PicaConstants from(final boolean isNormalized, final char ch) { + for (final PicaConstants value : values()) { + if (ch == (isNormalized ? value.normalized : value.nonNormalized)) { + return value; + } + } + return NO_MARKER; + } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaDecoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaDecoder.java index f0c818648..a94af6020 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaDecoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaDecoder.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.pica; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.biblio.pica; import org.metafacture.commons.StringUtil; import org.metafacture.framework.FluxCommand; @@ -27,6 +25,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Parses pica+ records. The parser only parses single records. A string * containing multiple records must be split into individual records before @@ -153,11 +154,8 @@ @In(String.class) @Out(StreamReceiver.class) @FluxCommand("decode-pica") -public final class PicaDecoder - extends DefaultObjectPipe { +public final class PicaDecoder extends DefaultObjectPipe { - private static String START_MARKERS; - private static Pattern ID_FIELDS_PATTERN; private static final int BUFFER_SIZE = 1024 * 1024; private Matcher idFieldMatcher; @@ -174,7 +172,7 @@ public PicaDecoder() { this(true); } - public PicaDecoder(boolean normalized) { + public PicaDecoder(final boolean normalized) { setNormalizedSerialization(normalized); } @@ -185,21 +183,19 @@ public PicaDecoder(boolean normalized) { * @param normalized if true, the input is treated as normalized pica+ ; * if false, it's treated as non-normalized. */ - public void setNormalizedSerialization(boolean normalized) { + public void setNormalizedSerialization(final boolean normalized) { this.isNormalized = normalized; - makeConstants(); - } - private void makeConstants() { - START_MARKERS = "(?:^|" + PicaConstants.FIELD_MARKER.get(isNormalized) + "|" - + PicaConstants.FIELD_END_MARKER.get(isNormalized) + "|" - + PicaConstants.RECORD_MARKER.get(isNormalized) + "|.*\n" + ")"; - ID_FIELDS_PATTERN = Pattern - .compile(START_MARKERS + "(?:003@|203@(?:/..+)?|107F) " - + " ?(\\" + PicaConstants.SUBFIELD_MARKER.get(isNormalized) + "|" - + PicaConstants.SUBFIELD_MARKER.get(isNormalized) + ")0"); - idFieldMatcher = ID_FIELDS_PATTERN.matcher(""); + final String startMarkers = "(?:^|" + PicaConstants.FIELD_MARKER.get(isNormalized) + "|" + + PicaConstants.FIELD_END_MARKER.get(isNormalized) + "|" + + PicaConstants.RECORD_MARKER.get(isNormalized) + "|.*\n" + ")"; + final Pattern idFieldsPattern = Pattern + .compile(startMarkers + "(?:003@|203@(?:/..+)?|107F) " + + " ?(\\" + PicaConstants.SUBFIELD_MARKER.get(isNormalized) + "|" + + PicaConstants.SUBFIELD_MARKER.get(isNormalized) + ")0"); + idFieldMatcher = idFieldsPattern.matcher(""); } + /** * Controls whether records having no record id are reported as faulty. By * default such records are reported by the {@code PicaDecoder} by throwing @@ -281,6 +277,7 @@ public void setTrimFieldNames(final boolean trimFieldNames) { public boolean getTrimFieldNames() { return parserContext.getTrimFieldNames(); } + @Override public void process(final String record) { assert !isClosed(); diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaEncoder.java index 93934c022..ffba87888 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaEncoder.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.pica; -import java.text.Normalizer; -import java.text.Normalizer.Form; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.biblio.pica; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.FormatException; @@ -30,6 +26,10 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.text.Normalizer.Form; +import java.text.Normalizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Encodes an event stream in pica+ format. @@ -68,6 +68,9 @@ public final class PicaEncoder extends DefaultStreamPipe> private String id; + public PicaEncoder() { + } + @Override public void startRecord(final String recordId) { // the name is a idn, which should be found in the encoded data under 003@. @@ -97,7 +100,7 @@ public void startEntity(final String name) { if (entityOpen) { //No nested entities are allowed in pica+. throw new FormatException(name); } - builder.append(name.trim()+ " "); + builder.append(name.trim() + " "); idnControlSubField = !ignoreRecordId && FIELD_IDN_INTERN.equals(name.trim()); //Now literals can be opened but no more entities. @@ -124,7 +127,7 @@ public void literal(final String name, final String value) { builder.append(SUB_DELIMITER); builder.append(name); builder.append(valueNew); -} + } @Override public void endEntity() { diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaMultiscriptRemodeler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaMultiscriptRemodeler.java index d5728ea96..5b8780c18 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaMultiscriptRemodeler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaMultiscriptRemodeler.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.pica; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; +package org.metafacture.biblio.pica; import org.metafacture.flowcontrol.StreamBuffer; import org.metafacture.framework.FluxCommand; @@ -27,6 +24,10 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + /** * Groups multiscript fields in entities. *

@@ -103,8 +104,7 @@ @Out(StreamReceiver.class) @Description("Groups multiscript fields in entities") @FluxCommand("remodel-pica-multiscript") -public final class PicaMultiscriptRemodeler extends - DefaultStreamPipe { +public final class PicaMultiscriptRemodeler extends DefaultStreamPipe { public static final String ENTITY_NAME_FOR_LATIN = "Latin"; public static final String ENTITY_NAME_FOR_NON_LATIN_LR = "NonLatinLR"; @@ -124,6 +124,9 @@ public final class PicaMultiscriptRemodeler extends private final SortedMap bufferedFields = new TreeMap(); + public PicaMultiscriptRemodeler() { + } + @Override public void startRecord(final String identifier) { getReceiver().startRecord(identifier); @@ -143,22 +146,24 @@ public void endRecord() { @Override public void startEntity(final String name) { currentField = new BufferedField(name); - currentField.stream.setReceiver(getReceiver()); + currentField.getStream().setReceiver(getReceiver()); - if (!lastField.name.equals(currentField.name)) { + if (!lastField.getName().equals(currentField.getName())) { emitAsSingleMultiscriptFields(bufferedFields); } } @Override public void endEntity() { - if (currentField.group == null || currentField.script == null) { + if (currentField.getGroup() == null || currentField.getScript() == null) { emitNonMultiscriptField(); - } else { - if (bufferedFields.containsKey(currentField.group)) { + } + else { + if (bufferedFields.containsKey(currentField.getGroup())) { emitAsSingleMultiscriptFields(getSingleMultiscriptFieldsBeforeCurrentField()); - emitRemodeledMultiscriptField(bufferedFields.remove(currentField.group), currentField); - } else { + emitRemodeledMultiscriptField(bufferedFields.remove(currentField.getGroup()), currentField); + } + else { bufferMultiscriptField(currentField); } } @@ -169,38 +174,39 @@ public void endEntity() { @Override public void literal(final String name, final String value) { - currentField.stream.literal(name, value); + currentField.getStream().literal(name, value); if (GROUP_SUBFIELD.equals(name)) { - currentField.group = value; - } else if (SCRIPT_SUBFIELD.equals(name)) { - currentField.script = value; + currentField.setGroup(value); + } + else if (SCRIPT_SUBFIELD.equals(name)) { + currentField.setScript(value); } } private void bufferMultiscriptField(final BufferedField field) { - bufferedFields.put(field.group, field); + bufferedFields.put(field.getGroup(), field); } private Map getSingleMultiscriptFieldsBeforeCurrentField() { - return bufferedFields.headMap(currentField.group); + return bufferedFields.headMap(currentField.getGroup()); } private void emitNonMultiscriptField() { - getReceiver().startEntity(currentField.name); - currentField.stream.replay(); + getReceiver().startEntity(currentField.getName()); + currentField.getStream().replay(); getReceiver().endEntity(); } private void emitRemodeledMultiscriptField(final BufferedField firstField, final BufferedField secondField) { - getReceiver().startEntity(firstField.name); + getReceiver().startEntity(firstField.getName()); - getReceiver().startEntity(mapScriptToEntityName(firstField.script)); - firstField.stream.replay(); + getReceiver().startEntity(mapScriptToEntityName(firstField.getScript())); + firstField.getStream().replay(); getReceiver().endEntity(); - getReceiver().startEntity(mapScriptToEntityName(secondField.script)); - secondField.stream.replay(); + getReceiver().startEntity(mapScriptToEntityName(secondField.getScript())); + secondField.getStream().replay(); getReceiver().endEntity(); getReceiver().endEntity(); @@ -208,42 +214,62 @@ private void emitRemodeledMultiscriptField(final BufferedField firstField, final private void emitAsSingleMultiscriptFields(final Map fields) { for (final BufferedField field : fields.values()) { - getReceiver().startEntity(field.name); - field.stream.replay(); + getReceiver().startEntity(field.getName()); + field.getStream().replay(); getReceiver().endEntity(); } fields.clear(); } private String mapScriptToEntityName(final String script) { - if (LATIN_SCRIPT.equals(script)) { - return ENTITY_NAME_FOR_LATIN; - } else if (ARABIC_SCRIPT.equals(script) - || HEBREW_SCRIPT.equals(script)) { - return ENTITY_NAME_FOR_NON_LATIN_RL; - } - return ENTITY_NAME_FOR_NON_LATIN_LR; + return LATIN_SCRIPT.equals(script) ? ENTITY_NAME_FOR_LATIN : + (ARABIC_SCRIPT.equals(script) || HEBREW_SCRIPT.equals(script)) ? ENTITY_NAME_FOR_NON_LATIN_RL : + ENTITY_NAME_FOR_NON_LATIN_LR; } private static class BufferedField { - public String group; - public String script; + private final String name; + private final StreamBuffer stream; - public final String name; - public final StreamBuffer stream; + private String group; + private String script; - public BufferedField(final String name) { + BufferedField(final String name) { this(name, new StreamBuffer()); } - public BufferedField(final String name, final StreamBuffer stream) { + BufferedField(final String name, final StreamBuffer stream) { this.group = null; this.script = null; this.name = name; this.stream = stream; } + public String getName() { + return name; + } + + public StreamBuffer getStream() { + return stream; + } + + public void setGroup(final String group) { + this.group = group; + } + + public String getGroup() { + return group; + } + + public void setScript(final String script) { + this.script = script; + } + + public String getScript() { + return script; + } + } } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserContext.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserContext.java index 08f2edaf3..c9c57de8e 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserContext.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserContext.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.pica; -import java.text.Normalizer; -import java.text.Normalizer.Form; +package org.metafacture.biblio.pica; import org.metafacture.framework.StreamReceiver; +import java.text.Normalizer.Form; +import java.text.Normalizer; + /** * Parser context for the PICA+ parser.The context implements * support for normalising the UTF8 encoding of values into NFC @@ -43,6 +44,9 @@ final class PicaParserContext { private String subfieldName; + PicaParserContext() { + } + public void setNormalizeUTF8(final boolean normalizeUTF8) { this.normalizeUTF8 = normalizeUTF8; } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserState.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserState.java index b99be0ddb..44fcd590b 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserState.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaParserState.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.pica; +package org.metafacture.biblio.pica; /** * A parser for PICA+ records. Only single records can be parsed as the parser @@ -37,23 +37,23 @@ enum PicaParserState { FIELD_NAME { @Override - protected PicaParserState parseChar(final char ch, final PicaParserContext ctx, boolean normalized) { + protected PicaParserState parseChar(final char ch, final PicaParserContext ctx, final boolean normalized) { final PicaParserState next; switch (PicaConstants.from(normalized, ch)) { - case RECORD_MARKER: - case FIELD_MARKER: - case FIELD_END_MARKER: - ctx.emitStartEntity(); - ctx.emitEndEntity(); - next = FIELD_NAME; - break; - case SUBFIELD_MARKER: - ctx.emitStartEntity(); - next = SUBFIELD_NAME; - break; - default: - ctx.appendText(ch); - next = this; + case RECORD_MARKER: + case FIELD_MARKER: + case FIELD_END_MARKER: + ctx.emitStartEntity(); + ctx.emitEndEntity(); + next = FIELD_NAME; + break; + case SUBFIELD_MARKER: + ctx.emitStartEntity(); + next = SUBFIELD_NAME; + break; + default: + ctx.appendText(ch); + next = this; } return next; } @@ -66,21 +66,21 @@ protected void endOfInput(final PicaParserContext ctx) { }, SUBFIELD_NAME { @Override - protected PicaParserState parseChar(final char ch, final PicaParserContext ctx, boolean normalized) { + protected PicaParserState parseChar(final char ch, final PicaParserContext ctx, final boolean normalized) { final PicaParserState next; switch (PicaConstants.from(normalized, ch)) { - case RECORD_MARKER: - case FIELD_MARKER: - case FIELD_END_MARKER: - ctx.emitEndEntity(); - next = FIELD_NAME; - break; - case SUBFIELD_MARKER: - next = this; - break; - default: - ctx.setSubfieldName(ch); - next = SUBFIELD_VALUE; + case RECORD_MARKER: + case FIELD_MARKER: + case FIELD_END_MARKER: + ctx.emitEndEntity(); + next = FIELD_NAME; + break; + case SUBFIELD_MARKER: + next = this; + break; + default: + ctx.setSubfieldName(ch); + next = SUBFIELD_VALUE; } return next; } @@ -92,23 +92,23 @@ protected void endOfInput(final PicaParserContext ctx) { }, SUBFIELD_VALUE { @Override - protected PicaParserState parseChar(final char ch, final PicaParserContext ctx, boolean normalized) { + protected PicaParserState parseChar(final char ch, final PicaParserContext ctx, final boolean normalized) { final PicaParserState next; switch (PicaConstants.from(normalized, ch)) { - case RECORD_MARKER: - case FIELD_MARKER: - case FIELD_END_MARKER: - ctx.emitLiteral(); - ctx.emitEndEntity(); - next = FIELD_NAME; - break; - case SUBFIELD_MARKER: - ctx.emitLiteral(); - next = SUBFIELD_NAME; - break; - default: - ctx.appendText(ch); - next = this; + case RECORD_MARKER: + case FIELD_MARKER: + case FIELD_END_MARKER: + ctx.emitLiteral(); + ctx.emitEndEntity(); + next = FIELD_NAME; + break; + case SUBFIELD_MARKER: + ctx.emitLiteral(); + next = SUBFIELD_NAME; + break; + default: + ctx.appendText(ch); + next = this; } return next; } @@ -120,8 +120,8 @@ protected void endOfInput(final PicaParserContext ctx) { } }; - protected abstract PicaParserState parseChar(final char ch, final PicaParserContext ctx, final boolean normalized); + protected abstract PicaParserState parseChar(char ch, PicaParserContext ctx, boolean normalized); - protected abstract void endOfInput(final PicaParserContext ctx); + protected abstract void endOfInput(PicaParserContext ctx); } diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaXmlHandler.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaXmlHandler.java index 129fa82f8..f943250c3 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaXmlHandler.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/pica/PicaXmlHandler.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.biblio.pica; -import java.text.Normalizer; +package org.metafacture.biblio.pica; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamReceiver; @@ -24,9 +23,12 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import java.text.Normalizer; + /** * A pica xml handler. * @@ -48,18 +50,24 @@ public final class PicaXmlHandler extends DefaultXmlPipe { private String currentTag = ""; private StringBuilder builder = new StringBuilder(); + public PicaXmlHandler() { + } + @Override public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { if (SUBFIELD.equals(localName)) { builder = new StringBuilder(); currentTag = attributes.getValue("id"); - } else if (DATAFIELD.equals(localName)) { + } + else if (DATAFIELD.equals(localName)) { getReceiver().startEntity( attributes.getValue("id") + attributes.getValue("occ")); - } else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { + } + else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { getReceiver().startRecord(""); - } else if (LEADER.equals(localName)) { + } + else if (LEADER.equals(localName)) { builder = new StringBuilder(); currentTag = LEADER; } @@ -71,9 +79,11 @@ public void endElement(final String uri, final String localName, if (SUBFIELD.equals(localName)) { getReceiver().literal(currentTag, Normalizer.normalize(builder.toString().trim(), Normalizer.Form.NFC)); - } else if (DATAFIELD.equals(localName)) { + } + else if (DATAFIELD.equals(localName)) { getReceiver().endEntity(); - } else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { + } + else if (RECORD.equals(localName) && NAMESPACE.equals(uri)) { getReceiver().endRecord(); } } diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/AlephMabXmlHandlerTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/AlephMabXmlHandlerTest.java index 7fb1bd542..418e8e9b5 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/AlephMabXmlHandlerTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/AlephMabXmlHandlerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio; import org.junit.Before; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/AseqDecoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/AseqDecoderTest.java index b6359d8a0..ac74bf3d2 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/AseqDecoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/AseqDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/ComarcXmlHandlerTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/ComarcXmlHandlerTest.java index 7eefb4a85..6f8ba61a5 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/ComarcXmlHandlerTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/ComarcXmlHandlerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio; import static org.mockito.Mockito.verify; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/MabDecoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/MabDecoderTest.java index e74fb29d4..51d477c9b 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/MabDecoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/MabDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/DirectoryEntryTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/DirectoryEntryTest.java index 1ee116021..acfe63097 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/DirectoryEntryTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/DirectoryEntryTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import static org.junit.Assert.assertArrayEquals; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/Iso646ByteBufferTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/Iso646ByteBufferTest.java index 0c56d6382..d575429e1 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/Iso646ByteBufferTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/Iso646ByteBufferTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import static org.junit.Assert.assertArrayEquals; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/LabelTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/LabelTest.java index 773d5e6b0..7697f59d6 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/LabelTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/LabelTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import static org.junit.Assert.assertArrayEquals; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordBuilderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordBuilderTest.java index 7117a691c..ec8c3d3f2 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordBuilderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordBuilderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import static org.junit.Assert.assertEquals; @@ -544,7 +545,8 @@ public void shouldLeaveRecordInACleanStateIfAppendingDataFieldFailed() { builder.appendSubfield(asChars("B"), "Value"); try { builder.endDataField(); - } catch (final FormatException e) { + } + catch (final FormatException e) { exceptionThrown = true; } diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordFormatTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordFormatTest.java index b3f78005b..51cc95d9e 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordFormatTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordFormatTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import static org.junit.Assert.assertEquals; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordTest.java index b6d76b42b..a3722f116 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/iso2709/RecordTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.iso2709; import static org.junit.Assert.assertEquals; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java index c65be8626..e983c9973 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21DecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java index 8317581ad..41e8d2b6c 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/Marc21EncoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; import static org.metafacture.biblio.marc21.Marc21EventNames.LEADER_ENTITY; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java index e74d38827..094b4547e 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlHandlerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.marc21; import static org.mockito.Mockito.verify; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaEncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaEncoderTest.java index a6cd3c058..2c83e392f 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaEncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaEncoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.pica; import static org.mockito.Mockito.verify; diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaMultiscriptRemodelerTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaMultiscriptRemodelerTest.java index 7dca1e449..be0f8a48a 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaMultiscriptRemodelerTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/pica/PicaMultiscriptRemodelerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.biblio.pica; import static org.mockito.Mockito.inOrder; @@ -305,7 +306,8 @@ private void verifySingleMultiscriptField(final InOrder ordered, private String mapScriptToEntityName(final String script) { if (SCRIPT_LATIN.equals(script)) { return PicaMultiscriptRemodeler.ENTITY_NAME_FOR_LATIN; - } else if (SCRIPT_ARABIC.equals(script) + } + else if (SCRIPT_ARABIC.equals(script) || SCRIPT_HEBREW.equals(script)) { return PicaMultiscriptRemodeler.ENTITY_NAME_FOR_NON_LATIN_RL; } From 5bb7af5fb47ea21c5777467affb46aa8793e9328 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 14:28:25 +0200 Subject: [PATCH 04/30] metafacture-commons/ (main): Fix Checkstyle violations. --- .../java/org/metafacture/commons/Require.java | 1 + .../org/metafacture/commons/ResourceUtil.java | 43 ++++++-------- .../org/metafacture/commons/StringUtil.java | 10 ++-- .../org/metafacture/commons/TimeUtil.java | 5 +- .../java/org/metafacture/commons/XmlUtil.java | 57 +++++++++++------- .../commons/reflection/ConfigurableClass.java | 58 ++++++++++--------- .../commons/reflection/ObjectFactory.java | 20 ++++--- .../reflection/ReflectionException.java | 5 +- .../commons/reflection/ReflectionUtil.java | 13 ++--- .../org/metafacture/commons/tries/ACNode.java | 20 +++---- .../metafacture/commons/tries/CharMap.java | 22 +++---- .../metafacture/commons/tries/SetMatcher.java | 30 ++++++---- .../commons/tries/SetReplacer.java | 28 ++++----- .../commons/tries/SimpleRegexTrie.java | 13 +++-- .../metafacture/commons/tries/SimpleTrie.java | 35 ++++++----- .../commons/tries/WildcardTrie.java | 21 ++++--- .../metafacture/commons/types/ListMap.java | 35 +++++------ .../metafacture/commons/types/NamedValue.java | 7 ++- .../commons/types/ScopedHashMap.java | 5 +- .../org/metafacture/commons/RequireTest.java | 1 + .../metafacture/commons/ResourceUtilTest.java | 1 + .../metafacture/commons/StringUtilTest.java | 1 + .../org/metafacture/commons/TimeUtilTest.java | 1 + .../org/metafacture/commons/XmlUtilTest.java | 1 + .../commons/tries/CharMapTest.java | 1 + .../commons/tries/SetMatchTest.java | 1 + .../commons/tries/SetReplaceTest.java | 1 + .../commons/tries/SimpleRegexTrieTest.java | 1 + .../commons/tries/SimpleTrieTest.java | 1 + .../commons/tries/WildcardTrieTest.java | 1 + .../commons/types/ListMapTest.java | 1 + .../commons/types/NamedValueTest.java | 1 + 32 files changed, 244 insertions(+), 197 deletions(-) diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/Require.java b/metafacture-commons/src/main/java/org/metafacture/commons/Require.java index b6b1c6840..d01f64a5a 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/Require.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/Require.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; /** diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/ResourceUtil.java b/metafacture-commons/src/main/java/org/metafacture/commons/ResourceUtil.java index 97d171962..a6d0fca39 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/ResourceUtil.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/ResourceUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import java.io.BufferedReader; @@ -30,7 +31,6 @@ import java.util.List; import java.util.Properties; - /** * Various utility methods for working with files, resources and streams. * @@ -38,7 +38,7 @@ * @author Markus Michael Geipel * */ -public final class ResourceUtil { +public final class ResourceUtil { // checkstyle-disable-line ClassDataAbstractionCoupling static final int BUFFER_SIZE = 4096; @@ -67,23 +67,27 @@ public static InputStream getStream(final String name) InputStream stream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(name); - if (stream != null) { - return stream; - } - - try { - stream = new URL(name).openStream(); - } catch (final IOException e) { - throwFileNotFoundException(name, e); - } if (stream == null) { - throwFileNotFoundException(name, null); + try { + stream = new URL(name).openStream(); + } + catch (final IOException e) { + throwFileNotFoundException(name, e); + } + if (stream == null) { + throwFileNotFoundException(name, null); + } } return stream; } + public static InputStream getStream(final File file) + throws FileNotFoundException { + return new FileInputStream(file); + } + private static void throwFileNotFoundException(final String name, final Throwable t) throws FileNotFoundException { final FileNotFoundException e = new FileNotFoundException( @@ -94,11 +98,6 @@ private static void throwFileNotFoundException(final String name, throw e; } - public static InputStream getStream(final File file) - throws FileNotFoundException { - return new FileInputStream(file); - } - public static Reader getReader(final String name) throws FileNotFoundException { return new InputStreamReader(getStream(name)); @@ -137,11 +136,7 @@ public static URL getUrl(final String name) throws MalformedURLException { final URL resourceUrl = Thread.currentThread().getContextClassLoader().getResource(name); - if (resourceUrl != null) { - return resourceUrl; - } - - return new URL(name); + return resourceUrl != null ? resourceUrl : new URL(name); } public static URL getUrl(final File file) throws MalformedURLException { @@ -191,14 +186,14 @@ public static List loadTextFile(final String location, return list; } - public static String readAll(InputStream inputStream, Charset encoding) + public static String readAll(final InputStream inputStream, final Charset encoding) throws IOException { try (Reader reader = new InputStreamReader(inputStream, encoding)) { return readAll(reader); } } - public static String readAll(Reader reader) throws IOException { + public static String readAll(final Reader reader) throws IOException { final StringBuilder loadedText = new StringBuilder(); try (Reader bufferedReader = new BufferedReader(reader)) { final CharBuffer buffer = CharBuffer.allocate(BUFFER_SIZE); diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/StringUtil.java b/metafacture-commons/src/main/java/org/metafacture/commons/StringUtil.java index 3880442f9..2d703bc10 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/StringUtil.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/StringUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import java.nio.CharBuffer; @@ -85,9 +86,10 @@ public static String format(final String format, final String varStartIndicator, if (varValue == null) { if (ignoreMissingVars) { varValue = ""; - } else { - throw new IllegalArgumentException("Variable '" + varName - + "' was not assigned!\nAssigned variables:\n" + variables); + } + else { + throw new IllegalArgumentException("Variable '" + varName + + "' was not assigned!\nAssigned variables:\n" + variables); } } builder.append(varValue); @@ -135,7 +137,7 @@ public static char[] copyToBuffer(final String str, final char[] currentBuffer) char[] buffer = currentBuffer; int bufferLen = buffer.length; - while(strLen > bufferLen) { + while (strLen > bufferLen) { bufferLen *= 2; } if (bufferLen > buffer.length) { diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/TimeUtil.java b/metafacture-commons/src/main/java/org/metafacture/commons/TimeUtil.java index 41109d6a5..df04cfd55 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/TimeUtil.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/TimeUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; /** @@ -22,8 +23,8 @@ */ public final class TimeUtil { - public static final String[] UNIT_SYMBOLS = { "ns", "µs", "ms", "s", "min", "h" }; - public static final long[] UNIT_FACTORS = { 1L, 1000L, 1000L, 1000L, 60L, 60L }; + public static final String[] UNIT_SYMBOLS = {"ns", "µs", "ms", "s", "min", "h"}; + public static final long[] UNIT_FACTORS = {1L, 1000L, 1000L, 1000L, 60L, 60L}; public static final int BASE_UNIT_INDEX = 3; diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/XmlUtil.java b/metafacture-commons/src/main/java/org/metafacture/commons/XmlUtil.java index 1d20ba63e..daa6f9ba2 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/XmlUtil.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/XmlUtil.java @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; -import static java.util.stream.Collectors.joining; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import java.io.StringWriter; - +import java.util.stream.Collectors; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; @@ -26,10 +28,6 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - - /** * Utility functions for working with XML data as strings. * @@ -41,6 +39,8 @@ public final class XmlUtil { private static final String TEXT_XML_MIME_TYPE = "text/xml"; private static final String XML_BASE_MIME_TYPE = "+xml"; + private static final int ESCAPE_CODE_POINT_THRESHOLD = 0x7f; + private XmlUtil() { // No instances allowed } @@ -55,20 +55,23 @@ public static String nodeToString(final Node node, final Transformer transformer; try { transformer = TransformerFactory.newInstance().newTransformer(); - } catch (final TransformerException e) { + } + catch (final TransformerException e) { throw new AssertionError( "No errors expected when creating an identity transformer", e); } if (omitXMLDecl) { transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - } else { + } + else { transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); } try { transformer.transform(new DOMSource(node), new StreamResult(writer)); - } catch (final TransformerException e) { + } + catch (final TransformerException e) { throw new AssertionError( "No errors expected during identity transformation", e); } @@ -79,7 +82,7 @@ public static String nodeToString(final Node node, public static String nodeListToString(final NodeList nodes) { final StringBuilder builder = new StringBuilder(); - for (int i=0; i < nodes.getLength(); ++i) { + for (int i = 0; i < nodes.getLength(); ++i) { builder.append(nodeToString(nodes.item(i), i != 0)); } @@ -102,7 +105,7 @@ public static String escape(final String unescaped) { public static String escape(final String unescaped, final boolean escapeUnicode) { return unescaped.codePoints() .mapToObj(value -> escapeCodePoint(value, escapeUnicode)) - .collect(joining()); + .collect(Collectors.joining()); } private static String escapeCodePoint(final int codePoint, final boolean escapeUnicode) { @@ -110,22 +113,34 @@ private static String escapeCodePoint(final int codePoint, final boolean escapeU if (entity != null) { return entity; } - if (escapeUnicode && codePoint > 0x7f) { - return "&#" + Integer.toString(codePoint) + ";"; - } - return Character.toString((char) codePoint); + return escapeUnicode && codePoint > ESCAPE_CODE_POINT_THRESHOLD ? + "&#" + Integer.toString(codePoint) + ";" : Character.toString((char) codePoint); } private static String entityFor(final int ch) { + final String entity; + switch (ch) { - case '<': return "<"; - case '>': return ">"; - case '&': return "&"; - case '"': return """; - case '\'': return "'"; + case '<': + entity = "<"; + break; + case '>': + entity = ">"; + break; + case '&': + entity = "&"; + break; + case '"': + entity = """; + break; + case '\'': + entity = "'"; + break; default: - return null; + entity = null; } + + return entity; } } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java index 6980dcf55..2fdb4d59d 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ConfigurableClass.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.commons.reflection; -import static java.util.Arrays.asList; +package org.metafacture.commons.reflection; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -33,19 +33,20 @@ * Instances of this class wrap {@link Class}. The wrapped instance is available * via {@link #getPlainClass()}. * + * @param object type * @author Christoph Böhme */ public final class ConfigurableClass { private static final String SETTER_PREFIX = "set"; private static final Set> ELIGIBLE_TYPES = new HashSet<>( - asList(boolean.class, int.class, String.class)); + Arrays.asList(boolean.class, int.class, String.class)); private final Class plainClass; private Map settersCache; - public ConfigurableClass(Class plainClass) { + public ConfigurableClass(final Class plainClass) { this.plainClass = plainClass; } @@ -62,7 +63,7 @@ public Map getSetters() { private void initSettersCache() { settersCache = new HashMap<>(); - for (Method method : plainClass.getMethods()) { + for (final Method method : plainClass.getMethods()) { if (isSetter(method)) { final String setterName = method.getName().substring( SETTER_PREFIX.length()).toLowerCase(); @@ -71,7 +72,7 @@ private void initSettersCache() { } } - private boolean isSetter(Method method) { + private boolean isSetter(final Method method) { if (method.getParameterTypes().length == 1) { final Class type = method.getParameterTypes()[0]; if (ELIGIBLE_TYPES.contains(type) || type.isEnum()) { @@ -81,9 +82,9 @@ private boolean isSetter(Method method) { return false; } - public Map> getSetterTypes() { + public Map> getSetterTypes() { final Map> setterTypes = new HashMap<>(); - for(Map.Entry method : getSetters().entrySet()) { + for (final Map.Entry method : getSetters().entrySet()) { final Class setterType = method.getValue().getParameterTypes()[0]; setterTypes.put(method.getKey(), setterType); } @@ -94,25 +95,24 @@ public T newInstance() { return newInstance(Collections.emptyMap()); } - public T newInstance(Map setterValues, - Object... constructorArgs) { + public T newInstance(final Map setterValues, final Object... constructorArgs) { try { final Constructor constructor = findConstructor(constructorArgs); final T instance = constructor.newInstance(constructorArgs); applySetters(instance, setterValues); return instance; - } catch (ReflectiveOperationException e) { + } + catch (final ReflectiveOperationException e) { throw new ReflectionException("class could not be instantiated: " + plainClass, e); } } - private Constructor findConstructor(Object... arguments) - throws NoSuchMethodException{ + private Constructor findConstructor(final Object... arguments) throws NoSuchMethodException { @SuppressWarnings("unchecked") // getConstructors() returns correct types final Constructor[] constructors = (Constructor[]) plainClass.getConstructors(); - for (Constructor constructor : constructors) { + for (final Constructor constructor : constructors) { if (checkArgumentTypes(constructor, arguments)) { return constructor; } @@ -121,8 +121,7 @@ private Constructor findConstructor(Object... arguments) "no appropriate constructor found for class " + plainClass); } - private boolean checkArgumentTypes(Constructor constructor, - Object[] constructorArgs) { + private boolean checkArgumentTypes(final Constructor constructor, final Object[] constructorArgs) { // checkstyle-disable-line ReturnCount final Class[] argTypes = constructor.getParameterTypes(); if (argTypes.length != constructorArgs.length) { return false; @@ -135,8 +134,8 @@ private boolean checkArgumentTypes(Constructor constructor, return true; } - private void applySetters(T target, Map setterValues) { - for (Map.Entry setterValue : setterValues.entrySet()) { + private void applySetters(final T target, final Map setterValues) { + for (final Map.Entry setterValue : setterValues.entrySet()) { final String setterName = setterValue.getKey().toLowerCase(); final Method setter = getSetters().get(setterName); if (setter == null) { @@ -147,26 +146,33 @@ private void applySetters(T target, Map setterValues) { final Object value = convertValue(setterValue.getValue(), valueType); try { setter.invoke(target, value); - } catch (ReflectiveOperationException e) { + } + catch (final ReflectiveOperationException e) { throw new ReflectionException("Cannot set " + setterName + " on class " + target.getClass().getSimpleName(), e); } } } - private Object convertValue(String value, Class type) { + private Object convertValue(final String value, final Class type) { + final Object result; + if (type == boolean.class) { - return Boolean.valueOf(value); + result = Boolean.valueOf(value); } - if (type == int.class) { - return Integer.valueOf(value); + else if (type == int.class) { + result = Integer.valueOf(value); } - if (type.isEnum()) { + else if (type.isEnum()) { @SuppressWarnings("unchecked") // protected by type.isEnum() check final Class enumType = (Class) type; - return Enum.valueOf(enumType, value.toUpperCase()); + result = Enum.valueOf(enumType, value.toUpperCase()); + } + else { + result = value; } - return value; + + return result; } } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ObjectFactory.java b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ObjectFactory.java index 16cd2c9f6..239d963ec 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ObjectFactory.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ObjectFactory.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.reflection; import java.util.Collections; @@ -36,7 +37,10 @@ public class ObjectFactory { private final Map> classes = new HashMap<>(); - public final void loadClassesFromMap(Map classMap, Class baseType) { + public ObjectFactory() { + } + + public final void loadClassesFromMap(final Map classMap, final Class baseType) { final ClassLoader loader = ReflectionUtil.getContextClassLoader(); for (final Entry entry : classMap.entrySet()) { final String key = entry.getKey().toString(); @@ -45,21 +49,19 @@ public final void loadClassesFromMap(Map classMap, Class baseType) { } } - public final void registerClass(String key, Class objectClass) { + public final void registerClass(final String key, final Class objectClass) { registerClass(key, new ConfigurableClass<>(objectClass)); } - public final void registerClass(String key, - ConfigurableClass objectClass) { + public final void registerClass(final String key, final ConfigurableClass objectClass) { classes.put(key, objectClass); } - public final T newInstance(String key, Object... constructorArgs) { + public final T newInstance(final String key, final Object... constructorArgs) { return newInstance(key, Collections.emptyMap(), constructorArgs); } - public final T newInstance(String key, Map values, - Object... constructorArgs) { + public final T newInstance(final String key, final Map values, final Object... constructorArgs) { if (!classes.containsKey(key)) { throw new NoSuchElementException("no registered class for: " + key); } @@ -67,7 +69,7 @@ public final T newInstance(String key, Map values, return instanceClass.newInstance(values, constructorArgs); } - public final boolean containsKey(String key) { + public final boolean containsKey(final String key) { return classes.containsKey(key); } @@ -75,7 +77,7 @@ public final Set keySet() { return Collections.unmodifiableSet(classes.keySet()); } - public final ConfigurableClass get(String key) { + public final ConfigurableClass get(final String key) { return classes.get(key); } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionException.java b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionException.java index ef6311532..0af42bfc5 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionException.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.reflection; /** @@ -20,11 +21,11 @@ */ public class ReflectionException extends RuntimeException { - ReflectionException(String message, Throwable cause) { + ReflectionException(final String message, final Throwable cause) { super(message, cause); } - ReflectionException(String message) { + ReflectionException(final String message) { super(message); } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionUtil.java b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionUtil.java index bb3a12d72..e381ea0b4 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionUtil.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/reflection/ReflectionUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.reflection; /** @@ -35,22 +36,20 @@ public static ClassLoader getContextClassLoader() { return loader; } - public static ConfigurableClass loadClass(String className, - Class baseType) { + public static ConfigurableClass loadClass(final String className, final Class baseType) { return loadClass(getContextClassLoader(), className, baseType); } - public static ConfigurableClass loadClass(ClassLoader loader, - String className, Class baseType) { + public static ConfigurableClass loadClass(final ClassLoader loader, final String className, final Class baseType) { final Class clazz; try { clazz = loader.loadClass(className); - } catch (ClassNotFoundException e) { + } + catch (final ClassNotFoundException e) { throw new ReflectionException("Class not found: " + className, e); } if (!baseType.isAssignableFrom(clazz)) { - throw new ReflectionException(className + " must extend or implement " + - baseType.getName()); + throw new ReflectionException(className + " must extend or implement " + baseType.getName()); } @SuppressWarnings("unchecked") // protected by isAssignableFrom check final Class castedClass = (Class) clazz; diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/ACNode.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/ACNode.java index 85602e1fe..8b6f8b54d 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/ACNode.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/ACNode.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import java.util.Collection; import java.util.Map.Entry; import java.util.Set; - /** * Node representing a character in a trie. * @@ -38,12 +38,12 @@ final class ACNode

{ this.depth = depth; } - ACNode

addNext(final char key){ + ACNode

addNext(final char key) { return addNext(key, null); } - ACNode

addNext(final char key, final P value){ - final ACNode

next = new ACNode

(value, depth+1); + ACNode

addNext(final char key, final P currentValue) { + final ACNode

next = new ACNode

(currentValue, depth + 1); links.put(key, next); return next; } @@ -52,14 +52,18 @@ void setValue(final P value) { this.value = value; } - P getValue(){ + P getValue() { return value; } - ACNode

getNext(final char key){ + ACNode

getNext(final char key) { return links.get(key); } + Collection> getNext() { + return links.values(); + } + ACNode

getFailure() { return failure; } @@ -72,10 +76,6 @@ int getDepth() { return depth; } - Collection> getNext(){ - return links.values(); - } - Set>> getLinks() { return links.entrySet(); } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/CharMap.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/CharMap.java index 1bc7c940b..4f45b9a2a 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/CharMap.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/CharMap.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import java.util.Collection; @@ -38,7 +39,7 @@ final class CharMap implements Map { private int size; @SuppressWarnings("unchecked") - public CharMap() { + CharMap() { table = new Entry[INITIAL_CAPACITY]; } @@ -97,14 +98,15 @@ public void put(final char key, final V value) { ++size; } - public void put(final Entry[] table, final char key, final V value) { + public void put(final Entry[] currentTable, final char key, final V value) { final Entry newEntry = new Entry(key, value); - Entry entry = table[key % table.length]; + Entry entry = currentTable[key % currentTable.length]; if (entry == null) { - table[key % table.length] = newEntry; - } else { + currentTable[key % currentTable.length] = newEntry; + } + else { while (entry.getNext() != null) { if (entry.getKeyChar() == key) { throw new IllegalStateException("Key '" + key + "' already used"); @@ -120,7 +122,7 @@ private void expand() { @SuppressWarnings("unchecked") final Entry[] newTable = new Entry[newSize]; - for (Entry entry : table) { + for (final Entry entry : table) { Entry temp = entry; while (temp != null) { put(newTable, temp.getKeyChar(), temp.getValue()); @@ -174,7 +176,7 @@ public Collection values() { @Override public Set> entrySet() { - final Set> entries = new HashSet> (); + final Set> entries = new HashSet>(); for (int i = 0; i < table.length; ++i) { Entry entry = table[i]; while (entry != null) { @@ -223,9 +225,9 @@ public V getValue() { } @Override - public V setValue(final V value) { - final V old = this.value; - this.value = value; + public V setValue(final V newValue) { + final V old = value; + value = newValue; return old; } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetMatcher.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetMatcher.java index 048fc5cd6..eaa706977 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetMatcher.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetMatcher.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import java.io.PrintStream; @@ -32,6 +33,9 @@ public final class SetMatcher { private final ACNode root = new ACNode<>(null, 0); private boolean isPrepared; + public SetMatcher() { + } + public void put(final String key, final T value) { if (isPrepared) { throw new IllegalStateException("keys cannot be added during matching."); @@ -50,9 +54,11 @@ public void put(final String key, final T value) { next = node.getNext(key.charAt(length - 1)); if (next == null) { next = node.addNext(key.charAt(length - 1), value); - } else if (next.getValue() == null) { + } + else if (next.getValue() == null) { next.setValue(value); - } else { + } + else { throw new IllegalStateException("Key '" + key + "' already in trie"); } } @@ -72,7 +78,8 @@ public List> match(final String text) { final ACNode next = node.getNext(text.charAt(index)); if (next != null) { node = next; - } else if (node != root) { + } + else if (node != root) { node = node.getFailure(); continue; } @@ -85,12 +92,12 @@ public List> match(final String text) { private void collectMatches(final ACNode node, final int index, final List> matches) { //direct hit or hit in chain of failure links? ACNode tempNode = node; - do{ + do { if (tempNode.getValue() != null) { matches.add(new Match(tempNode.getValue(), index - tempNode.getDepth(), tempNode.getDepth())); } tempNode = tempNode.getFailure(); - }while (tempNode != root); + } while (tempNode != root); } private void prepare() { @@ -98,7 +105,7 @@ private void prepare() { // prepare root root.setFailure(root); - for (ACNode child : root.getNext()) { + for (final ACNode child : root.getNext()) { child.setFailure(root); queue.add(child); } @@ -107,7 +114,7 @@ private void prepare() { final ACNode parent = queue.poll(); final ACNode parentFailure = parent.getFailure(); - for (Entry> link : parent.getLinks()) { + for (final Entry> link : parent.getLinks()) { final char key = link.getKey().charValue(); final ACNode child = link.getValue(); ACNode node = parentFailure; @@ -118,7 +125,8 @@ private void prepare() { if (node.getNext(key) == null) { child.setFailure(root); - } else { + } + else { child.setFailure(node.getNext(key)); } queue.add(child); @@ -141,14 +149,15 @@ public void printAutomaton(final PrintStream out) { private void printDebug(final PrintStream out, final ACNode node) { if (node.getValue() == null) { out.println(node.hashCode() + " [shape=point label=\"\"]"); - } else { + } + else { out.println(node.hashCode() + " [shape=circle style=filled label=\"\"]"); } if (node.getFailure() != root) { out.println(node.hashCode() + " -> " + node.getFailure().hashCode() + "[color=gray]"); } - for (Entry> link : node.getLinks()) { + for (final Entry> link : node.getLinks()) { out.println(node.hashCode() + " -> " + link.getValue().hashCode() + " [label=\"" + link.getKey() + "\"]"); printDebug(out, link.getValue()); } @@ -165,7 +174,6 @@ public static final class Match { private final int length; public Match(final T value, final int start, final int length) { - super(); this.value = value; this.start = start; this.length = length; diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetReplacer.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetReplacer.java index 1f0ae0d55..fbb2eae38 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetReplacer.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SetReplacer.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; +import org.metafacture.commons.tries.SetMatcher.Match; + import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Map; import java.util.Map.Entry; - -import org.metafacture.commons.tries.SetMatcher.Match; +import java.util.Map; /** * @author Markus Michael Geipel @@ -30,12 +31,15 @@ public final class SetReplacer { private final SetMatcher matcher = new SetMatcher(); + public SetReplacer() { + } + public void addReplacement(final String key, final String with) { matcher.put(key, with); } public void addReplacements(final Map replacements) { - for (Entry entry : replacements.entrySet()) { + for (final Entry entry : replacements.entrySet()) { addReplacement(entry.getKey(), entry.getValue()); } } @@ -49,25 +53,13 @@ public String replaceIn(final String text) { Collections.sort(matches, new Comparator>() { @Override public int compare(final Match o1, final Match o2) { - final int result; final int delta = o1.getStart() - o2.getStart(); - if (delta < 0) { - result = -1; - } else if (delta > 0) { - result = 1; - } else { - if (o1.getLength() > o2.getLength()) { - result = -1; - } else { - result = 1; - } - } - return result; + return delta < 0 ? -1 : delta > 0 ? 1 : o1.getLength() > o2.getLength() ? -1 : 1; } }); - for (SetMatcher.Match match : matches) { + for (final SetMatcher.Match match : matches) { if (match.getStart() < lastCut) { continue; diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleRegexTrie.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleRegexTrie.java index 2284eeb87..c871f6d11 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleRegexTrie.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleRegexTrie.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import java.util.List; @@ -49,14 +50,16 @@ public void put(final String keys, final P value) { if (keys.matches(SIMPLE_CHARACTER_CLASS)) { int charClassStart = keys.indexOf('[', 0); final int charClassEnd = keys.indexOf(']', 1); - String begin = keys.substring(0, charClassStart); - for (; charClassStart < charClassEnd - 1; charClassStart++) { - char middle = keys.charAt(charClassStart + 1); - String end = keys.substring(charClassEnd + 1, keys.length()); + final String begin = keys.substring(0, charClassStart); + for (; charClassStart < charClassEnd - 1; ++charClassStart) { + final char middle = keys.charAt(charClassStart + 1); + final String end = keys.substring(charClassEnd + 1, keys.length()); put(begin + middle + end, value); } - } else + } + else { trie.put(keys, value); + } } public List

get(final String key) { diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleTrie.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleTrie.java index a35f50e44..40f0f422f 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleTrie.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleTrie.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; /** @@ -24,32 +25,36 @@ public final class SimpleTrie

{ private final Node

root = new Node<>(null); - public void put(final String key, final P value){ + public SimpleTrie() { + } + + public void put(final String key, final P value) { Node

node = root; Node

next; final int length = key.length(); - for (int i = 0; i < length-1; ++i) { + for (int i = 0; i < length - 1; ++i) { next = node.getNext(key.charAt(i)); - if(next==null){ + if (next == null) { next = node.addNext(key.charAt(i)); } node = next; } - next = node.getNext(key.charAt(length-1)); - if(next==null){ - next = node.addNext(key.charAt(length-1), value); - }else{ + next = node.getNext(key.charAt(length - 1)); + if (next == null) { + next = node.addNext(key.charAt(length - 1), value); + } + else { throw new IllegalStateException("Value '" + value + "' already in trie"); } } - public P get(final String key){ + public P get(final String key) { Node

node = root; final int length = key.length(); for (int i = 0; i < length; ++i) { node = node.getNext(key.charAt(i)); - if(node==null){ + if (node == null) { return null; } } @@ -65,25 +70,25 @@ private static final class Node

{ private final P value; private final CharMap> links = new CharMap>(); - public Node(final P value) { + Node(final P value) { this.value = value; } - public Node

addNext(final char key){ + public Node

addNext(final char key) { return addNext(key, null); } - public Node

addNext(final char key, final P value){ - final Node

next = new Node

(value); + public Node

addNext(final char key, final P currentValue) { + final Node

next = new Node

(currentValue); links.put(key, next); return next; } - public P getValue(){ + public P getValue() { return value; } - public Node

getNext(final char key){ + public Node

getNext(final char key) { return links.get(key); } } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/tries/WildcardTrie.java b/metafacture-commons/src/main/java/org/metafacture/commons/tries/WildcardTrie.java index 14f13ba8b..1bada6d34 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/tries/WildcardTrie.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/tries/WildcardTrie.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import java.util.ArrayList; @@ -41,6 +42,9 @@ public final class WildcardTrie

{ private Set> nodes = new HashSet>(); private Set> nextNodes = new HashSet>(); + public WildcardTrie() { + } + /** * Inserts keys into the try. Use '|' to concatenate. Use '*' (0,inf) and * '?' (1,1) to express wildcards. @@ -51,10 +55,11 @@ public final class WildcardTrie

{ public void put(final String keys, final P value) { if (keys.contains(OR_STRING)) { final String[] keysSplit = OR_PATTERN.split(keys); - for (String string : keysSplit) { + for (final String string : keysSplit) { simplyPut(string, value); } - } else { + } + else { simplyPut(keys, value); } } @@ -76,13 +81,11 @@ private void simplyPut(final String key, final P value) { } public List

get(final String key) { - nodes.add(root); final int length = key.length(); for (int i = 0; i < length; ++i) { - for (Node

node : nodes) { - Node

temp; - temp = node.getNext(key.charAt(i)); + for (final Node

node : nodes) { + Node

temp = node.getNext(key.charAt(i)); if (temp != null) { nextNodes.add(temp); } @@ -108,8 +111,12 @@ public List

get(final String key) { nextNodes = temp; } + return matches(); + } + + private List

matches() { List

matches = Collections.emptyList(); - for (Node

node : nodes) { + for (final Node

node : nodes) { final Set

values = node.getValues(); if (!values.isEmpty()) { if (matches == Collections.emptyList()) { diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/types/ListMap.java b/metafacture-commons/src/main/java/org/metafacture/commons/types/ListMap.java index 186bee82a..2b0ec6859 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/types/ListMap.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/types/ListMap.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.types; import java.util.ArrayList; @@ -39,12 +40,10 @@ public class ListMap implements Map> { private final Map> map; public ListMap() { - super(); map = new HashMap>(); } public ListMap(final Map> map) { - super(); this.map = map; } @@ -62,7 +61,6 @@ public final List removeKey(final K key) { return map.remove(key); } - public final void clearKey(final K key) { final List values = map.get(key); if (values != null) { @@ -71,7 +69,7 @@ public final void clearKey(final K key) { } public final void clearAllKeys() { - for (Entry> entry: map.entrySet()) { + for (final Entry> entry: map.entrySet()) { entry.getValue().clear(); } } @@ -86,7 +84,6 @@ public final Set keySet() { return map.keySet(); } - public final void add(final K name, final V value) { List values = map.get(name); @@ -98,18 +95,6 @@ public final void add(final K name, final V value) { values.add(value); } - //@Override - public final void putAll(final K name, final Collection addValues) { - - List values = map.get(name); - if (values == null) { - values = new ArrayList(); - map.put(name, values); - } - - values.addAll(addValues); - } - @Override public final List get(final Object name) { final List values = map.get(name); @@ -136,8 +121,8 @@ public final String toString() { return map.toString(); } - public final void setId(final String identifier) { - this.identifier = identifier; + public final void setId(final String newIdentifier) { + identifier = newIdentifier; } public final String getId() { @@ -174,10 +159,20 @@ public final List remove(final Object key) { return map.remove(key); } + //@Override + public final void putAll(final K name, final Collection addValues) { + List values = map.get(name); + if (values == null) { + values = new ArrayList(); + map.put(name, values); + } + + values.addAll(addValues); + } + @Override public final void putAll(final Map> putMap) { map.putAll(putMap); - } @Override diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/types/NamedValue.java b/metafacture-commons/src/main/java/org/metafacture/commons/types/NamedValue.java index 46efa0221..f1c310945 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/types/NamedValue.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/types/NamedValue.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.types; /** @@ -61,9 +62,9 @@ public int hashCode() { public boolean equals(final Object obj) { if (obj instanceof NamedValue) { final NamedValue namedValue = (NamedValue) obj; - return namedValue.preCompHashCode == preCompHashCode - && namedValue.name.equals(name) - && namedValue.value.equals(value); + return namedValue.preCompHashCode == preCompHashCode && + namedValue.name.equals(name) && + namedValue.value.equals(value); } return false; } diff --git a/metafacture-commons/src/main/java/org/metafacture/commons/types/ScopedHashMap.java b/metafacture-commons/src/main/java/org/metafacture/commons/types/ScopedHashMap.java index 0a00c4eaf..a7031c65e 100644 --- a/metafacture-commons/src/main/java/org/metafacture/commons/types/ScopedHashMap.java +++ b/metafacture-commons/src/main/java/org/metafacture/commons/types/ScopedHashMap.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.types; import java.util.HashMap; @@ -26,18 +27,16 @@ * @param type of the values * @author Markus Michael Geipel */ -public final class ScopedHashMap extends HashMap { +public final class ScopedHashMap extends HashMap { // checkstyle-disable-line IllegalType private static final long serialVersionUID = -7184066609960144713L; private final ScopedHashMap outerScope; public ScopedHashMap(final ScopedHashMap outerScope) { - super(); this.outerScope = outerScope; } public ScopedHashMap() { - super(); outerScope = null; } diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/RequireTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/RequireTest.java index 6edbb437d..b08592b08 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/RequireTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/RequireTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/ResourceUtilTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/ResourceUtilTest.java index ddb48fa52..11ba1173a 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/ResourceUtilTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/ResourceUtilTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import static java.util.stream.Collectors.joining; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/StringUtilTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/StringUtilTest.java index 2b608c33f..3b527e0a6 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/StringUtilTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/StringUtilTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/TimeUtilTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/TimeUtilTest.java index cbfa8c910..ef5cb7561 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/TimeUtilTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/TimeUtilTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/XmlUtilTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/XmlUtilTest.java index e9056d260..c05ba03a3 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/XmlUtilTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/XmlUtilTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/tries/CharMapTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/tries/CharMapTest.java index c318d5728..79a14a586 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/tries/CharMapTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/tries/CharMapTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetMatchTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetMatchTest.java index 4701323ba..a82461d5a 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetMatchTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetMatchTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetReplaceTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetReplaceTest.java index 31838bb60..1376ea9f1 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetReplaceTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SetReplaceTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleRegexTrieTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleRegexTrieTest.java index 65e771ca4..46312a1b9 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleRegexTrieTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleRegexTrieTest.java @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import static org.junit.Assert.assertTrue; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleTrieTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleTrieTest.java index bf05c62a1..27263ed6b 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleTrieTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleTrieTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/tries/WildcardTrieTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/tries/WildcardTrieTest.java index cf7bb3b52..5ad08b05f 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/tries/WildcardTrieTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/tries/WildcardTrieTest.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.tries; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/types/ListMapTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/types/ListMapTest.java index 848e1d706..cb8fd793c 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/types/ListMapTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/types/ListMapTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.types; import static org.junit.Assert.assertEquals; diff --git a/metafacture-commons/src/test/java/org/metafacture/commons/types/NamedValueTest.java b/metafacture-commons/src/test/java/org/metafacture/commons/types/NamedValueTest.java index 5e2a41eff..fd405b747 100644 --- a/metafacture-commons/src/test/java/org/metafacture/commons/types/NamedValueTest.java +++ b/metafacture-commons/src/test/java/org/metafacture/commons/types/NamedValueTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.commons.types; import org.junit.Assert; From 823fddeccc46971d69292db0a256b226bbe4c050 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 14:40:44 +0200 Subject: [PATCH 05/30] metafacture-csv/ (main): Fix Checkstyle violations. --- .../java/org/metafacture/csv/CsvDecoder.java | 32 +++++++++++-------- .../org/metafacture/csv/CsvDecoderTest.java | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/metafacture-csv/src/main/java/org/metafacture/csv/CsvDecoder.java b/metafacture-csv/src/main/java/org/metafacture/csv/CsvDecoder.java index 3a39dc1a6..39de4d4f9 100644 --- a/metafacture-csv/src/main/java/org/metafacture/csv/CsvDecoder.java +++ b/metafacture-csv/src/main/java/org/metafacture/csv/CsvDecoder.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.csv; -import java.io.IOException; -import java.io.StringReader; -import java.util.List; +package org.metafacture.csv; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamReceiver; @@ -28,6 +25,10 @@ import com.opencsv.CSVReader; +import java.io.IOException; +import java.io.StringReader; +import java.util.List; + /** * Decodes lines of CSV files. First line is interpreted as header. * @@ -52,7 +53,6 @@ public final class CsvDecoder extends DefaultObjectPipe * @param separator to split lines */ public CsvDecoder(final String separator) { - super(); this.separator = separator.charAt(0); } @@ -60,12 +60,10 @@ public CsvDecoder(final String separator) { * @param separator to split lines */ public CsvDecoder(final char separator) { - super(); this.separator = separator; } public CsvDecoder() { - super(); this.separator = DEFAULT_SEP; } @@ -73,22 +71,25 @@ public CsvDecoder() { public void process(final String string) { assert !isClosed(); final String[] parts = parseCsv(string); - if(hasHeader){ - if(header.length==0){ + if (hasHeader) { + if (header.length == 0) { header = parts; - }else if(parts.length==header.length){ + } + else if (parts.length == header.length) { getReceiver().startRecord(String.valueOf(++count)); for (int i = 0; i < parts.length; ++i) { getReceiver().literal(header[i], parts[i]); } getReceiver().endRecord(); - }else{ + } + else { throw new IllegalArgumentException( String.format( "wrong number of columns (expected %s, was %s) in input line: %s", header.length, parts.length, string)); } - }else{ + } + else { getReceiver().startRecord(String.valueOf(++count)); for (int i = 0; i < parts.length; ++i) { getReceiver().literal(String.valueOf(i), parts[i]); @@ -107,7 +108,8 @@ private String[] parseCsv(final String string) { parts = lines.get(0); } reader.close(); - } catch (IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } return parts; @@ -117,5 +119,7 @@ public void setHasHeader(final boolean hasHeader) { this.hasHeader = hasHeader; } - public void setSeparator(final String separator) { this.separator = separator.charAt(0); } + public void setSeparator(final String separator) { + this.separator = separator.charAt(0); + } } diff --git a/metafacture-csv/src/test/java/org/metafacture/csv/CsvDecoderTest.java b/metafacture-csv/src/test/java/org/metafacture/csv/CsvDecoderTest.java index a7c345ca7..ed095383c 100644 --- a/metafacture-csv/src/test/java/org/metafacture/csv/CsvDecoderTest.java +++ b/metafacture-csv/src/test/java/org/metafacture/csv/CsvDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.csv; import static org.mockito.Mockito.inOrder; From 713c413a4b3d59a5b3c689932adc6a403294ab15 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 14:49:48 +0200 Subject: [PATCH 06/30] metafacture-elasticsearch/ (main): Fix Checkstyle violations. --- .../JsonToElasticsearchBulk.java | 149 ++++++++++-------- .../JsonToElasticsearchBulkTest.java | 1 + 2 files changed, 82 insertions(+), 68 deletions(-) diff --git a/metafacture-elasticsearch/src/main/java/org/metafacture/elasticsearch/JsonToElasticsearchBulk.java b/metafacture-elasticsearch/src/main/java/org/metafacture/elasticsearch/JsonToElasticsearchBulk.java index 35155b44d..804e762eb 100644 --- a/metafacture-elasticsearch/src/main/java/org/metafacture/elasticsearch/JsonToElasticsearchBulk.java +++ b/metafacture-elasticsearch/src/main/java/org/metafacture/elasticsearch/JsonToElasticsearchBulk.java @@ -13,8 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.elasticsearch; +import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.ObjectReceiver; +import org.metafacture.framework.annotations.In; +import org.metafacture.framework.annotations.Out; +import org.metafacture.framework.helpers.DefaultObjectPipe; + +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.IOException; import java.io.StringWriter; import java.util.Arrays; @@ -24,14 +33,6 @@ import java.util.Set; import java.util.regex.Pattern; -import org.metafacture.framework.FluxCommand; -import org.metafacture.framework.ObjectReceiver; -import org.metafacture.framework.annotations.In; -import org.metafacture.framework.annotations.Out; -import org.metafacture.framework.helpers.DefaultObjectPipe; - -import com.fasterxml.jackson.databind.ObjectMapper; - /** * Add Elasticsearch bulk indexing metadata to JSON input. * @@ -42,56 +43,14 @@ @In(String.class) @Out(String.class) @FluxCommand("json-to-elasticsearch-bulk") -public class JsonToElasticsearchBulk extends - DefaultObjectPipe> { - - /** - * Use a MultiMap with Jackson to collect values from multiple fields with - * identical names under a single key. - */ - static class MultiMap extends HashMap { - private static final long serialVersionUID = 490682490432334605L; - - MultiMap() { - // default constructor for Jackson - } - - @Override - public Object put(String key, Object value) { - if (containsKey(key)) { - Object oldValue = get(key); - if (oldValue instanceof Set) { - @SuppressWarnings("unchecked") - Set vals = ((Set) oldValue); - vals.add(value); - return super.put(key, vals); - } - HashSet set = new HashSet<>(Arrays.asList(oldValue, value)); - return super.put(key, set.size() == 1 ? value : set); - } - return super.put(key, value); - } - } +public class JsonToElasticsearchBulk extends DefaultObjectPipe> { private ObjectMapper mapper = new ObjectMapper(); private String[] idPath; private String type; private String index; - public void setIdKey(String idKey) { - this.idPath = new String[]{idKey}; - } - - public void setType(String type) { - this.type = type; - } - - public void setIndex(String index) { - this.index = index; - } - public JsonToElasticsearchBulk() { - super(); this.idPath = new String[]{}; this.type = null; this.index = null; @@ -103,8 +62,8 @@ public JsonToElasticsearchBulk() { * @param type The Elasticsearch index type * @param index The Elasticsearch index name */ - public JsonToElasticsearchBulk(String type, String index) { - this(new String[] { }, type, index); + public JsonToElasticsearchBulk(final String type, final String index) { + this(new String[] {}, type, index); } /** @@ -112,7 +71,7 @@ public JsonToElasticsearchBulk(String type, String index) { * @param type The Elasticsearch index type * @param index The Elasticsearch index name */ - public JsonToElasticsearchBulk(String[] idPath, String type, String index) { + public JsonToElasticsearchBulk(final String[] idPath, final String type, final String index) { this.idPath = idPath; this.type = type; this.index = index; @@ -123,7 +82,7 @@ public JsonToElasticsearchBulk(String[] idPath, String type, String index) { * @param type The Elasticsearch index type * @param index The Elasticsearch index name */ - public JsonToElasticsearchBulk(String idKey, String type, String index) { + public JsonToElasticsearchBulk(final String idKey, final String type, final String index) { this(new String[]{idKey}, type, index); } @@ -133,42 +92,96 @@ public JsonToElasticsearchBulk(String idKey, String type, String index) { * @param index The Elasticsearch index name * @param entitySeparator The separator between entity names in idKey */ - public JsonToElasticsearchBulk(String idKey, String type, String index, String entitySeparator) { + public JsonToElasticsearchBulk(final String idKey, final String type, final String index, final String entitySeparator) { this(idKey.split(Pattern.quote(entitySeparator)), type, index); } + public void setIdKey(final String idKey) { + this.idPath = new String[]{idKey}; + } + + public void setType(final String type) { + this.type = type; + } + + public void setIndex(final String index) { + this.index = index; + } + @Override - public void process(String obj) { - StringWriter stringWriter = new StringWriter(); + public void process(final String obj) { + final StringWriter stringWriter = new StringWriter(); try { - Map json = mapper.readValue(obj, MultiMap.class); - Map detailsMap = new HashMap(); - Map indexMap = new HashMap(); + final Map json = mapper.readValue(obj, MultiMap.class); + final Map detailsMap = new HashMap(); + final Map indexMap = new HashMap(); indexMap.put("index", detailsMap); - if (idPath.length > 0) detailsMap.put("_id", findId(json)); + if (idPath.length > 0) { + detailsMap.put("_id", findId(json)); + } detailsMap.put("_type", type); detailsMap.put("_index", index); mapper.writeValue(stringWriter, indexMap); stringWriter.write("\n"); mapper.writeValue(stringWriter, json); - } catch (IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } getReceiver().process(stringWriter.toString()); } - private Object findId(Object value) { + private Object findId(final Object value) { + Object newValue = value; + for (final String key : idPath) { - if (value instanceof Map) { + if (newValue instanceof Map) { @SuppressWarnings("unchecked") - final Map nestedMap = (Map) value; - value = nestedMap.get(key); + final Map nestedMap = (Map) newValue; + newValue = nestedMap.get(key); } else { return null; } } - return value; + return newValue; + } + + /** + * Use a MultiMap with Jackson to collect values from multiple fields with + * identical names under a single key. + */ + static class MultiMap extends HashMap { // checkstyle-disable-line IllegalType + private static final long serialVersionUID = 490682490432334605L; + + MultiMap() { + // default constructor for Jackson + } + + @Override + public Object put(final String key, final Object value) { + final Object newValue; + + if (containsKey(key)) { + final Object oldValue = get(key); + if (oldValue instanceof Set) { + @SuppressWarnings("unchecked") + final Set vals = (Set) oldValue; + vals.add(value); + newValue = vals; + } + else { + final Set set = new HashSet<>(Arrays.asList(oldValue, value)); + newValue = set.size() == 1 ? value : set; + } + } + else { + newValue = value; + } + + return super.put(key, newValue); + } } + } diff --git a/metafacture-elasticsearch/src/test/java/org/metafacture/elasticsearch/JsonToElasticsearchBulkTest.java b/metafacture-elasticsearch/src/test/java/org/metafacture/elasticsearch/JsonToElasticsearchBulkTest.java index db20e36df..ae715271a 100644 --- a/metafacture-elasticsearch/src/test/java/org/metafacture/elasticsearch/JsonToElasticsearchBulkTest.java +++ b/metafacture-elasticsearch/src/test/java/org/metafacture/elasticsearch/JsonToElasticsearchBulkTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.elasticsearch; import static org.mockito.Mockito.verify; From cfef405a84c51f93b9facf316f09499a0907e8c8 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 14:55:58 +0200 Subject: [PATCH 07/30] metafacture-files/ (main): Fix Checkstyle violations. --- .../java/org/metafacture/files/DirReader.java | 30 ++++++++----- .../files/FileDigestCalculator.java | 45 +++++++++++-------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/metafacture-files/src/main/java/org/metafacture/files/DirReader.java b/metafacture-files/src/main/java/org/metafacture/files/DirReader.java index c477cb285..952e0cd9b 100644 --- a/metafacture-files/src/main/java/org/metafacture/files/DirReader.java +++ b/metafacture-files/src/main/java/org/metafacture/files/DirReader.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.files; -import java.io.File; -import java.io.FilenameFilter; -import java.util.Arrays; +package org.metafacture.files; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -26,6 +23,10 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.File; +import java.io.FilenameFilter; +import java.util.Arrays; + /** * Reads a directory and emits all filenames found. * @@ -40,14 +41,17 @@ public final class DirReader extends DefaultObjectPipe receiver = getReceiver(); - final File[] files = filenameFilterPattern == null ? dir.listFiles() - : dir.listFiles(new FilenameFilter() { + final File[] files = filenameFilterPattern == null ? dir.listFiles() : + dir.listFiles(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name.matches(filenameFilterPattern); } }); Arrays.sort(files); - for (File file : files) { + for (final File file : files) { if (file.isDirectory()) { if (recursive) { dir(file); } - } else { + } + else { receiver.process(file.getAbsolutePath()); } } diff --git a/metafacture-files/src/main/java/org/metafacture/files/FileDigestCalculator.java b/metafacture-files/src/main/java/org/metafacture/files/FileDigestCalculator.java index 7c4c99dac..e36395868 100644 --- a/metafacture-files/src/main/java/org/metafacture/files/FileDigestCalculator.java +++ b/metafacture-files/src/main/java/org/metafacture/files/FileDigestCalculator.java @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.files; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; +package org.metafacture.files; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -30,6 +25,12 @@ import org.metafacture.framework.helpers.DefaultObjectPipe; import org.metafacture.framework.objects.Triple; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + /** * Interprets the input string as a file name and computes a cryptographic hash * for the file. @@ -48,13 +49,13 @@ public final class FileDigestCalculator extends private static final int HIGH_NIBBLE = 0xf0; private static final int LOW_NIBBLE = 0x0f; - private static final char[] NIBBLE_TO_HEX = - { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + private static final char[] NIBBLE_TO_HEX = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + + private static final int NIBBLE_TO_HEX_SHIFT_WIDTH = 4; private final DigestAlgorithm algorithm; private final MessageDigest messageDigest; - public FileDigestCalculator(final DigestAlgorithm algorithm) { this.algorithm = algorithm; this.messageDigest = this.algorithm.getInstance(); @@ -72,12 +73,17 @@ public void process(final String file) { try { stream = new FileInputStream(file); digest = bytesToHex(getDigest(stream, messageDigest)); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); - } finally { + } + finally { if (stream != null) { - try { stream.close(); } - catch (final IOException e) { } + try { + stream.close(); + } + catch (final IOException e) { + } } } getReceiver().process(new Triple(file, algorithm.name(), digest)); @@ -96,8 +102,8 @@ private static byte[] getDigest(final InputStream stream, final MessageDigest me private static String bytesToHex(final byte[] bytes) { final char[] hex = new char[bytes.length * 2]; - for (int i=0; i < bytes.length; ++i) { - hex[i * 2] = NIBBLE_TO_HEX[(bytes[i] & HIGH_NIBBLE) >>> 4]; + for (int i = 0; i < bytes.length; ++i) { + hex[i * 2] = NIBBLE_TO_HEX[(bytes[i] & HIGH_NIBBLE) >>> NIBBLE_TO_HEX_SHIFT_WIDTH]; hex[i * 2 + 1] = NIBBLE_TO_HEX[bytes[i] & LOW_NIBBLE]; } return new String(hex); @@ -115,19 +121,20 @@ public enum DigestAlgorithm { SHA1("SHA-1"), SHA256("SHA-256"), SHA384("SHA-384"), - SHA512 ("SHA-512"); + SHA512("SHA-512"); private final String identifier; - private DigestAlgorithm(final String identifier) { + DigestAlgorithm(final String identifier) { this.identifier = identifier; } public MessageDigest getInstance() { try { return MessageDigest.getInstance(identifier); - } catch (NoSuchAlgorithmException e) { - throw new MetafactureException (e); + } + catch (final NoSuchAlgorithmException e) { + throw new MetafactureException(e); } } From 7e744c729ce43014d33dd64bf6cd5334b5b1a3e8 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 15:05:57 +0200 Subject: [PATCH 08/30] metafacture-flowcontrol/ (main): Fix Checkstyle violations. --- .../flowcontrol/CloseSuppressor.java | 7 +-- .../flowcontrol/ObjectBatchResetter.java | 7 ++- .../flowcontrol/ObjectExceptionCatcher.java | 11 ++-- .../flowcontrol/ObjectPipeDecoupler.java | 28 ++++++---- .../flowcontrol/ObjectThreader.java | 25 +++++---- .../flowcontrol/StreamBatchResetter.java | 20 ++++--- .../metafacture/flowcontrol/StreamBuffer.java | 53 ++++++++++--------- .../flowcontrol/StreamDeferrer.java | 4 ++ .../flowcontrol/StreamExceptionCatcher.java | 22 ++++---- .../flowcontrol/CloseSuppressorTest.java | 1 + .../flowcontrol/ObjectBatchResetterTest.java | 1 + .../ObjectExceptionCatcherTest.java | 1 + .../flowcontrol/ObjectThreaderTest.java | 1 + .../flowcontrol/StreamBufferTest.java | 1 + .../flowcontrol/StreamDeferrerTest.java | 1 + 15 files changed, 108 insertions(+), 75 deletions(-) diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/CloseSuppressor.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/CloseSuppressor.java index b4cd8417b..5367da7ba 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/CloseSuppressor.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/CloseSuppressor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; @@ -59,9 +60,9 @@ public void process(final T obj) { } @Override - public > R setReceiver(final R receiver) { - this.receiver = receiver; - return receiver; + public > R setReceiver(final R newReceiver) { + receiver = newReceiver; + return newReceiver; } @Override diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectBatchResetter.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectBatchResetter.java index bff40c514..70137a785 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectBatchResetter.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectBatchResetter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; @@ -41,6 +42,9 @@ public class ObjectBatchResetter extends DefaultObjectPipereset-stream event is triggered. *

@@ -53,8 +57,7 @@ public class ObjectBatchResetter extends DefaultObjectPipereset-stream event is * triggered */ - public void setBatchSize(int batchSize) { - + public void setBatchSize(final int batchSize) { this.batchSize = batchSize; } diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectExceptionCatcher.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectExceptionCatcher.java index 934425f50..3b440b445 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectExceptionCatcher.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectExceptionCatcher.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.flowcontrol; -import java.io.PrintWriter; -import java.io.StringWriter; +package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -24,9 +22,12 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.PrintWriter; +import java.io.StringWriter; /** * Wraps the call to the process method of the downstream module @@ -57,7 +58,6 @@ public ObjectExceptionCatcher() { } public ObjectExceptionCatcher(final String logPrefix) { - super(); this.logPrefix = logPrefix; } @@ -81,7 +81,8 @@ public boolean isLogStackTrace() { public void process(final T obj) { try { getReceiver().process(obj); - } catch(final Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch LOG.error("{}'{}' while processing object: {}", logPrefix, e.getMessage(), obj); if (logStackTrace) { diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectPipeDecoupler.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectPipeDecoupler.java index a91981c06..38f275ca0 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectPipeDecoupler.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectPipeDecoupler.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.flowcontrol; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; +package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectPipe; @@ -24,9 +22,13 @@ import org.metafacture.framework.annotations.Description; import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + /** * Creates a new thread in which subsequent flow elements run. * @@ -76,7 +78,8 @@ public void process(final T obj) { if (debug) { LOG.info("Current buffer size: {}", queue.size()); } - } catch (InterruptedException e) { + } + catch (final InterruptedException e) { Thread.currentThread().interrupt(); } } @@ -87,20 +90,21 @@ private void start() { } @Override - public > R setReceiver(final R receiver) { + public > R setReceiver(final R newReceiver) { if (null != thread) { throw new IllegalStateException("Receiver cannot be changed while processing thread is running."); } - this.receiver = receiver; - return receiver; + receiver = newReceiver; + return newReceiver; } @Override public void resetStream() { try { queue.put(Feeder.BLUE_PILL); - } catch (InterruptedException e) { + } + catch (final InterruptedException e) { Thread.currentThread().interrupt(); } } @@ -110,7 +114,8 @@ public void closeStream() { try { queue.put(Feeder.RED_PILL); thread.join(); - } catch (InterruptedException e) { + } + catch (final InterruptedException e) { Thread.currentThread().interrupt(); } thread = null; @@ -128,7 +133,7 @@ static final class Feeder implements Runnable { private final ObjectReceiver receiver; private final BlockingQueue queue; - public Feeder(final ObjectReceiver receiver, final BlockingQueue queue) { + Feeder(final ObjectReceiver receiver, final BlockingQueue queue) { this.receiver = receiver; this.queue = queue; } @@ -150,7 +155,8 @@ public void run() { } receiver.process((T) object); } - } catch (InterruptedException e) { + } + catch (final InterruptedException e) { Thread.currentThread().interrupt(); return; } diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectThreader.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectThreader.java index 6b1f7ad1d..63aacc3ea 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectThreader.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/ObjectThreader.java @@ -15,9 +15,6 @@ package org.metafacture.flowcontrol; -import java.util.ArrayList; -import java.util.List; - import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectPipe; import org.metafacture.framework.ObjectReceiver; @@ -25,9 +22,13 @@ import org.metafacture.framework.annotations.Description; import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.List; + /** * Divides incoming objects and distributes them to added receivers. These * receivers are coupled with an @@ -48,22 +49,26 @@ public class ObjectThreader implements Tee>, ObjectPipe> receivers = new ArrayList>(); - private int objectNumber = 0; + private int objectNumber; + + public ObjectThreader() { + } @Override public void process(final T obj) { receivers.get(objectNumber).process(obj); if (objectNumber == receivers.size() - 1) { objectNumber = 0; - } else { - objectNumber++; + } + else { + ++objectNumber; } } @Override public Tee> addReceiver(final ObjectReceiver receiver) { - LOG.info("Adding thread {}", (receivers.size() + 1)); - ObjectPipeDecoupler opd = new ObjectPipeDecoupler<>(); + LOG.info("Adding thread {}", receivers.size() + 1); + final ObjectPipeDecoupler opd = new ObjectPipeDecoupler<>(); opd.setReceiver(receiver); receivers.add(opd); return this; @@ -77,7 +82,7 @@ public > R setReceiver(final R receiver) { } @Override - public > R setReceivers(R receiver, ObjectReceiver lateralReceiver) { + public > R setReceivers(final R receiver, final ObjectReceiver lateralReceiver) { receivers.clear(); addReceiver(receiver); addReceiver(lateralReceiver); @@ -95,7 +100,7 @@ public void closeStream() { } @Override - public Tee> removeReceiver(ObjectReceiver receiver) { + public Tee> removeReceiver(final ObjectReceiver receiver) { receivers.remove(receiver); return this; } diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBatchResetter.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBatchResetter.java index df505c79a..d6def5222 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBatchResetter.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBatchResetter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; @@ -40,35 +41,38 @@ public final class StreamBatchResetter extends ForwardingStreamPipe { private long recordCount; private long batchCount; - public final void setBatchSize(final int batchSize) { + public StreamBatchResetter() { + } + + public void setBatchSize(final int batchSize) { this.batchSize = batchSize; } - public final long getBatchSize() { + public long getBatchSize() { return batchSize; } - public final long getBatchCount() { + public long getBatchCount() { return batchCount; } - public final long getRecordCount() { + public long getRecordCount() { return recordCount; } @Override - public final void endRecord() { + public void endRecord() { getReceiver().endRecord(); - recordCount++; + ++recordCount; recordCount %= batchSize; if (recordCount == 0) { - batchCount++; + ++batchCount; getReceiver().resetStream(); } } @Override - protected final void onResetStream() { + protected void onResetStream() { recordCount = 0; batchCount = 0; } diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBuffer.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBuffer.java index 0e8f985a6..0f1940d63 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBuffer.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamBuffer.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.flowcontrol; -import java.util.ArrayList; -import java.util.List; +package org.metafacture.flowcontrol; import org.metafacture.framework.StreamPipe; import org.metafacture.framework.StreamReceiver; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.util.ArrayList; +import java.util.List; /** * {@link StreamPipe} which buffers incoming records and replays them upon @@ -30,8 +30,7 @@ * @author Markus Michael Geipel * */ -public final class StreamBuffer - extends DefaultStreamPipe { +public final class StreamBuffer extends DefaultStreamPipe { /** * Defines entity and literal message types. @@ -43,8 +42,10 @@ private enum MessageType { private final List typeBuffer = new ArrayList(); private final List valueBuffer = new ArrayList(); + public StreamBuffer() { + } - public boolean isEmpty(){ + public boolean isEmpty() { return typeBuffer.isEmpty(); } @@ -54,27 +55,27 @@ public boolean isEmpty(){ public void replay() { int index = 0; - for (MessageType type : typeBuffer) { + for (final MessageType type : typeBuffer) { switch (type) { - case RECORD_START: - getReceiver().startRecord(valueBuffer.get(index)); - ++index; - break; - case RECORD_END: - getReceiver().endRecord(); - break; - - case ENTITY_START: - getReceiver().startEntity(valueBuffer.get(index)); - ++index; - break; - case ENTITY_END: - getReceiver().endEntity(); - break; - default: - getReceiver().literal(valueBuffer.get(index), valueBuffer.get(index+1)); - index +=2; - break; + case RECORD_START: + getReceiver().startRecord(valueBuffer.get(index)); + ++index; + break; + case RECORD_END: + getReceiver().endRecord(); + break; + + case ENTITY_START: + getReceiver().startEntity(valueBuffer.get(index)); + ++index; + break; + case ENTITY_END: + getReceiver().endEntity(); + break; + default: + getReceiver().literal(valueBuffer.get(index), valueBuffer.get(index + 1)); + index += 2; + break; } } } diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamDeferrer.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamDeferrer.java index 60a48c250..f9ce9d702 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamDeferrer.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamDeferrer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; @@ -44,6 +45,9 @@ public class StreamDeferrer extends DefaultStreamPipe { private final StreamBuffer buffer = new StreamBuffer(); + public StreamDeferrer() { + } + @Override public void startRecord(final String identifier) { buffer.clear(); diff --git a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamExceptionCatcher.java b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamExceptionCatcher.java index e19f41a19..e0fe7aaad 100644 --- a/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamExceptionCatcher.java +++ b/metafacture-flowcontrol/src/main/java/org/metafacture/flowcontrol/StreamExceptionCatcher.java @@ -14,9 +14,6 @@ * limitations under the License. */ -/** - * - */ package org.metafacture.flowcontrol; import org.metafacture.framework.FluxCommand; @@ -25,6 +22,7 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +49,6 @@ public StreamExceptionCatcher() { } public StreamExceptionCatcher(final String logPrefix) { - super(); this.logPrefix = logPrefix; } @@ -59,7 +56,8 @@ public StreamExceptionCatcher(final String logPrefix) { public void startRecord(final String identifier) { try { getReceiver().startRecord(identifier); - } catch(final Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch LOG.error(MSG_PATTERN, logPrefix, "StartRecord" + identifier); LOG.error(MSG_PATTERN, logPrefix, e); } @@ -69,7 +67,8 @@ public void startRecord(final String identifier) { public void endRecord() { try { getReceiver().endRecord(); - } catch(final Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch LOG.error(MSG_PATTERN, logPrefix, "endRecord"); LOG.error(MSG_PATTERN, logPrefix, e); } @@ -79,7 +78,8 @@ public void endRecord() { public void startEntity(final String name) { try { getReceiver().startEntity(name); - } catch(final Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch LOG.error(MSG_PATTERN, logPrefix, "startEntity" + name); LOG.error(MSG_PATTERN, logPrefix, e); } @@ -89,7 +89,8 @@ public void startEntity(final String name) { public void endEntity() { try { getReceiver().endEntity(); - } catch(final Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch LOG.error(MSG_PATTERN, logPrefix, "endEntity"); LOG.error(MSG_PATTERN, logPrefix, e); } @@ -99,8 +100,9 @@ public void endEntity() { public void literal(final String name, final String value) { try { getReceiver().literal(name, value); - } catch(final Exception e) { - LOG.error(MSG_PATTERN, logPrefix, "literal " + name +" " + value); + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch + LOG.error(MSG_PATTERN, logPrefix, "literal " + name + " " + value); LOG.error(MSG_PATTERN, logPrefix, e); } } diff --git a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/CloseSuppressorTest.java b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/CloseSuppressorTest.java index dd7681cdc..7dcc60e3a 100644 --- a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/CloseSuppressorTest.java +++ b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/CloseSuppressorTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import org.junit.Test; diff --git a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectBatchResetterTest.java b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectBatchResetterTest.java index f857466c3..e28ae2a52 100644 --- a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectBatchResetterTest.java +++ b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectBatchResetterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import static org.assertj.core.api.Assertions.assertThat; diff --git a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectExceptionCatcherTest.java b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectExceptionCatcherTest.java index 0e27b3ba3..48e016e3a 100644 --- a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectExceptionCatcherTest.java +++ b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectExceptionCatcherTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import static org.mockito.ArgumentMatchers.anyString; diff --git a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectThreaderTest.java b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectThreaderTest.java index 240d37a43..ae88b18a1 100644 --- a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectThreaderTest.java +++ b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/ObjectThreaderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import static org.assertj.core.api.Assertions.assertThat; diff --git a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamBufferTest.java b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamBufferTest.java index d5db16737..4473c99f1 100644 --- a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamBufferTest.java +++ b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamBufferTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamDeferrerTest.java b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamDeferrerTest.java index 0f7a2d582..ee5e27045 100644 --- a/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamDeferrerTest.java +++ b/metafacture-flowcontrol/src/test/java/org/metafacture/flowcontrol/StreamDeferrerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flowcontrol; import static org.mockito.Mockito.inOrder; From c60f69df2bf4440be41ff37e29c631f09ef42338 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 16:35:00 +0200 Subject: [PATCH 09/30] metafacture-flux/ (main): Fix Checkstyle violations. --- config/checkstyle/checkstyle.xml | 4 ++ .../org/metafacture/flux/FluxCompiler.java | 18 ++++---- .../metafacture/flux/FluxParseException.java | 1 + .../org/metafacture/flux/HelpPrinter.java | 45 +++++++++---------- .../org/metafacture/flux/parser/Flow.java | 34 ++++++++------ .../metafacture/flux/parser/FluxProgramm.java | 31 ++++++++----- .../metafacture/flux/parser/StringSender.java | 11 ++--- .../org/metafacture/flux/FluxGrammarTest.java | 1 + .../metafacture/flux/FluxProgrammTest.java | 1 + 9 files changed, 85 insertions(+), 61 deletions(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 1693187d0..a5415c3d6 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -4,6 +4,10 @@ "https://checkstyle.org/dtds/configuration_1_3.dtd"> + + + + diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/FluxCompiler.java b/metafacture-flux/src/main/java/org/metafacture/flux/FluxCompiler.java index febc7a630..0805ddec3 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/FluxCompiler.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/FluxCompiler.java @@ -13,20 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; +import org.metafacture.flux.parser.FlowBuilder; +import org.metafacture.flux.parser.FluxLexer; +import org.metafacture.flux.parser.FluxParser; +import org.metafacture.flux.parser.FluxProgramm; import org.antlr.runtime.ANTLRInputStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.metafacture.flux.parser.FlowBuilder; -import org.metafacture.flux.parser.FluxLexer; -import org.metafacture.flux.parser.FluxParser; -import org.metafacture.flux.parser.FluxProgramm; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; /** * Creates a flow based on a flux script. @@ -38,7 +40,7 @@ private FluxCompiler() { // no instances } - public static FluxProgramm compile(final InputStream flux, final Map vars ) throws RecognitionException, IOException{ + public static FluxProgramm compile(final InputStream flux, final Map vars) throws RecognitionException, IOException { return compileFlow(compileAst(flux), vars); } diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/FluxParseException.java b/metafacture-flux/src/main/java/org/metafacture/flux/FluxParseException.java index 2811b6d77..ee1e331e6 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/FluxParseException.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/FluxParseException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux; import org.metafacture.framework.MetafactureException; diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java b/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java index fbe2410ee..fc173cf5e 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java @@ -13,8 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux; +import org.metafacture.commons.ResourceUtil; +import org.metafacture.commons.reflection.ObjectFactory; +import org.metafacture.framework.MetafactureException; +import org.metafacture.framework.annotations.Description; +import org.metafacture.framework.annotations.In; +import org.metafacture.framework.annotations.Out; +import org.metafacture.framework.annotations.ReturnsAvailableArguments; + import java.io.IOException; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -24,16 +33,8 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Map.Entry; - -import org.metafacture.commons.ResourceUtil; -import org.metafacture.commons.reflection.ObjectFactory; -import org.metafacture.framework.MetafactureException; -import org.metafacture.framework.annotations.Description; -import org.metafacture.framework.annotations.In; -import org.metafacture.framework.annotations.Out; -import org.metafacture.framework.annotations.ReturnsAvailableArguments; +import java.util.Map; /** * prints Flux help for a given {@link ObjectFactory} @@ -58,7 +59,7 @@ public static void print(final ObjectFactory factory, final List keyWords = new ArrayList(); keyWords.addAll(factory.keySet()); Collections.sort(keyWords); - for (String name : keyWords) { + for (final String name : keyWords) { describe(name, factory, out); } } @@ -66,20 +67,18 @@ public static void print(final ObjectFactory factory, private static String getVersionInfo() { try { return ResourceUtil.loadProperties("build.properties").toString(); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Failed to load build infos", e); } } - private static void describe(String name, ObjectFactory factory, - PrintStream out) { + private static void describe(final String name, final ObjectFactory factory, final PrintStream out) { final Class moduleClass = factory.get(name).getPlainClass(); final Description desc = moduleClass.getAnnotation(Description.class); out.println(name); - name.chars().forEach(c-> { - out.print("-"); - }); + name.chars().forEach(c -> out.print("-")); out.println(); if (desc != null) { @@ -95,13 +94,14 @@ private static void describe(String name, ObjectFactory factory, if (!attributes.isEmpty()) { out.print("- options:\t"); final StringBuilder builder = new StringBuilder(); - for (Entry> entry : attributes.entrySet()) { + for (final Entry> entry : attributes.entrySet()) { if (entry.getValue().isEnum()) { builder.append(entry.getKey()) .append(" ") .append(Arrays.asList(entry.getValue().getEnumConstants())) .append(", "); - } else { + } + else { builder.append(entry.getKey()) .append(" (") .append(entry.getValue().getSimpleName()) @@ -128,14 +128,13 @@ private static void describe(String name, ObjectFactory factory, } @SuppressWarnings("unchecked") - private static Collection getAvailableArguments( - Class moduleClass) { - for (Method method : moduleClass.getMethods()) { + private static Collection getAvailableArguments(final Class moduleClass) { + for (final Method method : moduleClass.getMethods()) { if (method.getAnnotation(ReturnsAvailableArguments.class) != null) { try { return (Collection) method.invoke(moduleClass); - } catch (IllegalAccessException | InvocationTargetException | - IllegalArgumentException e) { + } + catch (final IllegalAccessException | InvocationTargetException | IllegalArgumentException e) { // silently ignore } } diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/parser/Flow.java b/metafacture-flux/src/main/java/org/metafacture/flux/parser/Flow.java index b171f4843..a786e318f 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/parser/Flow.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/parser/Flow.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.flux.parser; -import java.util.ArrayList; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; +package org.metafacture.flux.parser; import org.metafacture.flux.FluxParseException; import org.metafacture.framework.LifeCycle; @@ -28,6 +24,10 @@ import org.metafacture.framework.Tee; import org.metafacture.io.StdInOpener; +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; /** * @author Markus Michael Geipel @@ -42,9 +42,12 @@ final class Flow { private ObjectReceiver start; private boolean joinLooseEnds; - @SuppressWarnings({ "unchecked", "rawtypes" }) + Flow() { + } + + @SuppressWarnings("unchecked") public void addElement(final Receiver nextElement) { - if(element==null){ + if (element == null) { setStart((ObjectReceiver) nextElement); return; } @@ -55,19 +58,23 @@ public void addElement(final Receiver nextElement) { for (final LifeCycle looseEnd : looseEndsStack.pop()) { if (looseEnd instanceof Tee) { ((Tee) looseEnd).addReceiver(nextElement); - } else { + } + else { ((Sender) looseEnd).setReceiver(nextElement); } } joinLooseEnds = false; - } else { + } + else { if (sender instanceof Tee) { ((Tee) sender).addReceiver(nextElement); - } else { + } + else { sender.setReceiver(nextElement); } } - } else { + } + else { throw new FluxParseException(element.getClass().getCanonicalName() + "is not a sender"); } element = nextElement; @@ -78,7 +85,8 @@ public void startTee() { final Tee tee = (Tee) element; teeStack.push(tee); looseEndsStack.push(new ArrayList()); - } else { + } + else { throw new FluxParseException("Flow cannot be split without a tee-element."); } } @@ -93,7 +101,7 @@ public void endSubFlow() { element = teeStack.peek(); } - private void setStart(final ObjectReceiver start){ + private void setStart(final ObjectReceiver start) { this.start = start; element = start; } diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/parser/FluxProgramm.java b/metafacture-flux/src/main/java/org/metafacture/flux/parser/FluxProgramm.java index 72d13be0a..0b1d162ca 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/parser/FluxProgramm.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/parser/FluxProgramm.java @@ -13,8 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux.parser; +import org.metafacture.commons.ResourceUtil; +import org.metafacture.commons.reflection.ConfigurableClass; +import org.metafacture.commons.reflection.ObjectFactory; +import org.metafacture.commons.reflection.ReflectionUtil; +import org.metafacture.flux.FluxParseException; +import org.metafacture.flux.HelpPrinter; +import org.metafacture.framework.Receiver; + import java.io.IOException; import java.io.PrintStream; import java.net.URL; @@ -27,14 +36,6 @@ import java.util.Map; import java.util.Set; -import org.metafacture.commons.ResourceUtil; -import org.metafacture.commons.reflection.ConfigurableClass; -import org.metafacture.commons.reflection.ObjectFactory; -import org.metafacture.commons.reflection.ReflectionUtil; -import org.metafacture.flux.FluxParseException; -import org.metafacture.flux.HelpPrinter; -import org.metafacture.framework.Receiver; - /** * @author Markus Michael Geipel * @@ -52,7 +53,8 @@ public final class FluxProgramm { final URL url = enumeration.nextElement(); COMMAND_FACTORY.loadClassesFromMap(ResourceUtil.loadProperties(url), Receiver.class); } - } catch (final IOException e) { + } + catch (final IOException e) { throw new FluxParseException("unable to load properties.", e); } } @@ -62,6 +64,9 @@ public final class FluxProgramm { private final Map wormholeNameMapping = new HashMap(); private final Map wormholeInFlowMapping = new Hashtable(); + public FluxProgramm() { + } + private static Receiver createElement(final String name, final Map namedArgs, final List cArgs) { @@ -69,7 +74,8 @@ private static Receiver createElement(final String name, final Map elementClass = ReflectionUtil.loadClass(name, Receiver.class); newElement = elementClass.newInstance(namedArgs, cArgs.toArray()); @@ -156,7 +162,8 @@ public void start() { flow.start(); if (!wormholeInFlowMapping.containsKey(flow)) { flow.close(); - } else { + } + else { wormholeInFlowMapping.get(flow).finished(flow); } } @@ -172,7 +179,7 @@ private static final class Wormhole { private Flow out; private final String name; - public Wormhole(final String name) { + Wormhole(final String name) { this.name = name; } diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/parser/StringSender.java b/metafacture-flux/src/main/java/org/metafacture/flux/parser/StringSender.java index 1637a5d94..095f8b830 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/parser/StringSender.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/parser/StringSender.java @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux.parser; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.helpers.DefaultObjectPipe; - /** * Helper class to start a pipe with a {@link String} * * @author Markus Michael Geipel */ -public final class StringSender extends DefaultObjectPipe>{ +public final class StringSender extends DefaultObjectPipe> { private final String string; @@ -34,9 +34,10 @@ public StringSender(final String string) { @Override public void process(final Object notUsed) { - if(notUsed==null){ - getReceiver().process(string); - }else{ + if (notUsed == null) { + getReceiver().process(string); + } + else { throw new IllegalArgumentException("Parameter not used. Must be null"); } } diff --git a/metafacture-flux/src/test/java/org/metafacture/flux/FluxGrammarTest.java b/metafacture-flux/src/test/java/org/metafacture/flux/FluxGrammarTest.java index 0a833fc87..6e51b3b8c 100644 --- a/metafacture-flux/src/test/java/org/metafacture/flux/FluxGrammarTest.java +++ b/metafacture-flux/src/test/java/org/metafacture/flux/FluxGrammarTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux; import static java.util.Collections.emptyMap; diff --git a/metafacture-flux/src/test/java/org/metafacture/flux/FluxProgrammTest.java b/metafacture-flux/src/test/java/org/metafacture/flux/FluxProgrammTest.java index cc9aebc69..482764d58 100644 --- a/metafacture-flux/src/test/java/org/metafacture/flux/FluxProgrammTest.java +++ b/metafacture-flux/src/test/java/org/metafacture/flux/FluxProgrammTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.flux; import java.io.IOException; From ee5d3c9275c3a6852db981e75dcd18577a7751c9 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 16:38:13 +0200 Subject: [PATCH 10/30] metafacture-formatting/ (main): Fix Checkstyle violations. --- .../metafacture/formatting/ObjectTemplate.java | 18 +++++++++--------- .../formatting/PreambleEpilogueAdder.java | 11 +++++++---- .../formatting/StreamLiteralFormatter.java | 10 +++++++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/metafacture-formatting/src/main/java/org/metafacture/formatting/ObjectTemplate.java b/metafacture-formatting/src/main/java/org/metafacture/formatting/ObjectTemplate.java index e0783a223..1e8676b08 100644 --- a/metafacture-formatting/src/main/java/org/metafacture/formatting/ObjectTemplate.java +++ b/metafacture-formatting/src/main/java/org/metafacture/formatting/ObjectTemplate.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.formatting; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.formatting; import org.metafacture.commons.StringUtil; import org.metafacture.framework.FluxCommand; @@ -29,6 +25,10 @@ import org.metafacture.framework.helpers.DefaultObjectPipe; import org.metafacture.framework.objects.Triple; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Builds a {@link String} from a template and an {@link Object}. ${o} marks @@ -54,19 +54,19 @@ public final class ObjectTemplate extends DefaultObjectPipepreamble string before the first string object in the * stream and an epilogue string before the end of the stream. @@ -44,7 +44,10 @@ public final class PreambleEpilogueAdder extends DefaultObjectPipepreamble string which is emitted before the first object. @@ -86,7 +89,7 @@ public String getEpilogue() { @Override public void process(final String obj) { - if(!objectsReceived && !preamble.isEmpty()) { + if (!objectsReceived && !preamble.isEmpty()) { getReceiver().process(preamble); } objectsReceived = true; @@ -95,7 +98,7 @@ public void process(final String obj) { @Override protected void onCloseStream() { - if(objectsReceived && !epilogue.isEmpty()) { + if (objectsReceived && !epilogue.isEmpty()) { getReceiver().process(epilogue); } } diff --git a/metafacture-formatting/src/main/java/org/metafacture/formatting/StreamLiteralFormatter.java b/metafacture-formatting/src/main/java/org/metafacture/formatting/StreamLiteralFormatter.java index cf3e98337..542612603 100644 --- a/metafacture-formatting/src/main/java/org/metafacture/formatting/StreamLiteralFormatter.java +++ b/metafacture-formatting/src/main/java/org/metafacture/formatting/StreamLiteralFormatter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formatting; import org.metafacture.framework.FluxCommand; @@ -45,8 +46,7 @@ @In(StreamReceiver.class) @Out(String.class) @FluxCommand("encode-literals") -public final class StreamLiteralFormatter - extends DefaultStreamPipe> { +public final class StreamLiteralFormatter extends DefaultStreamPipe> { /** * The default value for {@link #setSeparator(String)}. @@ -55,6 +55,9 @@ public final class StreamLiteralFormatter private String separator = DEFAULT_SEPARATOR; + public StreamLiteralFormatter() { + } + /** * Sets the separator between the literal name and value. The separator is * only added if the literal name is not empty. @@ -78,7 +81,8 @@ public String getSeparator() { public void literal(final String name, final String value) { if (name == null || name.isEmpty()) { getReceiver().process(value); - } else { + } + else { getReceiver().process(name + separator + value); } } From 4956554a9db88ffc06da4bac28ee4c084e433f02 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 16:52:45 +0200 Subject: [PATCH 11/30] metafacture-formeta/ (main): Fix Checkstyle violations. --- .../java/org/metafacture/formeta/Formeta.java | 1 + .../metafacture/formeta/FormetaDecoder.java | 1 + .../metafacture/formeta/FormetaEncoder.java | 8 +- .../formeta/FormetaRecordsReader.java | 67 +++++---- .../formeta/formatter/AbstractFormatter.java | 45 +++--- .../formeta/formatter/ConciseFormatter.java | 4 + .../formeta/formatter/Formatter.java | 5 +- .../formeta/formatter/FormatterStyle.java | 1 + .../formeta/formatter/MultilineFormatter.java | 2 +- .../formeta/formatter/VerboseFormatter.java | 4 + .../metafacture/formeta/parser/Emitter.java | 9 +- .../formeta/parser/FormetaParser.java | 24 ++-- .../formeta/parser/FullRecordEmitter.java | 10 +- .../formeta/parser/PartialRecordEmitter.java | 10 +- .../parser/StructureParserContext.java | 5 +- .../formeta/parser/StructureParserState.java | 77 +++++----- .../formeta/parser/TextParserContext.java | 27 ++-- .../formeta/parser/TextParserState.java | 135 +++++++++--------- .../formeta/FormetaDecoderTest.java | 1 + .../formeta/FormetaEncoderTest.java | 1 + .../formeta/FormetaRecordsReaderTest.java | 1 + .../formatter/AbstactFormatterTest.java | 1 + .../formatter/ConciseFormatterTest.java | 1 + .../formatter/MultilineFormatterTest.java | 1 + .../formatter/VerboseFormatterTest.java | 1 + .../formeta/parser/FormetaParserTest.java | 4 +- 26 files changed, 255 insertions(+), 191 deletions(-) diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/Formeta.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/Formeta.java index b3b06c339..fba2ed806 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/Formeta.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/Formeta.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta; /** diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaDecoder.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaDecoder.java index f75692676..5e74f080a 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaDecoder.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta; import org.metafacture.formeta.parser.Emitter; diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaEncoder.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaEncoder.java index d6e8740f4..e9f65ee6e 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaEncoder.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaEncoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta; import org.metafacture.formeta.formatter.Formatter; @@ -35,12 +36,14 @@ @In(StreamReceiver.class) @Out(String.class) @FluxCommand("encode-formeta") -public final class FormetaEncoder extends - DefaultStreamPipe> { +public final class FormetaEncoder extends DefaultStreamPipe> { private FormatterStyle style = FormatterStyle.CONCISE; private Formatter formatter = style.createFormatter(); + public FormetaEncoder() { + } + public FormatterStyle getStyle() { return style; } @@ -50,7 +53,6 @@ public void setStyle(final FormatterStyle formatterStyle) { formatter = formatterStyle.createFormatter(); } - @Override public void startRecord(final String identifier) { formatter.reset(); diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java index 983527017..47e3fc84f 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/FormetaRecordsReader.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.formeta; -import java.io.IOException; -import java.io.Reader; +package org.metafacture.formeta; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -26,6 +24,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.IOException; +import java.io.Reader; + /** * Reads a stream of formeta data and splits between each top-level element. * @@ -36,15 +37,17 @@ @Out(String.class) @Description("Reads a stream of formeta data and splits between each top-level element") @FluxCommand("as-formeta-records") -public final class FormetaRecordsReader extends - DefaultObjectPipe> { +public final class FormetaRecordsReader extends DefaultObjectPipe> { private static final int BUFFER_SIZE = 1024 * 1024 * 16; private final StringBuilder builder = new StringBuilder(); private final char[] buffer = new char[BUFFER_SIZE]; - @Override + public FormetaRecordsReader() { + } + + @Override // checkstyle-disable-line CyclomaticComplexity public void process(final Reader reader) { assert !isClosed(); @@ -58,29 +61,32 @@ public void process(final Reader reader) { int offset = 0; for (int i = 0; i < size; ++i) { switch (buffer[i]) { - case Formeta.ESCAPE_CHAR: - i += 1; // Skip next character - break; - case Formeta.GROUP_START: - if (!inQuotedText) { - groupLevel += 1; - } - break; - case Formeta.GROUP_END: - if (!inQuotedText) { - groupLevel -= 1; - } - // Fall through - case Formeta.ITEM_SEPARATOR: - if (!inQuotedText && groupLevel == 0) { - builder.append(buffer, offset, i - offset + 1); - offset = i + 1; - emitRecord(); - } - break; - case Formeta.QUOT_CHAR: - inQuotedText = !inQuotedText; - break; + case Formeta.ESCAPE_CHAR: + // Skip next character + i += 1; // checkstyle-disable-line ModifiedControlVariable + break; + case Formeta.GROUP_START: + if (!inQuotedText) { + groupLevel += 1; + } + break; + case Formeta.GROUP_END: + if (!inQuotedText) { + groupLevel -= 1; + } + // fall through + case Formeta.ITEM_SEPARATOR: + if (!inQuotedText && groupLevel == 0) { + builder.append(buffer, offset, i - offset + 1); + offset = i + 1; + emitRecord(); + } + break; + case Formeta.QUOT_CHAR: + inQuotedText = !inQuotedText; + break; + default: + // ignore } } builder.append(buffer, offset, size - offset); @@ -89,7 +95,8 @@ public void process(final Reader reader) { emitRecord(); } - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/AbstractFormatter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/AbstractFormatter.java index 14df23d1a..52ecf1daf 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/AbstractFormatter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/AbstractFormatter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import org.metafacture.commons.StringUtil; @@ -26,15 +27,15 @@ */ public abstract class AbstractFormatter implements Formatter { - public static final String CHARS_TO_ESCAPE_QUOTED = "\n\r" - + Formeta.QUOT_CHAR - + Formeta.ESCAPE_CHAR; + public static final String CHARS_TO_ESCAPE_QUOTED = "\n\r" + + Formeta.QUOT_CHAR + + Formeta.ESCAPE_CHAR; - public static final String CHARS_TO_ESCAPE = CHARS_TO_ESCAPE_QUOTED - + Formeta.GROUP_START - + Formeta.GROUP_END - + Formeta.ITEM_SEPARATOR - + Formeta.NAME_VALUE_SEPARATOR; + public static final String CHARS_TO_ESCAPE = CHARS_TO_ESCAPE_QUOTED + + Formeta.GROUP_START + + Formeta.GROUP_END + + Formeta.ITEM_SEPARATOR + + Formeta.NAME_VALUE_SEPARATOR; protected static final int BUFFER_SIZE = 1024; @@ -73,16 +74,17 @@ protected final void escapeAndAppend(final String str) { escapeAndAppendChar(buffer[i], CHARS_TO_ESCAPE_QUOTED); } builder.append(Formeta.QUOT_CHAR); - } else { + } + else { if (bufferLen > 0) { escapeAndAppendChar(buffer[0], CHARS_TO_ESCAPE + Formeta.WHITESPACE); } - for (int i = 1; i < bufferLen-1; ++i) { + for (int i = 1; i < bufferLen - 1; ++i) { escapeAndAppendChar(buffer[i], CHARS_TO_ESCAPE); } if (bufferLen > 1) { - escapeAndAppendChar(buffer[bufferLen-1], + escapeAndAppendChar(buffer[bufferLen - 1], CHARS_TO_ESCAPE + Formeta.WHITESPACE); } } @@ -92,12 +94,13 @@ protected void onReset() { // Default implementation does nothing } - protected abstract boolean shouldQuoteText(final char[] buffer, final int len); + protected abstract boolean shouldQuoteText(char[] currentBuffer, int len); private void escapeAndAppendChar(final char ch, final String charsToEscape) { if (charsToEscape.indexOf(ch) > -1) { appendEscapedChar(ch); - } else { + } + else { builder.append(ch); } } @@ -105,14 +108,14 @@ private void escapeAndAppendChar(final char ch, final String charsToEscape) { private void appendEscapedChar(final char ch) { builder.append(Formeta.ESCAPE_CHAR); switch (ch) { - case '\n': - builder.append(Formeta.NEWLINE_ESC_SEQ); - break; - case '\r': - builder.append(Formeta.CARRIAGE_RETURN_ESC_SEQ); - break; - default: - builder.append(ch); + case '\n': + builder.append(Formeta.NEWLINE_ESC_SEQ); + break; + case '\r': + builder.append(Formeta.CARRIAGE_RETURN_ESC_SEQ); + break; + default: + builder.append(ch); } } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/ConciseFormatter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/ConciseFormatter.java index 0dbf831fc..cbdef8f43 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/ConciseFormatter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/ConciseFormatter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import org.metafacture.formeta.Formeta; @@ -27,6 +28,9 @@ public final class ConciseFormatter extends AbstractFormatter { private boolean appendItemSeparator; + public ConciseFormatter() { + } + @Override public void startGroup(final String name) { if (appendItemSeparator) { diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/Formatter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/Formatter.java index 270abeddb..23f81959f 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/Formatter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/Formatter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; /** @@ -25,10 +26,10 @@ public interface Formatter { void reset(); - void startGroup(final String name); + void startGroup(String name); void endGroup(); - void literal(final String name, final String value); + void literal(String name, String value); } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/FormatterStyle.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/FormatterStyle.java index fc6ce9190..0415d5180 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/FormatterStyle.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/FormatterStyle.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; /** diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/MultilineFormatter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/MultilineFormatter.java index ded54f0a5..ec88cb750 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/MultilineFormatter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/MultilineFormatter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import org.metafacture.formeta.Formeta; @@ -36,7 +37,6 @@ public final class MultilineFormatter extends AbstractFormatter { private boolean firstItem; public MultilineFormatter() { - super(); onReset(); } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/VerboseFormatter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/VerboseFormatter.java index 3e055188a..3095c1014 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/VerboseFormatter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/formatter/VerboseFormatter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import org.metafacture.formeta.Formeta; @@ -32,6 +33,9 @@ public final class VerboseFormatter extends AbstractFormatter { private boolean appendItemSeparator; + public VerboseFormatter() { + } + @Override public void startGroup(final String name) { if (appendItemSeparator) { diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/Emitter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/Emitter.java index 5736360a1..63d12b17c 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/Emitter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/Emitter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.framework.StreamReceiver; @@ -25,12 +26,12 @@ */ public interface Emitter { - void setReceiver(final StreamReceiver receiver); + void setReceiver(StreamReceiver receiver); - void startGroup(final String name, final int nestingLevel); + void startGroup(String name, int nestingLevel); - void endGroup(final int nestingLevel); + void endGroup(int nestingLevel); - void literal(final String name, final String value, final int nestingLevel); + void literal(String name, String value, int nestingLevel); } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FormetaParser.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FormetaParser.java index 2fcecd6ba..9ed4ed3c4 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FormetaParser.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FormetaParser.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.commons.StringUtil; @@ -36,6 +37,9 @@ public final class FormetaParser { private char[] buffer = new char[BUFFER_SIZE]; private final StructureParserContext structureParserContext = new StructureParserContext(); + public FormetaParser() { + } + public void setEmitter(final Emitter emitter) { structureParserContext.setEmitter(emitter); } @@ -45,7 +49,7 @@ public Emitter getEmitter() { } public void parse(final String data) { - assert structureParserContext.getEmitter() != null: "No emitter set"; + assert structureParserContext.getEmitter() != null : "No emitter set"; // According to http://stackoverflow.com/a/11876086 it is faster to copy // a string into a char array then to use charAt(): @@ -59,16 +63,16 @@ public void parse(final String data) { for (; i < bufferLen; ++i) { state = state.processChar(buffer[i], structureParserContext); } - } catch (final FormatException e) { - final String errorMsg = "Parsing error at position " - + (i + 1) + ": " - + getErrorSnippet(data, i) + ", " - + e.getMessage(); + } + catch (final FormatException e) { + final String errorMsg = "Parsing error at position " + + (i + 1) + ": " + getErrorSnippet(data, i) + ", " + e.getMessage(); throw new FormatException(errorMsg, e); } try { state.endOfInput(structureParserContext); - } catch (final FormatException e) { + } + catch (final FormatException e) { throw new FormatException("Parsing error: " + e.getMessage(), e); } } @@ -88,7 +92,8 @@ private static String getErrorSnippet(final String record, final int pos) { final int start = pos - SNIPPET_SIZE / 2; if (start < 0) { snippet.append(record.substring(0, pos)); - } else { + } + else { snippet.append(SNIPPET_ELLIPSIS); snippet.append(record.substring(start, pos)); } @@ -101,7 +106,8 @@ private static String getErrorSnippet(final String record, final int pos) { final int end = pos + SNIPPET_SIZE / 2; if (end > record.length()) { snippet.append(record.substring(pos + 1)); - } else { + } + else { snippet.append(record.substring(pos + 1, end)); snippet.append(SNIPPET_ELLIPSIS); } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FullRecordEmitter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FullRecordEmitter.java index 2f166f299..edb349995 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FullRecordEmitter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/FullRecordEmitter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.framework.FormatException; @@ -28,6 +29,9 @@ public final class FullRecordEmitter implements Emitter { private StreamReceiver receiver; + public FullRecordEmitter() { + } + @Override public void setReceiver(final StreamReceiver receiver) { this.receiver = receiver; @@ -37,7 +41,8 @@ public void setReceiver(final StreamReceiver receiver) { public void startGroup(final String name, final int nestingLevel) { if (nestingLevel == 0) { receiver.startRecord(name); - } else { + } + else { receiver.startEntity(name); } } @@ -46,7 +51,8 @@ public void startGroup(final String name, final int nestingLevel) { public void endGroup(final int nestingLevel) { if (nestingLevel == 0) { receiver.endRecord(); - } else { + } + else { receiver.endEntity(); } } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/PartialRecordEmitter.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/PartialRecordEmitter.java index 863c4a0dc..55c4c1f7d 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/PartialRecordEmitter.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/PartialRecordEmitter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.framework.StreamReceiver; @@ -25,7 +26,8 @@ public final class PartialRecordEmitter implements Emitter { private StreamReceiver receiver; private String defaultName; - + public PartialRecordEmitter() { + } public void setDefaultName(final String defaultName) { this.defaultName = defaultName; @@ -44,7 +46,8 @@ public void setReceiver(final StreamReceiver receiver) { public void startGroup(final String name, final int nestingLevel) { if (nestingLevel == 0 && defaultName != null && name.isEmpty()) { receiver.startEntity(defaultName); - } else { + } + else { receiver.startEntity(name); } } @@ -58,7 +61,8 @@ public void endGroup(final int nestingLevel) { public void literal(final String name, final String value, final int nestingLevel) { if (nestingLevel == 0 && defaultName != null && name.isEmpty()) { receiver.literal(defaultName, value); - } else { + } + else { receiver.literal(name, value); } } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserContext.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserContext.java index ebe4aa6cf..65f78035a 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserContext.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserContext.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.formeta.parser; +package org.metafacture.formeta.parser; /** * Context of the record parser. It manages the text parser and the generation of @@ -31,6 +31,9 @@ class StructureParserContext { private String literalName; private int nestingLevel; + StructureParserContext() { + } + public void setEmitter(final Emitter emitter) { this.emitter = emitter; } diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserState.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserState.java index fa7c34aea..2784a0aa8 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserState.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/StructureParserState.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.formeta.Formeta; @@ -30,29 +31,29 @@ enum StructureParserState { protected StructureParserState delimiterReached(final char ch, final StructureParserContext ctx) { final StructureParserState newState; switch (ch) { - case Formeta.GROUP_START: - ctx.startGroup(); - newState = ITEM_NAME; - break; - case Formeta.NAME_VALUE_SEPARATOR: - ctx.startLiteral(); - newState = LITERAL_VALUE; - break; - case Formeta.ITEM_SEPARATOR: - if (!ctx.isTextEmpty()) { - throw new FormatException(getUnexpectedCharMsg(NAME_DELIMITER_EXPECTED, ch)); - } - newState = ITEM_NAME; - break; - case Formeta.GROUP_END: - if (!ctx.isTextEmpty() || !ctx.isNested()) { + case Formeta.GROUP_START: + ctx.startGroup(); + newState = ITEM_NAME; + break; + case Formeta.NAME_VALUE_SEPARATOR: + ctx.startLiteral(); + newState = LITERAL_VALUE; + break; + case Formeta.ITEM_SEPARATOR: + if (!ctx.isTextEmpty()) { + throw new FormatException(getUnexpectedCharMsg(NAME_DELIMITER_EXPECTED, ch)); + } + newState = ITEM_NAME; + break; + case Formeta.GROUP_END: + if (!ctx.isTextEmpty() || !ctx.isNested()) { + throw new FormatException(getUnexpectedCharMsg(NAME_DELIMITER_EXPECTED, ch)); + } + ctx.endGroup(); + newState = ITEM_NAME; + break; + default: throw new FormatException(getUnexpectedCharMsg(NAME_DELIMITER_EXPECTED, ch)); - } - ctx.endGroup(); - newState = ITEM_NAME; - break; - default: - throw new FormatException(getUnexpectedCharMsg(NAME_DELIMITER_EXPECTED, ch)); } return newState; } @@ -68,20 +69,20 @@ public void endOfInput(final StructureParserContext ctx) { protected StructureParserState delimiterReached(final char ch, final StructureParserContext ctx) { final StructureParserState newState; switch (ch) { - case Formeta.ITEM_SEPARATOR: - ctx.endLiteral(); - newState = ITEM_NAME; - break; - case Formeta.GROUP_END: - if (!ctx.isNested()) { - throw new FormatException(getUnexpectedCharMsg(ITEM_SEPARATOR_EXPECTED, ch)); - } - ctx.endLiteral(); - ctx.endGroup(); - newState = ITEM_NAME; - break; - default: - throw new FormatException(getUnexpectedCharMsg(VALUE_DELIMITER_EXPECTED, ch)); + case Formeta.ITEM_SEPARATOR: + ctx.endLiteral(); + newState = ITEM_NAME; + break; + case Formeta.GROUP_END: + if (!ctx.isNested()) { + throw new FormatException(getUnexpectedCharMsg(ITEM_SEPARATOR_EXPECTED, ch)); + } + ctx.endLiteral(); + ctx.endGroup(); + newState = ITEM_NAME; + break; + default: + throw new FormatException(getUnexpectedCharMsg(VALUE_DELIMITER_EXPECTED, ch)); } return newState; } @@ -107,9 +108,9 @@ public StructureParserState processChar(final char ch, final StructureParserCont return this; } - public abstract void endOfInput(final StructureParserContext ctx); + public abstract void endOfInput(StructureParserContext ctx); - protected abstract StructureParserState delimiterReached(final char ch, final StructureParserContext ctx); + protected abstract StructureParserState delimiterReached(char ch, StructureParserContext ctx); private static String getUnexpectedCharMsg(final String expected, final char actual) { return expected + " expected but got '" + actual + "'"; diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserContext.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserContext.java index 709f93e23..08ce74e21 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserContext.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserContext.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.formeta.Formeta; @@ -25,19 +26,22 @@ */ class TextParserContext { - private static final String ESCAPABLE_CHARS = Formeta.WHITESPACE - + Formeta.QUOT_CHAR - + Formeta.ESCAPE_CHAR - + Formeta.GROUP_START - + Formeta.GROUP_END - + Formeta.ITEM_SEPARATOR - + Formeta.NAME_VALUE_SEPARATOR; + private static final String ESCAPABLE_CHARS = Formeta.WHITESPACE + + Formeta.QUOT_CHAR + + Formeta.ESCAPE_CHAR + + Formeta.GROUP_START + + Formeta.GROUP_END + + Formeta.ITEM_SEPARATOR + + Formeta.NAME_VALUE_SEPARATOR; private final StringBuilder text = new StringBuilder(); private int lengthWithoutTrailingWs; private boolean quoted; + TextParserContext() { + } + public String getText() { return text.substring(0, lengthWithoutTrailingWs); } @@ -56,11 +60,14 @@ public void appendChar(final char ch) { public void appendEscapedChar(final char ch) { if (Formeta.NEWLINE_ESC_SEQ == ch) { text.append('\n'); - } else if (Formeta.CARRIAGE_RETURN_ESC_SEQ == ch) { + } + else if (Formeta.CARRIAGE_RETURN_ESC_SEQ == ch) { text.append('\r'); - } else if (ESCAPABLE_CHARS.indexOf(ch) > -1) { + } + else if (ESCAPABLE_CHARS.indexOf(ch) > -1) { text.append(ch); - } else { + } + else { throw new FormatException("invalid escape sequence: " + ch); } lengthWithoutTrailingWs = text.length(); diff --git a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserState.java b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserState.java index 905640692..0c2fc1a71 100644 --- a/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserState.java +++ b/metafacture-formeta/src/main/java/org/metafacture/formeta/parser/TextParserState.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import org.metafacture.formeta.Formeta; @@ -28,30 +29,31 @@ enum TextParserState { LEADING_WHITESPACE { public TextParserState processChar(final char ch, final TextParserContext ctx) { final TextParserState newState; - switch(ch) { - case Formeta.ESCAPE_CHAR: - ctx.setQuoted(false); - newState = ESCAPE_SEQ; - break; - case Formeta.QUOT_CHAR: - ctx.setQuoted(true); - newState = QUOTED_TEXT; - break; - case Formeta.GROUP_START: - case Formeta.GROUP_END: - case Formeta.ITEM_SEPARATOR: - case Formeta.NAME_VALUE_SEPARATOR: - ctx.setQuoted(false); - newState = DELIMITER_REACHED; - break; - default: - if (Formeta.isWhitespace(ch)) { - newState = LEADING_WHITESPACE; - } else { + switch (ch) { + case Formeta.ESCAPE_CHAR: ctx.setQuoted(false); - ctx.appendChar(ch); - newState = TEXT; - } + newState = ESCAPE_SEQ; + break; + case Formeta.QUOT_CHAR: + ctx.setQuoted(true); + newState = QUOTED_TEXT; + break; + case Formeta.GROUP_START: + case Formeta.GROUP_END: + case Formeta.ITEM_SEPARATOR: + case Formeta.NAME_VALUE_SEPARATOR: + ctx.setQuoted(false); + newState = DELIMITER_REACHED; + break; + default: + if (Formeta.isWhitespace(ch)) { + newState = LEADING_WHITESPACE; + } + else { + ctx.setQuoted(false); + ctx.appendChar(ch); + newState = TEXT; + } } return newState; } @@ -59,19 +61,19 @@ public TextParserState processChar(final char ch, final TextParserContext ctx) { TEXT { public TextParserState processChar(final char ch, final TextParserContext ctx) { final TextParserState newState; - switch(ch) { - case Formeta.ESCAPE_CHAR: - newState = ESCAPE_SEQ; - break; - case Formeta.GROUP_START: - case Formeta.GROUP_END: - case Formeta.ITEM_SEPARATOR: - case Formeta.NAME_VALUE_SEPARATOR: - newState = DELIMITER_REACHED; - break; - default: - ctx.appendChar(ch); - newState = TEXT; + switch (ch) { + case Formeta.ESCAPE_CHAR: + newState = ESCAPE_SEQ; + break; + case Formeta.GROUP_START: + case Formeta.GROUP_END: + case Formeta.ITEM_SEPARATOR: + case Formeta.NAME_VALUE_SEPARATOR: + newState = DELIMITER_REACHED; + break; + default: + ctx.appendChar(ch); + newState = TEXT; } return newState; } @@ -89,16 +91,16 @@ public void endOfInput(final TextParserContext ctx) { QUOTED_TEXT { public TextParserState processChar(final char ch, final TextParserContext ctx) { final TextParserState newState; - switch(ch) { - case Formeta.ESCAPE_CHAR: - newState = QUOTED_ESCAPE_SEQ; - break; - case Formeta.QUOT_CHAR: - newState = TRAILING_WHITESPACE; - break; - default: - ctx.appendChar(ch); - newState = QUOTED_TEXT; + switch (ch) { + case Formeta.ESCAPE_CHAR: + newState = QUOTED_ESCAPE_SEQ; + break; + case Formeta.QUOT_CHAR: + newState = TRAILING_WHITESPACE; + break; + default: + ctx.appendChar(ch); + newState = QUOTED_TEXT; } return newState; } @@ -120,25 +122,26 @@ public void endOfInput(final TextParserContext ctx) { TRAILING_WHITESPACE { public TextParserState processChar(final char ch, final TextParserContext ctx) { final TextParserState newState; - switch(ch) { - case Formeta.GROUP_START: - case Formeta.GROUP_END: - case Formeta.ITEM_SEPARATOR: - case Formeta.NAME_VALUE_SEPARATOR: - newState = DELIMITER_REACHED; - break; - default: - if (Formeta.isWhitespace(ch)) { - newState = TRAILING_WHITESPACE; - } else { - final String sep = "', '"; - final String expected = "whitespace or one of '" - + Formeta.GROUP_START + sep - + Formeta.GROUP_END + sep - + Formeta.ITEM_SEPARATOR + sep - + Formeta.NAME_VALUE_SEPARATOR + "'"; - throw new FormatException(getUnexpectedCharMsg(expected, ch)); - } + switch (ch) { + case Formeta.GROUP_START: + case Formeta.GROUP_END: + case Formeta.ITEM_SEPARATOR: + case Formeta.NAME_VALUE_SEPARATOR: + newState = DELIMITER_REACHED; + break; + default: + if (Formeta.isWhitespace(ch)) { + newState = TRAILING_WHITESPACE; + } + else { + final String sep = "', '"; + final String expected = "whitespace or one of '" + + Formeta.GROUP_START + sep + + Formeta.GROUP_END + sep + + Formeta.ITEM_SEPARATOR + sep + + Formeta.NAME_VALUE_SEPARATOR + "'"; + throw new FormatException(getUnexpectedCharMsg(expected, ch)); + } } return newState; } @@ -149,7 +152,7 @@ public TextParserState processChar(final char ch, final TextParserContext ctx) { } }; - public abstract TextParserState processChar(final char ch, final TextParserContext ctx); + public abstract TextParserState processChar(char ch, TextParserContext ctx); public void endOfInput(final TextParserContext ctx) { // Default implementation does nothing diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaDecoderTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaDecoderTest.java index 17f05af72..462ac4822 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaDecoderTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaEncoderTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaEncoderTest.java index ff34b32de..5d2872243 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaEncoderTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaEncoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta; import static org.mockito.Mockito.verify; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaRecordsReaderTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaRecordsReaderTest.java index cf5fea9ac..ba8b9f2c0 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaRecordsReaderTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/FormetaRecordsReaderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta; import static org.mockito.Mockito.verify; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/AbstactFormatterTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/AbstactFormatterTest.java index f3e38048f..d28ddcbc5 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/AbstactFormatterTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/AbstactFormatterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import static org.junit.Assert.assertEquals; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/ConciseFormatterTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/ConciseFormatterTest.java index cb2ed3904..cc5537d0b 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/ConciseFormatterTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/ConciseFormatterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import static org.junit.Assert.assertEquals; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/MultilineFormatterTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/MultilineFormatterTest.java index 9a5838a04..2252cff8e 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/MultilineFormatterTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/MultilineFormatterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import static org.junit.Assert.assertEquals; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/VerboseFormatterTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/VerboseFormatterTest.java index f519b55ae..abc5a5ce7 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/VerboseFormatterTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/formatter/VerboseFormatterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.formatter; import static org.junit.Assert.assertEquals; diff --git a/metafacture-formeta/src/test/java/org/metafacture/formeta/parser/FormetaParserTest.java b/metafacture-formeta/src/test/java/org/metafacture/formeta/parser/FormetaParserTest.java index 7b346d3ab..6bf5cf3b8 100644 --- a/metafacture-formeta/src/test/java/org/metafacture/formeta/parser/FormetaParserTest.java +++ b/metafacture-formeta/src/test/java/org/metafacture/formeta/parser/FormetaParserTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.formeta.parser; import static org.mockito.Mockito.inOrder; @@ -141,7 +142,8 @@ public void testShouldRecoverAfterIncompleteRecord() { // Try processing an incomplete record: try { parser.parse(BROKEN_RECORD); - } catch (FormatException e) { + } + catch (FormatException e) { // The decoder should recover automatically } From 2f8045f6c5f3a8882850f617875c81f6d827aae1 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 17:16:05 +0200 Subject: [PATCH 12/30] metafacture-framework/ (main): Fix Checkstyle violations. --- .../org/metafacture/framework/FluxCommand.java | 1 + .../metafacture/framework/FormatException.java | 1 + .../org/metafacture/framework/LifeCycle.java | 1 + .../framework/MetafactureException.java | 1 + .../framework/MissingIdException.java | 1 + .../org/metafacture/framework/ObjectPipe.java | 1 + .../metafacture/framework/ObjectReceiver.java | 1 + .../java/org/metafacture/framework/Receiver.java | 1 + .../java/org/metafacture/framework/Sender.java | 1 + .../framework/StandardEventNames.java | 1 + .../org/metafacture/framework/StreamPipe.java | 1 + .../metafacture/framework/StreamReceiver.java | 1 + .../main/java/org/metafacture/framework/Tee.java | 4 ++-- .../java/org/metafacture/framework/XmlPipe.java | 1 + .../org/metafacture/framework/XmlReceiver.java | 2 ++ .../framework/annotations/Description.java | 1 + .../metafacture/framework/annotations/In.java | 1 + .../metafacture/framework/annotations/Out.java | 1 + .../annotations/ReturnsAvailableArguments.java | 1 + .../framework/helpers/DefaultLifeCycle.java | 4 ++++ .../framework/helpers/DefaultObjectPipe.java | 7 +++++-- .../framework/helpers/DefaultObjectReceiver.java | 4 ++++ .../framework/helpers/DefaultSender.java | 10 +++++++--- .../framework/helpers/DefaultStreamPipe.java | 7 +++++-- .../framework/helpers/DefaultStreamReceiver.java | 6 +++++- .../framework/helpers/DefaultTee.java | 11 +++++++---- .../framework/helpers/DefaultXmlPipe.java | 12 ++++++++---- .../framework/helpers/DefaultXmlReceiver.java | 9 +++++++-- .../framework/helpers/ForwardingStreamPipe.java | 4 ++++ .../metafacture/framework/objects/Triple.java | 16 +++++++++------- .../framework/helpers/DefaultSenderTest.java | 1 + 31 files changed, 87 insertions(+), 27 deletions(-) diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/FluxCommand.java b/metafacture-framework/src/main/java/org/metafacture/framework/FluxCommand.java index 9d5e2bbec..29cc55fab 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/FluxCommand.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/FluxCommand.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import java.lang.annotation.Documented; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/FormatException.java b/metafacture-framework/src/main/java/org/metafacture/framework/FormatException.java index 50a000afb..b9ef85a4d 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/FormatException.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/FormatException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; /** diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/LifeCycle.java b/metafacture-framework/src/main/java/org/metafacture/framework/LifeCycle.java index 964b8f5b9..c366dac1f 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/LifeCycle.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/LifeCycle.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; /** diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/MetafactureException.java b/metafacture-framework/src/main/java/org/metafacture/framework/MetafactureException.java index e1ef616ca..3baa2c5b7 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/MetafactureException.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/MetafactureException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; /** diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/MissingIdException.java b/metafacture-framework/src/main/java/org/metafacture/framework/MissingIdException.java index 60496f791..f9dd9ab9c 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/MissingIdException.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/MissingIdException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; /** diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/ObjectPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/ObjectPipe.java index 7b00cd09d..e7e29cdea 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/ObjectPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/ObjectPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultObjectPipe; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/ObjectReceiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/ObjectReceiver.java index ec307b304..2c8330aab 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/ObjectReceiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/ObjectReceiver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultObjectReceiver; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/Receiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/Receiver.java index 6fde12af0..d6a499c0e 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/Receiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/Receiver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; /** diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/Sender.java b/metafacture-framework/src/main/java/org/metafacture/framework/Sender.java index 7a33f6037..b0c473395 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/Sender.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/Sender.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultSender; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/StandardEventNames.java b/metafacture-framework/src/main/java/org/metafacture/framework/StandardEventNames.java index 6c9dd7c8d..654844367 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/StandardEventNames.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/StandardEventNames.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; /** diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/StreamPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/StreamPipe.java index 24e71e5cf..633aa513e 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/StreamPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/StreamPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultStreamPipe; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/StreamReceiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/StreamReceiver.java index 4030f7c2c..ddabd00f5 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/StreamReceiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/StreamReceiver.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultStreamReceiver; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/Tee.java b/metafacture-framework/src/main/java/org/metafacture/framework/Tee.java index 8af592b53..a684511c7 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/Tee.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/Tee.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.framework; +package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultTee; @@ -75,6 +75,6 @@ public interface Tee extends Sender { * * @return reference to the tee for method chaining */ - Tee clearReceivers(); + Tee clearReceivers(); } diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/XmlPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/XmlPipe.java index d9ae63d84..a6868591e 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/XmlPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/XmlPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultXmlPipe; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/XmlReceiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/XmlReceiver.java index ad83ea4c6..5b145a38b 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/XmlReceiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/XmlReceiver.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework; import org.metafacture.framework.helpers.DefaultXmlReceiver; + import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Description.java b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Description.java index a5889ea4c..2bb4d5a5a 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Description.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Description.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.annotations; import java.lang.annotation.Documented; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/In.java b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/In.java index f025df675..40b8ba4a7 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/In.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/In.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.annotations; import java.lang.annotation.Documented; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Out.java b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Out.java index 31fb5727c..ee9b62723 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Out.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/Out.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.annotations; import java.lang.annotation.Documented; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/ReturnsAvailableArguments.java b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/ReturnsAvailableArguments.java index fa32d9728..8ea902f35 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/annotations/ReturnsAvailableArguments.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/annotations/ReturnsAvailableArguments.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.annotations; import java.lang.annotation.Documented; diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultLifeCycle.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultLifeCycle.java index 14eaafef7..4e7e8dc09 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultLifeCycle.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultLifeCycle.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.LifeCycle; @@ -26,6 +27,9 @@ */ public class DefaultLifeCycle implements LifeCycle { + public DefaultLifeCycle() { + } + @Override public void resetStream() { // Default implementation does nothing diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectPipe.java index 6ef27ffd9..866bb103c 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.ObjectPipe; @@ -28,8 +29,10 @@ * @author Christoph Böhme * */ -public class DefaultObjectPipe - extends DefaultSender implements ObjectPipe { +public class DefaultObjectPipe extends DefaultSender implements ObjectPipe { + + public DefaultObjectPipe() { + } @Override public void process(final T obj) { diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectReceiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectReceiver.java index 8208580b4..6c9999b77 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectReceiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultObjectReceiver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.ObjectPipe; @@ -33,6 +34,9 @@ */ public class DefaultObjectReceiver extends DefaultLifeCycle implements ObjectReceiver { + public DefaultObjectReceiver() { + } + @Override public void process(final T obj) { // Default implementation does nothing diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultSender.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultSender.java index 50895599c..a785fa213 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultSender.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultSender.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.Receiver; @@ -38,15 +39,18 @@ public class DefaultSender implements Sender { private T receiver; private boolean isClosed; + public DefaultSender() { + } + public final boolean isClosed() { return isClosed; } @Override - public final R setReceiver(final R receiver) { - this.receiver = receiver; + public final R setReceiver(final R newReceiver) { + receiver = newReceiver; onSetReceiver(); - return receiver; + return newReceiver; } @Override diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamPipe.java index 3e5c0b164..ac31632f6 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.Receiver; @@ -27,8 +28,10 @@ * @author Christoph Böhme * @see ForwardingStreamPipe */ -public class DefaultStreamPipe - extends DefaultSender implements StreamPipe { +public class DefaultStreamPipe extends DefaultSender implements StreamPipe { + + public DefaultStreamPipe() { + } @Override public void startRecord(final String identifier) { diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamReceiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamReceiver.java index 22b9d0471..88781c78b 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamReceiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultStreamReceiver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.StreamPipe; @@ -31,13 +32,16 @@ */ public class DefaultStreamReceiver extends DefaultLifeCycle implements StreamReceiver { + public DefaultStreamReceiver() { + } + @Override public void startRecord(final String identifier) { // Default implementation does nothing } @Override - public void endRecord(){ + public void endRecord() { // Default implementation does nothing } diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultTee.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultTee.java index 26cceadc4..6d73fe074 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultTee.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultTee.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.framework.helpers; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +package org.metafacture.framework.helpers; import org.metafacture.framework.Receiver; import org.metafacture.framework.Tee; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * Default implementation for tee modules. @@ -34,6 +34,9 @@ public class DefaultTee implements Tee { private final List receivers = new ArrayList(); + public DefaultTee() { + } + @Override public final R setReceiver(final R receiver) { receivers.clear(); diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java index 1345a17ae..773bcdad4 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlPipe.java @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.framework.helpers; -import java.io.IOException; +package org.metafacture.framework.helpers; import org.metafacture.framework.Receiver; import org.metafacture.framework.XmlPipe; + import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import java.io.IOException; + /** * Default implementation for {@link XmlPipe}s which simply * does nothing. @@ -34,8 +36,10 @@ * @author Christoph Böhme * */ -public class DefaultXmlPipe - extends DefaultSender implements XmlPipe { +public class DefaultXmlPipe extends DefaultSender implements XmlPipe { + + public DefaultXmlPipe() { + } @Override public void setDocumentLocator(final Locator locator) { diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlReceiver.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlReceiver.java index 529bb36e1..07bb1c0a6 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlReceiver.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/DefaultXmlReceiver.java @@ -13,18 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.framework.helpers; -import java.io.IOException; +package org.metafacture.framework.helpers; import org.metafacture.framework.XmlPipe; import org.metafacture.framework.XmlReceiver; + import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import java.io.IOException; + /** * Default implementation of {@link XmlReceiver} which * simply does nothing. Do not use this class as a base class @@ -38,6 +40,9 @@ */ public class DefaultXmlReceiver extends DefaultLifeCycle implements XmlReceiver { + public DefaultXmlReceiver() { + } + @Override public void setDocumentLocator(final Locator locator) { // Default implementation does nothing diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/ForwardingStreamPipe.java b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/ForwardingStreamPipe.java index 8b2da1bf1..2bffeb8c3 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/helpers/ForwardingStreamPipe.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/helpers/ForwardingStreamPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import org.metafacture.framework.StreamPipe; @@ -28,6 +29,9 @@ */ public class ForwardingStreamPipe extends DefaultStreamPipe { + public ForwardingStreamPipe() { + } + @Override public void startRecord(final String identifier) { getReceiver().startRecord(identifier); diff --git a/metafacture-framework/src/main/java/org/metafacture/framework/objects/Triple.java b/metafacture-framework/src/main/java/org/metafacture/framework/objects/Triple.java index e6d216a7d..f793d3cf3 100644 --- a/metafacture-framework/src/main/java/org/metafacture/framework/objects/Triple.java +++ b/metafacture-framework/src/main/java/org/metafacture/framework/objects/Triple.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.objects; import java.io.IOException; @@ -72,7 +73,8 @@ public static Triple read(final ObjectInputStream in) throws IOException { try { return new Triple(in.readUTF(), in.readUTF(), in.readUTF(), (ObjectType) in.readObject()); - } catch (final ClassNotFoundException e) { + } + catch (final ClassNotFoundException e) { throw new IOException("Cannot read triple", e); } } @@ -98,11 +100,11 @@ public boolean equals(final Object obj) { return false; } final Triple other = (Triple) obj; - return other.preCompHashCode == preCompHashCode - && other.predicate.equals(predicate) - && other.object.equals(object) - && other.subject.equals(subject) - && other.objectType == objectType; + return other.preCompHashCode == preCompHashCode && + other.predicate.equals(predicate) && + other.object.equals(object) && + other.subject.equals(subject) && + other.objectType == objectType; } @Override @@ -112,7 +114,7 @@ public int compareTo(final Triple triple) { result = predicate.compareTo(triple.predicate); if (result == 0) { result = object.compareTo(triple.object); - if(result == 0) { + if (result == 0) { return objectType.compareTo(triple.objectType); } } diff --git a/metafacture-framework/src/test/java/org/metafacture/framework/helpers/DefaultSenderTest.java b/metafacture-framework/src/test/java/org/metafacture/framework/helpers/DefaultSenderTest.java index b8e937450..2645e7032 100644 --- a/metafacture-framework/src/test/java/org/metafacture/framework/helpers/DefaultSenderTest.java +++ b/metafacture-framework/src/test/java/org/metafacture/framework/helpers/DefaultSenderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.framework.helpers; import static org.junit.Assert.assertFalse; From 781261530c6ea10a21aed1f4582d2d944fce3b86 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 19:46:40 +0200 Subject: [PATCH 13/30] metafacture-html/ (main): Fix Checkstyle violations. --- .../metafacture/html/ElementExtractor.java | 23 ++-- .../org/metafacture/html/HtmlDecoder.java | 102 +++++++++--------- .../html/ElementExtractorTest.java | 1 + .../org/metafacture/html/HtmlDecoderTest.java | 1 + 4 files changed, 68 insertions(+), 59 deletions(-) diff --git a/metafacture-html/src/main/java/org/metafacture/html/ElementExtractor.java b/metafacture-html/src/main/java/org/metafacture/html/ElementExtractor.java index 19acdc868..5092378de 100644 --- a/metafacture-html/src/main/java/org/metafacture/html/ElementExtractor.java +++ b/metafacture-html/src/main/java/org/metafacture/html/ElementExtractor.java @@ -13,15 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.html; -import java.io.IOException; -import java.io.Reader; +package org.metafacture.html; -import org.apache.commons.io.IOUtils; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.annotations.Description; @@ -29,6 +23,14 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import org.apache.commons.io.IOUtils; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import java.io.IOException; +import java.io.Reader; + /** * Extracts the the specified element from an HTML document * @@ -51,10 +53,11 @@ public ElementExtractor(final String selector) { @Override public void process(final Reader reader) { try { - Document document = Jsoup.parse(IOUtils.toString(reader)); - Element firstElement = document.select(selector).first(); + final Document document = Jsoup.parse(IOUtils.toString(reader)); + final Element firstElement = document.select(selector).first(); getReceiver().process(firstElement.data()); - } catch (IOException e) { + } + catch (final IOException e) { e.printStackTrace(); } } diff --git a/metafacture-html/src/main/java/org/metafacture/html/HtmlDecoder.java b/metafacture-html/src/main/java/org/metafacture/html/HtmlDecoder.java index 0f285c68c..26ae792d5 100644 --- a/metafacture-html/src/main/java/org/metafacture/html/HtmlDecoder.java +++ b/metafacture-html/src/main/java/org/metafacture/html/HtmlDecoder.java @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.html; -import java.io.IOException; -import java.io.Reader; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.StreamReceiver; +import org.metafacture.framework.annotations.Description; +import org.metafacture.framework.annotations.In; +import org.metafacture.framework.annotations.Out; +import org.metafacture.framework.helpers.DefaultObjectPipe; import org.apache.commons.io.IOUtils; import org.jsoup.Jsoup; @@ -30,40 +29,44 @@ import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; -import org.metafacture.framework.FluxCommand; -import org.metafacture.framework.StreamReceiver; -import org.metafacture.framework.annotations.Description; -import org.metafacture.framework.annotations.In; -import org.metafacture.framework.annotations.Out; -import org.metafacture.framework.helpers.DefaultObjectPipe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + /** * Decode HTML to metadata events. Each input document represents one record. * * @author Fabian Steeg (fsteeg) * */ -@Description("Decode HTML to metadata events. The attrValsAsSubfields option can be used to override " - + "the default attribute values to be used as subfields (e.g. by default " - + "`link rel=\"canonical\" href=\"http://example.org\"` becomes `link.canonical`). " - + "It expects an HTTP-style query string specifying as key the attributes whose value should " - + "be used as a subfield, and as value the attribute whose value should be the subfield value, " - + "e.g. the default contains `link.rel=href`. To use the HTML element text as the value " - + "(instead of another attribute), omit the value of the query-string key-value pair, " - + "e.g. `title.lang`. To add to the defaults, instead of replacing them, start with an `&`, " - + "e.g. `&h3.class`") +@Description("Decode HTML to metadata events. The attrValsAsSubfields option can be used to override " + + "the default attribute values to be used as subfields (e.g. by default " + + "`link rel=\"canonical\" href=\"http://example.org\"` becomes `link.canonical`). " + + "It expects an HTTP-style query string specifying as key the attributes whose value should " + + "be used as a subfield, and as value the attribute whose value should be the subfield value, " + + "e.g. the default contains `link.rel=href`. To use the HTML element text as the value " + + "(instead of another attribute), omit the value of the query-string key-value pair, " + + "e.g. `title.lang`. To add to the defaults, instead of replacing them, start with an `&`, " + + "e.g. `&h3.class`") @In(Reader.class) @Out(StreamReceiver.class) @FluxCommand("decode-html") public class HtmlDecoder extends DefaultObjectPipe { + private static final Logger LOG = LoggerFactory.getLogger(HtmlDecoder.class); + private static final String DEFAULT_ATTR_VALS_AS_SUBFIELDS = // "meta.name=content&meta.property=content&link.rel=href&a.rel=href"; + private Map attrValsAsSubfields; - private static final Logger LOG = - LoggerFactory.getLogger(HtmlDecoder.class); public HtmlDecoder() { setAttrValsAsSubfields(DEFAULT_ATTR_VALS_AS_SUBFIELDS); @@ -72,28 +75,29 @@ public HtmlDecoder() { @Override public void process(final Reader reader) { try { - StreamReceiver receiver = getReceiver(); + final StreamReceiver receiver = getReceiver(); receiver.startRecord(UUID.randomUUID().toString()); - Document document = Jsoup.parse(IOUtils.toString(reader)); + final Document document = Jsoup.parse(IOUtils.toString(reader)); process(document, receiver); receiver.endRecord(); - } catch (IOException e) { + } + catch (final IOException e) { LOG.error(e.getMessage(), e); } } - private void process(Element parent, StreamReceiver receiver) { - for (Element element : parent.children()) { + private void process(final Element parent, final StreamReceiver receiver) { + for (final Element element : parent.children()) { receiver.startEntity(element.nodeName()); - Attributes attributes = element.attributes(); + final Attributes attributes = element.attributes(); boolean addedValueAsSubfield = false; - for (Attribute attribute : attributes) { + for (final Attribute attribute : attributes) { addedValueAsSubfield = handleAttributeValuesAsSubfields(receiver, element, attributes, attribute); receiver.literal(attribute.getKey(), attribute.getValue()); } if (element.children().isEmpty()) { - String text = element.text().trim(); - String value = text.isEmpty() ? element.data() : text; + final String text = element.text().trim(); + final String value = text.isEmpty() ? element.data() : text; if (!value.isEmpty() && !addedValueAsSubfield) { receiver.literal("value", value); } @@ -103,34 +107,34 @@ private void process(Element parent, StreamReceiver receiver) { } } - private boolean handleAttributeValuesAsSubfields(StreamReceiver receiver, Element element, - Attributes attributes, Attribute attribute) { - String fullFieldKey = element.nodeName() + "." + attribute.getKey(); + private boolean handleAttributeValuesAsSubfields(final StreamReceiver receiver, final Element element, final Attributes attributes, final Attribute attribute) { + final String fullFieldKey = element.nodeName() + "." + attribute.getKey(); if (attrValsAsSubfields.containsKey(fullFieldKey)) { - String configValue = attrValsAsSubfields.get(fullFieldKey); + final String configValue = attrValsAsSubfields.get(fullFieldKey); if (configValue.trim().isEmpty()) { receiver.literal(attribute.getValue(), element.text().trim()); return true; - } else { - String value = attributes.get(configValue); + } + else { + final String value = attributes.get(configValue); receiver.literal(attribute.getValue(), value); } } return false; } - public void setAttrValsAsSubfields(String mapString) { + public void setAttrValsAsSubfields(final String mapString) { this.attrValsAsSubfields = new HashMap(); - String input = mapString.startsWith("&") ? DEFAULT_ATTR_VALS_AS_SUBFIELDS + mapString - : mapString; - for (String nameValuePair : input.split("&")) { - String[] nameValue = nameValuePair.split("="); + final String input = mapString.startsWith("&") ? DEFAULT_ATTR_VALS_AS_SUBFIELDS + mapString : mapString; + for (final String nameValuePair : input.split("&")) { + final String[] nameValue = nameValuePair.split("="); try { - String utf8 = StandardCharsets.UTF_8.name(); - String key = URLDecoder.decode(nameValue[0], utf8); - String val = nameValue.length > 1 ? URLDecoder.decode(nameValue[1], utf8) : ""; + final String utf8 = StandardCharsets.UTF_8.name(); + final String key = URLDecoder.decode(nameValue[0], utf8); + final String val = nameValue.length > 1 ? URLDecoder.decode(nameValue[1], utf8) : ""; attrValsAsSubfields.put(key, val); - } catch (UnsupportedEncodingException e) { + } + catch (final UnsupportedEncodingException e) { LOG.error(e.getMessage(), e); } } diff --git a/metafacture-html/src/test/java/org/metafacture/html/ElementExtractorTest.java b/metafacture-html/src/test/java/org/metafacture/html/ElementExtractorTest.java index abf8d0293..b8fb665c4 100644 --- a/metafacture-html/src/test/java/org/metafacture/html/ElementExtractorTest.java +++ b/metafacture-html/src/test/java/org/metafacture/html/ElementExtractorTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.html; import static org.mockito.Mockito.verify; diff --git a/metafacture-html/src/test/java/org/metafacture/html/HtmlDecoderTest.java b/metafacture-html/src/test/java/org/metafacture/html/HtmlDecoderTest.java index 0fcf93cf4..66d737875 100644 --- a/metafacture-html/src/test/java/org/metafacture/html/HtmlDecoderTest.java +++ b/metafacture-html/src/test/java/org/metafacture/html/HtmlDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.html; import static org.mockito.Mockito.inOrder; From 25401d572a428eef79aff2f9d824dba218b81144 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 20:05:04 +0200 Subject: [PATCH 14/30] metafacture-io/ (main): Fix Checkstyle violations. --- .../metafacture/io/AbstractObjectWriter.java | 1 + .../metafacture/io/ByteStreamFileWriter.java | 32 +++++----- .../java/org/metafacture/io/CloseFailed.java | 6 +- .../io/ConfigurableObjectWriter.java | 11 ++-- .../org/metafacture/io/FileCompression.java | 58 ++++++++++++------- .../java/org/metafacture/io/FileOpener.java | 30 ++++++---- .../java/org/metafacture/io/HttpOpener.java | 21 ++++--- .../java/org/metafacture/io/IoFailed.java | 6 +- .../org/metafacture/io/IoWriterFactory.java | 1 + .../java/org/metafacture/io/LineReader.java | 21 ++++--- .../org/metafacture/io/ObjectFileWriter.java | 46 +++++++++------ .../metafacture/io/ObjectJavaIoWriter.java | 20 ++++--- .../metafacture/io/ObjectStdoutWriter.java | 11 +++- .../java/org/metafacture/io/ObjectWriter.java | 16 ++--- .../java/org/metafacture/io/OpenFailed.java | 6 +- .../java/org/metafacture/io/RecordReader.java | 19 +++--- .../org/metafacture/io/ResourceOpener.java | 15 +++-- .../java/org/metafacture/io/StdInOpener.java | 19 +++--- .../java/org/metafacture/io/TarReader.java | 51 ++++++++-------- .../java/org/metafacture/io/WriteFailed.java | 6 +- .../AbstractConfigurableObjectWriterTest.java | 1 + .../io/FileOpenerCompressionTest.java | 1 + .../org/metafacture/io/FileOpenerTest.java | 1 + .../io/ObjectFileWriterCompressionTest.java | 1 + .../metafacture/io/ObjectFileWriterTest.java | 1 + .../io/ObjectStdoutWriterTest.java | 1 + .../org/metafacture/io/RecordReaderTest.java | 1 + 27 files changed, 237 insertions(+), 166 deletions(-) diff --git a/metafacture-io/src/main/java/org/metafacture/io/AbstractObjectWriter.java b/metafacture-io/src/main/java/org/metafacture/io/AbstractObjectWriter.java index 721dc1ab7..acfb1d9be 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/AbstractObjectWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/AbstractObjectWriter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; /** diff --git a/metafacture-io/src/main/java/org/metafacture/io/ByteStreamFileWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ByteStreamFileWriter.java index 66afa1a73..6032d860c 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ByteStreamFileWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ByteStreamFileWriter.java @@ -1,16 +1,15 @@ package org.metafacture.io; -import static java.util.Objects.requireNonNull; +import org.metafacture.framework.helpers.DefaultObjectReceiver; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.Objects; import java.util.function.Supplier; -import org.metafacture.framework.helpers.DefaultObjectReceiver; - /** * Writes byte arrays to regular output files. *

@@ -28,6 +27,9 @@ public class ByteStreamFileWriter extends DefaultObjectReceiver { private OutputStream outputStream; + public ByteStreamFileWriter() { + } + /** * Supplier for file names. *

@@ -42,9 +44,8 @@ public class ByteStreamFileWriter extends DefaultObjectReceiver { * * @param fileNameSupplier a supplier that returns file names. */ - public void setFileNameSupplier(Supplier fileNameSupplier) { - - this.fileNameSupplier = requireNonNull(fileNameSupplier); + public void setFileNameSupplier(final Supplier fileNameSupplier) { + this.fileNameSupplier = Objects.requireNonNull(fileNameSupplier); } /** @@ -58,8 +59,7 @@ public void setFileNameSupplier(Supplier fileNameSupplier) { * @param appendIfFileExists true if new data should be appended, * false to overwrite the existing file. */ - public void setAppendIfFileExists(boolean appendIfFileExists) { - + public void setAppendIfFileExists(final boolean appendIfFileExists) { this.appendIfFileExists = appendIfFileExists; } @@ -75,8 +75,7 @@ public void setAppendIfFileExists(boolean appendIfFileExists) { * @param flushAfterWrite true if the output stream should be flushed * after every write. */ - public void setFlushAfterWrite(boolean flushAfterWrite) { - + public void setFlushAfterWrite(final boolean flushAfterWrite) { this.flushAfterWrite = flushAfterWrite; } @@ -88,7 +87,6 @@ public void setFlushAfterWrite(boolean flushAfterWrite) { */ @Override public void process(final byte[] bytes) { - ensureOpenStream(); try { outputStream.write(bytes); @@ -96,7 +94,8 @@ public void process(final byte[] bytes) { outputStream.flush(); } - } catch (IOException e) { + } + catch (final IOException e) { throw new WriteFailed("Error while writing bytes to output stream", e); } } @@ -109,7 +108,6 @@ public void process(final byte[] bytes) { */ @Override public void resetStream() { - closeStream(); ensureOpenStream(); } @@ -121,12 +119,12 @@ public void resetStream() { */ @Override public void closeStream() { - if (outputStream != null) { try { outputStream.close(); - } catch (IOException e) { + } + catch (final IOException e) { throw new CloseFailed("Error while closing output stream", e); } outputStream = null; @@ -134,14 +132,14 @@ public void closeStream() { } private void ensureOpenStream() { - if (outputStream != null) { return; } try { outputStream = new FileOutputStream(fileNameSupplier.get(), appendIfFileExists); - } catch (FileNotFoundException e) { + } + catch (final FileNotFoundException e) { throw new OpenFailed("Cannot open output stream. File not found.", e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/CloseFailed.java b/metafacture-io/src/main/java/org/metafacture/io/CloseFailed.java index 88b339125..53c60c42a 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/CloseFailed.java +++ b/metafacture-io/src/main/java/org/metafacture/io/CloseFailed.java @@ -2,15 +2,15 @@ public class CloseFailed extends IoFailed { - public CloseFailed(String message) { + public CloseFailed(final String message) { super(message); } - public CloseFailed(Throwable cause) { + public CloseFailed(final Throwable cause) { super(cause); } - public CloseFailed(String message, Throwable cause) { + public CloseFailed(final String message, final Throwable cause) { super(message, cause); } diff --git a/metafacture-io/src/main/java/org/metafacture/io/ConfigurableObjectWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ConfigurableObjectWriter.java index d376ed442..7689b24b4 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ConfigurableObjectWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ConfigurableObjectWriter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import org.metafacture.framework.ObjectReceiver; @@ -58,14 +59,14 @@ public interface ConfigurableObjectWriter extends ObjectReceiver { * * @param compression type of compression */ - void setCompression(final FileCompression compression); + void setCompression(FileCompression compression); /** * Sets the compression mode. * * @param compression type of compression */ - void setCompression(final String compression); + void setCompression(String compression); /** * Returns the header which is output before the first object. @@ -79,7 +80,7 @@ public interface ConfigurableObjectWriter extends ObjectReceiver { * * @param header new header string */ - void setHeader(final String header); + void setHeader(String header); /** * Returns the footer which is output after the last object. @@ -93,7 +94,7 @@ public interface ConfigurableObjectWriter extends ObjectReceiver { * * @param footer new footer string */ - void setFooter(final String footer); + void setFooter(String footer); /** * Returns the separator which is output between objects. @@ -107,6 +108,6 @@ public interface ConfigurableObjectWriter extends ObjectReceiver { * * @param separator new separator string */ - void setSeparator(final String separator); + void setSeparator(String separator); } diff --git a/metafacture-io/src/main/java/org/metafacture/io/FileCompression.java b/metafacture-io/src/main/java/org/metafacture/io/FileCompression.java index 96435dafd..116fc3367 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/FileCompression.java +++ b/metafacture-io/src/main/java/org/metafacture/io/FileCompression.java @@ -13,19 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.InputStream; -import java.io.OutputStream; +import org.metafacture.framework.MetafactureException; import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorStreamFactory; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.input.ProxyInputStream; import org.apache.commons.io.output.ProxyOutputStream; -import org.metafacture.framework.MetafactureException; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.InputStream; +import java.io.OutputStream; /** * Provides a convenient interface for using stream compressors @@ -61,15 +63,20 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi final FileCompression compressor; if ("gz".equalsIgnoreCase(extension)) { compressor = GZIP; - } else if ("gzip".equalsIgnoreCase(extension)) { + } + else if ("gzip".equalsIgnoreCase(extension)) { compressor = GZIP; - } else if ("bz2".equalsIgnoreCase(extension)) { + } + else if ("bz2".equalsIgnoreCase(extension)) { compressor = BZIP2; - } else if ("bzip2".equalsIgnoreCase(extension)) { + } + else if ("bzip2".equalsIgnoreCase(extension)) { compressor = BZIP2; - } else if ("xz".equalsIgnoreCase(extension)) { + } + else if ("xz".equalsIgnoreCase(extension)) { compressor = XZ; - } else { + } + else { compressor = NONE; } @@ -83,7 +90,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean return decompressConcatenated ? APACHE_COMPRESSOR_FACTORY_DECOMPRESS_CONCATENATED.createCompressorInputStream(bufferedStream) : APACHE_COMPRESSOR_FACTORY_NO_DECOMPRESS_CONCATENATED.createCompressorInputStream(bufferedStream); - } catch (CompressorException e) { + } + catch (final CompressorException e) { return NONE.createDecompressor(bufferedStream, decompressConcatenated); } } @@ -95,7 +103,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi try { return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream( CompressorStreamFactory.BZIP2, bufferStream(writeTo)); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -105,7 +114,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean try { return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream( CompressorStreamFactory.BZIP2, bufferStream(readFrom), decompressConcatenated); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -117,7 +127,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi try { return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream( CompressorStreamFactory.GZIP, bufferStream(writeTo)); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -127,7 +138,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean try { return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream( CompressorStreamFactory.GZIP, bufferStream(readFrom), decompressConcatenated); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -139,7 +151,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi try { return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream( CompressorStreamFactory.PACK200, bufferStream(writeTo)); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -149,7 +162,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean try { return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream( CompressorStreamFactory.PACK200, bufferStream(readFrom), decompressConcatenated); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -161,7 +175,8 @@ public OutputStream createCompressor(final OutputStream writeTo, final String fi try { return APACHE_COMPRESSOR_FACTORY.createCompressorOutputStream( CompressorStreamFactory.XZ, bufferStream(writeTo)); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -171,7 +186,8 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean try { return APACHE_COMPRESSOR_FACTORY.createCompressorInputStream( CompressorStreamFactory.XZ, bufferStream(readFrom), decompressConcatenated); - } catch (CompressorException e) { + } + catch (final CompressorException e) { throw new MetafactureException(e); } } @@ -186,9 +202,9 @@ public InputStream createDecompressor(final InputStream readFrom, final boolean private static final int BUFFER_SIZE = 8 * 1024 * 1024; - public abstract OutputStream createCompressor(final OutputStream writeTo, final String fileName); + public abstract OutputStream createCompressor(OutputStream writeTo, String fileName); - public abstract InputStream createDecompressor(final InputStream readFrom, final boolean decompressConcatenated); + public abstract InputStream createDecompressor(InputStream readFrom, boolean decompressConcatenated); public InputStream createDecompressor(final InputStream readFrom) { return createDecompressor(readFrom, DEFAULT_DECOMPRESS_CONCATENATED); diff --git a/metafacture-io/src/main/java/org/metafacture/io/FileOpener.java b/metafacture-io/src/main/java/org/metafacture/io/FileOpener.java index 405ce7272..55abf99b4 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/FileOpener.java +++ b/metafacture-io/src/main/java/org/metafacture/io/FileOpener.java @@ -13,15 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; +package org.metafacture.io; -import org.apache.commons.io.input.BOMInputStream; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; import org.metafacture.framework.ObjectReceiver; @@ -30,6 +24,13 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import org.apache.commons.io.input.BOMInputStream; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; /** * Opens a file and passes a reader for it to the receiver. @@ -41,13 +42,15 @@ @In(String.class) @Out(java.io.Reader.class) @FluxCommand("open-file") -public final class FileOpener - extends DefaultObjectPipe> { +public final class FileOpener extends DefaultObjectPipe> { private String encoding = "UTF-8"; private FileCompression compression = FileCompression.AUTO; private boolean decompressConcatenated = FileCompression.DEFAULT_DECOMPRESS_CONCATENATED; + public FileOpener() { + } + /** * Returns the encoding used to open the resource. * @@ -98,15 +101,18 @@ public void process(final String file) { final Reader reader = new InputStreamReader(new BOMInputStream( decompressor), encoding); getReceiver().process(reader); - } catch (final IOException | MetafactureException e) { + } + catch (final IOException | MetafactureException e) { decompressor.close(); throw e; } - } catch (final IOException | MetafactureException e) { + } + catch (final IOException | MetafactureException e) { fileStream.close(); throw e; } - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java b/metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java index 9b551998b..657b5b8b0 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java +++ b/metafacture-io/src/main/java/org/metafacture/io/HttpOpener.java @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.net.URLConnection; +package org.metafacture.io; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -29,6 +24,11 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.net.URLConnection; /** * Opens a {@link URLConnection} and passes a reader to the receiver. @@ -40,12 +40,14 @@ @In(String.class) @Out(java.io.Reader.class) @FluxCommand("open-http") -public final class HttpOpener - extends DefaultObjectPipe> { +public final class HttpOpener extends DefaultObjectPipe> { private String encoding = "UTF-8"; private String accept = "*/*"; + public HttpOpener() { + } + /** * Sets the HTTP accept header value. This is a mime-type such as text/plain * or text/html. The default value of the accept is */* which means @@ -82,7 +84,8 @@ public void process(final String urlStr) { enc = encoding; } getReceiver().process(new InputStreamReader(con.getInputStream(), enc)); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/IoFailed.java b/metafacture-io/src/main/java/org/metafacture/io/IoFailed.java index aaff7da2a..dd9ef6448 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/IoFailed.java +++ b/metafacture-io/src/main/java/org/metafacture/io/IoFailed.java @@ -4,15 +4,15 @@ public class IoFailed extends MetafactureException { - public IoFailed(String message) { + public IoFailed(final String message) { super(message); } - public IoFailed(Throwable cause) { + public IoFailed(final Throwable cause) { super(cause); } - public IoFailed(String message, Throwable cause) { + public IoFailed(final String message, final Throwable cause) { super(message, cause); } diff --git a/metafacture-io/src/main/java/org/metafacture/io/IoWriterFactory.java b/metafacture-io/src/main/java/org/metafacture/io/IoWriterFactory.java index 2464239fa..1c43c0fef 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/IoWriterFactory.java +++ b/metafacture-io/src/main/java/org/metafacture/io/IoWriterFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import java.io.Writer; diff --git a/metafacture-io/src/main/java/org/metafacture/io/LineReader.java b/metafacture-io/src/main/java/org/metafacture/io/LineReader.java index d5d885ebd..45860bd96 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/LineReader.java +++ b/metafacture-io/src/main/java/org/metafacture/io/LineReader.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; +package org.metafacture.io; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -27,6 +24,10 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; + /** * Processes input from a reader line by line. * @@ -37,14 +38,17 @@ @In(Reader.class) @Out(String.class) @FluxCommand("as-lines") -public final class LineReader - extends DefaultObjectPipe> { +public final class LineReader extends DefaultObjectPipe> { + private static final int BUFFER_SIZE = 1024 * 1024 * 16; + public LineReader() { + } + @Override public void process(final Reader reader) { assert !isClosed(); - assert null!=reader; + assert null != reader; process(reader, getReceiver()); } @@ -56,7 +60,8 @@ public static void process(final Reader reader, final ObjectReceiver rec receiver.process(line); line = lineReader.readLine(); } - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java index 06689a9c8..fd487f0d1 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ObjectFileWriter.java @@ -13,8 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; +import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.MetafactureException; +import org.metafacture.framework.annotations.In; + import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -23,10 +28,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.metafacture.framework.FluxCommand; -import org.metafacture.framework.MetafactureException; -import org.metafacture.framework.annotations.In; - /** * @param * object type @@ -52,8 +53,6 @@ public final class ObjectFileWriter extends AbstractObjectWriter { private FileCompression compression = FileCompression.AUTO; public ObjectFileWriter(final String path) { - super(); - this.path = path; startNewFile(); @@ -95,11 +94,13 @@ public void process(final T obj) { if (firstObject) { writer.write(getHeader()); firstObject = false; - } else { + } + else { writer.write(getSeparator()); } writer.write(obj.toString()); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } @@ -112,9 +113,11 @@ public void resetStream() { writer.write(getFooter()); } writer.close(); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); - } finally { + } + finally { closed = true; } } @@ -130,9 +133,11 @@ public void closeStream() { writer.write(getFooter()); } writer.close(); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); - } finally { + } + finally { closed = true; } } @@ -140,25 +145,28 @@ public void closeStream() { private void startNewFile() { final Matcher matcher = VAR_PATTERN.matcher(this.path); - final String path = matcher.replaceAll(String.valueOf(count)); + final String currentPath = matcher.replaceAll(String.valueOf(count)); try { - final OutputStream file = new FileOutputStream(path); + final OutputStream file = new FileOutputStream(currentPath); try { - final OutputStream compressor = compression.createCompressor(file, path); + final OutputStream compressor = compression.createCompressor(file, currentPath); try { writer = new OutputStreamWriter(compressor, encoding); firstObject = true; closed = false; - } catch (final IOException e) { + } + catch (final IOException e) { compressor.close(); throw e; } - } catch (final IOException e) { + } + catch (final IOException e) { file.close(); throw e; } - } catch (final IOException e) { - throw new MetafactureException("Error creating file '" + path + "'.", e); + } + catch (final IOException e) { + throw new MetafactureException("Error creating file '" + currentPath + "'.", e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/ObjectJavaIoWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ObjectJavaIoWriter.java index 31094f658..fd431ca73 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ObjectJavaIoWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ObjectJavaIoWriter.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.IOException; -import java.io.Writer; +package org.metafacture.io; import org.metafacture.framework.MetafactureException; import org.metafacture.framework.ObjectReceiver; +import java.io.IOException; +import java.io.Writer; + /** * @param * object type @@ -51,14 +52,15 @@ public void process(final T obj) { try { writer.write(obj.toString()); writer.append('\n'); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } @Override public void resetStream() { - if(writerFactory==null){ + if (writerFactory == null) { throw new UnsupportedOperationException("Cannot reset ObjectJavaIoWriter. No IOWriterFactory set."); } writer = writerFactory.createWriter(); @@ -70,10 +72,12 @@ public void closeStream() { if (!closed) { try { writer.close(); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); - }finally{ - closed=true; + } + finally { + closed = true; } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/ObjectStdoutWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ObjectStdoutWriter.java index c9db49078..b7824cd76 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ObjectStdoutWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ObjectStdoutWriter.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.nio.charset.Charset; +package org.metafacture.io; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.annotations.Description; import org.metafacture.framework.annotations.In; +import java.nio.charset.Charset; + /** * @param object type * @@ -38,6 +39,9 @@ public final class ObjectStdoutWriter extends AbstractObjectWriter { private boolean firstObject = true; private boolean closed; + public ObjectStdoutWriter() { + } + @Override public String getEncoding() { return Charset.defaultCharset().toString(); @@ -70,7 +74,8 @@ public void process(final T obj) { if (firstObject) { System.out.print(getHeader()); firstObject = false; - } else { + } + else { System.out.print(getSeparator()); } System.out.print(obj); diff --git a/metafacture-io/src/main/java/org/metafacture/io/ObjectWriter.java b/metafacture-io/src/main/java/org/metafacture/io/ObjectWriter.java index a3b26f411..279c36832 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ObjectWriter.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ObjectWriter.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +package org.metafacture.io; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.annotations.Description; @@ -26,6 +22,10 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.annotations.ReturnsAvailableArguments; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; /** * Writes objects to stdout or a file @@ -34,7 +34,6 @@ * @author Christoph Böhme * */ - @Description("Writes objects to stdout or a file") @In(Object.class) @Out(Void.class) @@ -49,7 +48,8 @@ public final class ObjectWriter implements ConfigurableObjectWriter { public ObjectWriter(final String destination) { if (STDOUT.equals(destination)) { objectWriter = new ObjectStdoutWriter(); - } else { + } + else { objectWriter = new ObjectFileWriter(destination); } } @@ -58,6 +58,7 @@ public ObjectWriter(final String destination) { public static Collection getArguments() { return ARGUMENTS; } + @Override public String getEncoding() { return objectWriter.getEncoding(); @@ -83,7 +84,6 @@ public void setCompression(final String compression) { objectWriter.setCompression(compression); } - @Override public String getHeader() { return objectWriter.getHeader(); diff --git a/metafacture-io/src/main/java/org/metafacture/io/OpenFailed.java b/metafacture-io/src/main/java/org/metafacture/io/OpenFailed.java index ee69cc572..58e47ae2c 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/OpenFailed.java +++ b/metafacture-io/src/main/java/org/metafacture/io/OpenFailed.java @@ -2,15 +2,15 @@ public class OpenFailed extends IoFailed { - public OpenFailed(String message) { + public OpenFailed(final String message) { super(message); } - public OpenFailed(Throwable cause) { + public OpenFailed(final Throwable cause) { super(cause); } - public OpenFailed(String message, Throwable cause) { + public OpenFailed(final String message, final Throwable cause) { super(message, cause); } diff --git a/metafacture-io/src/main/java/org/metafacture/io/RecordReader.java b/metafacture-io/src/main/java/org/metafacture/io/RecordReader.java index 7f7325793..2ddbdb56a 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/RecordReader.java +++ b/metafacture-io/src/main/java/org/metafacture/io/RecordReader.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.IOException; -import java.io.Reader; +package org.metafacture.io; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -26,6 +24,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.IOException; +import java.io.Reader; + /** *

Reads data from a {@code Reader} and splits it into individual * records.

@@ -40,8 +41,7 @@ @In(Reader.class) @Out(String.class) @FluxCommand("as-records") -public final class RecordReader extends - DefaultObjectPipe> { +public final class RecordReader extends DefaultObjectPipe> { public static final char DEFAULT_SEPARATOR = '\u001d'; @@ -53,10 +53,14 @@ public final class RecordReader extends private char separator = DEFAULT_SEPARATOR; private boolean skipEmptyRecords = true; + public RecordReader() { + } + public void setSeparator(final String separator) { if (separator.length() >= 1) { this.separator = separator.charAt(0); - } else { + } + else { this.separator = DEFAULT_SEPARATOR; } } @@ -100,7 +104,8 @@ public void process(final Reader reader) { emitRecord(); } - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/ResourceOpener.java b/metafacture-io/src/main/java/org/metafacture/io/ResourceOpener.java index 8d765a3c9..410d8ff38 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/ResourceOpener.java +++ b/metafacture-io/src/main/java/org/metafacture/io/ResourceOpener.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.Reader; +package org.metafacture.io; import org.metafacture.commons.ResourceUtil; import org.metafacture.framework.FluxCommand; @@ -26,7 +25,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; - +import java.io.IOException; +import java.io.Reader; /** * Opens a resource or file and passes a reader for it to the receiver. @@ -38,11 +38,13 @@ @In(String.class) @Out(java.io.Reader.class) @FluxCommand("open-resource") -public final class ResourceOpener - extends DefaultObjectPipe> { +public final class ResourceOpener extends DefaultObjectPipe> { private String encoding = "UTF-8"; + public ResourceOpener() { + } + /** * Returns the encoding used to open the resource. * @@ -65,7 +67,8 @@ public void setEncoding(final String encoding) { public void process(final String file) { try { getReceiver().process(ResourceUtil.getReader(file, encoding)); - } catch (java.io.IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/StdInOpener.java b/metafacture-io/src/main/java/org/metafacture/io/StdInOpener.java index 79d66c472..660d95c04 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/StdInOpener.java +++ b/metafacture-io/src/main/java/org/metafacture/io/StdInOpener.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; +package org.metafacture.io; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.annotations.Description; @@ -25,6 +22,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; /** * Helper class to open stdin @@ -37,17 +37,22 @@ @Out(java.io.Reader.class) public final class StdInOpener extends DefaultObjectPipe> { + public StdInOpener() { + } + @Override public void process(final Object notUsed) { if (notUsed == null) { - BufferedReader stdin; + final BufferedReader stdin; try { stdin = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); - } catch (UnsupportedEncodingException e) { + } + catch (final UnsupportedEncodingException e) { throw new IllegalStateException("UTF-8 not supported", e); } getReceiver().process(stdin); - } else { + } + else { throw new IllegalArgumentException("Parameter not used. Must be null"); } } diff --git a/metafacture-io/src/main/java/org/metafacture/io/TarReader.java b/metafacture-io/src/main/java/org/metafacture/io/TarReader.java index 12725a17d..d3e3e9c49 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/TarReader.java +++ b/metafacture-io/src/main/java/org/metafacture/io/TarReader.java @@ -13,18 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.io; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.Charset; +package org.metafacture.io; -import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.ArchiveInputStream; -import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.io.input.ReaderInputStream; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; import org.metafacture.framework.ObjectReceiver; @@ -33,6 +24,17 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.io.input.ReaderInputStream; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; + /** * Opens (aka 'untar') a tar archive and passes every entry. * @@ -43,15 +45,16 @@ @In(Reader.class) @Out(Reader.class) @FluxCommand("open-tar") -public class TarReader - extends DefaultObjectPipe> { +public class TarReader extends DefaultObjectPipe> { + + public TarReader() { + } @Override public void process(final Reader reader) { try ( - InputStream stream = new ReaderInputStream(reader, - Charset.defaultCharset()); - ArchiveInputStream tarStream = new TarArchiveInputStream(stream); + InputStream stream = new ReaderInputStream(reader, Charset.defaultCharset()); + ArchiveInputStream tarStream = new TarArchiveInputStream(stream) ) { ArchiveEntry entry; while ((entry = tarStream.getNextEntry()) != null) { @@ -59,16 +62,16 @@ public void process(final Reader reader) { processFileEntry(tarStream); } } - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } - private void processFileEntry(ArchiveInputStream archiveStream) - throws IOException { + private void processFileEntry(final ArchiveInputStream archiveStream) throws IOException { try ( InputStream entryStream = new ArchiveEntryInputStream(archiveStream); - Reader entryReader = new InputStreamReader(entryStream); + Reader entryReader = new InputStreamReader(entryStream) ) { getReceiver().process(entryReader); } @@ -96,7 +99,7 @@ private static class ArchiveEntryInputStream extends InputStream { private final ArchiveInputStream archiveStream; - ArchiveEntryInputStream(ArchiveInputStream archiveStream) { + ArchiveEntryInputStream(final ArchiveInputStream archiveStream) { this.archiveStream = archiveStream; } @@ -106,17 +109,17 @@ public int read() throws IOException { } @Override - public int read(byte[] b) throws IOException { + public int read(final byte[] b) throws IOException { return archiveStream.read(b); } @Override - public int read(byte[] b, int off, int len) throws IOException { + public int read(final byte[] b, final int off, final int len) throws IOException { return archiveStream.read(b, off, len); } @Override - public long skip(long n) throws IOException { + public long skip(final long n) throws IOException { return archiveStream.skip(n); } @@ -131,7 +134,7 @@ public void close() throws IOException { } @Override - public void mark(int readlimit) { + public void mark(final int readlimit) { archiveStream.mark(readlimit); } diff --git a/metafacture-io/src/main/java/org/metafacture/io/WriteFailed.java b/metafacture-io/src/main/java/org/metafacture/io/WriteFailed.java index e9e08c479..606de11ae 100644 --- a/metafacture-io/src/main/java/org/metafacture/io/WriteFailed.java +++ b/metafacture-io/src/main/java/org/metafacture/io/WriteFailed.java @@ -2,15 +2,15 @@ public class WriteFailed extends IoFailed { - public WriteFailed(String message) { + public WriteFailed(final String message) { super(message); } - public WriteFailed(Throwable cause) { + public WriteFailed(final Throwable cause) { super(cause); } - public WriteFailed(String message, Throwable cause) { + public WriteFailed(final String message, final Throwable cause) { super(message, cause); } diff --git a/metafacture-io/src/test/java/org/metafacture/io/AbstractConfigurableObjectWriterTest.java b/metafacture-io/src/test/java/org/metafacture/io/AbstractConfigurableObjectWriterTest.java index fb9a80622..a780d7273 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/AbstractConfigurableObjectWriterTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/AbstractConfigurableObjectWriterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import static org.junit.Assert.assertEquals; diff --git a/metafacture-io/src/test/java/org/metafacture/io/FileOpenerCompressionTest.java b/metafacture-io/src/test/java/org/metafacture/io/FileOpenerCompressionTest.java index 7c37dfe60..ac665fe13 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/FileOpenerCompressionTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/FileOpenerCompressionTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import static org.junit.Assert.assertEquals; diff --git a/metafacture-io/src/test/java/org/metafacture/io/FileOpenerTest.java b/metafacture-io/src/test/java/org/metafacture/io/FileOpenerTest.java index 0a2fc6132..ad834b544 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/FileOpenerTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/FileOpenerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import static org.junit.Assert.assertEquals; diff --git a/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterCompressionTest.java b/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterCompressionTest.java index 001ec2b65..4d810d35c 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterCompressionTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterCompressionTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import static org.junit.Assert.assertArrayEquals; diff --git a/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java b/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java index 89f07849e..6842cd7aa 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/ObjectFileWriterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import static org.junit.Assert.assertArrayEquals; diff --git a/metafacture-io/src/test/java/org/metafacture/io/ObjectStdoutWriterTest.java b/metafacture-io/src/test/java/org/metafacture/io/ObjectStdoutWriterTest.java index 692f9ac58..2d2db8a7c 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/ObjectStdoutWriterTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/ObjectStdoutWriterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import java.io.ByteArrayOutputStream; diff --git a/metafacture-io/src/test/java/org/metafacture/io/RecordReaderTest.java b/metafacture-io/src/test/java/org/metafacture/io/RecordReaderTest.java index ee0492563..62569f905 100644 --- a/metafacture-io/src/test/java/org/metafacture/io/RecordReaderTest.java +++ b/metafacture-io/src/test/java/org/metafacture/io/RecordReaderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.io; import static org.mockito.Mockito.inOrder; From 7e0ed18aa330e89be0701e99872866ed1b501343 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 22:27:17 +0200 Subject: [PATCH 15/30] metafacture-runner/ (main): Fix Checkstyle violations. --- .../java/org/metafacture/runner/Flux.java | 25 +++++++++---------- .../runner/util/DirectoryClassLoader.java | 21 ++++++++-------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/metafacture-runner/src/main/java/org/metafacture/runner/Flux.java b/metafacture-runner/src/main/java/org/metafacture/runner/Flux.java index 012cd0e6b..c10adffdd 100644 --- a/metafacture-runner/src/main/java/org/metafacture/runner/Flux.java +++ b/metafacture-runner/src/main/java/org/metafacture/runner/Flux.java @@ -13,8 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.runner; +import org.metafacture.commons.ResourceUtil; +import org.metafacture.flux.FluxCompiler; +import org.metafacture.flux.parser.FluxProgramm; +import org.metafacture.runner.util.DirectoryClassLoader; + +import org.antlr.runtime.RecognitionException; + import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -22,12 +30,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.antlr.runtime.RecognitionException; -import org.metafacture.commons.ResourceUtil; -import org.metafacture.flux.FluxCompiler; -import org.metafacture.flux.parser.FluxProgramm; -import org.metafacture.runner.util.DirectoryClassLoader; - /** * @author Markus Michael Geipel * @author Christoph Böhme @@ -46,25 +48,22 @@ private Flux() { } public static void main(final String[] args) throws IOException, RecognitionException { - loadCustomJars(); - if (args.length < (1)) { + if (args.length < 1) { FluxProgramm.printHelp(System.out); System.exit(2); - } else { - + } + else { final File fluxFile = new File(args[0]); if (!fluxFile.exists()) { System.err.println("File not found: " + args[0]); System.exit(1); - return; } // get variable assignments final Map vars = new HashMap(); - vars.put(SCRIPT_HOME, fluxFile.getAbsoluteFile().getParent() - + System.getProperty("file.separator")); + vars.put(SCRIPT_HOME, fluxFile.getAbsoluteFile().getParent() + System.getProperty("file.separator")); for (int i = 1; i < args.length; ++i) { final Matcher matcher = VAR_PATTERN.matcher(args[i]); diff --git a/metafacture-runner/src/main/java/org/metafacture/runner/util/DirectoryClassLoader.java b/metafacture-runner/src/main/java/org/metafacture/runner/util/DirectoryClassLoader.java index ff3d4f592..1116928d6 100644 --- a/metafacture-runner/src/main/java/org/metafacture/runner/util/DirectoryClassLoader.java +++ b/metafacture-runner/src/main/java/org/metafacture/runner/util/DirectoryClassLoader.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.runner.util; +import org.metafacture.framework.MetafactureException; + import java.io.File; import java.io.FilenameFilter; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import org.metafacture.framework.MetafactureException; - /** * A class loader which allows adding directories to the class * path instead of class-files or jar-files. @@ -36,14 +37,13 @@ public final class DirectoryClassLoader extends URLClassLoader { private static final String CLASS_FILE_EXTENSION = ".class"; private static final FilenameFilter JAR_AND_CLASS_FILTER = - new FilenameFilter() { + new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - return name.endsWith(JAR_FILE_EXTENSION) - || name.endsWith(CLASS_FILE_EXTENSION); - } - }; + @Override + public boolean accept(final File dir, final String name) { + return name.endsWith(JAR_FILE_EXTENSION) || name.endsWith(CLASS_FILE_EXTENSION); + } + }; public DirectoryClassLoader(final ClassLoader parent) { super(new URL[0], parent); @@ -53,7 +53,8 @@ public void addDirectory(final File dir) { for (final File file : dir.listFiles(JAR_AND_CLASS_FILTER)) { try { addURL(file.toURI().toURL()); - } catch (final MalformedURLException e) { + } + catch (final MalformedURLException e) { throw new MetafactureException("Could not add " + file + " to class loader", e); } } From 5aa75d6a90271536c1683323fd9cdf7e3b537fe3 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 22:29:27 +0200 Subject: [PATCH 16/30] metafacture-scripting/ (main): Fix Checkstyle violations. --- .../scripting/JScriptObjectPipe.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/metafacture-scripting/src/main/java/org/metafacture/scripting/JScriptObjectPipe.java b/metafacture-scripting/src/main/java/org/metafacture/scripting/JScriptObjectPipe.java index 724de9ef8..80f681cb1 100644 --- a/metafacture-scripting/src/main/java/org/metafacture/scripting/JScriptObjectPipe.java +++ b/metafacture-scripting/src/main/java/org/metafacture/scripting/JScriptObjectPipe.java @@ -13,14 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.scripting; - -import java.io.FileNotFoundException; -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; +package org.metafacture.scripting; import org.metafacture.commons.ResourceUtil; import org.metafacture.framework.FluxCommand; @@ -31,6 +25,12 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.FileNotFoundException; +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + /** * Executes the function process(obj) in a given jscript. * @@ -62,16 +62,16 @@ private void setScript(final String file) { try { // LOG.info("loading code from '" + file + "'"); engine.eval(ResourceUtil.getReader(file)); - } catch (ScriptException e) { + } + catch (final ScriptException e) { throw new MetafactureException("Error in script", e); - } catch (FileNotFoundException e) { + } + catch (final FileNotFoundException e) { throw new MetafactureException("Error loading script '" + file + "'", e); } invocable = (Invocable) engine; } - - @Override public void process(final Object obj) { assert !isClosed(); @@ -83,9 +83,11 @@ public void process(final Object obj) { getReceiver().process(retObj); - } catch (ScriptException e) { + } + catch (final ScriptException e) { throw new MetafactureException("Error in script while evaluating 'process' method", e); - } catch (NoSuchMethodException e) { + } + catch (final NoSuchMethodException e) { throw new MetafactureException("'process' method is missing in script", e); } } From d23f1654e020b7ef9b04c18181e1e0c61813afae Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 22:34:08 +0200 Subject: [PATCH 17/30] metafacture-plumbing/ (main): Fix Checkstyle violations. --- .../plumbing/IdentityStreamPipe.java | 4 ++++ .../org/metafacture/plumbing/ObjectTee.java | 9 ++++++--- .../metafacture/plumbing/StreamBatchMerger.java | 4 ++++ .../org/metafacture/plumbing/StreamMerger.java | 7 +++++-- .../org/metafacture/plumbing/StreamTee.java | 17 ++++++++++------- .../java/org/metafacture/plumbing/XmlTee.java | 11 ++++++++--- .../plumbing/IdentityStreamPipeTest.java | 1 + .../plumbing/StreamBatchMergerTest.java | 1 + .../metafacture/plumbing/StreamMergerTest.java | 1 + .../org/metafacture/plumbing/StreamTeeTest.java | 1 + 10 files changed, 41 insertions(+), 15 deletions(-) diff --git a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/IdentityStreamPipe.java b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/IdentityStreamPipe.java index 872cd3de0..89f6a26f5 100644 --- a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/IdentityStreamPipe.java +++ b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/IdentityStreamPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import org.metafacture.framework.FluxCommand; @@ -33,4 +34,7 @@ @FluxCommand("pass-through") public final class IdentityStreamPipe extends ForwardingStreamPipe { + public IdentityStreamPipe() { + } + } diff --git a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/ObjectTee.java b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/ObjectTee.java index c46a7e334..53e1bee0f 100644 --- a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/ObjectTee.java +++ b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/ObjectTee.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import org.metafacture.framework.FluxCommand; @@ -35,12 +36,14 @@ @In(Object.class) @Out(Object.class) @FluxCommand("object-tee") -public final class ObjectTee extends DefaultTee> - implements ObjectPipe> { +public final class ObjectTee extends DefaultTee> implements ObjectPipe> { + + public ObjectTee() { + } @Override public void process(final T obj) { - for (ObjectReceiver receiver : getReceivers()) { + for (final ObjectReceiver receiver : getReceivers()) { receiver.process(obj); } } diff --git a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamBatchMerger.java b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamBatchMerger.java index 5c5a8a638..7b5245c3e 100644 --- a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamBatchMerger.java +++ b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamBatchMerger.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import org.metafacture.framework.FluxCommand; @@ -44,6 +45,9 @@ public final class StreamBatchMerger extends DefaultStreamPipe { private long batchSize = DEFAULT_BATCH_SIZE; private long recordCount; + public StreamBatchMerger() { + } + /** * Sets the number of records that should be merged into a batch. *

diff --git a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamMerger.java b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamMerger.java index dec325eeb..b6876f46c 100644 --- a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamMerger.java +++ b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamMerger.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import org.metafacture.framework.FluxCommand; @@ -37,12 +38,14 @@ @In(StreamReceiver.class) @Out(StreamReceiver.class) @FluxCommand("merge-same-ids") -public final class StreamMerger - extends DefaultStreamPipe { +public final class StreamMerger extends DefaultStreamPipe { private boolean hasRecordsReceived; private String currentId = ""; + public StreamMerger() { + } + @Override public void startRecord(final String identifier) { assert !isClosed(); diff --git a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamTee.java b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamTee.java index 4883d5c6d..cc82f257c 100644 --- a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamTee.java +++ b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/StreamTee.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import org.metafacture.framework.FluxCommand; @@ -33,40 +34,42 @@ @In(StreamReceiver.class) @Out(StreamReceiver.class) @FluxCommand("stream-tee") -public final class StreamTee extends DefaultTee - implements StreamPipe { +public final class StreamTee extends DefaultTee implements StreamPipe { + + public StreamTee() { + } @Override public void startRecord(final String identifier) { - for (StreamReceiver receiver : getReceivers()) { + for (final StreamReceiver receiver : getReceivers()) { receiver.startRecord(identifier); } } @Override public void endRecord() { - for (StreamReceiver receiver : getReceivers()) { + for (final StreamReceiver receiver : getReceivers()) { receiver.endRecord(); } } @Override public void startEntity(final String name) { - for (StreamReceiver receiver : getReceivers()) { + for (final StreamReceiver receiver : getReceivers()) { receiver.startEntity(name); } } @Override public void endEntity() { - for (StreamReceiver receiver : getReceivers()) { + for (final StreamReceiver receiver : getReceivers()) { receiver.endEntity(); } } @Override public void literal(final String name, final String value) { - for (StreamReceiver receiver : getReceivers()) { + for (final StreamReceiver receiver : getReceivers()) { receiver.literal(name, value); } } diff --git a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/XmlTee.java b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/XmlTee.java index da7173f90..cae1bed57 100644 --- a/metafacture-plumbing/src/main/java/org/metafacture/plumbing/XmlTee.java +++ b/metafacture-plumbing/src/main/java/org/metafacture/plumbing/XmlTee.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.plumbing; -import java.io.IOException; +package org.metafacture.plumbing; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.XmlPipe; @@ -24,12 +23,15 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultTee; + import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; +import java.io.IOException; + /** * Sends one {@link XmlReceiver} to two {@link XmlReceiver}s. * @@ -40,7 +42,10 @@ @In(XmlReceiver.class) @Out(XmlReceiver.class) @FluxCommand("xml-tee") -public final class XmlTee extends DefaultTeeimplements XmlPipe { +public final class XmlTee extends DefaultTee implements XmlPipe { + + public XmlTee() { + } @Override public void characters(final char[] ch, final int start, final int length) throws SAXException { diff --git a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/IdentityStreamPipeTest.java b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/IdentityStreamPipeTest.java index ba2f5e2a4..36f126923 100644 --- a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/IdentityStreamPipeTest.java +++ b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/IdentityStreamPipeTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamBatchMergerTest.java b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamBatchMergerTest.java index c48c054f5..495ff6c51 100644 --- a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamBatchMergerTest.java +++ b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamBatchMergerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import org.junit.Before; diff --git a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamMergerTest.java b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamMergerTest.java index e3f2f2f10..f79939397 100644 --- a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamMergerTest.java +++ b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamMergerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamTeeTest.java b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamTeeTest.java index a1b99d613..6c328d2bc 100644 --- a/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamTeeTest.java +++ b/metafacture-plumbing/src/test/java/org/metafacture/plumbing/StreamTeeTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.plumbing; import static org.mockito.Mockito.inOrder; From 52c9559fddc093678ccf3b44673882444a55eb18 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Sun, 5 Sep 2021 22:39:49 +0200 Subject: [PATCH 18/30] metafacture-mangling/ (main): Fix Checkstyle violations. --- .../mangling/DuplicateObjectFilter.java | 7 +++++-- .../metafacture/mangling/EntityPathTracker.java | 8 ++++++-- .../metafacture/mangling/LiteralToObject.java | 10 +++++++--- .../org/metafacture/mangling/NullFilter.java | 9 +++++++-- .../metafacture/mangling/ObjectToLiteral.java | 6 +++--- .../metafacture/mangling/RecordIdChanger.java | 7 ++++++- .../metafacture/mangling/RecordPathFilter.java | 2 +- .../metafacture/mangling/RecordToEntity.java | 4 ++++ .../mangling/StreamEventDiscarder.java | 17 +++++++++++------ .../metafacture/mangling/StreamFlattener.java | 1 + .../mangling/DuplicateObjectFilterTest.java | 1 + .../mangling/EntityPathTrackerTest.java | 1 + .../mangling/LiteralToObjectTest.java | 1 + .../metafacture/mangling/NullFilterTest.java | 1 + .../mangling/ObjectToLiteralTest.java | 1 + .../mangling/RecordIdChangerTest.java | 1 + .../mangling/RecordPathFilterTest.java | 1 + .../mangling/RecordToEntityTest.java | 1 + .../mangling/StreamEventDiscarderTest.java | 1 + .../mangling/StreamFlattenerTest.java | 1 + .../org/metafacture/mangling/TestHelpers.java | 1 + 21 files changed, 62 insertions(+), 20 deletions(-) diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/DuplicateObjectFilter.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/DuplicateObjectFilter.java index f581c604e..d8f40b58a 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/DuplicateObjectFilter.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/DuplicateObjectFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.metafacture.framework.FluxCommand; @@ -34,11 +35,13 @@ @In(Object.class) @Out(Object.class) @FluxCommand("filter-duplicate-objects") -public final class DuplicateObjectFilter extends - DefaultObjectPipe> { +public final class DuplicateObjectFilter extends DefaultObjectPipe> { private T lastObj; + public DuplicateObjectFilter() { + } + @Override public void process(final T obj) { if (!obj.equals(lastObj)) { diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/EntityPathTracker.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/EntityPathTracker.java index 44b5e2e90..afea4a39b 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/EntityPathTracker.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/EntityPathTracker.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.ArrayDeque; import java.util.Deque; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - /** * Tracks the path of the current entity. The entity path consists of the * names of all parent entities of the current entity separated by a separator @@ -46,6 +47,9 @@ public class EntityPathTracker extends DefaultStreamReceiver { private String entitySeparator = DEFAULT_ENTITY_SEPARATOR; + public EntityPathTracker() { + } + /** * Returns the current entity path. * diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/LiteralToObject.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/LiteralToObject.java index 1294c7b2b..44f53b35a 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/LiteralToObject.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/LiteralToObject.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.mangling; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.mangling; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -26,6 +24,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Emits the values of literals matching {@literal #setPattern(String)} * as objects. @@ -49,6 +50,9 @@ public final class LiteralToObject extends DefaultStreamPipe extends private int recordCount; public ObjectToLiteral() { - super(); setLiteralName(DEFAULT_LITERAL_NAME); setRecordId(DEFAULT_RECORD_ID); - recordCount=0; + recordCount = 0; } public void setLiteralName(final String literalName) { @@ -65,7 +65,7 @@ public String getRecordId() { @Override public void process(final T obj) { - assert obj!=null; + assert obj != null; assert !isClosed(); getReceiver().startRecord(String.format(recordId, ++recordCount)); getReceiver().literal(literalName, obj.toString()); diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordIdChanger.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordIdChanger.java index f123936af..6513784f7 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordIdChanger.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordIdChanger.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.metafacture.flowcontrol.StreamBuffer; @@ -78,6 +79,9 @@ public final class RecordIdChanger extends DefaultStreamPipe { private boolean keepRecordsWithoutIdLiteral = true; private boolean keepIdLiteral; + public RecordIdChanger() { + } + /** * Sets the name of the literal that contains the new record id. This must be * a qualified literal name including the entities in which the literal is @@ -158,7 +162,8 @@ public void endRecord() { if (currentIdentifier != null || keepRecordsWithoutIdLiteral) { if (currentIdentifier == null) { getReceiver().startRecord(originalIdentifier); - } else { + } + else { getReceiver().startRecord(currentIdentifier); } streamBuffer.replay(); diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordPathFilter.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordPathFilter.java index 683986083..bba0e6210 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordPathFilter.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordPathFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.metafacture.framework.FluxCommand; @@ -49,7 +50,6 @@ public RecordPathFilter() { } public RecordPathFilter(final String path) { - super(); resetRecord(); setPath(path); setRecordIdFormat(DEFAULT_RECORD_ID_FORMAT); diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordToEntity.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordToEntity.java index 9ea0044ed..fac5938df 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordToEntity.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/RecordToEntity.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.metafacture.framework.FluxCommand; @@ -47,6 +48,9 @@ public class RecordToEntity extends ForwardingStreamPipe { private String entityName = DEFAULT_ENTITY_NAME; private String idLiteralName; + public RecordToEntity() { + } + public String getEntityName() { return entityName; } diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamEventDiscarder.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamEventDiscarder.java index 1e9d27ca8..f94f88589 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamEventDiscarder.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamEventDiscarder.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.mangling; -import java.util.EnumSet; +package org.metafacture.mangling; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamPipe; @@ -23,6 +22,8 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; +import java.util.EnumSet; + /** * Discards stream events by type. The type of a stream event is either * {@linkplain EventType#RECORD record}, {@linkplain EventType#ENTITY entity}, @@ -48,10 +49,13 @@ public class StreamEventDiscarder implements StreamPipe { private EnumSet discardedEvents = EnumSet.noneOf(EventType.class); + public StreamEventDiscarder() { + } + @Override - public R setReceiver(final R receiver) { - this.receiver = receiver; - return receiver; + public R setReceiver(final R newReceiver) { + receiver = newReceiver; + return newReceiver; } /** @@ -122,7 +126,8 @@ private void setDiscardEventsByType(final EventType type, final boolean discard) { if (discard) { discardedEvents.add(type); - } else { + } + else { discardedEvents.remove(type); } } diff --git a/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamFlattener.java b/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamFlattener.java index 06e36bd20..aabf055f5 100644 --- a/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamFlattener.java +++ b/metafacture-mangling/src/main/java/org/metafacture/mangling/StreamFlattener.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.metafacture.framework.FluxCommand; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/DuplicateObjectFilterTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/DuplicateObjectFilterTest.java index eea09db6a..c5a1b9ab5 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/DuplicateObjectFilterTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/DuplicateObjectFilterTest.java @@ -17,6 +17,7 @@ /** * */ + package org.metafacture.mangling; import static org.mockito.Mockito.verify; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/EntityPathTrackerTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/EntityPathTrackerTest.java index 2c2a77dc7..1c4a5bff9 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/EntityPathTrackerTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/EntityPathTrackerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.junit.Assert.assertEquals; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/LiteralToObjectTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/LiteralToObjectTest.java index 929f0a1e7..7780413b7 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/LiteralToObjectTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/LiteralToObjectTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.mockito.Mockito.verify; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/NullFilterTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/NullFilterTest.java index da6c31df4..1d9d64084 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/NullFilterTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/NullFilterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/ObjectToLiteralTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/ObjectToLiteralTest.java index ad55ae849..01ce9a0a0 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/ObjectToLiteralTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/ObjectToLiteralTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordIdChangerTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordIdChangerTest.java index 3bd8c1cf4..ae805cb8f 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordIdChangerTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordIdChangerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordPathFilterTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordPathFilterTest.java index ead4c8b39..f019dc4c2 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordPathFilterTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordPathFilterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.junit.Rule; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordToEntityTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordToEntityTest.java index d73190c10..426f50441 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordToEntityTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/RecordToEntityTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamEventDiscarderTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamEventDiscarderTest.java index 6f375a613..69b4db53a 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamEventDiscarderTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamEventDiscarderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamFlattenerTest.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamFlattenerTest.java index ee093bc69..c606d64bb 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamFlattenerTest.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/StreamFlattenerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import static org.junit.Assert.assertEquals; diff --git a/metafacture-mangling/src/test/java/org/metafacture/mangling/TestHelpers.java b/metafacture-mangling/src/test/java/org/metafacture/mangling/TestHelpers.java index 12d053c8c..c5acf510e 100644 --- a/metafacture-mangling/src/test/java/org/metafacture/mangling/TestHelpers.java +++ b/metafacture-mangling/src/test/java/org/metafacture/mangling/TestHelpers.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.mangling; import org.metafacture.framework.StreamReceiver; From 0cd5d86cafb9c2bf43398739791287f428aa2b8c Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 19:55:46 +0200 Subject: [PATCH 19/30] metafacture-jdom/ (main): Fix Checkstyle violations. --- .../jdom/JDomDocumentToStream.java | 13 +++-- .../jdom/StreamToJDomDocument.java | 48 ++++++++++--------- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/metafacture-jdom/src/main/java/org/metafacture/jdom/JDomDocumentToStream.java b/metafacture-jdom/src/main/java/org/metafacture/jdom/JDomDocumentToStream.java index 6eef5bbec..dc9309078 100644 --- a/metafacture-jdom/src/main/java/org/metafacture/jdom/JDomDocumentToStream.java +++ b/metafacture-jdom/src/main/java/org/metafacture/jdom/JDomDocumentToStream.java @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.jdom; -import org.jdom2.Document; -import org.jdom2.JDOMException; -import org.jdom2.output.SAXOutputter; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectPipe; import org.metafacture.framework.StreamReceiver; @@ -25,6 +23,10 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; +import org.jdom2.Document; +import org.jdom2.JDOMException; +import org.jdom2.output.SAXOutputter; + /** * Converts a {@link Document} to a stream. * @@ -46,10 +48,11 @@ public JDomDocumentToStream(final XmlPipe xmlPipe) { @Override public void process(final Document document) { - assert null!=document; + assert null != document; try { saxOutputer.output(document); - } catch (JDOMException e) { + } + catch (final JDOMException e) { throw new IllegalArgumentException("Invalid JDOM document", e); } } diff --git a/metafacture-jdom/src/main/java/org/metafacture/jdom/StreamToJDomDocument.java b/metafacture-jdom/src/main/java/org/metafacture/jdom/StreamToJDomDocument.java index cdf873369..b1cc3101a 100644 --- a/metafacture-jdom/src/main/java/org/metafacture/jdom/StreamToJDomDocument.java +++ b/metafacture-jdom/src/main/java/org/metafacture/jdom/StreamToJDomDocument.java @@ -13,18 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.jdom; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.regex.Pattern; +package org.metafacture.jdom; -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.Namespace; import org.metafacture.commons.ResourceUtil; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -35,6 +26,17 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.Namespace; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Map; +import java.util.Properties; +import java.util.regex.Pattern; + /** * Converts a stream into a {@link Document}. * @@ -54,7 +56,7 @@ public final class StreamToJDomDocument private Document document; private Element currentElement; private final String rootTagName; - private final Map namespaces = new HashMap(); + private final Map namespaces = new HashMap(); public StreamToJDomDocument(final String rootTagName, final String namespaceProperties) { this.rootTagName = rootTagName; @@ -62,26 +64,25 @@ public StreamToJDomDocument(final String rootTagName, final String namespaceProp final Properties properties; try { properties = ResourceUtil.loadProperties(namespaceProperties); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Cannot load namespaces list", e); } - for (Entry entry : properties.entrySet()) { + for (final Entry entry : properties.entrySet()) { namespaces.put(entry.getKey().toString(), Namespace.getNamespace(entry.getKey().toString(), entry.getValue().toString())); } } - @Override public void startRecord(final String identifier) { assert !isClosed(); currentElement = createElement(rootTagName); - for (Namespace namespace : namespaces.values()) { + for (final Namespace namespace : namespaces.values()) { currentElement.addNamespaceDeclaration(namespace); } document = new Document(currentElement); } - @Override public void startEntity(final String name) { assert !isClosed(); @@ -98,36 +99,37 @@ private Element createElement(final String name) { return new Element(name); } - private Namespace getNamespace(final String name){ + private Namespace getNamespace(final String name) { final Namespace namespace = namespaces.get(name); - if(namespace==null){ + if (namespace == null) { throw new IllegalArgumentException("Namespace " + name + " not registered"); } return namespace; } - @Override public void endEntity() { assert !isClosed(); currentElement = currentElement.getParentElement(); } - @Override public void literal(final String name, final String value) { assert !isClosed(); if (name.isEmpty()) { currentElement.addContent(value); - } else if (name.startsWith(ATTRIBUTE_MARKER)) { + } + else if (name.startsWith(ATTRIBUTE_MARKER)) { final String[] parts = NAMESPACE_DELIMITER.split(name); if (parts.length == 2) { currentElement.setAttribute(parts[1], value, getNamespace(parts[0].substring(1))); - } else{ + } + else { currentElement.setAttribute(name.substring(1), value); } - } else { + } + else { final Element temp = createElement(name); currentElement.addContent(temp); temp.setText(value); From d3ad35bee6ca51778054fd0609bc3d2960292288 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 20:11:13 +0200 Subject: [PATCH 20/30] metafacture-monitoring/ (main): Fix Checkstyle violations. --- .../monitoring/ObjectBatchLogger.java | 11 +++++----- .../metafacture/monitoring/ObjectLogger.java | 4 ++-- .../metafacture/monitoring/ObjectTimer.java | 1 + .../monitoring/StreamBatchLogger.java | 20 ++++++++++--------- .../metafacture/monitoring/StreamLogger.java | 4 ++-- .../metafacture/monitoring/StreamTimer.java | 1 + .../org/metafacture/monitoring/TimerBase.java | 20 +++++++++---------- .../monitoring/ObjectTimerTest.java | 4 +++- .../monitoring/StreamLoggerTest.java | 1 + .../monitoring/StreamTimerTest.java | 4 +++- 10 files changed, 39 insertions(+), 31 deletions(-) diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectBatchLogger.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectBatchLogger.java index 71ef05f11..2554eedc8 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectBatchLogger.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectBatchLogger.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.monitoring; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.monitoring; import org.metafacture.commons.StringUtil; import org.metafacture.framework.FluxCommand; @@ -25,9 +23,13 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; + /** * Writes log info for every BATCHSIZE records. * @@ -60,18 +62,15 @@ public final class ObjectBatchLogger extends DefaultObjectPipe vars) { - super(); this.format = format; this.vars.putAll(vars); } diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectLogger.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectLogger.java index 18c26ee4e..9ba9bab27 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectLogger.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectLogger.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.monitoring; import org.metafacture.framework.FluxCommand; @@ -21,10 +22,10 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Logs the string representation of every object. * @@ -49,7 +50,6 @@ public ObjectLogger() { } public ObjectLogger(final String logPrefix) { - super(); this.logPrefix = logPrefix; } diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectTimer.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectTimer.java index 632b62d39..40021a5c5 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectTimer.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/ObjectTimer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.monitoring; import org.metafacture.framework.FluxCommand; diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamBatchLogger.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamBatchLogger.java index d9884227d..53cca5f53 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamBatchLogger.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamBatchLogger.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.monitoring; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.monitoring; import org.metafacture.commons.StringUtil; import org.metafacture.framework.FluxCommand; @@ -25,9 +23,13 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.ForwardingStreamPipe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; +import java.util.Map; + /** * Writes log info every {@code batchSize} records. * @@ -73,11 +75,11 @@ public StreamBatchLogger(final String format, final Map vars) { this.vars.putAll(vars); } - public final void setBatchSize(final int batchSize) { + public void setBatchSize(final int batchSize) { this.batchSize = batchSize; } - public final long getBatchSize() { + public long getBatchSize() { return batchSize; } @@ -90,12 +92,12 @@ public long getRecordCount() { } @Override - public final void endRecord() { + public void endRecord() { getReceiver().endRecord(); - recordCount++; + ++recordCount; recordCount %= batchSize; if (recordCount == 0) { - batchCount++; + ++batchCount; writeLog(); } } @@ -106,7 +108,7 @@ protected void onCloseStream() { } @Override - protected final void onResetStream() { + protected void onResetStream() { recordCount = 0; batchCount = 0; } diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamLogger.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamLogger.java index efc484cb6..db6960e9a 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamLogger.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamLogger.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.monitoring; import org.metafacture.framework.FluxCommand; @@ -21,10 +22,10 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Leaves the event stream untouched but logs it to the info log. * The {@link StreamReceiver} may be {@code null}. @@ -49,7 +50,6 @@ public StreamLogger() { } public StreamLogger(final String logPrefix) { - super(); this.logPrefix = logPrefix; } diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamTimer.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamTimer.java index b0140b1a1..9a6690873 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamTimer.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/StreamTimer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.monitoring; import org.metafacture.framework.FluxCommand; diff --git a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/TimerBase.java b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/TimerBase.java index 07d1d834e..bfaeb9e2a 100644 --- a/metafacture-monitoring/src/main/java/org/metafacture/monitoring/TimerBase.java +++ b/metafacture-monitoring/src/main/java/org/metafacture/monitoring/TimerBase.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.monitoring; import org.metafacture.commons.TimeUtil; import org.metafacture.framework.Receiver; import org.metafacture.framework.Sender; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * @author Christoph Böhme * @@ -41,14 +42,13 @@ public class TimerBase implements Sender { private R receiver; protected TimerBase(final String logPrefix) { - super(); this.logPrefix = logPrefix; } @Override - public final S setReceiver(final S receiver) { - this.receiver = receiver; - return receiver; + public final S setReceiver(final S newReceiver) { + receiver = newReceiver; + return newReceiver; } public final R getReceiver() { @@ -69,12 +69,12 @@ public final void closeStream() { final long averageDuration; if (count > 0) { averageDuration = cumulativeDuration / count; - } else { + } + else { averageDuration = 0; } - LOG.info(logPrefix - + String.format("Executions: %d; Cumulative duration: %s; Average duration: %s", Long.valueOf(count), - TimeUtil.formatDuration(cumulativeDuration), TimeUtil.formatDuration(averageDuration))); + LOG.info(logPrefix + String.format("Executions: %d; Cumulative duration: %s; Average duration: %s", Long.valueOf(count), + TimeUtil.formatDuration(cumulativeDuration), TimeUtil.formatDuration(averageDuration))); startMeasurement(); if (receiver != null) { receiver.closeStream(); @@ -86,7 +86,7 @@ protected final void startMeasurement() { startTime = System.nanoTime(); } - protected final void stopMeasurement(){ + protected final void stopMeasurement() { stopMeasurement("Execution %1$d:"); } diff --git a/metafacture-monitoring/src/test/java/org/metafacture/monitoring/ObjectTimerTest.java b/metafacture-monitoring/src/test/java/org/metafacture/monitoring/ObjectTimerTest.java index 19ed9f45f..49cb1c46b 100644 --- a/metafacture-monitoring/src/test/java/org/metafacture/monitoring/ObjectTimerTest.java +++ b/metafacture-monitoring/src/test/java/org/metafacture/monitoring/ObjectTimerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.monitoring; import org.junit.Before; @@ -41,7 +42,8 @@ private static final class BenchmarkedModule extends DefaultObjectReceiver Date: Tue, 7 Sep 2021 20:05:57 +0200 Subject: [PATCH 21/30] metamorph-api/ (main): Fix Checkstyle violations. --- .../metafacture/metamorph/api/Collect.java | 6 ++-- .../metamorph/api/ConditionAware.java | 1 + .../metamorph/api/FlushListener.java | 3 +- .../metafacture/metamorph/api/Function.java | 3 +- .../metamorph/api/InterceptorFactory.java | 1 + .../metamorph/api/KnowsSourceLocation.java | 3 +- .../org/metafacture/metamorph/api/Maps.java | 1 + .../metamorph/api/MorphBuildException.java | 1 + .../metamorph/api/MorphErrorHandler.java | 1 + .../api/MorphExecutionException.java | 1 + .../metamorph/api/NamedValuePipe.java | 1 + .../metamorph/api/NamedValueReceiver.java | 6 ++-- .../metamorph/api/NamedValueSource.java | 1 + .../metamorph/api/SourceLocation.java | 1 + .../api/helpers/AbstractCollect.java | 19 ++++++------ .../metamorph/api/helpers/AbstractFilter.java | 5 ++-- .../api/helpers/AbstractFlushingCollect.java | 3 +- .../api/helpers/AbstractFunction.java | 15 +++++----- .../api/helpers/AbstractNamedValuePipe.java | 1 + .../api/helpers/AbstractReadOnlyMap.java | 1 + .../AbstractSimpleStatelessFunction.java | 1 + .../api/helpers/AbstractStatefulFunction.java | 30 +++++++++---------- 22 files changed, 62 insertions(+), 43 deletions(-) diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/Collect.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/Collect.java index de739d259..46c4c8699 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/Collect.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/Collect.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** @@ -21,10 +22,9 @@ * @author Markus Michael Geipel * */ -public interface Collect extends FlushListener, ConditionAware, - NamedValuePipe { +public interface Collect extends FlushListener, ConditionAware, NamedValuePipe { - void setWaitForFlush(final boolean waitForFlush); + void setWaitForFlush(boolean waitForFlush); void setSameEntity(boolean sameEntity); diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/ConditionAware.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/ConditionAware.java index f5b3e596c..e5b8305ca 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/ConditionAware.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/ConditionAware.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/FlushListener.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/FlushListener.java index ff41b75e1..0beedb906 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/FlushListener.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/FlushListener.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** @@ -22,6 +23,6 @@ */ public interface FlushListener { - void flush(final int recordCount, final int entityCount); + void flush(int recordCount, int entityCount); } diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/Function.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/Function.java index 23c913b5d..671ab7d79 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/Function.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/Function.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.api; +package org.metafacture.metamorph.api; /** * Interface for functions used in Metamorph. @@ -25,6 +25,7 @@ public interface Function extends NamedValuePipe, FlushListener { void putValue(String key, String value); + void setMaps(Maps maps); } diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/InterceptorFactory.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/InterceptorFactory.java index c3392a04d..1668c69ef 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/InterceptorFactory.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/InterceptorFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/KnowsSourceLocation.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/KnowsSourceLocation.java index 84f2b1873..2292fbd29 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/KnowsSourceLocation.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/KnowsSourceLocation.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** @@ -31,7 +32,7 @@ public interface KnowsSourceLocation { * * @param sourceLocation a source location */ - void setSourceLocation(final SourceLocation sourceLocation); + void setSourceLocation(SourceLocation sourceLocation); /** * Gets the location object for the location in the morph definition file diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/Maps.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/Maps.java index 302fc287b..b11feda4b 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/Maps.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/Maps.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; import java.util.Collection; diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphBuildException.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphBuildException.java index 6ef33e484..f720f71fc 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphBuildException.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphBuildException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphErrorHandler.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphErrorHandler.java index 715b33d32..8404d4c93 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphErrorHandler.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphErrorHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphExecutionException.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphExecutionException.java index b750e5b9d..be6e6e08a 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphExecutionException.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/MorphExecutionException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValuePipe.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValuePipe.java index e426c3ecf..71f8cb709 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValuePipe.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValuePipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueReceiver.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueReceiver.java index 7395ec55e..fb0f6e6a0 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueReceiver.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueReceiver.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** @@ -24,9 +25,8 @@ */ public interface NamedValueReceiver extends KnowsSourceLocation { - void receive(String name, String value, NamedValueSource source, - int recordCount, int entityCount); + void receive(String name, String value, NamedValueSource source, int recordCount, int entityCount); - void addNamedValueSource(final NamedValueSource namedValueSource); + void addNamedValueSource(NamedValueSource namedValueSource); } diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueSource.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueSource.java index 600e6e525..2ed03aab0 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueSource.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/NamedValueSource.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/SourceLocation.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/SourceLocation.java index 056a3c121..3e3e01c48 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/SourceLocation.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/SourceLocation.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api; /** diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractCollect.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractCollect.java index 4cce5d3dc..6a5892726 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractCollect.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractCollect.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; import org.metafacture.metamorph.api.Collect; @@ -130,8 +131,12 @@ protected final boolean isSameRecord(final int currentRecord) { return currentRecord == oldRecord; } + protected final boolean sameEntityConstraintSatisfied(final int entityCount) { + return !sameEntity || oldEntity == entityCount; + } + @Override - public final void receive(final String name, final String value, + public final void receive(final String currentName, final String currentValue, final NamedValueSource source, final int recordCount, final int entityCount) { @@ -139,8 +144,9 @@ public final void receive(final String name, final String value, if (source == conditionSource) { conditionMet = true; - } else { - receive(name, value, source); + } + else { + receive(currentName, currentValue, source); } if (!waitForFlush && isConditionMet() && isComplete()) { @@ -152,12 +158,7 @@ public final void receive(final String name, final String value, } } - protected final boolean sameEntityConstraintSatisfied(final int entityCount) { - return !sameEntity || oldEntity == entityCount; - } - - protected abstract void receive(final String name, final String value, - final NamedValueSource source); + protected abstract void receive(String currentName, String currentValue, NamedValueSource source); protected abstract boolean isComplete(); diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFilter.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFilter.java index 545df3473..a110805da 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFilter.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; /** @@ -26,7 +27,7 @@ public abstract class AbstractFilter extends AbstractSimpleStatelessFunction { @Override public final String process(final String value) { - if(accept(value)){ + if (accept(value)) { return value; } return null; @@ -34,7 +35,7 @@ public final String process(final String value) { protected abstract boolean accept(String value); - protected final String getString() { + protected final String getString() { return string; } diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFlushingCollect.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFlushingCollect.java index 1a555f9e7..f6d99c4ae 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFlushingCollect.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFlushingCollect.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; /** @@ -33,7 +34,7 @@ public final void setFlushIncomplete(final boolean flushIncomplete) { @Override public final void flush(final int recordCount, final int entityCount) { if (isSameRecord(recordCount) && sameEntityConstraintSatisfied(entityCount)) { - if(isConditionMet() && (flushIncomplete || isComplete())) { + if (isConditionMet() && (flushIncomplete || isComplete())) { emit(); } if (getReset()) { diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFunction.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFunction.java index 2561fdc9e..8aaf1f5da 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFunction.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractFunction.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.api.helpers; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.metamorph.api.helpers; import org.metafacture.metamorph.api.Function; import org.metafacture.metamorph.api.Maps; +import java.util.HashMap; +import java.util.Map; + /** * Base class for functions. * @@ -33,8 +34,8 @@ public abstract class AbstractFunction extends AbstractNamedValuePipe private Map localMap; private String mapName; - protected final String getValue(final String mapName, final String key) { - return maps.getValue(mapName, key); + protected final String getValue(final String currentMapName, final String key) { + return maps.getValue(currentMapName, key); } protected final String getLocalValue(final String key) { @@ -55,8 +56,8 @@ public final Map getMap() { return localMap; } - public final void setMap(final String mapName) { - this.mapName = mapName; + public final void setMap(final String newMapName) { + mapName = newMapName; } @Override diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractNamedValuePipe.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractNamedValuePipe.java index aa9f1ea18..c7bfd6b4f 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractNamedValuePipe.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractNamedValuePipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; import org.metafacture.metamorph.api.NamedValuePipe; diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractReadOnlyMap.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractReadOnlyMap.java index b696b7ebb..e2e26187d 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractReadOnlyMap.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractReadOnlyMap.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; import java.util.Collection; diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractSimpleStatelessFunction.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractSimpleStatelessFunction.java index 0dea24f8f..8c37bc481 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractSimpleStatelessFunction.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractSimpleStatelessFunction.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; import org.metafacture.metamorph.api.Function; diff --git a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractStatefulFunction.java b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractStatefulFunction.java index c69004d5c..83a8f3cfb 100644 --- a/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractStatefulFunction.java +++ b/metamorph-api/src/main/java/org/metafacture/metamorph/api/helpers/AbstractStatefulFunction.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.api.helpers; import org.metafacture.metamorph.api.NamedValueSource; @@ -46,36 +47,35 @@ protected final String getLastName() { } @Override - public final void receive(final String name, final String value, - final NamedValueSource source, final int recordCount, - final int entityCount) { + public final void receive(final String currentName, final String value, + final NamedValueSource currentSource, final int currentRecordCount, + final int currentEntityCount) { - if (!sameRecord(recordCount)) { + if (!sameRecord(currentRecordCount)) { reset(); - this.recordCount = recordCount; + recordCount = currentRecordCount; } - if (entityClearNeeded(entityCount)) { + if (entityClearNeeded(currentEntityCount)) { reset(); } - this.entityCount = entityCount; - this.source = source; - this.lastName = name; + entityCount = currentEntityCount; + source = currentSource; + lastName = currentName; final String processedValue = process(value); if (processedValue == null) { return; } - getNamedValueReceiver().receive(name, processedValue, this, - recordCount, entityCount); + getNamedValueReceiver().receive(currentName, processedValue, this, currentRecordCount, currentEntityCount); } - private boolean entityClearNeeded(final int entityCount) { - return doResetOnEntityChange() && this.entityCount != entityCount; + private boolean entityClearNeeded(final int currentEntityCount) { + return doResetOnEntityChange() && entityCount != currentEntityCount; } - private boolean sameRecord(final int recordCount) { - return this.recordCount == recordCount; + private boolean sameRecord(final int currentRecordCount) { + return recordCount == currentRecordCount; } protected abstract String process(String value); From 859d4781a655c5ce50ae9b913285fa07fd8d230a Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 20:23:03 +0200 Subject: [PATCH 22/30] metafacture-linkeddata/ (main): Fix Checkstyle violations. --- .../metafacture/linkeddata/BeaconReader.java | 36 ++++++++++------ .../linkeddata/OreAggregationAdder.java | 43 +++++++++++-------- .../metafacture/linkeddata/RdfMacroPipe.java | 16 ++++--- .../linkeddata/OreAggregationAdderTest.java | 1 + 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/BeaconReader.java b/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/BeaconReader.java index 00f0a0f56..9a9ce94ae 100644 --- a/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/BeaconReader.java +++ b/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/BeaconReader.java @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.linkeddata; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.linkeddata; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -31,6 +24,14 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Reads BEACON format * @@ -56,6 +57,9 @@ public final class BeaconReader extends DefaultObjectPipe institution = new HashMap(); @@ -92,16 +96,19 @@ public void process(final Reader reader) { final String value = line.substring(splitPoint + 1).trim(); if (TARGET.equals(key)) { target = value; - } else if (metaDataFilter.matcher(key).find()) { + } + else if (metaDataFilter.matcher(key).find()) { institution.put(key, value); } } - } else { + } + else { final String[] parts = line.split("\\|"); final String url; if (parts.length == COLUMNS_EXTENDED_BEACON) { url = parts[2]; - } else { + } + else { if (target == null || target.isEmpty()) { throw new MetafactureException("Error in BEACON file: target missing"); } @@ -111,7 +118,7 @@ public void process(final Reader reader) { receiver.startRecord(parts[0]); receiver.startEntity(relation); receiver.literal("url", url); - for (Map.Entry instEntry : institution.entrySet()) { + for (final Map.Entry instEntry : institution.entrySet()) { receiver.literal(instEntry.getKey(), instEntry.getValue()); } receiver.endEntity(); @@ -122,7 +129,8 @@ public void process(final Reader reader) { } bReader.close(); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Error reading BEACON format", e); } } diff --git a/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/OreAggregationAdder.java b/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/OreAggregationAdder.java index 1e776c7c7..78971be26 100644 --- a/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/OreAggregationAdder.java +++ b/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/OreAggregationAdder.java @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.linkeddata; -import java.io.IOException; -import java.util.Deque; -import java.util.LinkedList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.regex.Pattern; +package org.metafacture.linkeddata; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.types.ListMap; @@ -33,7 +26,13 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; - +import java.io.IOException; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.regex.Pattern; /** * Adds ore:Aggregation to an Europeana Data Model stream. The aggregation id is @@ -63,18 +62,22 @@ public final class OreAggregationAdder extends DefaultStreamPipe final Properties properties; try { properties = ResourceUtil.loadProperties(ORE_AGGREGATION_PROPERTIES); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Failed to load properties", e); } - for (Entry entry : properties.entrySet()) { + for (final Entry entry : properties.entrySet()) { final String[] parts = SPLIT_PATTERN.split(entry.getValue().toString()); final String name = entry.getKey().toString(); - for (String value : parts) { + for (final String value : parts) { AGGREGATED_ENTITIES.add(name, value); } } } + public OreAggregationAdder() { + } + @Override public void startRecord(final String identifier) { entityStack.clear(); @@ -94,19 +97,20 @@ private void writeAggregation() { final StreamReceiver receiver = getReceiver(); receiver.startEntity(ORE_AGGREGATION); receiver.literal(RDF_ABOUT, aggregationId); - for (Entry> entry : aggregation.entrySet()) { + for (final Entry> entry : aggregation.entrySet()) { final String key = entry.getKey(); if (AGGREGATED_ENTITIES.containsKey(key)) { - for (String entity : AGGREGATED_ENTITIES.get(key)) { - for (String value : entry.getValue()) { + for (final String entity : AGGREGATED_ENTITIES.get(key)) { + for (final String value : entry.getValue()) { receiver.startEntity(entity); receiver.literal(RDF_REFERENCE, value); receiver.endEntity(); } } - } else { - for (String value : entry.getValue()) { + } + else { + for (final String value : entry.getValue()) { receiver.literal(key, value); } } @@ -132,13 +136,14 @@ public void literal(final String name, final String value) { if (entityStack.isEmpty()) { if (AGGREGATION_ID.equals(name)) { aggregationId = value; - } else { + } + else { aggregation.add(name, value); } return; } - if (entityStack.size()==1 && RDF_ABOUT.equals(name) && AGGREGATED_ENTITIES.containsKey(entityStack.peek())) { + if (entityStack.size() == 1 && RDF_ABOUT.equals(name) && AGGREGATED_ENTITIES.containsKey(entityStack.peek())) { aggregation.add(entityStack.peek(), value); } getReceiver().literal(name, value); diff --git a/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/RdfMacroPipe.java b/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/RdfMacroPipe.java index cad62dcdc..0f947bfe8 100644 --- a/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/RdfMacroPipe.java +++ b/metafacture-linkeddata/src/main/java/org/metafacture/linkeddata/RdfMacroPipe.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.linkeddata; import org.metafacture.framework.FluxCommand; @@ -34,7 +35,6 @@ @FluxCommand("rdf-macros") public final class RdfMacroPipe extends DefaultStreamPipe { - public static final char REFERENCE_MARKER = '*'; public static final char LANGUAGE_MARKER = '$'; public static final String RDF_REFERENCE = "~rdf:resource"; @@ -42,15 +42,17 @@ public final class RdfMacroPipe extends DefaultStreamPipe { public static final String XML_LANG = "~xml:lang"; private String autoAddedSubject = ""; + public RdfMacroPipe() { + } + public void setAutoAddedSubject(final String autoAddedSubject) { this.autoAddedSubject = autoAddedSubject; } - @Override public void startRecord(final String identifier) { getReceiver().startRecord(identifier); - if(!autoAddedSubject.isEmpty()){ + if (!autoAddedSubject.isEmpty()) { getReceiver().startEntity(autoAddedSubject); getReceiver().literal(RDF_ABOUT, identifier); } @@ -58,7 +60,7 @@ public void startRecord(final String identifier) { @Override public void endRecord() { - if(!autoAddedSubject.isEmpty()){ + if (!autoAddedSubject.isEmpty()) { getReceiver().endEntity(); } getReceiver().endRecord(); @@ -82,12 +84,14 @@ public void literal(final String name, final String value) { getReceiver().startEntity(name.substring(1)); getReceiver().literal(RDF_REFERENCE, value); getReceiver().endEntity(); - } else if (index > 0) { + } + else if (index > 0) { getReceiver().startEntity(name.substring(0, index)); getReceiver().literal(XML_LANG, name.substring(index + 1)); getReceiver().literal("", value); getReceiver().endEntity(); - } else { + } + else { getReceiver().literal(name, value); } } diff --git a/metafacture-linkeddata/src/test/java/org/metafacture/linkeddata/OreAggregationAdderTest.java b/metafacture-linkeddata/src/test/java/org/metafacture/linkeddata/OreAggregationAdderTest.java index c402f63ac..6626ca4b3 100644 --- a/metafacture-linkeddata/src/test/java/org/metafacture/linkeddata/OreAggregationAdderTest.java +++ b/metafacture-linkeddata/src/test/java/org/metafacture/linkeddata/OreAggregationAdderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.linkeddata; import static org.mockito.Mockito.inOrder; From 54bd7a92139a7555367880a739e559c2b8000c37 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 20:30:50 +0200 Subject: [PATCH 23/30] metafacture-json/ (main): Fix Checkstyle violations. --- .../org/metafacture/json/JsonDecoder.java | 37 ++++---- .../org/metafacture/json/JsonEncoder.java | 92 ++++++++++++------- .../org/metafacture/json/JsonDecoderTest.java | 1 + .../org/metafacture/json/JsonEncoderTest.java | 1 + 4 files changed, 82 insertions(+), 49 deletions(-) diff --git a/metafacture-json/src/main/java/org/metafacture/json/JsonDecoder.java b/metafacture-json/src/main/java/org/metafacture/json/JsonDecoder.java index 6cb795fee..410fe7bd0 100644 --- a/metafacture-json/src/main/java/org/metafacture/json/JsonDecoder.java +++ b/metafacture-json/src/main/java/org/metafacture/json/JsonDecoder.java @@ -13,14 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.json; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.jayway.jsonpath.JsonPath; +package org.metafacture.json; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -30,6 +24,13 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jayway.jsonpath.JsonPath; + import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -41,8 +42,8 @@ * @author Jens Wille * */ -@Description("Decodes JSON to metadata events. The \'recordPath\' option can be used to set a JsonPath " - + "to extract a path as JSON - or to split the data into multiple JSON documents.") +@Description("Decodes JSON to metadata events. The \'recordPath\' option can be used to set a JsonPath " + + "to extract a path as JSON - or to split the data into multiple JSON documents.") @In(String.class) @Out(StreamReceiver.class) @FluxCommand("decode-json") @@ -67,8 +68,6 @@ public final class JsonDecoder extends DefaultObjectPipe private String recordPath; public JsonDecoder() { - super(); - setArrayMarker(DEFAULT_ARRAY_MARKER); setArrayName(DEFAULT_ARRAY_NAME); setRecordId(DEFAULT_RECORD_ID); @@ -134,30 +133,34 @@ public void process(final String json) { assert !isClosed(); if (recordPath.isEmpty()) { processRecord(json); - } else { + } + else { matches(JsonPath.read(json, recordPath)).forEach(record -> { processRecord(record); }); } } - private void processRecord(String record) { + private void processRecord(final String record) { createParser(record); try { decode(); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); - } finally { + } + finally { closeParser(); } } - private Stream matches(Object obj) { + private Stream matches(final Object obj) { final List records = (obj instanceof List) ? ((List) obj) : Arrays.asList(obj); return records.stream().map(doc -> { try { return new ObjectMapper().writeValueAsString(doc); - } catch (JsonProcessingException e) { + } + catch (final JsonProcessingException e) { e.printStackTrace(); return doc.toString(); } diff --git a/metafacture-json/src/main/java/org/metafacture/json/JsonEncoder.java b/metafacture-json/src/main/java/org/metafacture/json/JsonEncoder.java index d486351f2..7261f5d25 100644 --- a/metafacture-json/src/main/java/org/metafacture/json/JsonEncoder.java +++ b/metafacture-json/src/main/java/org/metafacture/json/JsonEncoder.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.json; -import java.io.IOException; -import java.io.StringWriter; +package org.metafacture.json; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -36,6 +34,9 @@ import com.fasterxml.jackson.core.io.SerializedString; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import java.io.IOException; +import java.io.StringWriter; + /** * Serialises an object as JSON. Records and entities are represented * as objects unless their name ends with []. If the name ends with [], @@ -54,6 +55,9 @@ public final class JsonEncoder extends public static final String ARRAY_MARKER = "[]"; + private static final char ESCAPE_CHAR_LOW = 0x20; + private static final char ESCAPE_CHAR_HIGH = 0x7f; + private final JsonGenerator jsonGenerator; private final StringWriter writer = new StringWriter(); @@ -61,7 +65,8 @@ public JsonEncoder() { try { jsonGenerator = new JsonFactory().createGenerator(writer); jsonGenerator.setRootValueSeparator(null); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } @@ -126,7 +131,8 @@ public void endRecord() { endGroup(); try { jsonGenerator.flush(); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } getReceiver().process(writer.toString()); @@ -151,10 +157,12 @@ public void literal(final String name, final String value) { } if (value == null) { jsonGenerator.writeNull(); - } else { + } + else { jsonGenerator.writeString(value); } - } catch (final JsonGenerationException e) { + } + catch (final JsonGenerationException e) { throw new MetafactureException(e); } catch (final IOException e) { @@ -170,13 +178,15 @@ private void startGroup(final String name) { jsonGenerator.writeFieldName(name.substring(0, name.length() - ARRAY_MARKER.length())); } jsonGenerator.writeStartArray(); - } else { + } + else { if (ctx.inObject()) { jsonGenerator.writeFieldName(name); } jsonGenerator.writeStartObject(); } - } catch (final JsonGenerationException e) { + } + catch (final JsonGenerationException e) { throw new MetafactureException(e); } catch (final IOException e) { @@ -189,10 +199,12 @@ private void endGroup() { final JsonStreamContext ctx = jsonGenerator.getOutputContext(); if (ctx.inObject()) { jsonGenerator.writeEndObject(); - } else if (ctx.inArray()) { + } + else if (ctx.inArray()) { jsonGenerator.writeEndArray(); } - } catch (final JsonGenerationException e) { + } + catch (final JsonGenerationException e) { throw new MetafactureException(e); } catch (final IOException e) { @@ -200,34 +212,50 @@ private void endGroup() { } } - private String escapeChar(char ch) { + private String escapeChar(final char ch) { final String namedEscape = namedEscape(ch); - if (namedEscape != null) { - return namedEscape; - } - if (ch < 0x20 || 0x7f < ch ) { - return unicodeEscape(ch); - } - return Character.toString(ch); + return namedEscape != null ? namedEscape : (ch < ESCAPE_CHAR_LOW || ESCAPE_CHAR_HIGH < ch) ? unicodeEscape(ch) : Character.toString(ch); } - private String namedEscape(char ch) { - switch(ch) { - case '\b': return "\\b"; - case '\n': return "\\n"; - case '\t': return "\\t"; - case '\f': return "\\f"; - case '\r': return "\\r"; - case '\'': return "\\'"; - case '\\': return "\\\\"; - case '"': return "\\\""; - case '/': return "\\/"; + private String namedEscape(final char ch) { + final String result; + + switch (ch) { + case '\b': + result = "\\b"; + break; + case '\n': + result = "\\n"; + break; + case '\t': + result = "\\t"; + break; + case '\f': + result = "\\f"; + break; + case '\r': + result = "\\r"; + break; + case '\'': + result = "\\'"; + break; + case '\\': + result = "\\\\"; + break; + case '"': + result = "\\\""; + break; + case '/': + result = "\\/"; + break; default: - return null; + result = null; } + + return result; } - private String unicodeEscape(char ch) { + private String unicodeEscape(final char ch) { return String.format("\\u%4H", ch).replace(' ', '0'); } diff --git a/metafacture-json/src/test/java/org/metafacture/json/JsonDecoderTest.java b/metafacture-json/src/test/java/org/metafacture/json/JsonDecoderTest.java index 8d14bb466..2b3d3c431 100644 --- a/metafacture-json/src/test/java/org/metafacture/json/JsonDecoderTest.java +++ b/metafacture-json/src/test/java/org/metafacture/json/JsonDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.json; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-json/src/test/java/org/metafacture/json/JsonEncoderTest.java b/metafacture-json/src/test/java/org/metafacture/json/JsonEncoderTest.java index 2b80c3c58..ee126e4fb 100644 --- a/metafacture-json/src/test/java/org/metafacture/json/JsonEncoderTest.java +++ b/metafacture-json/src/test/java/org/metafacture/json/JsonEncoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.json; import static org.mockito.Mockito.inOrder; From 000f06c8756afb11ddc3bcc87b68dccd97774f72 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 20:38:23 +0200 Subject: [PATCH 24/30] metafacture-statistics/ (main): Fix Checkstyle violations. --- .../statistics/AbstractCountProcessor.java | 20 ++++++------- .../CooccurrenceMetricCalculator.java | 30 +++++++++---------- .../org/metafacture/statistics/Counter.java | 20 ++++++------- .../org/metafacture/statistics/Histogram.java | 8 ++--- .../statistics/UniformSampler.java | 21 ++++++------- .../CooccurrenceMetricCalculatorTest.java | 1 + .../metafacture/statistics/HistogramTest.java | 1 + .../statistics/UniformSamplerTest.java | 1 + 8 files changed, 48 insertions(+), 54 deletions(-) diff --git a/metafacture-statistics/src/main/java/org/metafacture/statistics/AbstractCountProcessor.java b/metafacture-statistics/src/main/java/org/metafacture/statistics/AbstractCountProcessor.java index 4003ffe89..229d3f626 100644 --- a/metafacture-statistics/src/main/java/org/metafacture/statistics/AbstractCountProcessor.java +++ b/metafacture-statistics/src/main/java/org/metafacture/statistics/AbstractCountProcessor.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.statistics; -import java.util.Hashtable; -import java.util.Map; -import java.util.regex.Pattern; +package org.metafacture.statistics; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.helpers.DefaultObjectPipe; import org.metafacture.framework.objects.Triple; +import java.util.Hashtable; +import java.util.Map; +import java.util.regex.Pattern; + /** * Base class for operating on count data. The expected inputs are triples * containing as subject the variable name and as object the count. Marginal @@ -33,7 +34,6 @@ */ public abstract class AbstractCountProcessor extends DefaultObjectPipe> { - private static final Pattern KEY_SPLIT_PATTERN = Pattern.compile("&", Pattern.LITERAL); private static final String MARGINAL_PREFIX = "1:"; @@ -67,7 +67,8 @@ public final void process(final Triple triple) { marginals.put(triple.getSubject().substring(2), Integer.valueOf(marginal)); } - } else { + } + else { inHeader = false; if (!triple.getSubject().startsWith(JOINT_PREFIX)) { throw new IllegalArgumentException("Joint counts must start with '2:'"); @@ -84,12 +85,11 @@ public final void process(final Triple triple) { } } - protected abstract void processCount(final String varA, final String varB, final int countA, final int countB, - final int countAandB); + protected abstract void processCount(String varA, String varB, int countA, int countB, int countAandB); private int getMarginal(final String string) { final Integer value = marginals.get(string); - if(null==value){ + if (null == value) { return 0; } return value.intValue(); @@ -104,7 +104,6 @@ protected final void onResetStream() { protected void reset() { // nothing to do - } @Override @@ -115,7 +114,6 @@ protected final void onCloseStream() { protected void close() { // nothing to do - } } diff --git a/metafacture-statistics/src/main/java/org/metafacture/statistics/CooccurrenceMetricCalculator.java b/metafacture-statistics/src/main/java/org/metafacture/statistics/CooccurrenceMetricCalculator.java index 9edf39eca..2f37159b8 100644 --- a/metafacture-statistics/src/main/java/org/metafacture/statistics/CooccurrenceMetricCalculator.java +++ b/metafacture-statistics/src/main/java/org/metafacture/statistics/CooccurrenceMetricCalculator.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.statistics; -import java.util.ArrayList; -import java.util.List; +package org.metafacture.statistics; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.annotations.Description; @@ -24,6 +22,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.objects.Triple; +import java.util.ArrayList; +import java.util.List; + /** * Calculates values for various co-occurrence metrics. The expected inputs are * triples containing as subject the var name and as object the count. Marginal @@ -32,8 +33,8 @@ * * @author Markus Michael Geipel */ -@Description("Calculates values for various cooccurrence metrics. The expected inputs are triples containing as subject the var name and as object the count. " - + "Marginal counts must appear first, joint counts second. Marinal counts must be written as 1:A, Joint counts as 2:A&B") +@Description("Calculates values for various cooccurrence metrics. The expected inputs are triples containing as subject the var name and as object the count. " + + "Marginal counts must appear first, joint counts second. Marinal counts must be written as 1:A, Joint counts as 2:A&B") @In(Triple.class) @Out(Triple.class) @FluxCommand("calculate-metrics") @@ -51,8 +52,7 @@ enum Metric { final double o22 = total - countAandB; final double d = (countAandB * o22) - (o12 * o21); - final double x2 = total * Math.pow(d, 2) - / ((countAandB + o12) * (countAandB + o21) * (o12 + o22) * (o21 + o22)); + final double x2 = total * Math.pow(d, 2) / ((countAandB + o12) * (countAandB + o21) * (o12 + o22) * (o21 + o22)); return x2 * Math.signum(d); } }, @@ -87,11 +87,11 @@ enum Metric { JACCARD { @Override double calculate(final int countA, final int countB, final int countAandB, final int total) { - return countAandB / (double)(countA + countB - countAandB); + return countAandB / (double) (countA + countB - countAandB); } }; - abstract double calculate(final int countA, final int countB, final int countAandB, final int total); + abstract double calculate(int countA, int countB, int countAandB, int total); } private static final int MIN_COUNT = 5; @@ -99,24 +99,22 @@ enum Metric { private final List metrics = new ArrayList(); public CooccurrenceMetricCalculator(final String allMetrics) { - final String[] metrics = allMetrics.split("\\s*,\\s*"); setMinCount(MIN_COUNT); - for (String metric : metrics) { - this.metrics.add(Metric.valueOf(metric)); + for (final String metric : allMetrics.split("\\s*,\\s*")) { + metrics.add(Metric.valueOf(metric)); } } public CooccurrenceMetricCalculator(final Metric... metrics) { setMinCount(MIN_COUNT); - for (Metric metric : metrics) { + for (final Metric metric : metrics) { this.metrics.add(metric); } } @Override - protected void processCount(final String varA, final String varB, final int countA, final int countB, - final int countAandB) { - for (Metric metric : metrics) { + protected void processCount(final String varA, final String varB, final int countA, final int countB, final int countAandB) { + for (final Metric metric : metrics) { final double value = metric.calculate(countA, countB, countAandB, getTotal()); getReceiver().process(new Triple(varA + "&" + varB, metric.toString(), String.valueOf(value))); } diff --git a/metafacture-statistics/src/main/java/org/metafacture/statistics/Counter.java b/metafacture-statistics/src/main/java/org/metafacture/statistics/Counter.java index b4ccfc7a9..43b383fb4 100644 --- a/metafacture-statistics/src/main/java/org/metafacture/statistics/Counter.java +++ b/metafacture-statistics/src/main/java/org/metafacture/statistics/Counter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.statistics; import org.metafacture.framework.FluxCommand; @@ -42,6 +43,9 @@ public final class Counter extends DefaultStreamPipe { private int numEntities; private int numLiterals; + public Counter() { + } + /** * @return the numRecords */ @@ -67,7 +71,7 @@ public int getNumLiterals() { public void startRecord(final String identifier) { assert !isClosed(); ++numRecords; - if(getReceiver() != null) { + if (getReceiver() != null) { getReceiver().startRecord(identifier); } } @@ -76,7 +80,7 @@ public void startRecord(final String identifier) { public void startEntity(final String name) { assert !isClosed(); ++numEntities; - if(getReceiver() != null) { + if (getReceiver() != null) { getReceiver().startEntity(name); } } @@ -85,21 +89,21 @@ public void startEntity(final String name) { public void literal(final String name, final String value) { assert !isClosed(); ++numLiterals; - if(getReceiver() != null) { + if (getReceiver() != null) { getReceiver().literal(name, value); } } @Override public void endRecord() { - if(getReceiver() != null) { + if (getReceiver() != null) { getReceiver().endRecord(); } } @Override public void endEntity() { - if(getReceiver() != null) { + if (getReceiver() != null) { getReceiver().endEntity(); } } @@ -113,11 +117,7 @@ public void onResetStream() { @Override public String toString() { - String streamClosed = ""; - if (isClosed()) { - streamClosed =" Stream has been closed."; - } - + final String streamClosed = isClosed() ? " Stream has been closed." : ""; return "counted " + numRecords + " records, " + numEntities + " entities, " + numLiterals + " literals." + streamClosed; } } diff --git a/metafacture-statistics/src/main/java/org/metafacture/statistics/Histogram.java b/metafacture-statistics/src/main/java/org/metafacture/statistics/Histogram.java index 1144c6f7b..56e99ba03 100644 --- a/metafacture-statistics/src/main/java/org/metafacture/statistics/Histogram.java +++ b/metafacture-statistics/src/main/java/org/metafacture/statistics/Histogram.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.statistics; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - - /** * Counts entity names, literal names, or literal values. * @@ -36,7 +36,6 @@ public final class Histogram extends DefaultStreamReceiver { private String countField; public Histogram() { - super(); } /** @@ -45,7 +44,6 @@ public Histogram() { * @param countField name of the field whose content is counted */ public Histogram(final String countField) { - super(); setCountField(countField); } diff --git a/metafacture-statistics/src/main/java/org/metafacture/statistics/UniformSampler.java b/metafacture-statistics/src/main/java/org/metafacture/statistics/UniformSampler.java index db1807783..8af90b332 100644 --- a/metafacture-statistics/src/main/java/org/metafacture/statistics/UniformSampler.java +++ b/metafacture-statistics/src/main/java/org/metafacture/statistics/UniformSampler.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.statistics; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +package org.metafacture.statistics; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -26,6 +23,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; /** * Draws a uniform sample of records from the input stream. @@ -50,22 +50,18 @@ public final class UniformSampler extends private long count; public UniformSampler(final int sampleSize) { - super(); this.sampleSize = sampleSize; sample = new ArrayList(sampleSize); } - public UniformSampler(final String sampleSize) { this(Integer.parseInt(sampleSize)); } - public int getSampleSize() { return sampleSize; } - public void setSeed(final long seed) { random.setSeed(seed); } @@ -73,12 +69,13 @@ public void setSeed(final long seed) { @Override public void process(final T obj) { assert !isClosed(); - assert null!=obj; + assert null != obj; count += 1; if (sample.size() < sampleSize) { sample.add(obj); - } else { - final double p = sampleSize / (double)count; + } + else { + final double p = sampleSize / (double) count; if (random.nextDouble() < p) { sample.set(random.nextInt(sampleSize), obj); } @@ -87,7 +84,7 @@ public void process(final T obj) { @Override protected void onCloseStream() { - for(T obj : sample) { + for (final T obj : sample) { getReceiver().process(obj); } sample.clear(); diff --git a/metafacture-statistics/src/test/java/org/metafacture/statistics/CooccurrenceMetricCalculatorTest.java b/metafacture-statistics/src/test/java/org/metafacture/statistics/CooccurrenceMetricCalculatorTest.java index 5247675b0..9dd56b86f 100644 --- a/metafacture-statistics/src/test/java/org/metafacture/statistics/CooccurrenceMetricCalculatorTest.java +++ b/metafacture-statistics/src/test/java/org/metafacture/statistics/CooccurrenceMetricCalculatorTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.statistics; import static org.junit.Assert.assertEquals; diff --git a/metafacture-statistics/src/test/java/org/metafacture/statistics/HistogramTest.java b/metafacture-statistics/src/test/java/org/metafacture/statistics/HistogramTest.java index a2f536ed3..33dd23e55 100644 --- a/metafacture-statistics/src/test/java/org/metafacture/statistics/HistogramTest.java +++ b/metafacture-statistics/src/test/java/org/metafacture/statistics/HistogramTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.statistics; import static org.junit.Assert.assertEquals; diff --git a/metafacture-statistics/src/test/java/org/metafacture/statistics/UniformSamplerTest.java b/metafacture-statistics/src/test/java/org/metafacture/statistics/UniformSamplerTest.java index 95ed2bbe5..e958d8912 100644 --- a/metafacture-statistics/src/test/java/org/metafacture/statistics/UniformSamplerTest.java +++ b/metafacture-statistics/src/test/java/org/metafacture/statistics/UniformSamplerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.statistics; import static org.mockito.Mockito.inOrder; From b600d814c74a670014773ebd5fa270b5b3fdbd24 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 21:32:49 +0200 Subject: [PATCH 25/30] metafacture-strings/ (main): Fix Checkstyle violations. --- .../org/metafacture/strings/LineRecorder.java | 17 ++++++++++------ .../org/metafacture/strings/LineSplitter.java | 14 +++++++------ .../org/metafacture/strings/RegexDecoder.java | 10 +++++----- .../strings/StreamUnicodeNormalizer.java | 20 +++++++++---------- .../strings/StringConcatenator.java | 11 +++++----- .../metafacture/strings/StringDecoder.java | 12 ++++++----- .../org/metafacture/strings/StringFilter.java | 10 +++++----- .../metafacture/strings/StringMatcher.java | 14 +++++++------ .../org/metafacture/strings/StringReader.java | 10 ++++++---- .../strings/UnicodeNormalizer.java | 14 +++++++------ .../metafacture/strings/LineRecorderTest.java | 1 + .../metafacture/strings/LineSplitterTest.java | 1 + .../metafacture/strings/RegexDecoderTest.java | 1 + .../strings/StreamUnicodeNormalizerTest.java | 1 + .../metafacture/strings/StringFilterTest.java | 1 + .../strings/StringMatcherTest.java | 1 + .../strings/UnicodeNormalizerTest.java | 1 + 17 files changed, 81 insertions(+), 58 deletions(-) diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java b/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java index 75634bb3b..190a07d48 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/LineRecorder.java @@ -41,7 +41,10 @@ public final class LineRecorder implements ObjectPipe receiver; - private boolean isClosed = false; + private boolean isClosed; + + public LineRecorder() { + } public void setRecordMarkerRegexp(final String regexp) { recordMarkerRegexp = regexp; @@ -53,8 +56,10 @@ public void process(final String line) { if (line.matches(recordMarkerRegexp)) { getReceiver().process(record.toString()); record = new StringBuilder(SB_CAPACITY); - } else + } + else { record.append(line + "\n"); + } } private boolean isClosed() { @@ -73,9 +78,9 @@ public void closeStream() { } @Override - public > R setReceiver(R receiver) { - this.receiver = receiver; - return receiver; + public > R setReceiver(final R newReceiver) { + receiver = newReceiver; + return newReceiver; } /** @@ -83,7 +88,7 @@ public > R setReceiver(R receiver) { * * @return reference to the downstream module */ - protected final ObjectReceiver getReceiver() { + protected ObjectReceiver getReceiver() { return receiver; } diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/LineSplitter.java b/metafacture-strings/src/main/java/org/metafacture/strings/LineSplitter.java index b2868872b..40840fb14 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/LineSplitter.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/LineSplitter.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.util.regex.Pattern; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -24,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.regex.Pattern; + /** * Splits a string at new lines and sends each line to the receiver. * @@ -34,12 +35,13 @@ @In(String.class) @Out(String.class) @FluxCommand("split-lines") -public final class LineSplitter - extends DefaultObjectPipe> { +public final class LineSplitter extends DefaultObjectPipe> { private static final char NEWLINE = '\n'; - private static final Pattern LINE_PATTERN = Pattern.compile( - String.valueOf(NEWLINE), Pattern.LITERAL); + private static final Pattern LINE_PATTERN = Pattern.compile(String.valueOf(NEWLINE), Pattern.LITERAL); + + public LineSplitter() { + } @Override public void process(final String lines) { diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/RegexDecoder.java b/metafacture-strings/src/main/java/org/metafacture/strings/RegexDecoder.java index d7250c64d..aca3f5573 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/RegexDecoder.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/RegexDecoder.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamReceiver; @@ -27,6 +23,10 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Decodes a string based on a regular expression using named capture groups. diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/StreamUnicodeNormalizer.java b/metafacture-strings/src/main/java/org/metafacture/strings/StreamUnicodeNormalizer.java index bac63b4ad..26c17927f 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/StreamUnicodeNormalizer.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/StreamUnicodeNormalizer.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.text.Normalizer; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamReceiver; @@ -24,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.text.Normalizer; + /** * Normalises Unicode characters in record identifiers, entity and literal * names and literal values. Unicode normalisation converts between precomposed @@ -42,14 +43,12 @@ @In(StreamReceiver.class) @Out(StreamReceiver.class) @FluxCommand("normalize-unicode-stream") -public final class StreamUnicodeNormalizer - extends DefaultStreamPipe { +public final class StreamUnicodeNormalizer extends DefaultStreamPipe { /** * The default value for {@link #setNormalizationForm(Normalizer.Form)}. */ - public static final Normalizer.Form DEFAULT_NORMALIZATION_FORM = - Normalizer.Form.NFC; + public static final Normalizer.Form DEFAULT_NORMALIZATION_FORM = Normalizer.Form.NFC; private boolean normalizeIds; private boolean normalizeKeys; @@ -57,6 +56,9 @@ public final class StreamUnicodeNormalizer private Normalizer.Form normalizationForm = DEFAULT_NORMALIZATION_FORM; + public StreamUnicodeNormalizer() { + } + /** * Controls whether to normalise record identifiers. By default record * identifiers are not normalised. @@ -161,10 +163,8 @@ public void endEntity() { @Override public void literal(final String name, final String value) { - final String normalizedName = - normalizeKeys ? normalize(name) : name; - final String normalizedValue= - normalizeValues ? normalize(value) : value; + final String normalizedName = normalizeKeys ? normalize(name) : name; + final String normalizedValue = normalizeValues ? normalize(value) : value; getReceiver().literal(normalizedName, normalizedValue); } diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/StringConcatenator.java b/metafacture-strings/src/main/java/org/metafacture/strings/StringConcatenator.java index feb23cd49..64d727c02 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/StringConcatenator.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/StringConcatenator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import org.metafacture.framework.ObjectReceiver; @@ -28,10 +29,12 @@ public final class StringConcatenator implements ObjectReceiver { private StringBuilder builder = new StringBuilder(); private String separator = ""; + public StringConcatenator() { + } + @Override public void resetStream() { reset(); - } public void setSeparator(final String separator) { @@ -41,21 +44,19 @@ public void setSeparator(final String separator) { @Override public void closeStream() { // nothing to do - } @Override public void process(final String obj) { builder.append(separator); builder.append(obj); - } - public void reset(){ + public void reset() { builder = new StringBuilder(); } - public String getString(){ + public String getString() { return builder.toString(); } diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/StringDecoder.java b/metafacture-strings/src/main/java/org/metafacture/strings/StringDecoder.java index b0c55b9dd..85a0c9585 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/StringDecoder.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/StringDecoder.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -25,6 +23,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Splits a {@link String} into several {@link String}s, either by extracting * parts that match a regexp or by splitting by a regexp. @@ -65,10 +66,11 @@ public void process(final String obj) { final ObjectReceiver receiver = getReceiver(); if (mode == Mode.SPLIT) { - for (String part : pattern.split(obj)) { + for (final String part : pattern.split(obj)) { receiver.process(part); } - } else { + } + else { final Matcher matcher = pattern.matcher(obj); while (matcher.find()) { receiver.process(matcher.group()); diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/StringFilter.java b/metafacture-strings/src/main/java/org/metafacture/strings/StringFilter.java index fe64a2d8c..c91d026d2 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/StringFilter.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/StringFilter.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -25,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Only forwards records which match (or do not match) a regular expression @@ -41,7 +41,7 @@ public final class StringFilter extends DefaultObjectPipe> { private final Matcher matcher; - private boolean passMatches=true; + private boolean passMatches = true; public StringFilter(final String pattern) { this.matcher = Pattern.compile(pattern).matcher(""); @@ -62,7 +62,7 @@ public void setPassMatches(final boolean passMatches) { @Override public void process(final String obj) { assert !isClosed(); - assert null!=obj; + assert null != obj; matcher.reset(obj); if (matcher.find() == passMatches) { getReceiver().process(obj); diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/StringMatcher.java b/metafacture-strings/src/main/java/org/metafacture/strings/StringMatcher.java index 6c2d92116..f0c791310 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/StringMatcher.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/StringMatcher.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -25,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Matches the incoming strings against a regular expression and replaces @@ -36,12 +36,14 @@ @In(String.class) @Out(String.class) @FluxCommand("match") -public final class StringMatcher extends - DefaultObjectPipe> { +public final class StringMatcher extends DefaultObjectPipe> { private Matcher matcher; private String replacement; + public StringMatcher() { + } + public String getPattern() { return matcher.pattern().pattern(); } @@ -61,7 +63,7 @@ public void setReplacement(final String replacement) { @Override public void process(final String obj) { assert !isClosed(); - assert null!=obj; + assert null != obj; matcher.reset(obj); getReceiver().process(matcher.replaceAll(replacement)); } diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/StringReader.java b/metafacture-strings/src/main/java/org/metafacture/strings/StringReader.java index 7411e1193..27df03966 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/StringReader.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/StringReader.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.io.Reader; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -24,6 +23,7 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.io.Reader; /** * Creates a reader for the supplied string and sends it to the receiver. @@ -35,8 +35,10 @@ @In(String.class) @Out(java.io.Reader.class) @FluxCommand("read-string") -public final class StringReader - extends DefaultObjectPipe> { +public final class StringReader extends DefaultObjectPipe> { + + public StringReader() { + } @Override public void process(final String str) { diff --git a/metafacture-strings/src/main/java/org/metafacture/strings/UnicodeNormalizer.java b/metafacture-strings/src/main/java/org/metafacture/strings/UnicodeNormalizer.java index bd26846a1..8163bb18b 100644 --- a/metafacture-strings/src/main/java/org/metafacture/strings/UnicodeNormalizer.java +++ b/metafacture-strings/src/main/java/org/metafacture/strings/UnicodeNormalizer.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.strings; -import java.text.Normalizer; +package org.metafacture.strings; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -24,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.text.Normalizer; + /** * Normalises Unicode characters in strings. Unicode normalisation converts * between precomposed characters and composed characters. There are four @@ -37,17 +38,18 @@ @In(String.class) @Out(String.class) @FluxCommand("normalize-unicode-string") -public final class UnicodeNormalizer extends - DefaultObjectPipe> { +public final class UnicodeNormalizer extends DefaultObjectPipe> { /** * The default value for {@link #setNormalizationForm(Normalizer.Form)}. */ - public static final Normalizer.Form DEFAULT_NORMALIZATION_FORM = - Normalizer.Form.NFC; + public static final Normalizer.Form DEFAULT_NORMALIZATION_FORM = Normalizer.Form.NFC; private Normalizer.Form normalizationForm = DEFAULT_NORMALIZATION_FORM; + public UnicodeNormalizer() { + } + /** * Sets the normalisation form used for normalising strings. *

diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java index 50c5f4097..805854091 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/LineRecorderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/LineSplitterTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/LineSplitterTest.java index a7ccc7ec9..6bba90086 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/LineSplitterTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/LineSplitterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/RegexDecoderTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/RegexDecoderTest.java index 93432f978..5822d774b 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/RegexDecoderTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/RegexDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.ArgumentMatchers.any; diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/StreamUnicodeNormalizerTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/StreamUnicodeNormalizerTest.java index 0cfd9ae69..99ab2f3c7 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/StreamUnicodeNormalizerTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/StreamUnicodeNormalizerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/StringFilterTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/StringFilterTest.java index 6b6ae53c6..391db14bd 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/StringFilterTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/StringFilterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/StringMatcherTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/StringMatcherTest.java index e966db903..bc8d0df06 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/StringMatcherTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/StringMatcherTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.Mockito.verify; diff --git a/metafacture-strings/src/test/java/org/metafacture/strings/UnicodeNormalizerTest.java b/metafacture-strings/src/test/java/org/metafacture/strings/UnicodeNormalizerTest.java index 958fa8f5f..4e3e74f1d 100644 --- a/metafacture-strings/src/test/java/org/metafacture/strings/UnicodeNormalizerTest.java +++ b/metafacture-strings/src/test/java/org/metafacture/strings/UnicodeNormalizerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.strings; import static org.mockito.Mockito.verify; From 635f84f44f045b418407071567e001b95ad06950 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Tue, 7 Sep 2021 21:46:50 +0200 Subject: [PATCH 26/30] metamorph-test/ (main): Fix Checkstyle violations. --- .../metamorph/test/MetamorphTestCase.java | 35 +++--- .../metamorph/test/MetamorphTestLoader.java | 25 ++-- .../metamorph/test/MetamorphTestRunner.java | 10 +- .../metamorph/test/MetamorphTestSuite.java | 21 ++-- .../metamorph/test/reader/CGXmlReader.java | 1 + .../metamorph/test/reader/FormetaReader.java | 1 + .../test/reader/JsonLinesReader.java | 1 + .../metamorph/test/reader/JsonReader.java | 1 + .../metamorph/test/reader/MarcXmlReader.java | 1 + .../test/reader/MultiFormatReader.java | 7 +- .../metamorph/test/reader/PicaReader.java | 1 + .../metamorph/test/reader/Reader.java | 1 + .../metamorph/test/reader/ReaderBase.java | 2 +- .../metamorph/test/reader/ReaderFactory.java | 11 +- .../metamorph/test/reader/XmlReaderBase.java | 2 +- .../test/validators/StreamValidator.java | 109 ++++++++---------- .../validators/WellformednessChecker.java | 26 +++-- .../metamorph/test/FrameworkTest.java | 1 + .../metamorph/test/MetamorphTestCaseTest.java | 1 + .../test/TestCaseRunnerMetamorphTest.java | 1 + .../test/validators/StreamValidatorTest.java | 1 + .../validators/WellformednessCheckerTest.java | 1 + 22 files changed, 138 insertions(+), 122 deletions(-) diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestCase.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestCase.java index aa8161a7c..10a50c6bc 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestCase.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestCase.java @@ -13,13 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.test; -import java.io.FileNotFoundException; -import java.io.StringReader; +package org.metafacture.metamorph.test; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.Statement; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.XmlUtil; import org.metafacture.commons.reflection.ReflectionUtil; @@ -30,20 +26,25 @@ import org.metafacture.metamorph.test.reader.MultiFormatReader; import org.metafacture.metamorph.test.reader.Reader; import org.metafacture.metamorph.test.validators.StreamValidator; + +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.Statement; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import java.io.FileNotFoundException; +import java.io.StringReader; + /** * Runs a test defined in a Metamorph-Test definition. * * @author Christoph Böhme * */ -final class MetamorphTestCase extends Statement { +final class MetamorphTestCase extends Statement { // checkstyle-disable-line ClassDataAbstractionCoupling - private static final String NO_DATA_FOUND = - "Please specify either element content or a src attribute"; + private static final String NO_DATA_FOUND = "Please specify either element content or a src attribute"; private static final String NAME_ATTR = "name"; private static final String IGNORE_ATTR = "ignore"; @@ -77,12 +78,13 @@ public boolean isIgnore() { public void evaluate() throws InitializationError { final Reader inputReader = getReader(INPUT_TAG); @SuppressWarnings("unchecked") - final StreamPipetransformation = getTransformation(); + final StreamPipe transformation = getTransformation(); final EventList resultStream = new EventList(); if (transformation == null) { inputReader.setReceiver(resultStream); - } else { + } + else { inputReader.setReceiver(transformation).setReceiver(resultStream); } @@ -90,7 +92,9 @@ public void evaluate() throws InitializationError { inputReader.closeStream(); final StreamValidator validator = new StreamValidator(resultStream.getEvents()); - validator.setErrorHandler(msg -> { throw new AssertionError(msg); }); + validator.setErrorHandler(msg -> { + throw new AssertionError(msg); + }); final Element result = (Element) config.getElementsByTagName(RESULT_TAG).item(0); validator.setStrictRecordOrder(Boolean.parseBoolean( @@ -113,8 +117,7 @@ private Reader getReader(final String tag) { return new MultiFormatReader(mimeType); } - @SuppressWarnings("rawtypes") - private StreamPipe getTransformation() throws InitializationError { + private StreamPipe getTransformation() throws InitializationError { // checkstyle-disable-line ReturnCount final NodeList nodes = config.getElementsByTagName(TRANSFORMATION_TAG); if (nodes.getLength() == 0) { return null; @@ -133,7 +136,8 @@ private StreamPipe getTransformation() throws InitializationError { } return new Metamorph(src); - } else if (MIME_JAVACLASS.equals(type)) { + } + else if (MIME_JAVACLASS.equals(type)) { if (src.isEmpty()) { throw new InitializationError( "class defining transformation not specified"); @@ -165,7 +169,8 @@ private java.io.Reader getDataFromSource(final String src) throws InitializationError { try { return ResourceUtil.getReader(src); - } catch (final FileNotFoundException e) { + } + catch (final FileNotFoundException e) { throw new InitializationError("Could not find input file '" + src + "': " + e.getMessage()); } diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestLoader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestLoader.java index 56eac0bb1..fff1f13dc 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestLoader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestLoader.java @@ -1,4 +1,4 @@ - /* +/* * Copyright 2013, 2014 Deutsche Nationalbibliothek * * Licensed under the Apache License, Version 2.0 the "License"; @@ -13,13 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test; +import org.junit.runners.model.InitializationError; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.List; - import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -27,14 +34,6 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; -import org.junit.runners.model.InitializationError; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - - /** * Utility methods for loading Metamorph-Test resources. * @@ -81,17 +80,17 @@ private static List load(final InputSource inputSource) final List metamorphTestCases = new ArrayList<>(); final NodeList testCaseNodes = doc.getElementsByTagName(TEST_CASE_TAG); - for(int i=0; i < testCaseNodes.getLength(); ++i) { + for (int i = 0; i < testCaseNodes.getLength(); ++i) { final Element testCaseElement = (Element) testCaseNodes.item(i); metamorphTestCases.add(new MetamorphTestCase(testCaseElement)); } return metamorphTestCases; - } catch (final ParserConfigurationException|SAXException|IOException e) { + } + catch (final ParserConfigurationException | SAXException | IOException e) { throw new InitializationError(e); } } } - diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestRunner.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestRunner.java index e82c8bb12..7d0bc5e32 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestRunner.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestRunner.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.test; -import java.net.URL; -import java.util.List; +package org.metafacture.metamorph.test; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; import org.junit.runners.ParentRunner; import org.junit.runners.model.InitializationError; +import java.net.URL; +import java.util.List; + /** * Executes test cases defined in a metamorph-test file. * @@ -71,7 +72,8 @@ protected void runChild(final MetamorphTestCase child, final Description description = describeChild(child); if (child.isIgnore()) { notifier.fireTestIgnored(description); - } else { + } + else { runLeaf(child, description, notifier); } } diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestSuite.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestSuite.java index 40a2a4d1c..a7534fe5c 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestSuite.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/MetamorphTestSuite.java @@ -13,8 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test; +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.ParentRunner; +import org.junit.runners.model.InitializationError; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -22,12 +29,6 @@ import java.util.ArrayList; import java.util.List; -import org.junit.runner.Description; -import org.junit.runner.Runner; -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.ParentRunner; -import org.junit.runners.model.InitializationError; - /** * Binds a list of Metamorph-Test resources to a class. * @@ -45,8 +46,7 @@ public MetamorphTestSuite(final Class suiteRoot) runners = loadDefinitions(suiteRoot); } - private static List loadDefinitions(final Class suiteRoot) - throws InitializationError{ + private static List loadDefinitions(final Class suiteRoot) throws InitializationError { final List runners = new ArrayList<>(); for (final String testDef : getTestDefinitionNames(suiteRoot)) { runners.add(new MetamorphTestRunner(suiteRoot, testDef)); @@ -54,9 +54,8 @@ private static List loadDefinitions(final Class suiteRoot) return runners; } - private static String[] getTestDefinitionNames(final Class suiteRoot){ - final TestDefinitions testDefs = - suiteRoot.getAnnotation(TestDefinitions.class); + private static String[] getTestDefinitionNames(final Class suiteRoot) { + final TestDefinitions testDefs = suiteRoot.getAnnotation(TestDefinitions.class); if (testDefs == null) { // if no xmls are given assume an xml with the same name as the class: return new String[]{suiteRoot.getSimpleName() + ".xml"}; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/CGXmlReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/CGXmlReader.java index e4cab4d08..ff5db8248 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/CGXmlReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/CGXmlReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.xml.CGXmlHandler; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/FormetaReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/FormetaReader.java index 012b316bc..912501c3f 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/FormetaReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/FormetaReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.formeta.FormetaDecoder; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonLinesReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonLinesReader.java index b918fe0ed..dc4af25db 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonLinesReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonLinesReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.io.LineReader; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonReader.java index 8159e50a9..48f601afe 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/JsonReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.io.RecordReader; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MarcXmlReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MarcXmlReader.java index a4973100d..f1c1a461b 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MarcXmlReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MarcXmlReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.biblio.marc21.MarcXmlHandler; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MultiFormatReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MultiFormatReader.java index 601d8f27a..9ce4e76a1 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MultiFormatReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/MultiFormatReader.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.framework.StreamReceiver; - /** * Dynamically instantiated a reader for a specific data format. This module * allows to select a concrete reader only at runtime. @@ -36,9 +36,8 @@ public MultiFormatReader(final String format) { } public void setFormat(final String format) { - if(!READER_FACTORY.containsKey(format)){ - throw new IllegalArgumentException("Format '" + format + - "' not regognized"); + if (!READER_FACTORY.containsKey(format)) { + throw new IllegalArgumentException("Format '" + format + "' not regognized"); } currentReader = READER_FACTORY.newInstance(format); currentReader.setReceiver(downstreamReceiver); diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/PicaReader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/PicaReader.java index 74b9dfd2f..207635740 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/PicaReader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/PicaReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.biblio.pica.PicaDecoder; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/Reader.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/Reader.java index 3caf2fff4..44e5beec9 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/Reader.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/Reader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.framework.ObjectPipe; diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderBase.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderBase.java index 6cad9862e..81eb8175c 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderBase.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderBase.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.framework.ObjectPipe; import org.metafacture.framework.ObjectReceiver; import org.metafacture.framework.StreamReceiver; - /** * Base class for {@link Reader}s that are constructed from a record reader and * a record decoder. diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderFactory.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderFactory.java index f3a1c49ad..6535e0ccd 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderFactory.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/ReaderFactory.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.test.reader; -import java.io.IOException; +package org.metafacture.metamorph.test.reader; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.reflection.ObjectFactory; import org.metafacture.framework.MetafactureException; +import java.io.IOException; + /** * Instantiates instances of the {@link Reader} interface. * @@ -31,9 +32,9 @@ final class ReaderFactory extends ObjectFactory { ReaderFactory() { try { - loadClassesFromMap(ResourceUtil.loadProperties( - "test-readers.properties"), Reader.class); - } catch (IOException e) { + loadClassesFromMap(ResourceUtil.loadProperties("test-readers.properties"), Reader.class); + } + catch (final IOException e) { throw new MetafactureException("Failed to load readers list", e); } } diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/XmlReaderBase.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/XmlReaderBase.java index 75d4945fb..66c9d983f 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/XmlReaderBase.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/reader/XmlReaderBase.java @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.reader; import org.metafacture.framework.StreamReceiver; import org.metafacture.framework.XmlPipe; import org.metafacture.xml.XmlDecoder; - /** * Base class for {@link Reader}s for xml formats. * diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/StreamValidator.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/StreamValidator.java index dce600489..49e58b731 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/StreamValidator.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/StreamValidator.java @@ -13,8 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.validators; +import org.metafacture.framework.StreamReceiver; +import org.metafacture.javaintegration.EventList.Event; +import org.metafacture.javaintegration.EventList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; @@ -22,13 +30,6 @@ import java.util.List; import java.util.function.Consumer; -import org.metafacture.framework.StreamReceiver; -import org.metafacture.javaintegration.EventList; -import org.metafacture.javaintegration.EventList.Event; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - /** * Validates a stream of events using a list of expected stream events. * If the stream is invalid, the error handler set via @@ -43,23 +44,18 @@ */ public final class StreamValidator implements StreamReceiver { - public static final Consumer DEFAULT_ERROR_HANDLER = - msg -> { /* do nothing */ }; + public static final Consumer DEFAULT_ERROR_HANDLER = msg -> { /* do nothing */ }; - private static final Logger LOG = - LoggerFactory.getLogger(StreamValidator.class); + private static final Logger LOG = LoggerFactory.getLogger(StreamValidator.class); - private static final String CANNOT_CHANGE_OPTIONS = - "Cannot change options during validation"; - private static final String VALIDATION_FAILED = - "Validation failed. Please reset the validator"; + private static final String CANNOT_CHANGE_OPTIONS = "Cannot change options during validation"; + private static final String VALIDATION_FAILED = "Validation failed. Please reset the validator"; private static final String NO_RECORD_FOUND = "No record found: "; private static final String NO_ENTITY_FOUND = "No entity found: "; private static final String NO_LITERAL_FOUND = "No literal found: "; - private static final String UNCONSUMED_RECORDS_FOUND = - "Unconsumed records found"; + private static final String UNCONSUMED_RECORDS_FOUND = "Unconsumed records found"; private final Deque> stack = new ArrayDeque<>(); private final EventNode eventStream; @@ -72,8 +68,7 @@ public final class StreamValidator implements StreamReceiver { private boolean strictKeyOrder; private boolean strictValueOrder; - private final WellformednessChecker wellformednessChecker = - new WellformednessChecker(); + private final WellformednessChecker wellformednessChecker = new WellformednessChecker(); public StreamValidator(final List expectedStream) { this.eventStream = new EventNode(null, null); @@ -167,8 +162,7 @@ public void endRecord() { if (!closeGroups()) { validationFailed = true; logEventStream(); - errorHandler.accept(NO_RECORD_FOUND + - "No record matched the sequence of stream events"); + errorHandler.accept(NO_RECORD_FOUND + "No record matched the sequence of stream events"); } } @@ -199,8 +193,7 @@ public void endEntity() { if (!closeGroups()) { validationFailed = true; logEventStream(); - errorHandler.accept(NO_ENTITY_FOUND + - "No entity matched the sequence of stream events"); + errorHandler.accept(NO_ENTITY_FOUND + "No entity matched the sequence of stream events"); } } @@ -258,40 +251,39 @@ public void closeStream() { if (isGroupConsumed(eventStream)) { eventStream.setConsumed(true); - } else { + } + else { validationFailed = true; logEventStream(); errorHandler.accept(UNCONSUMED_RECORDS_FOUND); } } - private void foldEventStream(final EventNode parent, - final Iterator eventStream) { - while (eventStream.hasNext()) { - final Event event = eventStream.next(); + private void foldEventStream(final EventNode parent, final Iterator currentEventStream) { + while (currentEventStream.hasNext()) { + final Event event = currentEventStream.next(); if (event.getType() == Event.Type.LITERAL) { parent.getChildren().add(new EventNode(event, parent)); - } else if (event.getType() == Event.Type.START_RECORD - || event.getType() == Event.Type.START_ENTITY) { + } + else if (event.getType() == Event.Type.START_RECORD || event.getType() == Event.Type.START_ENTITY) { final EventNode newNode = new EventNode(event, parent); parent.getChildren().add(newNode); - foldEventStream(newNode, eventStream); - } else if (event.getType() == Event.Type.END_RECORD - || event.getType() == Event.Type.END_ENTITY) { + foldEventStream(newNode, currentEventStream); + } + else if (event.getType() == Event.Type.END_RECORD || event.getType() == Event.Type.END_ENTITY) { return; } } } - private boolean openGroups(final Event.Type type, final String name, - final boolean strictKeyOrder, final boolean strictValueOrder) { + private boolean openGroups(final Event.Type type, final String name, final boolean currentStrictKeyOrder, final boolean currentStrictValueOrder) { final List stackFrame = stack.peek(); stack.push(new LinkedList<>()); final Iterator iter = stackFrame.iterator(); while (iter.hasNext()) { final EventNode eventNode = iter.next(); - if (!consumeGroups(eventNode, type, name, strictKeyOrder, strictValueOrder)) { + if (!consumeGroups(eventNode, type, name, currentStrictKeyOrder, currentStrictValueOrder)) { resetGroup(eventNode); iter.remove(); } @@ -303,11 +295,11 @@ private boolean openGroups(final Event.Type type, final String name, private boolean closeGroups() { EventNode lastMatchParent = null; for (final EventNode eventNode : stack.pop()) { - if (eventNode.getParent() != lastMatchParent - && isGroupConsumed(eventNode)) { + if (eventNode.getParent() != lastMatchParent && isGroupConsumed(eventNode)) { eventNode.setConsumed(true); lastMatchParent = eventNode.getParent(); - } else { + } + else { resetGroup(eventNode); } } @@ -316,8 +308,8 @@ && isGroupConsumed(eventNode)) { } private boolean consumeGroups(final EventNode group, final Event.Type type, - final String name, final boolean strictKeyOrder, - final boolean strictValueOrder) { + final String name, final boolean currentStrictKeyOrder, + final boolean currentStrictValueOrder) { boolean foundMatch = false; for (final EventNode c : group.getChildren()) { if (!c.isConsumed()) { @@ -326,11 +318,12 @@ private boolean consumeGroups(final EventNode group, final Event.Type type, if (event.getType() == type) { stack.peek().add(c); foundMatch = true; - } else if (strictValueOrder) { + } + else if (currentStrictValueOrder) { break; } } - if (strictKeyOrder) { + if (currentStrictKeyOrder) { break; } } @@ -338,22 +331,22 @@ private boolean consumeGroups(final EventNode group, final Event.Type type, return foundMatch; } - private boolean consumeLiteral(final EventNode group, final String name, - final String value) { + private boolean consumeLiteral(final EventNode group, final String name, final String value) { boolean foundMatch = false; for (final EventNode eventNode : group.getChildren()) { if (!eventNode.isConsumed()) { final Event event = eventNode.getEvent(); if (compare(name, event.getName())) { - if (event.getType() == Event.Type.LITERAL - && compare(value, event.getValue())) { + if (event.getType() == Event.Type.LITERAL && compare(value, event.getValue())) { eventNode.setConsumed(true); foundMatch = true; break; - } else if (strictValueOrder) { + } + else if (strictValueOrder) { break; } - } else if (strictKeyOrder) { + } + else if (strictKeyOrder) { break; } } @@ -407,10 +400,10 @@ private static final class EventNode { this.event = event; this.parent = parent; // The null-event is used to indicate the stream-start: - if (this.event == null || this.event.getType() == Event.Type.START_RECORD - || this.event.getType() == Event.Type.START_ENTITY) { + if (this.event == null || this.event.getType() == Event.Type.START_RECORD || this.event.getType() == Event.Type.START_ENTITY) { children = new LinkedList<>(); - } else { + } + else { children = null; } @@ -443,31 +436,29 @@ public String toString() { final String consumedIndicator; if (consumed) { consumedIndicator = CONSUMED_INDICATOR; - } else { + } + else { consumedIndicator = ""; } if (event == null) { appendChildren(builder); - } else { + } + else { switch (event.getType()) { case START_RECORD: builder.append(event.getName()).append(consumedIndicator).append("{"); appendChildren(builder); builder.append("}"); break; - case START_ENTITY: builder.append(event.getName()).append(consumedIndicator).append("["); appendChildren(builder); builder.append("]"); break; - case LITERAL: - builder.append(event.getName()).append("=").append(event.getValue()) - .append(consumedIndicator); + builder.append(event.getName()).append("=").append(event.getValue()).append(consumedIndicator); break; - default: break; } diff --git a/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/WellformednessChecker.java b/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/WellformednessChecker.java index 95a1a9e53..c6eb8b972 100644 --- a/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/WellformednessChecker.java +++ b/metamorph-test/src/main/java/org/metafacture/metamorph/test/validators/WellformednessChecker.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.test.validators; -import java.util.function.Consumer; +package org.metafacture.metamorph.test.validators; import org.metafacture.framework.StreamReceiver; +import java.util.function.Consumer; + /** * Checks that the received stream events are in the correct order and contain * valid data. If not, a user-supplied error handler method is invoked. The @@ -43,8 +44,7 @@ public final class WellformednessChecker implements StreamReceiver { * The default error handler which is used if no other error handler was set * via {@link #setErrorHandler(Consumer)}. It does nothing. */ - public static final Consumer DEFAULT_ERROR_HANDLER = - msg -> { /* do nothing */ }; + public static final Consumer DEFAULT_ERROR_HANDLER = msg -> { /* do nothing */ }; private static final String ID_MUST_NOT_BE_NULL = "id must not be null"; private static final String NAME_MUST_NOT_BE_NULL = "name must not be null"; @@ -58,6 +58,9 @@ public final class WellformednessChecker implements StreamReceiver { private int nestingLevel; + public WellformednessChecker() { + } + /** * Sets the error handler which is called when a invalid event stream is * received. @@ -78,7 +81,8 @@ public Consumer getErrorHandler() { public void startRecord(final String identifier) { if (nestingLevel > 0) { errorHandler.accept(IN_RECORD); - } else { + } + else { nestingLevel += 1; } if (identifier == null) { @@ -90,9 +94,11 @@ public void startRecord(final String identifier) { public void endRecord() { if (nestingLevel < 1) { errorHandler.accept(NOT_IN_RECORD); - } else if (nestingLevel > 1) { + } + else if (nestingLevel > 1) { errorHandler.accept(IN_ENTITY); - } else { + } + else { nestingLevel -= 1; } } @@ -101,7 +107,8 @@ public void endRecord() { public void startEntity(final String name) { if (nestingLevel < 1) { errorHandler.accept(NOT_IN_RECORD); - } else { + } + else { nestingLevel += 1; } if (name == null) { @@ -113,7 +120,8 @@ public void startEntity(final String name) { public void endEntity() { if (nestingLevel < 2) { errorHandler.accept(NOT_IN_ENTITY); - } else { + } + else { nestingLevel -= 1; } } diff --git a/metamorph-test/src/test/java/org/metafacture/metamorph/test/FrameworkTest.java b/metamorph-test/src/test/java/org/metafacture/metamorph/test/FrameworkTest.java index 500642124..39808460c 100644 --- a/metamorph-test/src/test/java/org/metafacture/metamorph/test/FrameworkTest.java +++ b/metamorph-test/src/test/java/org/metafacture/metamorph/test/FrameworkTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test; import org.junit.runner.RunWith; diff --git a/metamorph-test/src/test/java/org/metafacture/metamorph/test/MetamorphTestCaseTest.java b/metamorph-test/src/test/java/org/metafacture/metamorph/test/MetamorphTestCaseTest.java index 31b953948..9a82ba96c 100644 --- a/metamorph-test/src/test/java/org/metafacture/metamorph/test/MetamorphTestCaseTest.java +++ b/metamorph-test/src/test/java/org/metafacture/metamorph/test/MetamorphTestCaseTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test; import javax.xml.parsers.DocumentBuilder; diff --git a/metamorph-test/src/test/java/org/metafacture/metamorph/test/TestCaseRunnerMetamorphTest.java b/metamorph-test/src/test/java/org/metafacture/metamorph/test/TestCaseRunnerMetamorphTest.java index 5c5ac4dfa..3569ab228 100644 --- a/metamorph-test/src/test/java/org/metafacture/metamorph/test/TestCaseRunnerMetamorphTest.java +++ b/metamorph-test/src/test/java/org/metafacture/metamorph/test/TestCaseRunnerMetamorphTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test; import static org.junit.Assert.assertNotNull; diff --git a/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/StreamValidatorTest.java b/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/StreamValidatorTest.java index 84b724d62..e55c9c41e 100644 --- a/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/StreamValidatorTest.java +++ b/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/StreamValidatorTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.validators; import static org.mockito.ArgumentMatchers.any; diff --git a/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/WellformednessCheckerTest.java b/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/WellformednessCheckerTest.java index fe5be2c65..dc3a5a026 100644 --- a/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/WellformednessCheckerTest.java +++ b/metamorph-test/src/test/java/org/metafacture/metamorph/test/validators/WellformednessCheckerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.test.validators; import static org.mockito.ArgumentMatchers.any; From d1d49e81eaad4681565ee42c47dcc9740f0e1d61 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Wed, 8 Sep 2021 18:28:07 +0200 Subject: [PATCH 27/30] metafacture-javaintegration/ (main): Fix Checkstyle violations. --- .../javaintegration/Collector.java | 3 +- .../javaintegration/EventList.java | 10 +++- .../javaintegration/MapToStream.java | 14 +++-- .../javaintegration/NamedValueList.java | 55 +++++++++---------- .../javaintegration/NamedValueSet.java | 13 ++--- .../javaintegration/ObjectCollector.java | 6 +- .../javaintegration/SingleValue.java | 13 ++--- .../javaintegration/StringListMap.java | 23 ++++---- .../StringListMapToStream.java | 19 ++++--- .../javaintegration/StringMap.java | 16 ++---- .../metafacture/javaintegration/ValueSet.java | 11 ++-- .../pojo/ArrayTypeDecoder.java | 1 + .../pojo/CollectionTypeDecoder.java | 11 ++-- .../pojo/ComplexTypeDecoder.java | 26 ++++----- .../pojo/ComplexTypeEncoder.java | 33 +++++------ .../pojo/FieldValueGetter.java | 18 +++--- .../pojo/FieldValueSetter.java | 18 +++--- .../javaintegration/pojo/ListTypeEncoder.java | 1 + .../javaintegration/pojo/MapTypeDecoder.java | 11 ++-- .../javaintegration/pojo/MapTypeEncoder.java | 1 + .../pojo/MetafactureSource.java | 3 +- .../pojo/MetafactureSourceTypeDecoder.java | 7 ++- .../pojo/MethodValueGetter.java | 33 ++++++----- .../pojo/MethodValueSetter.java | 32 +++++------ .../javaintegration/pojo/PojoDecoder.java | 4 ++ .../javaintegration/pojo/PojoEncoder.java | 29 ++++------ .../pojo/SimpleTypeDecoder.java | 7 ++- .../javaintegration/pojo/TypeDecoder.java | 4 +- .../pojo/TypeDecoderFactory.java | 26 ++++++--- .../javaintegration/pojo/TypeEncoder.java | 1 + .../pojo/TypeEncoderFactory.java | 17 ++++-- .../javaintegration/pojo/ValueGetter.java | 3 +- .../javaintegration/pojo/ValueSetter.java | 3 +- .../javaintegration/pojo/ValueType.java | 7 ++- .../javaintegration/MapToStreamTest.java | 1 + .../javaintegration/pojo/PojoDecoderTest.java | 1 + .../javaintegration/pojo/PojoEncoderTest.java | 1 + 37 files changed, 249 insertions(+), 233 deletions(-) diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/Collector.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/Collector.java index 1dfde53d8..df463fe32 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/Collector.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/Collector.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; import java.util.Collection; @@ -25,7 +26,7 @@ * @author Markus Michael Geipel * */ -public interface Collector { +public interface Collector { Collection getCollection(); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/EventList.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/EventList.java index 22971e8c9..72e250617 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/EventList.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/EventList.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.framework.StreamReceiver; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.metafacture.framework.StreamReceiver; - /** * Stores the received stream events in a list. * @@ -33,6 +34,9 @@ public final class EventList implements StreamReceiver { private boolean closed; + public EventList() { + } + public List getEvents() { return Collections.unmodifiableList(events); } @@ -131,7 +135,7 @@ public String toString() { final StringBuilder builder = new StringBuilder(); builder.append(type); if (name != null) { - builder.append("(" ); + builder.append("("); builder.append(name); if (value != null) { builder.append("="); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/MapToStream.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/MapToStream.java index 00f74b11f..a53936486 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/MapToStream.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/MapToStream.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.javaintegration; -import java.util.Map; +package org.metafacture.javaintegration; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StandardEventNames; @@ -24,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.Map; + /** * Emits a {@link Map} as a record with a literal for each entry in the map. * When receiving an empty map only a start-record and end-record @@ -59,11 +60,13 @@ @In(Map.class) @Out(StreamReceiver.class) @FluxCommand("map-to-stream") -public final class MapToStream extends - DefaultObjectPipe, StreamReceiver> { +public final class MapToStream extends DefaultObjectPipe, StreamReceiver> { private Object idKey = StandardEventNames.ID; + public MapToStream() { + } + /** * Sets the key of the map entry that is used for the record id. *

@@ -88,7 +91,8 @@ public void process(final Map map) { final Object id = map.get(idKey); if (id == null) { getReceiver().startRecord(""); - } else { + } + else { getReceiver().startRecord(id.toString()); } for (final Map.Entry entry: map.entrySet()) { diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueList.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueList.java index 1550aa911..d2dc101b4 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueList.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueList.java @@ -13,37 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.commons.types.NamedValue; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; -import org.metafacture.commons.types.NamedValue; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - - /** * Collects the received results in a {@link List}. * * @author Markus Michael Geipel * */ -public final class NamedValueList extends DefaultStreamReceiver - implements List, Collector> { +public final class NamedValueList extends DefaultStreamReceiver implements List, Collector> { private Collection> collection; private List list; public NamedValueList() { - super(); list = new ArrayList(); } public NamedValueList(final Collection> collection) { - super(); list = new ArrayList(); this.collection = collection; } @@ -83,36 +80,44 @@ public boolean add(final NamedValue element) { return list.add(element); } + @Override + public void add(final int index, final NamedValue element) { + list.add(index, element); + } + @Override public boolean remove(final Object object) { return list.remove(object); } @Override - public boolean containsAll(final Collection collection) { - return list.containsAll(collection); + public NamedValue remove(final int index) { + return list.remove(index); } @Override - public boolean addAll(final Collection collection) { - return list.addAll(collection); + public boolean containsAll(final Collection currentCollection) { + return list.containsAll(currentCollection); } @Override - public boolean addAll(final int index, final Collection collection) { - return list.addAll(index, collection); + public boolean addAll(final Collection currentCollection) { + return list.addAll(currentCollection); } @Override - public boolean removeAll(final Collection collection) { - - return list.removeAll(collection); + public boolean addAll(final int index, final Collection currentCollection) { + return list.addAll(index, currentCollection); } @Override - public boolean retainAll(final Collection collection) { + public boolean removeAll(final Collection currentCollection) { + return list.removeAll(currentCollection); + } - return list.retainAll(collection); + @Override + public boolean retainAll(final Collection currentCollection) { + return list.retainAll(currentCollection); } @Override @@ -130,16 +135,6 @@ public NamedValue set(final int index, final NamedValue element) { return list.set(index, element); } - @Override - public void add(final int index, final NamedValue element) { - list.add(index, element); - } - - @Override - public NamedValue remove(final int index) { - return list.remove(index); - } - @Override public int indexOf(final Object object) { return list.indexOf(object); @@ -166,7 +161,7 @@ public List subList(final int fromIndex, final int toIndex) { } @Override - public void startRecord(final String identifier){ + public void startRecord(final String identifier) { list.clear(); } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueSet.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueSet.java index 9025d489d..0630172ea 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueSet.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/NamedValueSet.java @@ -13,31 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.commons.types.NamedValue; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.metafacture.commons.types.NamedValue; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - - /** * Collects {@link NamedValue}s in a {@link Set}. So there will not be * duplicates. * * @author Markus Michael Geipel */ -public final class NamedValueSet extends DefaultStreamReceiver - implements Set, Collector> { +public final class NamedValueSet extends DefaultStreamReceiver implements Set, Collector> { private Collection> collection; private Set set; public NamedValueSet() { - super(); set = new HashSet<>(); this.collection = null; @@ -50,7 +48,6 @@ public NamedValueSet() { * @param collection is filled with the received results. */ public NamedValueSet(final Collection> collection) { - super(); set = new HashSet<>(); this.collection = collection; } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ObjectCollector.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ObjectCollector.java index 03b24537e..a432afd8d 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ObjectCollector.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ObjectCollector.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.framework.ObjectReceiver; + import java.util.LinkedList; import java.util.Queue; -import org.metafacture.framework.ObjectReceiver; - /** * Collects the objects emitted by an upstream module. * @@ -40,7 +41,6 @@ public ObjectCollector() { } public ObjectCollector(final int maxCapacity) { - super(); this.maxCapacity = maxCapacity; } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/SingleValue.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/SingleValue.java index 0d5c2b9cf..bb94b3d03 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/SingleValue.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/SingleValue.java @@ -13,32 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.javaintegration; -import java.util.Collection; +package org.metafacture.javaintegration; import org.metafacture.framework.helpers.DefaultStreamReceiver; +import java.util.Collection; /** * just records the value of the last received literal. * @author Markus Michael Geipel * */ -public final class SingleValue extends DefaultStreamReceiver - implements Collector { +public final class SingleValue extends DefaultStreamReceiver implements Collector { private boolean closed; private String value = ""; private Collection collection; public SingleValue() { - super(); collection = null; } public SingleValue(final Collection collection) { - super(); this.collection = collection; } @@ -72,9 +69,9 @@ public void endRecord() { } @Override - public void literal(final String name, final String value) { + public void literal(final String name, final String newValue) { assert !closed; - this.setValue(value); + setValue(newValue); } @Override diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMap.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMap.java index 3001ab95a..39f78f34c 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMap.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMap.java @@ -13,36 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.commons.types.ListMap; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; -import org.metafacture.commons.types.ListMap; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - - /** * Collects the received results in a {@link ListMap}. * * @author Markus Michael Geipel * */ -public final class StringListMap extends DefaultStreamReceiver - implements Collector>, Map> { +public final class StringListMap extends DefaultStreamReceiver implements Collector>, Map> { private boolean closed; private Collection> collection; private ListMap listMap = new ListMap(); public StringListMap() { - super(); } public StringListMap(final Collection> collection) { - super(); this.collection = collection; } @@ -85,6 +82,11 @@ public void putAll(final String name, final Collection addValues) { listMap.putAll(name, addValues); } + @Override + public void putAll(final Map> putMap) { + listMap.putAll(putMap); + } + @Override public int hashCode() { return listMap.hashCode(); @@ -146,11 +148,6 @@ public List remove(final Object key) { return listMap.remove(key); } - @Override - public void putAll(final Map> putMap) { - listMap.putAll(putMap); - } - @Override public Collection> values() { return listMap.values(); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMapToStream.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMapToStream.java index 5979493ec..a9ccf95b0 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMapToStream.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringListMapToStream.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.javaintegration; -import java.util.List; -import java.util.Map.Entry; +package org.metafacture.javaintegration; import org.metafacture.commons.types.ListMap; import org.metafacture.framework.FluxCommand; @@ -25,6 +23,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; +import java.util.List; +import java.util.Map.Entry; /** * Reads a {@link ListMap} and sends it to a {@link StreamReceiver} @@ -35,21 +35,22 @@ @In(ListMap.class) @Out(StreamReceiver.class) @FluxCommand("string-list-map-to-stream") -public final class StringListMapToStream - extends DefaultObjectPipe, StreamReceiver> { +public final class StringListMapToStream extends DefaultObjectPipe, StreamReceiver> { + + public StringListMapToStream() { + } @Override - public void process(final ListMap listMap){ + public void process(final ListMap listMap) { assert !isClosed(); process(listMap, getReceiver()); } public static void process(final ListMap listMap, final StreamReceiver receiver) { - receiver.startRecord(listMap.getId()); - for(Entry> entry: listMap.entrySet()){ + for (final Entry> entry: listMap.entrySet()) { final String name = entry.getKey(); - for(String value:entry.getValue()){ + for (final String value:entry.getValue()) { receiver.literal(name, value); } } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringMap.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringMap.java index 8af7b6816..fd7113ede 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringMap.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/StringMap.java @@ -13,46 +13,42 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - - /** * Collects the received results in a {@link Map}. Duplicate names are thus lost. * * @author Markus Michael Geipel * */ -public final class StringMap extends DefaultStreamReceiver - implements Map , Collector>{ +public final class StringMap extends DefaultStreamReceiver implements Map, Collector> { private boolean closed; private Collection> collection; private Map map; public StringMap() { - super(); map = new HashMap(); - collection=null; + collection = null; } public StringMap(final Collection> collection) { - super(); map = new HashMap(); - this.collection=collection; + this.collection = collection; } /** * @param map is filled with the received results. */ public StringMap(final Map map) { - super(); this.map = map; } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ValueSet.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ValueSet.java index 810ea6aef..b079a7e08 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ValueSet.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/ValueSet.java @@ -13,30 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; +import org.metafacture.framework.helpers.DefaultStreamReceiver; + import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.metafacture.framework.helpers.DefaultStreamReceiver; - - /** * Collects {@link String}s in a {@link Set}. * * @author Markus Michael Geipel * */ -public final class ValueSet extends DefaultStreamReceiver - implements Set, Collector> { +public final class ValueSet extends DefaultStreamReceiver implements Set, Collector> { private Collection> collection; private Set set; public ValueSet() { - super(); set = new HashSet<>(); this.collection = null; @@ -49,7 +47,6 @@ public ValueSet() { * @param collection is filled with the received results. */ public ValueSet(final Collection> collection) { - super(); set = new HashSet<>(); this.collection = collection; } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ArrayTypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ArrayTypeDecoder.java index fff586ba9..5e46950b6 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ArrayTypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ArrayTypeDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/CollectionTypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/CollectionTypeDecoder.java index 7829e9af2..348e485cf 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/CollectionTypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/CollectionTypeDecoder.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.javaintegration.pojo; -import java.util.Collection; +package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; +import java.util.Collection; + /** * Decodes a {@link Collection} to a Metafacture event stream. * @@ -37,12 +38,10 @@ static boolean supportsType(final Class clazz) { } @Override - public void decodeToStream(final StreamReceiver streamReceiver, - final String name, final Object object) { + public void decodeToStream(final StreamReceiver streamReceiver, final String name, final Object object) { final Collection collection = (Collection) object; for (final Object element : collection) { - final TypeDecoder typeDecoder = typeDecoderFactury - .create(element.getClass()); + final TypeDecoder typeDecoder = typeDecoderFactury.create(element.getClass()); typeDecoder.decodeToStream(streamReceiver, name, element); } } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeDecoder.java index b6c6e44bf..a35219cca 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeDecoder.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.StreamReceiver; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.metafacture.framework.StreamReceiver; - /** * Decodes a POJO to a Metafacture event stream. * @@ -32,15 +33,14 @@ class ComplexTypeDecoder implements TypeDecoder { private final TypeDecoderFactory typeDecoderFactory; private final List valueGetters; - ComplexTypeDecoder(final Class clazz, - final TypeDecoderFactory typeDecoderFactory) { + ComplexTypeDecoder(final Class clazz, final TypeDecoderFactory typeDecoderFactory) { this.typeDecoderFactory = typeDecoderFactory; valueGetters = new ArrayList<>(); addFieldValueGettersFor(clazz); addMethodValueGettersFor(clazz); } - private void addFieldValueGettersFor(Class clazz) { + private void addFieldValueGettersFor(final Class clazz) { final Field[] fields = clazz.getDeclaredFields(); for (final Field field : fields) { if (FieldValueGetter.supportsField(field)) { @@ -49,7 +49,7 @@ private void addFieldValueGettersFor(Class clazz) { } } - private void addMethodValueGettersFor(Class clazz) { + private void addMethodValueGettersFor(final Class clazz) { final Method[] methods = clazz.getDeclaredMethods(); for (final Method method : methods) { if (MethodValueGetter.supportsMethod(method)) { @@ -59,17 +59,15 @@ private void addMethodValueGettersFor(Class clazz) { } static boolean supportsType(final Class clazz) { - return !SimpleTypeDecoder.supportsType(clazz) - && !MetafactureSourceTypeDecoder.supportsType(clazz) - && !CollectionTypeDecoder.supportsType(clazz) - && !ArrayTypeDecoder.supportsType(clazz) - && !MapTypeDecoder.supportsType(clazz); + return !SimpleTypeDecoder.supportsType(clazz) && // checkstyle-disable-line BooleanExpressionComplexity + !MetafactureSourceTypeDecoder.supportsType(clazz) && + !CollectionTypeDecoder.supportsType(clazz) && + !ArrayTypeDecoder.supportsType(clazz) && + !MapTypeDecoder.supportsType(clazz); } @Override - public void decodeToStream(final StreamReceiver streamReceiver, - final String name, final Object object) { - + public void decodeToStream(final StreamReceiver streamReceiver, final String name, final Object object) { if (name != null) { streamReceiver.startEntity(name); } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeEncoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeEncoder.java index 549975bba..3d32dde72 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeEncoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ComplexTypeEncoder.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.metafacture.framework.MetafactureException; - /** * Encodes a Metafacture event stream to a POJO. * @@ -43,40 +44,36 @@ class ComplexTypeEncoder implements TypeEncoder { private static Object createInstance(final Class clazz) { try { return clazz.newInstance(); - } catch (final Exception e) { - throw new MetafactureException( - "Can't instantiate object of class: " + clazz, e); + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch + throw new MetafactureException("Can't instantiate object of class: " + clazz, e); } } - private void addFieldValueSettersFor(Class clazz) { + private void addFieldValueSettersFor(final Class clazz) { final Field[] fields = clazz.getDeclaredFields(); for (final Field field : fields) { if (FieldValueSetter.supportsField(field)) { - final FieldValueSetter fieldValueSetter = new FieldValueSetter( - field); - valueSetters.put(fieldValueSetter.getName(), - fieldValueSetter); + final FieldValueSetter fieldValueSetter = new FieldValueSetter(field); + valueSetters.put(fieldValueSetter.getName(), fieldValueSetter); } } } - private void addMethodValueSettersFor(Class clazz) { + private void addMethodValueSettersFor(final Class clazz) { final Method[] methods = clazz.getDeclaredMethods(); for (final Method method : methods) { if (MethodValueSetter.supportsMethod(method)) { - final MethodValueSetter methodValueSetter = new MethodValueSetter( - method); - valueSetters.put(methodValueSetter.getName(), - methodValueSetter); + final MethodValueSetter methodValueSetter = new MethodValueSetter(method); + valueSetters.put(methodValueSetter.getName(), methodValueSetter); } } } static boolean supportsType(final Class clazz) { - return !clazz.isPrimitive() && !clazz.equals(String.class) - && !MapTypeEncoder.supportsType(clazz) - && !ListTypeEncoder.supportsType(clazz); + return !clazz.isPrimitive() && !clazz.equals(String.class) && + !MapTypeEncoder.supportsType(clazz) && + !ListTypeEncoder.supportsType(clazz); } @Override diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueGetter.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueGetter.java index 8ca265a64..682099bed 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueGetter.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueGetter.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import org.metafacture.framework.MetafactureException; - /** * Retrieves a property of an object by reading a field. * @@ -42,13 +43,12 @@ static boolean supportsField(final Field f) { public Object getValue(final Object object) { try { return field.get(object); - } catch (final IllegalArgumentException e) { - throw new MetafactureException( - "The given object don't have a field named " - + field.getName(), e); - } catch (final IllegalAccessException e) { - throw new MetafactureException("Can't access the field named " - + field.getName(), e); + } + catch (final IllegalArgumentException e) { + throw new MetafactureException("The given object don't have a field named " + field.getName(), e); + } + catch (final IllegalAccessException e) { + throw new MetafactureException("Can't access the field named " + field.getName(), e); } } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueSetter.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueSetter.java index 8b4149530..0f19933dc 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueSetter.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/FieldValueSetter.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import org.metafacture.framework.MetafactureException; - /** * Sets the value of a field. The field must be publicly accessible. * @@ -42,13 +43,12 @@ static boolean supportsField(final Field f) { public void setValue(final Object object, final Object value) { try { field.set(object, value); - } catch (final IllegalArgumentException e) { - throw new MetafactureException( - "The given object don't have a field named " - + field.getName(), e); - } catch (final IllegalAccessException e) { - throw new MetafactureException("Can't access the field named " - + field.getName(), e); + } + catch (final IllegalArgumentException e) { + throw new MetafactureException("The given object don't have a field named " + field.getName(), e); + } + catch (final IllegalAccessException e) { + throw new MetafactureException("Can't access the field named " + field.getName(), e); } } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ListTypeEncoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ListTypeEncoder.java index e24bf7fef..b0d2d2936 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ListTypeEncoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ListTypeEncoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import java.util.ArrayList; diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeDecoder.java index 6b88a65c8..77e72417d 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeDecoder.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.javaintegration.pojo; -import java.util.Map; +package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; +import java.util.Map; + /** * Decodes a {@link Map} to a Metafacture event stream. * @@ -37,8 +38,7 @@ static boolean supportsType(final Class clazz) { } @Override - public void decodeToStream(final StreamReceiver streamReceiver, - final String name, final Object object) { + public void decodeToStream(final StreamReceiver streamReceiver, final String name, final Object object) { final Map map = (Map) object; if (name != null) { streamReceiver.startEntity(name); @@ -46,8 +46,7 @@ public void decodeToStream(final StreamReceiver streamReceiver, for (final Map.Entry entry : map.entrySet()) { final String key = entry.getKey().toString(); final Object value = entry.getValue(); - final TypeDecoder typeDecoder = typeDecoderFactory.create(value - .getClass()); + final TypeDecoder typeDecoder = typeDecoderFactory.create(value.getClass()); typeDecoder.decodeToStream(streamReceiver, key, value); } if (name != null) { diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeEncoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeEncoder.java index 89624f3da..8aacb96d3 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeEncoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MapTypeEncoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import java.util.HashMap; diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSource.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSource.java index 6a1f53096..6b5280924 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSource.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSource.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; @@ -27,6 +28,6 @@ */ public interface MetafactureSource { - void sendToStream(final StreamReceiver streamReceiver); + void sendToStream(StreamReceiver streamReceiver); } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSourceTypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSourceTypeDecoder.java index 24912297c..c59326402 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSourceTypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MetafactureSourceTypeDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; @@ -24,13 +25,15 @@ */ class MetafactureSourceTypeDecoder implements TypeDecoder { + MetafactureSourceTypeDecoder() { + } + public static boolean supportsType(final Class clazz) { return MetafactureSource.class.isAssignableFrom(clazz); } @Override - public void decodeToStream(final StreamReceiver streamReceiver, - final String name, final Object object) { + public void decodeToStream(final StreamReceiver streamReceiver, final String name, final Object object) { final MetafactureSource metafactureSource = (MetafactureSource) object; streamReceiver.startEntity(name); metafactureSource.sendToStream(streamReceiver); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueGetter.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueGetter.java index e02fcbeda..ce0c8d1dc 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueGetter.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueGetter.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.beans.Introspector; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.metafacture.framework.MetafactureException; - /** * Retrieves a property of an object by calling a getter method. * @@ -38,30 +39,28 @@ class MethodValueGetter implements ValueGetter { assert supportsMethod(method); this.method = method; // remove prefix then lower case first character - name = Introspector.decapitalize(method.getName().substring( - METHOD_PREFIX.length())); + name = Introspector.decapitalize(method.getName().substring(METHOD_PREFIX.length())); } static boolean supportsMethod(final Method m) { - return Modifier.isPublic(m.getModifiers()) - && m.getName().length() > METHOD_PREFIX.length() - && m.getName().startsWith(METHOD_PREFIX); + return Modifier.isPublic(m.getModifiers()) && + m.getName().length() > METHOD_PREFIX.length() && + m.getName().startsWith(METHOD_PREFIX); } @Override public Object getValue(final Object object) { try { return method.invoke(object); - } catch (final IllegalArgumentException e) { - throw new MetafactureException( - "The given object don't have a method named " - + method.getName(), e); - } catch (final IllegalAccessException e) { - throw new MetafactureException("Can't access the method named " - + method.getName(), e); - } catch (final InvocationTargetException e) { - throw new MetafactureException("Invoking the method named " - + method.getName() + " throws an excpetion", e); + } + catch (final IllegalArgumentException e) { + throw new MetafactureException("The given object don't have a method named " + method.getName(), e); + } + catch (final IllegalAccessException e) { + throw new MetafactureException("Can't access the method named " + method.getName(), e); + } + catch (final InvocationTargetException e) { + throw new MetafactureException("Invoking the method named " + method.getName() + " throws an excpetion", e); } } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueSetter.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueSetter.java index 726ea31c1..ffa5beff0 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueSetter.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/MethodValueSetter.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.beans.Introspector; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.metafacture.framework.MetafactureException; - /** * Invokes a setter method on an object. The method must be public, have exactly * one argument and its name must begin with "set". @@ -44,26 +45,25 @@ class MethodValueSetter implements ValueSetter { } static boolean supportsMethod(final Method m) { - return Modifier.isPublic(m.getModifiers()) - && m.getName().length() > METHOD_PREFIX.length() - && m.getName().startsWith(METHOD_PREFIX) - && m.getParameterTypes().length == 1; + return Modifier.isPublic(m.getModifiers()) && + m.getName().length() > METHOD_PREFIX.length() && + m.getName().startsWith(METHOD_PREFIX) && + m.getParameterTypes().length == 1; } @Override public void setValue(final Object object, final Object value) { try { method.invoke(object, value); - } catch (final IllegalArgumentException e) { - throw new MetafactureException( - "The given object don't have a method named " - + method.getName(), e); - } catch (final IllegalAccessException e) { - throw new MetafactureException("Can't access the method named " - + method.getName(), e); - } catch (final InvocationTargetException e) { - throw new MetafactureException("Invoking the method named " - + method.getName() + " throws an excpetion", e); + } + catch (final IllegalArgumentException e) { + throw new MetafactureException("The given object don't have a method named " + method.getName(), e); + } + catch (final IllegalAccessException e) { + throw new MetafactureException("Can't access the method named " + method.getName(), e); + } + catch (final InvocationTargetException e) { + throw new MetafactureException("Invoking the method named " + method.getName() + " throws an excpetion", e); } } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoDecoder.java index 25e7b0cc1..1a473dfe9 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import org.metafacture.framework.FluxCommand; @@ -79,6 +80,9 @@ public class PojoDecoder extends DefaultObjectPipe { private final TypeDecoderFactory typeDecoderFactory = new TypeDecoderFactory(); + public PojoDecoder() { + } + @Override public void process(final T obj) { if (obj == null) { diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoEncoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoEncoder.java index c9a588550..6f72ba333 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoEncoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/PojoEncoder.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.javaintegration.pojo; -import java.beans.PropertyEditor; -import java.beans.PropertyEditorManager; -import java.util.ArrayDeque; -import java.util.Deque; +package org.metafacture.javaintegration.pojo; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -28,6 +24,11 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.beans.PropertyEditor; +import java.beans.PropertyEditorManager; +import java.util.ArrayDeque; +import java.util.Deque; + /** * Creates and fills a new object instance with stream data and sends the result * to the given object receiver. @@ -44,12 +45,9 @@ public class PojoEncoder extends DefaultStreamPipe> { static { // Initialize the property manager to map the primitive data types to // the corresponding object based types, e.g. int to Integer - PropertyEditorManager.registerEditor(Boolean.class, - PropertyEditorManager.findEditor(boolean.class).getClass()); - PropertyEditorManager.registerEditor(Integer.class, - PropertyEditorManager.findEditor(int.class).getClass()); - PropertyEditorManager.registerEditor(Long.class, PropertyEditorManager - .findEditor(long.class).getClass()); + PropertyEditorManager.registerEditor(Boolean.class, PropertyEditorManager.findEditor(boolean.class).getClass()); + PropertyEditorManager.registerEditor(Integer.class, PropertyEditorManager.findEditor(int.class).getClass()); + PropertyEditorManager.registerEditor(Long.class, PropertyEditorManager.findEditor(long.class).getClass()); } private final TypeEncoderFactory typeEncoderFactory = new TypeEncoderFactory(); @@ -92,16 +90,13 @@ public void endEntity() { @Override public void literal(final String name, final String value) { final TypeEncoder currentTypeEncoder = typeEncoderStack.peek(); - final Class targetType = currentTypeEncoder.getValueType(name) - .getRawClass(); - currentTypeEncoder.setValue(name, - createObjectFromString(value, targetType)); + final Class targetType = currentTypeEncoder.getValueType(name).getRawClass(); + currentTypeEncoder.setValue(name, createObjectFromString(value, targetType)); } private static Object createObjectFromString(final String value, final Class targetType) { - final PropertyEditor propertyEditor = PropertyEditorManager - .findEditor(targetType); + final PropertyEditor propertyEditor = PropertyEditorManager.findEditor(targetType); propertyEditor.setAsText(value); return propertyEditor.getValue(); } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/SimpleTypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/SimpleTypeDecoder.java index 0cfbe35a2..eea86e6a8 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/SimpleTypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/SimpleTypeDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; @@ -24,13 +25,15 @@ */ class SimpleTypeDecoder implements TypeDecoder { + SimpleTypeDecoder() { + } + static boolean supportsType(final Class clazz) { return clazz.isPrimitive() || clazz.equals(String.class); } @Override - public void decodeToStream(final StreamReceiver streamReceiver, - final String name, final Object object) { + public void decodeToStream(final StreamReceiver streamReceiver, final String name, final Object object) { streamReceiver.literal(name, object.toString()); } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoder.java index eaa675eb2..c290bb4e7 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import org.metafacture.framework.StreamReceiver; @@ -25,7 +26,6 @@ */ interface TypeDecoder { - void decodeToStream(final StreamReceiver streamReceiver, final String name, - final Object object); + void decodeToStream(StreamReceiver streamReceiver, String name, Object object); } diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoderFactory.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoderFactory.java index 9b3770a53..2c9b3359c 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoderFactory.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeDecoderFactory.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.util.HashMap; import java.util.Map; -import org.metafacture.framework.MetafactureException; - /** * Returns a decoder for a given class. * @@ -29,6 +30,9 @@ class TypeDecoderFactory { private final Map, TypeDecoder> typeDecoders = new HashMap<>(); + TypeDecoderFactory() { + } + TypeDecoder create(final Class clazz) { if (typeDecoders.containsKey(clazz)) { return typeDecoders.get(clazz); @@ -36,17 +40,23 @@ TypeDecoder create(final Class clazz) { final TypeDecoder typeDecoder; if (SimpleTypeDecoder.supportsType(clazz)) { typeDecoder = new SimpleTypeDecoder(); - } else if (MetafactureSourceTypeDecoder.supportsType(clazz)) { + } + else if (MetafactureSourceTypeDecoder.supportsType(clazz)) { typeDecoder = new MetafactureSourceTypeDecoder(); - } else if (CollectionTypeDecoder.supportsType(clazz)) { + } + else if (CollectionTypeDecoder.supportsType(clazz)) { typeDecoder = new CollectionTypeDecoder(this); - } else if (ArrayTypeDecoder.supportsType(clazz)) { + } + else if (ArrayTypeDecoder.supportsType(clazz)) { typeDecoder = new ArrayTypeDecoder(this); - } else if (ComplexTypeDecoder.supportsType(clazz)) { + } + else if (ComplexTypeDecoder.supportsType(clazz)) { typeDecoder = new ComplexTypeDecoder(clazz, this); - } else if (MapTypeDecoder.supportsType(clazz)) { + } + else if (MapTypeDecoder.supportsType(clazz)) { typeDecoder = new MapTypeDecoder(this); - } else { + } + else { throw new MetafactureException("Can't decode type " + clazz); } typeDecoders.put(clazz, typeDecoder); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoder.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoder.java index 767d93088..db96149ce 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoder.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; /** diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoderFactory.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoderFactory.java index 3589f6caa..4fb541a86 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoderFactory.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/TypeEncoderFactory.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; +import org.metafacture.framework.MetafactureException; + import java.util.List; import java.util.Map; -import org.metafacture.framework.MetafactureException; - /** * Returns {@link TypeEncoder}s for POJOs, {@link Map}s and {@link List}s. * @@ -27,16 +28,22 @@ */ class TypeEncoderFactory { + TypeEncoderFactory() { + } + TypeEncoder create(final ValueType valueType) { final TypeEncoder typeEncoder; final Class rawClass = valueType.getRawClass(); if (MapTypeEncoder.supportsType(rawClass)) { typeEncoder = new MapTypeEncoder(valueType); - } else if (ListTypeEncoder.supportsType(rawClass)) { + } + else if (ListTypeEncoder.supportsType(rawClass)) { typeEncoder = new ListTypeEncoder(valueType); - } else if (ComplexTypeEncoder.supportsType(rawClass)) { + } + else if (ComplexTypeEncoder.supportsType(rawClass)) { typeEncoder = new ComplexTypeEncoder(rawClass); - } else { + } + else { throw new MetafactureException("Can't encode type " + rawClass); } return typeEncoder; diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueGetter.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueGetter.java index 496686cdc..7484274ad 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueGetter.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueGetter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; /** @@ -24,7 +25,7 @@ */ interface ValueGetter { - Object getValue(final Object object); + Object getValue(Object object); String getName(); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueSetter.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueSetter.java index e0a296725..0f9b1821f 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueSetter.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueSetter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; /** @@ -23,7 +24,7 @@ */ interface ValueSetter { - void setValue(final Object object, final Object value); + void setValue(Object object, Object value); String getName(); diff --git a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueType.java b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueType.java index 7f103fc0c..f7b448da1 100644 --- a/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueType.java +++ b/metafacture-javaintegration/src/main/java/org/metafacture/javaintegration/pojo/ValueType.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import java.lang.reflect.ParameterizedType; @@ -41,10 +42,12 @@ class ValueType { .getActualTypeArguments(); if (Map.class.isAssignableFrom(clazz)) { elementClass = (Class) actualTypeArguments[1]; - } else { + } + else { elementClass = (Class) actualTypeArguments[0]; } - } else { + } + else { elementClass = null; } } diff --git a/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/MapToStreamTest.java b/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/MapToStreamTest.java index 68f75ed1c..276210e3b 100644 --- a/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/MapToStreamTest.java +++ b/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/MapToStreamTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoDecoderTest.java b/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoDecoderTest.java index 1c53267f7..47cbfcb80 100644 --- a/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoDecoderTest.java +++ b/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoDecoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import static org.junit.Assert.assertEquals; diff --git a/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoEncoderTest.java b/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoEncoderTest.java index d643c8eb5..d2a6e89f6 100644 --- a/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoEncoderTest.java +++ b/metafacture-javaintegration/src/test/java/org/metafacture/javaintegration/pojo/PojoEncoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.javaintegration.pojo; import static org.junit.Assert.assertEquals; From dfbeb844582d71ba0d73f517452c00184ee07530 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Wed, 8 Sep 2021 18:44:58 +0200 Subject: [PATCH 28/30] metafacture-triples/ (main): Fix Checkstyle violations. --- .../triples/AbstractTripleSort.java | 105 ++++++++++-------- .../triples/MemoryWarningSystem.java | 7 +- .../triples/SortedTripleFileFacade.java | 21 ++-- .../metafacture/triples/StreamToTriples.java | 40 ++++--- .../metafacture/triples/TripleCollect.java | 12 +- .../org/metafacture/triples/TripleCount.java | 44 ++++---- .../org/metafacture/triples/TripleFilter.java | 13 ++- .../triples/TripleObjectRetriever.java | 36 +++--- .../triples/TripleObjectWriter.java | 35 +++--- .../org/metafacture/triples/TripleReader.java | 28 +++-- .../metafacture/triples/TripleReorder.java | 11 +- .../org/metafacture/triples/TripleSort.java | 9 +- .../org/metafacture/triples/TripleWriter.java | 20 ++-- .../metafacture/triples/TriplesToStream.java | 9 +- .../triples/AbstractTripleSortTest.java | 1 + .../triples/StreamToTriplesTest.java | 1 + .../triples/TripleCollectTest.java | 1 + .../metafacture/triples/TripleFilterTest.java | 1 + .../triples/TripleObjectRetrieverTest.java | 1 + .../triples/TripleObjectWriterTest.java | 1 + .../triples/TripleReaderWriterTest.java | 1 + 21 files changed, 229 insertions(+), 168 deletions(-) diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java b/metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java index 9f8e8bfb4..1ccd21710 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java @@ -13,8 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; +import org.metafacture.framework.MetafactureException; +import org.metafacture.framework.ObjectReceiver; +import org.metafacture.framework.helpers.DefaultObjectPipe; +import org.metafacture.framework.objects.Triple; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -25,11 +31,6 @@ import java.util.List; import java.util.PriorityQueue; -import org.metafacture.framework.MetafactureException; -import org.metafacture.framework.ObjectReceiver; -import org.metafacture.framework.helpers.DefaultObjectPipe; -import org.metafacture.framework.objects.Triple; - /** * @author markus geipel * @@ -39,7 +40,7 @@ public abstract class AbstractTripleSort extends DefaultObjectPipe comparator = createComparator(compare, order); final PriorityQueue queue = new PriorityQueue(11, new Comparator() { @@ -158,14 +163,17 @@ public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade sortedTriple(triple); if (sortedFileFacade.isEmpty()) { sortedFileFacade.close(); - } else { + } + else { queue.add(sortedFileFacade); } } onFinished(); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Error merging temp files", e); - } finally { + } + finally { for (final SortedTripleFileFacade sortedFileFacade : queue) { sortedFileFacade.close(); } @@ -176,7 +184,6 @@ public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade protected void onFinished() { // nothing to do - } protected abstract void sortedTriple(Triple namedValue); @@ -188,39 +195,39 @@ public final Comparator createComparator() { public static Comparator createComparator(final Compare compareBy, final Order order) { final Comparator comparator; switch (compareBy) { - case ALL: - comparator = new Comparator() { - @Override - public int compare(final Triple o1, final Triple o2) { - return order.order(o1.compareTo(o2)); - } - }; - break; - case OBJECT: - comparator = new Comparator() { - @Override - public int compare(final Triple o1, final Triple o2) { - return order.order(o1.getObject().compareTo(o2.getObject())); - } - }; - break; - case SUBJECT: - comparator = new Comparator() { - @Override - public int compare(final Triple o1, final Triple o2) { - return order.order(o1.getSubject().compareTo(o2.getSubject())); - } - }; - break; - case PREDICATE: - default: - comparator = new Comparator() { - @Override - public int compare(final Triple o1, final Triple o2) { - return order.order(o1.getPredicate().compareTo(o2.getPredicate())); - } - }; - break; + case ALL: + comparator = new Comparator() { + @Override + public int compare(final Triple o1, final Triple o2) { + return order.order(o1.compareTo(o2)); + } + }; + break; + case OBJECT: + comparator = new Comparator() { + @Override + public int compare(final Triple o1, final Triple o2) { + return order.order(o1.getObject().compareTo(o2.getObject())); + } + }; + break; + case SUBJECT: + comparator = new Comparator() { + @Override + public int compare(final Triple o1, final Triple o2) { + return order.order(o1.getSubject().compareTo(o2.getSubject())); + } + }; + break; + case PREDICATE: + default: + comparator = new Comparator() { + @Override + public int compare(final Triple o1, final Triple o2) { + return order.order(o1.getPredicate().compareTo(o2.getPredicate())); + } + }; + break; } return comparator; diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/MemoryWarningSystem.java b/metafacture-triples/src/main/java/org/metafacture/triples/MemoryWarningSystem.java index 1e400ae99..776266f2a 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/MemoryWarningSystem.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/MemoryWarningSystem.java @@ -16,6 +16,7 @@ /* * Code based on http://www.javaspecialists.eu/archive/Issue092.html */ + package org.metafacture.triples; import java.lang.management.ManagementFactory; @@ -25,7 +26,6 @@ import java.lang.management.MemoryType; import java.util.Collection; import java.util.concurrent.CopyOnWriteArrayList; - import javax.management.Notification; import javax.management.NotificationEmitter; import javax.management.NotificationListener; @@ -61,7 +61,7 @@ public void handleNotification(final Notification notification, final Object han }, null, null); } - private static Collection getListeners(){ + private static Collection getListeners() { return LISTENERS; } @@ -97,10 +97,11 @@ private static void setUsageThreshold(final double threshold) { private static MemoryPoolMXBean findTenuredGenPool() { // I don't know whether this approach is better, or whether // we should rather check for the pool name "Tenured Gen"? - for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) + for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { return pool; } + } throw new AssertionError("Could not find tenured space"); } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/SortedTripleFileFacade.java b/metafacture-triples/src/main/java/org/metafacture/triples/SortedTripleFileFacade.java index 043883ab7..00490bd6b 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/SortedTripleFileFacade.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/SortedTripleFileFacade.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; +import org.metafacture.framework.MetafactureException; +import org.metafacture.framework.objects.Triple; + import java.io.BufferedInputStream; import java.io.EOFException; import java.io.File; @@ -22,10 +26,6 @@ import java.io.IOException; import java.io.ObjectInputStream; -import org.metafacture.framework.MetafactureException; -import org.metafacture.framework.objects.Triple; - - /** * @author markus geipel * @@ -51,18 +51,18 @@ private void next() throws IOException { try { triple = Triple.read(in); empty = false; - - } catch (EOFException e) { + } + catch (final EOFException e) { empty = true; triple = null; } } public void close() { - try { in.close(); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Error closing input stream", e); } if (file.exists()) { @@ -78,10 +78,9 @@ public Triple peek() { } public Triple pop() throws IOException { - final Triple triple = peek(); + final Triple nextTriple = peek(); next(); - return triple; + return nextTriple; } - } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/StreamToTriples.java b/metafacture-triples/src/main/java/org/metafacture/triples/StreamToTriples.java index 69457e9fa..727245cc9 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/StreamToTriples.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/StreamToTriples.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.triples; import org.metafacture.formeta.formatter.ConciseFormatter; import org.metafacture.formeta.formatter.Formatter; @@ -30,8 +26,13 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; -import org.metafacture.framework.objects.Triple; import org.metafacture.framework.objects.Triple.ObjectType; +import org.metafacture.framework.objects.Triple; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Emits the literals which are received as triples such @@ -82,6 +83,9 @@ public final class StreamToTriples extends DefaultStreamPipe encodeLevel) { formatter.startGroup(name); - } else { + } + else { startEncode(name); } ++nestingLevel; @@ -153,7 +159,8 @@ public void endEntity() { --nestingLevel; if (nestingLevel == encodeLevel) { endEncode(); - } else { + } + else { formatter.endGroup(); } } @@ -165,10 +172,12 @@ public void literal(final String name, final String value) { if (nestingLevel > encodeLevel) { if (nestingLevel == 1 && redirect && StandardEventNames.ID.equals(name)) { currentId = value; - } else { + } + else { formatter.literal(name, value); } - } else { + } + else { dispatch(name, value, ObjectType.STRING); } } @@ -188,17 +197,20 @@ private void dispatch(final String name, final String value, final ObjectType ty if (redirect) { if (StandardEventNames.ID.equals(name)) { currentId = value; - } else { + } + else { final Matcher matcher = REDIRECT_PATTERN.matcher(name); if (matcher.find()) { getReceiver().process(new Triple(matcher.group(1), matcher.group(2), value, type)); - } else { + } + else { nameBuffer.add(name); valueBuffer.add(value); typeBuffer.add(type); } } - } else { + } + else { getReceiver().process(new Triple(currentId, name, value, type)); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleCollect.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleCollect.java index 5b58c9e0b..14b1053be 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleCollect.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleCollect.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import org.metafacture.formeta.parser.FormetaParser; @@ -57,7 +58,8 @@ public void process(final Triple triple) { if (currentSubject.equals(triple.getSubject())) { decodeTriple(triple); - } else { + } + else { getReceiver().endRecord(); currentSubject = triple.getSubject(); getReceiver().startRecord(currentSubject); @@ -66,12 +68,14 @@ public void process(final Triple triple) { } public void decodeTriple(final Triple triple) { - if(triple.getObjectType() == ObjectType.STRING){ + if (triple.getObjectType() == ObjectType.STRING) { getReceiver().literal(triple.getPredicate(), triple.getObject()); - }else if (triple.getObjectType() == ObjectType.ENTITY){ + } + else if (triple.getObjectType() == ObjectType.ENTITY) { emitter.setDefaultName(triple.getPredicate()); parser.parse(triple.getObject()); - }else{ + } + else { throw new UnsupportedOperationException(triple.getObjectType() + " can not yet be decoded"); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleCount.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleCount.java index ec5523e10..2babf30bd 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleCount.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleCount.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.util.Comparator; +package org.metafacture.triples; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.annotations.Description; @@ -23,6 +22,8 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.objects.Triple; +import java.util.Comparator; + /** * Counts triples. * @@ -44,17 +45,20 @@ public final class TripleCount extends AbstractTripleSort { private String countPredicate = DEFAULT_COUNTP_REDICATE; private Comparator comparator; + public TripleCount() { + } + @Override protected void sortedTriple(final Triple triple) { - - if(current==INIT){ + if (current == INIT) { current = triple; comparator = createComparator(); } - if(comparator.compare(current, triple)==0){ + if (comparator.compare(current, triple) == 0) { ++count; - }else{ + } + else { writeResult(); current = triple; count = 1; @@ -73,23 +77,23 @@ protected void onFinished() { private void writeResult() { final Compare compareBy = getCompare(); switch (compareBy) { - case ALL: - getReceiver().process(new Triple(current.toString(), countPredicate , String.valueOf(count))); - break; - case OBJECT: - getReceiver().process(new Triple(current.getObject(), countPredicate, String.valueOf(count))); - break; - case PREDICATE: - getReceiver().process(new Triple(current.getPredicate(), countPredicate, String.valueOf(count))); - break; - case SUBJECT: - default: - getReceiver().process(new Triple(current.getSubject(), countPredicate, String.valueOf(count))); - break; + case ALL: + getReceiver().process(new Triple(current.toString(), countPredicate, String.valueOf(count))); + break; + case OBJECT: + getReceiver().process(new Triple(current.getObject(), countPredicate, String.valueOf(count))); + break; + case PREDICATE: + getReceiver().process(new Triple(current.getPredicate(), countPredicate, String.valueOf(count))); + break; + case SUBJECT: + default: + getReceiver().process(new Triple(current.getSubject(), countPredicate, String.valueOf(count))); + break; } } - public void setCountBy(final Compare countBy){ + public void setCountBy(final Compare countBy) { setCompare(countBy); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleFilter.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleFilter.java index c809eab1b..68743441c 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleFilter.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleFilter.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +package org.metafacture.triples; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.ObjectReceiver; @@ -26,6 +24,9 @@ import org.metafacture.framework.helpers.DefaultObjectPipe; import org.metafacture.framework.objects.Triple; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Filters triples. The patterns for subject, predicate and object are disjunctive. * @@ -36,8 +37,7 @@ @In(Triple.class) @Out(Triple.class) @FluxCommand("filter-triples") -public final class TripleFilter extends - DefaultObjectPipe> { +public final class TripleFilter extends DefaultObjectPipe> { // A regexp that is guaranteed to never match ( an `a` after the end // of the string, see http://stackoverflow.com/a/1723225 for details): @@ -48,6 +48,9 @@ public final class TripleFilter extends private Matcher objectMatcher = MATCH_NOTHING; private boolean passMatches = true; + public TripleFilter() { + } + public String getSubjectPattern() { return subjectMatcher.pattern().pattern(); } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectRetriever.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectRetriever.java index 86cb56a96..aa655d0b1 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectRetriever.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectRetriever.java @@ -13,14 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; +package org.metafacture.triples; import org.metafacture.commons.ResourceUtil; import org.metafacture.framework.FluxCommand; @@ -30,8 +24,15 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; -import org.metafacture.framework.objects.Triple; import org.metafacture.framework.objects.Triple.ObjectType; +import org.metafacture.framework.objects.Triple; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * Uses the object value of the triple as a URL and emits a new triple @@ -40,17 +41,19 @@ * * @author Christoph Böhme */ -@Description("Uses the object value of the triple as a URL and emits a new triple " - + "in which the object value is replaced with the contents of the resource " - + "identified by the URL.") +@Description("Uses the object value of the triple as a URL and emits a new triple " + + "in which the object value is replaced with the contents of the resource " + + "identified by the URL.") @In(Triple.class) @Out(Triple.class) @FluxCommand("retrieve-triple-objects") -public final class TripleObjectRetriever - extends DefaultObjectPipe> { +public final class TripleObjectRetriever extends DefaultObjectPipe> { private Charset defaultEncoding = StandardCharsets.UTF_8; + public TripleObjectRetriever() { + } + /** * Sets the default encoding to use when no encoding is * provided by the server. The default setting is UTF-8. @@ -98,13 +101,12 @@ private String retrieveObjectValue(final String urlString) { final URLConnection connection = url.openConnection(); connection.connect(); final String encodingName = connection.getContentEncoding(); - final Charset encoding = encodingName != null ? - Charset.forName(encodingName) : - defaultEncoding; + final Charset encoding = encodingName != null ? Charset.forName(encodingName) : defaultEncoding; try (InputStream inputStream = connection.getInputStream()) { return ResourceUtil.readAll(inputStream, encoding); } - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectWriter.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectWriter.java index 5364f486e..fc635c7e1 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectWriter.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleObjectWriter.java @@ -13,15 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.io.IOException; -import java.io.Writer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +package org.metafacture.triples; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -31,6 +24,14 @@ import org.metafacture.framework.helpers.DefaultObjectReceiver; import org.metafacture.framework.objects.Triple; +import java.io.IOException; +import java.io.Writer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + /** * Writes the object value of the triple into a file. The filename * is constructed from subject and predicate. @@ -42,11 +43,11 @@ * * @author Christoph Böhme */ -@Description("Writes the object value of the triple into a file. The filename is " - + "constructed from subject and predicate. Please note: This module does " - + "not check if the filename constructed from subject and predicate stays " - + "within `baseDir`. THIS MODULE SHOULD NOT BE USED IN ENVIRONMENTS IN WHICH " - + "THE VALUES OF SUBJECT AND PREDICATE A PROVIDED BY AN UNTRUSTED SOURCE!") +@Description("Writes the object value of the triple into a file. The filename is " + + "constructed from subject and predicate. Please note: This module does " + + "not check if the filename constructed from subject and predicate stays " + + "within `baseDir`. THIS MODULE SHOULD NOT BE USED IN ENVIRONMENTS IN WHICH " + + "THE VALUES OF SUBJECT AND PREDICATE A PROVIDED BY AN UNTRUSTED SOURCE!") @In(Triple.class) @Out(Void.class) @FluxCommand("write-triple-objects") @@ -93,9 +94,10 @@ public String getEncoding() { public void process(final Triple triple) { final Path filePath = buildFilePath(triple); ensureParentPathExists(filePath); - try(final Writer writer = Files.newBufferedWriter(filePath, encoding)) { + try (Writer writer = Files.newBufferedWriter(filePath, encoding)) { writer.write(triple.getObject()); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } @@ -110,7 +112,8 @@ private void ensureParentPathExists(final Path path) { if (parentDir != null) { try { Files.createDirectories(parentDir); - } catch (final IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleReader.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleReader.java index fa3b8d52b..935d6467d 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleReader.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleReader.java @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.io.BufferedInputStream; -import java.io.EOFException; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; +package org.metafacture.triples; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -27,16 +22,24 @@ import org.metafacture.framework.helpers.DefaultObjectPipe; import org.metafacture.framework.objects.Triple; +import java.io.BufferedInputStream; +import java.io.EOFException; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; + /** * @author Christoph Böhme * */ @FluxCommand("read-triples") -public final class TripleReader extends - DefaultObjectPipe> { +public final class TripleReader extends DefaultObjectPipe> { public static final int BUFFERSIZE = 2048; + public TripleReader() { + } + @Override public void process(final String filename) { try { @@ -46,11 +49,14 @@ public void process(final String filename) { while (true) { getReceiver().process(Triple.read(in)); } - } catch (EOFException e) { - } finally { + } + catch (final EOFException e) { + } + finally { in.close(); } - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleReorder.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleReorder.java index 43a79b1fb..ab14d7e1a 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleReorder.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleReorder.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import org.metafacture.framework.FluxCommand; @@ -33,13 +34,12 @@ @In(Triple.class) @Out(Triple.class) @FluxCommand("reorder-triple") -public final class TripleReorder extends - DefaultObjectPipe> { +public final class TripleReorder extends DefaultObjectPipe> { /** * Names of the elements in the triple */ - public enum TripleElement { SUBJECT, PREDICATE, OBJECT }; + public enum TripleElement { SUBJECT, PREDICATE, OBJECT } // Do not change the item order because the process method // uses ordinal(). @@ -47,6 +47,9 @@ public enum TripleElement { SUBJECT, PREDICATE, OBJECT }; private TripleElement predicateFrom = TripleElement.PREDICATE; private TripleElement objectFrom = TripleElement.OBJECT; + public TripleReorder() { + } + public TripleElement getSubjectFrom() { return subjectFrom; } @@ -76,7 +79,7 @@ public void process(final Triple triple) { final String[] elements = { triple.getSubject(), triple.getPredicate(), - triple.getObject(), + triple.getObject() }; getReceiver().process(new Triple( diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleSort.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleSort.java index 43be183b8..f563b3b31 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleSort.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleSort.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import org.metafacture.framework.FluxCommand; @@ -32,18 +33,20 @@ @FluxCommand("sort-triples") public final class TripleSort extends AbstractTripleSort { + public TripleSort() { + } + @Override protected void sortedTriple(final Triple triple) { getReceiver().process(triple); } - public void setBy(final Compare compare){ + public void setBy(final Compare compare) { setCompare(compare); } - public void setOrder(final Order order){ + public void setOrder(final Order order) { setSortOrder(order); } - } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TripleWriter.java b/metafacture-triples/src/main/java/org/metafacture/triples/TripleWriter.java index d9107ff0c..ab39de294 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TripleWriter.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TripleWriter.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.triples; -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; +package org.metafacture.triples; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -28,6 +24,11 @@ import org.metafacture.framework.helpers.DefaultObjectReceiver; import org.metafacture.framework.objects.Triple; +import java.io.BufferedOutputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; + /** * @author Christoph Böhme * @@ -53,7 +54,8 @@ public TripleWriter(final String filename) { public void process(final Triple obj) { try { obj.write(outputStream); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } @@ -65,7 +67,8 @@ public void resetStream() { outputStream.close(); } outputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename), BUFFERSIZE)); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } @@ -76,7 +79,8 @@ public void closeStream() { if (outputStream != null) { outputStream.close(); } - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); } } diff --git a/metafacture-triples/src/main/java/org/metafacture/triples/TriplesToStream.java b/metafacture-triples/src/main/java/org/metafacture/triples/TriplesToStream.java index f1c4f4b04..c297f1ce0 100644 --- a/metafacture-triples/src/main/java/org/metafacture/triples/TriplesToStream.java +++ b/metafacture-triples/src/main/java/org/metafacture/triples/TriplesToStream.java @@ -17,6 +17,7 @@ /** * */ + package org.metafacture.triples; import org.metafacture.formeta.parser.FormetaParser; @@ -53,12 +54,14 @@ public TriplesToStream() { @Override public void process(final Triple triple) { getReceiver().startRecord(triple.getSubject()); - if(triple.getObjectType() == ObjectType.STRING){ + if (triple.getObjectType() == ObjectType.STRING) { getReceiver().literal(triple.getPredicate(), triple.getObject()); - }else if (triple.getObjectType() == ObjectType.ENTITY){ + } + else if (triple.getObjectType() == ObjectType.ENTITY) { emitter.setDefaultName(triple.getPredicate()); parser.parse(triple.getObject()); - }else{ + } + else { throw new UnsupportedOperationException(triple.getObjectType() + " can not yet be decoded"); } getReceiver().endRecord(); diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/AbstractTripleSortTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/AbstractTripleSortTest.java index cffc27786..f361b326a 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/AbstractTripleSortTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/AbstractTripleSortTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import static org.junit.Assert.assertTrue; diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/StreamToTriplesTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/StreamToTriplesTest.java index ce9e4bad7..226c96384 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/StreamToTriplesTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/StreamToTriplesTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import org.junit.Before; diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/TripleCollectTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/TripleCollectTest.java index 8c0f5bbfe..389fa61e6 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/TripleCollectTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/TripleCollectTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import static org.mockito.Mockito.never; diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/TripleFilterTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/TripleFilterTest.java index ff42df40e..746fcdb05 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/TripleFilterTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/TripleFilterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import static org.mockito.Mockito.verify; diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectRetrieverTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectRetrieverTest.java index 3afc43a72..3207f614b 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectRetrieverTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectRetrieverTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import static org.mockito.Mockito.verify; diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectWriterTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectWriterTest.java index f22c34a6c..0b76c6d5c 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectWriterTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/TripleObjectWriterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import static org.junit.Assert.assertEquals; diff --git a/metafacture-triples/src/test/java/org/metafacture/triples/TripleReaderWriterTest.java b/metafacture-triples/src/test/java/org/metafacture/triples/TripleReaderWriterTest.java index 75dd8a561..e2619a125 100644 --- a/metafacture-triples/src/test/java/org/metafacture/triples/TripleReaderWriterTest.java +++ b/metafacture-triples/src/test/java/org/metafacture/triples/TripleReaderWriterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.triples; import static org.mockito.Mockito.verify; From 0fc0346792eadda39a504aac8ee544f83b9bf6e6 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Wed, 8 Sep 2021 19:09:54 +0200 Subject: [PATCH 29/30] metafacture-xml/ (main): Fix Checkstyle violations. --- .../org/metafacture/xml/CGXmlHandler.java | 14 +- .../metafacture/xml/FilenameExtractor.java | 128 +++++++++++++----- .../metafacture/xml/GenericXmlHandler.java | 47 +++---- .../org/metafacture/xml/RecordIdentifier.java | 3 +- .../org/metafacture/xml/SimpleXmlEncoder.java | 57 +++++--- .../java/org/metafacture/xml/XmlDecoder.java | 26 ++-- .../metafacture/xml/XmlElementSplitter.java | 72 +++++----- .../metafacture/xml/XmlFilenameWriter.java | 98 +++++++------- .../org/metafacture/xml/CGXmlHandlerTest.java | 1 + .../xml/GenericXMLHandlerTest.java | 1 + .../metafacture/xml/SimpleXmlEncoderTest.java | 1 + .../xml/XmlElementSplitterTest.java | 1 + .../xml/XmlFilenameWriterTest.java | 1 + 13 files changed, 269 insertions(+), 181 deletions(-) diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/CGXmlHandler.java b/metafacture-xml/src/main/java/org/metafacture/xml/CGXmlHandler.java index 9c262653d..e794d29a0 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/CGXmlHandler.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/CGXmlHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import org.metafacture.framework.FluxCommand; @@ -23,6 +24,7 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; /** @@ -60,8 +62,7 @@ @FluxCommand("handle-cg-xml") public final class CGXmlHandler extends DefaultXmlPipe { - public static final String CGXML_NAMESPACE = - "http://www.culturegraph.org/cgxml"; + public static final String CGXML_NAMESPACE = "http://www.culturegraph.org/cgxml"; private static final String ROOT_TAG = "cgxml"; private static final String RECORDS_TAG = "records"; @@ -76,6 +77,9 @@ public final class CGXmlHandler extends DefaultXmlPipe { private static final String VERSION = "1.0"; + public CGXmlHandler() { + } + @Override public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { @@ -114,7 +118,8 @@ private void emitStartRecord(final Attributes attributes) { final String recordId = attributes.getValue("", ID_ATTR); if (recordId == null) { getReceiver().startRecord(""); - } else { + } + else { getReceiver().startRecord(recordId); } } @@ -144,7 +149,8 @@ public void endElement(final String uri, final String localName, } if (RECORD_TAG.equals(localName)) { getReceiver().endRecord(); - } else if (ENTITY_TAG.equals(localName)) { + } + else if (ENTITY_TAG.equals(localName)) { getReceiver().endEntity(); } } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/FilenameExtractor.java b/metafacture-xml/src/main/java/org/metafacture/xml/FilenameExtractor.java index 662dd5a3a..5dd7facca 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/FilenameExtractor.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/FilenameExtractor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import java.io.File; @@ -25,34 +26,6 @@ */ public interface FilenameExtractor extends RecordIdentifier { - /** - * Provides functions and fields that all {@link FilenameExtractor} - * implementing classes may found useful. - * - * @author Pascal Christoph (dr0i) - * - */ - class FilenameUtil { - public String target = "tmp"; - public String encoding = "UTF-8"; - public String property = null; - public String fileSuffix = null; - public int startIndex = 0; - public int endIndex = 0; - public String filename = "test"; - - /** - * Ensures that path exists. If not, make it. - * - * @param path - * the path of the to be stored file. - */ - public void ensurePathExists(final File path) { - final File parent = path.getAbsoluteFile().getParentFile(); - parent.mkdirs(); - } - } - /** * Returns the encoding used to open the resource. * @@ -66,7 +39,7 @@ public void ensurePathExists(final File path) { * @param encoding * new encoding */ - void setEncoding(final String encoding); + void setEncoding(String encoding); /** * Sets the end of the index in the filename to extract the name of the @@ -75,7 +48,7 @@ public void ensurePathExists(final File path) { * @param endIndex * This marks the index' end. */ - void setEndIndex(final int endIndex); + void setEndIndex(int endIndex); /** * Sets the file's suffix. @@ -83,7 +56,7 @@ public void ensurePathExists(final File path) { * @param fileSuffix * the suffix used for the to be generated files */ - void setFileSuffix(final String fileSuffix); + void setFileSuffix(String fileSuffix); /** * Sets the beginning of the index in the filename to extract the name of @@ -92,7 +65,7 @@ public void ensurePathExists(final File path) { * @param startIndex * This marks the index' beginning. */ - void setStartIndex(final int startIndex); + void setStartIndex(int startIndex); /** * Sets the target path. @@ -100,6 +73,95 @@ public void ensurePathExists(final File path) { * @param target * the basis directory in which the files are stored */ - void setTarget(final String target); + void setTarget(String target); + + /** + * Provides functions and fields that all {@link FilenameExtractor} + * implementing classes may found useful. + * + * @author Pascal Christoph (dr0i) + * + */ + class FilenameUtil { + + private String encoding = "UTF-8"; + private String fileSuffix; + private String filename = "test"; + private String property; + private String target = "tmp"; + private int endIndex; + private int startIndex; + + FilenameUtil() { + } + + /** + * Ensures that path exists. If not, make it. + * + * @param path + * the path of the to be stored file. + */ + public void ensurePathExists(final File path) { + final File parent = path.getAbsoluteFile().getParentFile(); + parent.mkdirs(); + } + + public void setEncoding(final String encoding) { + this.encoding = encoding; + } + + public String getEncoding() { + return encoding; + } + + public void setFileSuffix(final String fileSuffix) { + this.fileSuffix = fileSuffix; + } + + public String getFileSuffix() { + return fileSuffix; + } + + public void setFilename(final String filename) { + this.filename = filename; + } + + public String getFilename() { + return filename; + } + + public void setProperty(final String property) { + this.property = property; + } + + public String getProperty() { + return property; + } + + public void setTarget(final String target) { + this.target = target; + } + + public String getTarget() { + return target; + } + + public void setEndIndex(final int endIndex) { + this.endIndex = endIndex; + } + + public int getEndIndex() { + return endIndex; + } + + public void setStartIndex(final int startIndex) { + this.startIndex = startIndex; + } + + public int getStartIndex() { + return startIndex; + } + + } } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java index 878623953..abc3aaeb9 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/GenericXmlHandler.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.xml; -import java.util.regex.Pattern; +package org.metafacture.xml; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.StreamReceiver; @@ -24,8 +23,10 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; +import java.util.regex.Pattern; /** * A generic xml reader. @@ -41,6 +42,8 @@ public final class GenericXmlHandler extends DefaultXmlPipe { public static final String DEFAULT_RECORD_TAG = "record"; + public static final boolean EMIT_NAMESPACE = false; + private static final Pattern TABS = Pattern.compile("\t+"); private String recordTagName = DEFAULT_RECORD_TAG; @@ -48,15 +51,12 @@ public final class GenericXmlHandler extends DefaultXmlPipe { private boolean inRecord; private StringBuilder valueBuffer = new StringBuilder(); - public static final boolean EMIT_NAMESPACE = false; private boolean emitNamespace = EMIT_NAMESPACE; public GenericXmlHandler() { - super(); - final String recordTagNameProperty = System.getProperty( - "org.culturegraph.metamorph.xml.recordtag"); + final String recordTagNameProperty = System.getProperty("org.culturegraph.metamorph.xml.recordtag"); if (recordTagNameProperty != null) { - recordTagName = recordTagNameProperty; + recordTagName = recordTagNameProperty; } } @@ -71,7 +71,6 @@ public GenericXmlHandler() { */ @Deprecated public GenericXmlHandler(final String recordTagName) { - super(); this.recordTagName = recordTagName; } @@ -85,7 +84,7 @@ public GenericXmlHandler(final String recordTagName) { * * @param recordTagName the tag name which marks the start of a record. */ - public void setRecordTagName(String recordTagName) { + public void setRecordTagName(final String recordTagName) { this.recordTagName = recordTagName; } @@ -103,7 +102,7 @@ public String getRecordTagName() { * @param emitNamespace set to "true" if namespace should be emitted. Defaults * to "false". */ - public void setEmitNamespace(boolean emitNamespace) { + public void setEmitNamespace(final boolean emitNamespace) { this.emitNamespace = emitNamespace; } @@ -112,22 +111,23 @@ public boolean getEmitNamespace() { } @Override - public void startElement(final String uri, final String localName, - final String qName, final Attributes attributes) { - + public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) { if (inRecord) { writeValue(); if (emitNamespace) { getReceiver().startEntity(qName); - } else { + } + else { getReceiver().startEntity(localName); } writeAttributes(attributes); - } else if (localName.equals(recordTagName)) { + } + else if (localName.equals(recordTagName)) { final String identifier = attributes.getValue("id"); if (identifier == null) { getReceiver().startRecord(""); - } else { + } + else { getReceiver().startRecord(identifier); } writeAttributes(attributes); @@ -136,14 +136,14 @@ public void startElement(final String uri, final String localName, } @Override - public void endElement(final String uri, final String localName, - final String qName) { + public void endElement(final String uri, final String localName, final String qName) { if (inRecord) { writeValue(); if (localName.equals(recordTagName)) { inRecord = false; getReceiver().endRecord(); - } else { + } + else { getReceiver().endEntity(); } } @@ -152,8 +152,7 @@ public void endElement(final String uri, final String localName, @Override public void characters(final char[] chars, final int start, final int length) { if (inRecord) { - valueBuffer.append(TABS.matcher(new String(chars, start, length)) - .replaceAll("")); + valueBuffer.append(TABS.matcher(new String(chars, start, length)).replaceAll("")); } } @@ -169,11 +168,7 @@ private void writeAttributes(final Attributes attributes) { final int length = attributes.getLength(); for (int i = 0; i < length; ++i) { - String name; - if (emitNamespace) { - name = attributes.getQName(i); - } else - name = attributes.getLocalName(i); + final String name = emitNamespace ? attributes.getQName(i) : attributes.getLocalName(i); final String value = attributes.getValue(i); getReceiver().literal(name, value); } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/RecordIdentifier.java b/metafacture-xml/src/main/java/org/metafacture/xml/RecordIdentifier.java index 8960e3019..4ac72e4f8 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/RecordIdentifier.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/RecordIdentifier.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; /** @@ -32,6 +33,6 @@ public interface RecordIdentifier { * @param property * the property which will be used to extract a record name. */ - public void setProperty(final String property); + void setProperty(String property); } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java index 0448eab91..4cfb69c28 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/SimpleXmlEncoder.java @@ -13,17 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.xml; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; +package org.metafacture.xml; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.XmlUtil; @@ -36,6 +27,16 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultStreamPipe; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; +import java.util.Map; +import java.util.Properties; + /** * * Encodes a stream as XML @@ -84,6 +85,9 @@ public final class SimpleXmlEncoder extends DefaultStreamPipe entry : properties.entrySet()) { @@ -108,7 +113,8 @@ public void setNamespaceFile(final URL url) { final Properties properties; try { properties = ResourceUtil.loadProperties(url); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException("Failed to load namespaces list", e); } for (final Entry entry : properties.entrySet()) { @@ -120,9 +126,13 @@ public void setWriteXmlHeader(final boolean writeXmlHeader) { this.writeXmlHeader = writeXmlHeader; } - public void setXmlHeaderEncoding(final String xmlHeaderEncoding) { this.xmlHeaderEncoding = xmlHeaderEncoding; } + public void setXmlHeaderEncoding(final String xmlHeaderEncoding) { + this.xmlHeaderEncoding = xmlHeaderEncoding; + } - public void setXmlHeaderVersion(final String xmlHeaderVersion) { this.xmlHeaderVersion = xmlHeaderVersion; } + public void setXmlHeaderVersion(final String xmlHeaderVersion) { + this.xmlHeaderVersion = xmlHeaderVersion; + } public void setWriteRootTag(final boolean writeRootTag) { this.writeRootTag = writeRootTag; @@ -140,7 +150,8 @@ public void setNamespaces(final Map namespaces) { public void startRecord(final String identifier) { if (separateRoots) { writeHeader(); - } else if (atStreamStart) { + } + else if (atStreamStart) { writeHeader(); sendAndClearData(); } @@ -183,9 +194,11 @@ public void endEntity() { public void literal(final String name, final String value) { if (name.isEmpty()) { element.setText(value); - } else if (name.startsWith(ATTRIBUTE_MARKER)) { + } + else if (name.startsWith(ATTRIBUTE_MARKER)) { element.addAttribute(name.substring(1), value); - } else { + } + else { element.createChild(name).setText(value); } } @@ -263,7 +276,7 @@ private static final class Element { private String text = ""; private List children = NO_CHILDREN; - public Element(final String name) { + Element(final String name) { this.name = name; this.parent = null; } @@ -273,9 +286,9 @@ private Element(final String name, final Element parent) { this.parent = parent; } - public void addAttribute(final String name, final String value) { + public void addAttribute(final String attributeName, final String value) { attributes.append(" "); - attributes.append(name); + attributes.append(attributeName); attributes.append(BEGIN_ATTRIBUTE); writeEscaped(attributes, value); attributes.append(END_ATTRIBUTE); @@ -285,8 +298,8 @@ public void setText(final String text) { this.text = text; } - public Element createChild(final String name) { - final Element child = new Element(name, this); + public Element createChild(final String attributeName) { + final Element child = new Element(attributeName, this); if (children == NO_CHILDREN) { children = new ArrayList(); } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java b/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java index 1b563b1f8..623088949 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/XmlDecoder.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.xml; -import java.io.IOException; -import java.io.Reader; +package org.metafacture.xml; import org.metafacture.framework.FluxCommand; import org.metafacture.framework.MetafactureException; @@ -25,6 +23,7 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultObjectPipe; + import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; @@ -32,6 +31,8 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; +import java.io.IOException; +import java.io.Reader; /** * Reads an XML file and passes the XML events to a receiver. @@ -43,18 +44,17 @@ @In(Reader.class) @Out(XmlReceiver.class) @FluxCommand("decode-xml") -public final class XmlDecoder - extends DefaultObjectPipe { +public final class XmlDecoder extends DefaultObjectPipe { private static final String SAX_PROPERTY_LEXICAL_HANDLER = "http://xml.org/sax/properties/lexical-handler"; private final XMLReader saxReader; public XmlDecoder() { - super(); try { saxReader = XMLReaderFactory.createXMLReader(); - } catch (SAXException e) { + } + catch (final SAXException e) { throw new MetafactureException(e); } } @@ -63,9 +63,11 @@ public XmlDecoder() { public void process(final Reader reader) { try { saxReader.parse(new InputSource(reader)); - } catch (IOException e) { + } + catch (final IOException e) { throw new MetafactureException(e); - } catch (SAXException e) { + } + catch (final SAXException e) { throw new MetafactureException(e); } } @@ -78,9 +80,11 @@ protected void onSetReceiver() { saxReader.setErrorHandler(getReceiver()); try { saxReader.setProperty(SAX_PROPERTY_LEXICAL_HANDLER, getReceiver()); - } catch (SAXNotRecognizedException e) { + } + catch (final SAXNotRecognizedException e) { throw new MetafactureException(e); - } catch (SAXNotSupportedException e) { + } + catch (final SAXNotSupportedException e) { throw new MetafactureException(e); } } diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/XmlElementSplitter.java b/metafacture-xml/src/main/java/org/metafacture/xml/XmlElementSplitter.java index 44ef2894b..6ecfbd31c 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/XmlElementSplitter.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/XmlElementSplitter.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.xml; -import java.util.HashSet; +package org.metafacture.xml; import org.metafacture.commons.XmlUtil; import org.metafacture.framework.FluxCommand; @@ -25,9 +24,13 @@ import org.metafacture.framework.annotations.In; import org.metafacture.framework.annotations.Out; import org.metafacture.framework.helpers.DefaultXmlPipe; + import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import java.util.HashSet; +import java.util.Set; + /** * An XML Element splitter. * @@ -39,16 +42,16 @@ @FluxCommand("split-xml-elements") public final class XmlElementSplitter extends DefaultXmlPipe { - private String Element; + private String element; private StringBuilder builder = new StringBuilder(); - private HashSet namespaces = new HashSet<>(); - private boolean inElement = false; - private int recordCnt = 0; + private Set namespaces = new HashSet<>(); + private boolean inElement; + private int recordCnt; private String root; private String rootStart = ""; private String rootEnd = ""; private String xmlDeclaration = ""; - private int ElementDepth = 0; + private int elementDepth; /** * Default constructor @@ -62,9 +65,9 @@ public XmlElementSplitter() { * @param aTopLevelElement the name of the top level XML tag * @param aElementName the name of the tag defining a new Element to be split */ - public XmlElementSplitter(String aTopLevelElement, String aElementName) { - setTopLevelElement(aTopLevelElement); - setElementName(aElementName); + public XmlElementSplitter(final String topLevelElement, final String elementName) { + setTopLevelElement(topLevelElement); + setElementName(elementName); } /** @@ -74,7 +77,7 @@ public XmlElementSplitter(String aTopLevelElement, String aElementName) { * @param name Identifies the elements */ public void setElementName(final String name) { - this.Element = name; + this.element = name; } /** @@ -83,10 +86,10 @@ public void setElementName(final String name) { * @param root the top level element. Don't set it to omit setting top level * element. */ - public void setTopLevelElement(final String root) { - this.root = root; - this.rootStart = "<" + root; - this.rootEnd = ""; + public void setTopLevelElement(final String newRoot) { + root = newRoot; + rootStart = "<" + newRoot; + rootEnd = ""; } /** @@ -102,7 +105,7 @@ public void setXmlDeclaration(final String xmlDeclaration) { } @Override - public void startPrefixMapping(String prefix, String uri) throws SAXException { + public void startPrefixMapping(final String prefix, final String uri) throws SAXException { super.startPrefixMapping(prefix, uri); if (root != null & !prefix.isEmpty() && uri != null) { namespaces.add(" xmlns:" + prefix + "=\"" + uri + "\""); @@ -110,19 +113,20 @@ public void startPrefixMapping(String prefix, String uri) throws SAXException { } @Override - public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) - throws SAXException { + public void startElement(final String uri, final String localName, final String qName, final Attributes attributes) throws SAXException { if (!inElement) { - if (Element.equals(localName)) { + if (element.equals(localName)) { builder = new StringBuilder(); - getReceiver().startRecord(String.valueOf(this.recordCnt++)); + getReceiver().startRecord(String.valueOf(recordCnt)); + ++recordCnt; inElement = true; appendValuesToElement(qName, attributes); - ElementDepth++; + ++elementDepth; } - } else { - if (Element.equals(localName)) { - ElementDepth++; + } + else { + if (element.equals(localName)) { + ++elementDepth; } appendValuesToElement(qName, attributes); } @@ -131,9 +135,8 @@ public void startElement(final String uri, final String localName, final String private void appendValuesToElement(final String qName, final Attributes attributes) { this.builder.append("<" + qName); if (attributes.getLength() > 0) { - for (int i = 0; i < attributes.getLength(); i++) { - builder.append(" " + attributes.getQName(i) + "=\"" - + XmlUtil.escape(attributes.getValue(i)) + "\""); + for (int i = 0; i < attributes.getLength(); ++i) { + builder.append(" " + attributes.getQName(i) + "=\"" + XmlUtil.escape(attributes.getValue(i)) + "\""); } } @@ -144,11 +147,11 @@ private void appendValuesToElement(final String qName, final Attributes attribut public void endElement(final String uri, final String localName, final String qName) throws SAXException { if (inElement) { builder.append(""); - if (Element.equals(localName)) { - if (ElementDepth <= 1) { - StringBuilder sb = new StringBuilder(xmlDeclaration + rootStart); + if (element.equals(localName)) { + if (elementDepth <= 1) { + final StringBuilder sb = new StringBuilder(xmlDeclaration + rootStart); if (this.root != null && namespaces.size() > 0) { - for (String ns : namespaces) { + for (final String ns : namespaces) { sb.append(ns); } sb.append(">"); @@ -159,7 +162,7 @@ public void endElement(final String uri, final String localName, final String qN reset(); return; } - ElementDepth--; + --elementDepth; } } } @@ -168,7 +171,8 @@ public void endElement(final String uri, final String localName, final String qN public void characters(final char[] chars, final int start, final int length) throws SAXException { try { builder.append(XmlUtil.escape(new String(chars, start, length))); - } catch (Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch reset(); } } @@ -176,7 +180,7 @@ public void characters(final char[] chars, final int start, final int length) th private void reset() { inElement = false; builder = new StringBuilder(); - ElementDepth = 0; + elementDepth = 0; } /** diff --git a/metafacture-xml/src/main/java/org/metafacture/xml/XmlFilenameWriter.java b/metafacture-xml/src/main/java/org/metafacture/xml/XmlFilenameWriter.java index 6689f6a31..77ed89d2e 100644 --- a/metafacture-xml/src/main/java/org/metafacture/xml/XmlFilenameWriter.java +++ b/metafacture-xml/src/main/java/org/metafacture/xml/XmlFilenameWriter.java @@ -13,8 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; +import org.metafacture.framework.FluxCommand; +import org.metafacture.framework.MetafactureException; +import org.metafacture.framework.ObjectReceiver; +import org.metafacture.framework.StreamReceiver; +import org.metafacture.framework.annotations.Description; +import org.metafacture.framework.annotations.In; +import org.metafacture.framework.annotations.Out; +import org.metafacture.framework.helpers.DefaultStreamPipe; + +import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.InputSource; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -25,24 +40,10 @@ import java.io.Writer; import java.nio.file.Paths; import java.util.function.Function; - import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; -import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; -import org.metafacture.framework.FluxCommand; -import org.metafacture.framework.MetafactureException; -import org.metafacture.framework.ObjectReceiver; -import org.metafacture.framework.StreamReceiver; -import org.metafacture.framework.annotations.Description; -import org.metafacture.framework.annotations.In; -import org.metafacture.framework.annotations.Out; -import org.metafacture.framework.helpers.DefaultStreamPipe; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xml.sax.InputSource; - /** * A sink, writing an xml file. The filename is constructed from the xpath given * via setProperty(). @@ -50,20 +51,17 @@ * @author Pascal Christoph * @author Christoph Böhme */ -@Description("Writes the xml into the filesystem. The filename is constructed from the xpath given as 'property'.\n" - + " Variables are\n" + "- 'target' (determining the output directory)\n" - + "- 'property' (the element in the XML entity. Constitutes the main part of the file's name.)\n" - + "- 'startIndex' ( a subfolder will be extracted out of the filename. This marks the index' beginning )\n" - + "- 'stopIndex' ( a subfolder will be extracted out of the filename. This marks the index' end )\n") +@Description("Writes the xml into the filesystem. The filename is constructed from the xpath given as 'property'.\n" + // checkstyle-disable-line ClassDataAbstractionCoupling|ClassFanOutComplexity + " Variables are\n" + "- 'target' (determining the output directory)\n" + + "- 'property' (the element in the XML entity. Constitutes the main part of the file's name.)\n" + + "- 'startIndex' ( a subfolder will be extracted out of the filename. This marks the index' beginning )\n" + + "- 'stopIndex' ( a subfolder will be extracted out of the filename. This marks the index' end )\n") @In(StreamReceiver.class) @Out(Void.class) @FluxCommand("write-xml-files") -public final class XmlFilenameWriter - extends DefaultStreamPipe> - implements FilenameExtractor { +public final class XmlFilenameWriter extends DefaultStreamPipe> implements FilenameExtractor { - private static final Logger LOG = LoggerFactory.getLogger( - XmlFilenameWriter.class); + private static final Logger LOG = LoggerFactory.getLogger(XmlFilenameWriter.class); private final XPath xPath = XPathFactory.newInstance().newXPath(); private final FilenameUtil filenameUtil = new FilenameUtil(); @@ -89,38 +87,38 @@ public void setCompression(final String compression) { @Override public void setEncoding(final String encoding) { - filenameUtil.encoding = encoding; + filenameUtil.setEncoding(encoding); } @Override public String getEncoding() { - return filenameUtil.encoding; + return filenameUtil.getEncoding(); } @Override public void setEndIndex(final int endIndex) { - filenameUtil.endIndex = endIndex; + filenameUtil.setEndIndex(endIndex); } @Override public void setFileSuffix(final String fileSuffix) { - filenameUtil.fileSuffix = fileSuffix; + filenameUtil.setFileSuffix(fileSuffix); } @Override public void setProperty(final String property) { - filenameUtil.property = property; + filenameUtil.setProperty(property); } @Override public void setStartIndex(final int startIndex) { - filenameUtil.startIndex = startIndex; + filenameUtil.setStartIndex(startIndex); } @Override public void setTarget(final String target) { - filenameUtil.target = target; + filenameUtil.setTarget(target); } @Override @@ -133,21 +131,22 @@ public void literal(final String str, final String xml) { filenameUtil.ensurePathExists(file); if (compression == null) { writeXml(xml, file); - } else if ("bz2".equals(compression)) { + } + else if ("bz2".equals(compression)) { final File compressedFile = new File(file.getPath() + ".bz2"); writeXml(xml, compressedFile, this::createBZip2Compressor); } } - private String extractIdentifier(String xml) { + private String extractIdentifier(final String xml) { final String identifier; try { - identifier = xPath.evaluate(this.filenameUtil.property, - new InputSource(new StringReader(xml))); - } catch (XPathExpressionException e) { + identifier = xPath.evaluate(this.filenameUtil.getProperty(), new InputSource(new StringReader(xml))); + } + catch (final XPathExpressionException e) { throw new MetafactureException(e); } - if (identifier == null || identifier.length() < filenameUtil.endIndex) { + if (identifier == null || identifier.length() < filenameUtil.getEndIndex()) { LOG.info("No identifier found, skip writing"); LOG.debug("the xml: {}", xml); return null; @@ -155,37 +154,36 @@ private String extractIdentifier(String xml) { return identifier; } - private File buildTargetFileName(String identifier) { - final String directory = identifier.substring(filenameUtil.startIndex, - filenameUtil.endIndex); - return Paths.get(filenameUtil.target) + private File buildTargetFileName(final String identifier) { + final String directory = identifier.substring(filenameUtil.getStartIndex(), filenameUtil.getEndIndex()); + return Paths.get(filenameUtil.getTarget()) .resolve(directory) - .resolve(identifier + filenameUtil.fileSuffix) + .resolve(identifier + filenameUtil.getFileSuffix()) .toFile(); } - private void writeXml(String xml, File file) { + private void writeXml(final String xml, final File file) { writeXml(xml, file, Function.identity()); } - private void writeXml(String xml, File file, - Function compressorFactory) { + private void writeXml(final String xml, final File file, final Function compressorFactory) { try ( OutputStream fileStream = new FileOutputStream(file); OutputStream compressedStream = compressorFactory.apply(fileStream); - Writer writer = new OutputStreamWriter(compressedStream, - filenameUtil.encoding); + Writer writer = new OutputStreamWriter(compressedStream, filenameUtil.getEncoding()) ) { writer.write(xml); - } catch (IOException | UncheckedIOException e) { + } + catch (final IOException | UncheckedIOException e) { throw new MetafactureException(e); } } - private OutputStream createBZip2Compressor(OutputStream stream) { + private OutputStream createBZip2Compressor(final OutputStream stream) { try { return new BZip2CompressorOutputStream(stream); - } catch (IOException e) { + } + catch (final IOException e) { throw new UncheckedIOException(e); } } diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/CGXmlHandlerTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/CGXmlHandlerTest.java index 6bf0cffd3..602b22b3e 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/CGXmlHandlerTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/CGXmlHandlerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java index 595118409..e376c24b1 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/GenericXMLHandlerTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java index f13bd6f5a..7ea246f0e 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/SimpleXmlEncoderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import static org.junit.Assert.assertEquals; diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/XmlElementSplitterTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/XmlElementSplitterTest.java index 1b99cdb1b..792d84d8c 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/XmlElementSplitterTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/XmlElementSplitterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import static org.mockito.Mockito.inOrder; diff --git a/metafacture-xml/src/test/java/org/metafacture/xml/XmlFilenameWriterTest.java b/metafacture-xml/src/test/java/org/metafacture/xml/XmlFilenameWriterTest.java index bea24a2de..920d46039 100644 --- a/metafacture-xml/src/test/java/org/metafacture/xml/XmlFilenameWriterTest.java +++ b/metafacture-xml/src/test/java/org/metafacture/xml/XmlFilenameWriterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.xml; import static org.junit.Assert.assertEquals; From 85f3e2d4f9936dce6c429be6d90d7ffecc0ad0f9 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Thu, 9 Sep 2021 22:06:16 +0200 Subject: [PATCH 30/30] metamorph/ (main): Fix Checkstyle violations. --- .../metamorph/AbstractMetamorphDomWalker.java | 140 ++++++++-------- .../metafacture/metamorph/CollectFactory.java | 12 +- .../java/org/metafacture/metamorph/Data.java | 12 +- .../metamorph/DefaultErrorHandler.java | 9 +- .../org/metafacture/metamorph/Entity.java | 33 ++-- .../org/metafacture/metamorph/Filter.java | 14 +- .../java/org/metafacture/metamorph/Flush.java | 2 +- .../metamorph/FunctionFactory.java | 12 +- .../metafacture/metamorph/InlineMorph.java | 24 +-- .../org/metafacture/metamorph/MapFactory.java | 23 +-- .../org/metafacture/metamorph/Metamorph.java | 80 +++++---- .../metamorph/MetamorphException.java | 3 +- .../metafacture/metamorph/MorphBuilder.java | 155 ++++++++++-------- .../metamorph/NullInterceptorFactory.java | 4 + .../org/metafacture/metamorph/Registry.java | 1 + .../metamorph/SimpleDataRegistry.java | 4 + .../org/metafacture/metamorph/Splitter.java | 13 +- ...ataRegistry.java => WildcardRegistry.java} | 8 +- .../metamorph/XmlSourceLocation.java | 1 + .../metafacture/metamorph/collectors/All.java | 10 +- .../metafacture/metamorph/collectors/Any.java | 4 + .../metamorph/collectors/Choose.java | 24 +-- .../metamorph/collectors/Combine.java | 18 +- .../metamorph/collectors/Concat.java | 10 +- .../metamorph/collectors/EqualsFilter.java | 44 ++--- .../metamorph/collectors/Group.java | 7 +- .../metamorph/collectors/None.java | 4 + .../metamorph/collectors/Range.java | 39 +++-- .../metamorph/collectors/Square.java | 16 +- .../metamorph/collectors/Tuples.java | 13 +- .../metamorph/functions/AbstractCompose.java | 1 + .../metamorph/functions/AbstractLookup.java | 4 +- .../metamorph/functions/BlackList.java | 8 +- .../metamorph/functions/Buffer.java | 16 +- .../metafacture/metamorph/functions/Case.java | 13 +- .../metamorph/functions/Compose.java | 4 + .../metamorph/functions/Constant.java | 4 + .../metamorph/functions/Contains.java | 4 + .../metamorph/functions/Count.java | 4 + .../metamorph/functions/DateFormat.java | 19 ++- .../metamorph/functions/Equals.java | 4 + .../metamorph/functions/HtmlAnchor.java | 15 +- .../metafacture/metamorph/functions/ISBN.java | 23 ++- .../metamorph/functions/Lookup.java | 8 +- .../metamorph/functions/NormalizeUTF8.java | 10 +- .../metamorph/functions/NotContains.java | 4 + .../metamorph/functions/NotEquals.java | 4 + .../metamorph/functions/Occurrence.java | 16 +- .../metamorph/functions/Regexp.java | 21 ++- .../metamorph/functions/Replace.java | 10 +- .../metamorph/functions/Script.java | 27 +-- .../metamorph/functions/SetReplace.java | 4 + .../metamorph/functions/Split.java | 12 +- .../metamorph/functions/Substring.java | 7 +- .../metamorph/functions/SwitchNameValue.java | 13 +- .../metamorph/functions/Timestamp.java | 13 +- .../metafacture/metamorph/functions/Trim.java | 4 + .../metamorph/functions/URLEncode.java | 16 +- .../metamorph/functions/Unique.java | 11 +- .../metamorph/functions/WhiteList.java | 10 +- .../metafacture/metamorph/maps/FileMap.java | 35 ++-- .../metamorph/maps/JndiSqlMap.java | 37 +++-- .../metafacture/metamorph/maps/RestMap.java | 26 +-- .../metafacture/metamorph/maps/SqlMap.java | 44 ++--- .../metamorph/xml/CDataFilter.java | 1 + .../metamorph/xml/CommentsFilter.java | 1 + .../metafacture/metamorph/xml/DomLoader.java | 92 +++++------ .../xml/IgnorableWhitespaceFilter.java | 1 + .../xml/LexicalHandlerXmlFilter.java | 23 +-- .../metafacture/metamorph/xml/Location.java | 1 + .../metamorph/xml/LocationAnnotator.java | 25 ++- .../metafacture/metamorph/MetamorphTest.java | 1 + .../metafacture/metamorph/SplitterTest.java | 1 + .../metafacture/metamorph/TestHelpers.java | 1 + .../metamorph/TestMetamorphBasics.java | 1 + .../metamorph/TestMetamorphMacros.java | 1 + .../metamorph/collectors/AllTest.java | 1 + .../metamorph/collectors/AnyTest.java | 1 + .../metamorph/collectors/ChooseTest.java | 1 + .../metamorph/collectors/CombineTest.java | 1 + .../metamorph/collectors/ConcatTest.java | 1 + .../metamorph/collectors/EntityTest.java | 1 + .../collectors/EqualsFilterTest.java | 1 + .../metamorph/collectors/GroupTest.java | 1 + .../metamorph/collectors/NoneTest.java | 1 + .../metamorph/collectors/RangeTest.java | 1 + .../metamorph/collectors/SquareTest.java | 1 + .../collectors/TestCollectorBasics.java | 1 + .../metamorph/collectors/TestCollectorIf.java | 1 + .../metamorph/collectors/TuplesTest.java | 1 + .../metamorph/functions/DateFormatTest.java | 1 + .../metamorph/functions/ISBNTest.java | 1 + .../metamorph/functions/LookupTest.java | 1 + .../functions/NormalizeUTF8Test.java | 1 + .../metamorph/functions/RegexpTest.java | 1 + .../metamorph/functions/ScriptTest.java | 1 + .../metamorph/functions/SplitTest.java | 1 + .../functions/StringOperationsTest.java | 1 + .../functions/SwitchNameValueTest.java | 1 + .../functions/TestFunctionBasics.java | 1 + .../functions/TestVariousFunctions.java | 1 + .../metamorph/functions/UniqueTest.java | 1 + .../metamorph/maps/FileMapTest.java | 1 + .../metamorph/maps/JavaMapTest.java | 1 + .../metamorph/xml/DomLoaderTest.java | 1 + 105 files changed, 786 insertions(+), 582 deletions(-) rename metamorph/src/main/java/org/metafacture/metamorph/{WildcardDataRegistry.java => WildcardRegistry.java} (97%) diff --git a/metamorph/src/main/java/org/metafacture/metamorph/AbstractMetamorphDomWalker.java b/metamorph/src/main/java/org/metafacture/metamorph/AbstractMetamorphDomWalker.java index 32a8d2700..4f884b399 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/AbstractMetamorphDomWalker.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/AbstractMetamorphDomWalker.java @@ -13,21 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.metamorph; import org.metafacture.commons.StringUtil; import org.metafacture.commons.types.ScopedHashMap; import org.metafacture.metamorph.api.MorphBuildException; import org.metafacture.metamorph.xml.DomLoader; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.xml.sax.InputSource; +import java.util.HashMap; +import java.util.Map; /** * Builds a {@link Metamorph} from an xml description @@ -99,8 +100,8 @@ protected final MapFactory getMapFactory() { return mapFactory; } - public final void walk(final InputSource morphScript, final Map vars) { - this.vars.putAll(vars); + public final void walk(final InputSource morphScript, final Map newVars) { + vars.putAll(newVars); walk(morphScript); } @@ -108,6 +109,47 @@ public final void walk(final InputSource morphScript) { walk(DomLoader.parse(SCHEMA_FILE, morphScript)); } + protected final void walk(final Document doc) { + functionFactory = new FunctionFactory(); + collectFactory = new CollectFactory(); + collectFactory.registerClass(ENTITY, Entity.class); + mapFactory = new MapFactory(); + + init(); + + final Element root = doc.getDocumentElement(); + final int version = Integer.parseInt(attribute(root, AttributeName.VERSION)); + checkVersionCompatibility(version); + + setEntityMarker(attribute(root, AttributeName.ENTITY_MARKER)); + + for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) { + switch (tagOf(node)) { + case META: + handleMeta(node); + break; + case FUNCTIONS: + handleFunctionDefinitions(node); + break; + case RULES: + handleRules(node); + break; + case MAPS: + handleMaps(node); + break; + case VARS: + handleVars(node); + break; + case MACROS: + handleMacros(node); + break; + default: + illegalChild(node); + } + } + finish(); + } + private static Tags tagOf(final Node child) { return Tags.valueOf(child.getLocalName().toUpperCase()); } @@ -131,7 +173,7 @@ protected static Map attributeMap(final Node elementNode) { return attributes; } - protected final String resolveVars(final String string){ + protected final String resolveVars(final String string) { return StringUtil.format(string, Metamorph.VAR_START, Metamorph.VAR_END, ignoreMissingVars, vars); } @@ -141,7 +183,7 @@ protected final void setIgnoreMissingVars(final boolean ignoreMissingVars) { protected final String resolvedAttribute(final Node node, final AttributeName attr) { final String value = attribute(node, attr); - if(null==value){ + if (null == value) { return null; } return resolveVars(value); @@ -159,48 +201,6 @@ protected final Map resolvedAttributeMap(final Node node) { return attributes; } - protected final void walk(final Document doc) { - functionFactory = new FunctionFactory(); - collectFactory = new CollectFactory(); - collectFactory.registerClass(ENTITY, Entity.class); - mapFactory = new MapFactory(); - - init(); - - final Element root = doc.getDocumentElement(); - final int version = Integer.parseInt(attribute(root, AttributeName.VERSION)); - checkVersionCompatibility(version); - - setEntityMarker(attribute(root, AttributeName.ENTITY_MARKER)); - - for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) { - - switch (tagOf(node)) { - case META: - handleMeta(node); - break; - case FUNCTIONS: - handleFunctionDefinitions(node); - break; - case RULES: - handleRules(node); - break; - case MAPS: - handleMaps(node); - break; - case VARS: - handleVars(node); - break; - case MACROS: - handleMacros(node); - break; - default: - illegalChild(node); - } - } - finish(); - } - private void handleMeta(final Node node) { for (Node metaEntryNode = node.getFirstChild(); metaEntryNode != null; metaEntryNode = metaEntryNode .getNextSibling()) { @@ -231,39 +231,44 @@ private void handleRule(final Node node) { enterIf(child); handleRule(child.getFirstChild()); exitIf(child); - } else if (POSTPROCESS.equals(child.getLocalName())) { + } + else if (POSTPROCESS.equals(child.getLocalName())) { handlePostprocess(child); - } else if (ENTITY_NAME.equals(child.getLocalName())) { + } + else if (ENTITY_NAME.equals(child.getLocalName())) { enterName(child); handleRule(child.getFirstChild()); exitName(child); - } else { + } + else { handleRule(child); } } exitCollect(node); - } else if (DATA.equals(nodeName)) { + } + else if (DATA.equals(nodeName)) { enterData(node); handlePostprocess(node); exitData(node); - } else if (CALL_MACRO.equals(nodeName)){ + } + else if (CALL_MACRO.equals(nodeName)) { final String macroName = attribute(node, AttributeName.NAME); final Node macroNode = macros.get(macroName); - if (macroNode==null){ + if (macroNode == null) { throw new MorphBuildException("Macro '" + macroName + "' undefined!"); } vars = new ScopedHashMap(vars); vars.putAll(resolvedAttributeMap(node)); handleRules(macroNode); vars = vars.getOuterScope(); - }else { + } + else { illegalChild(node); } } private void handlePostprocess(final Node node) { - for (Node functionNode = node.getFirstChild(); functionNode != null; functionNode = functionNode - .getNextSibling()) { + for (Node functionNode = node.getFirstChild(); functionNode != null; functionNode = functionNode.getNextSibling()) { handleFunction(functionNode); } } @@ -272,7 +277,8 @@ private void handleMaps(final Node node) { for (Node mapNode = node.getFirstChild(); mapNode != null; mapNode = mapNode.getNextSibling()) { if (MAP.equals(mapNode.getLocalName())) { handleInternalMap(mapNode); - } else { + } + else { handleMapClass(mapNode); } } @@ -296,29 +302,27 @@ private void handleMacros(final Node node) { private void checkVersionCompatibility(final int version) { if (version < LOWEST_COMPATIBLE_VERSION || version > CURRENT_VERSION) { - throw new MorphBuildException("Version " + version - + " of definition file not supported by metamorph version " + CURRENT_VERSION); + throw new MorphBuildException("Version " + version + " of definition file not supported by metamorph version " + CURRENT_VERSION); } } protected final void illegalChild(final Node child) { - throw new MorphBuildException("Schema mismatch: illegal tag " + child.getLocalName() + " in node " - + child.getParentNode().getLocalName()); + throw new MorphBuildException("Schema mismatch: illegal tag " + child.getLocalName() + " in node " + child.getParentNode().getLocalName()); } protected abstract void init(); protected abstract void finish(); - protected abstract void setEntityMarker(final String entityMarker); + protected abstract void setEntityMarker(String entityMarker); - protected abstract void handleInternalMap(final Node mapNode); + protected abstract void handleInternalMap(Node mapNode); - protected abstract void handleMapClass(final Node mapNode); + protected abstract void handleMapClass(Node mapNode); - protected abstract void handleMetaEntry(final String name, final String value); + protected abstract void handleMetaEntry(String name, String value); - protected abstract void handleFunctionDefinition(final Node functionDefNode); + protected abstract void handleFunctionDefinition(Node functionDefNode); protected abstract void enterData(Node node); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/CollectFactory.java b/metamorph/src/main/java/org/metafacture/metamorph/CollectFactory.java index f817c9ce9..aa3d463f1 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/CollectFactory.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/CollectFactory.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; - -import java.io.IOException; +package org.metafacture.metamorph; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.reflection.ObjectFactory; import org.metafacture.framework.MetafactureException; import org.metafacture.metamorph.api.Collect; +import java.io.IOException; + /** * Creates the collectors available in Metamorph. * @@ -33,9 +33,9 @@ final class CollectFactory extends ObjectFactory { CollectFactory() { try { - loadClassesFromMap(ResourceUtil.loadProperties( - "morph-collectors.properties"), Collect.class); - } catch (IOException e) { + loadClassesFromMap(ResourceUtil.loadProperties("morph-collectors.properties"), Collect.class); + } + catch (final IOException e) { throw new MetafactureException("Failed to load collectors list", e); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Data.java b/metamorph/src/main/java/org/metafacture/metamorph/Data.java index e7dff0efe..2ad7a98d4 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Data.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Data.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import org.metafacture.commons.StringUtil; @@ -28,13 +29,12 @@ final class Data extends AbstractNamedValuePipe { private String name; - @Override - public void receive(final String recName, final String recValue, - final NamedValueSource source, final int recordCount, - final int entityCount) { + Data() { + } - getNamedValueReceiver().receive(StringUtil.fallback(name, recName), - recValue, this, recordCount, entityCount); + @Override + public void receive(final String recName, final String recValue, final NamedValueSource source, final int recordCount, final int entityCount) { + getNamedValueReceiver().receive(StringUtil.fallback(name, recName), recValue, this, recordCount, entityCount); } public void setName(final String name) { diff --git a/metamorph/src/main/java/org/metafacture/metamorph/DefaultErrorHandler.java b/metamorph/src/main/java/org/metafacture/metamorph/DefaultErrorHandler.java index 484ad9ce8..be7dcdfa7 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/DefaultErrorHandler.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/DefaultErrorHandler.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; +package org.metafacture.metamorph; import org.metafacture.metamorph.api.MorphErrorHandler; @@ -26,11 +26,12 @@ */ public final class DefaultErrorHandler implements MorphErrorHandler { + public DefaultErrorHandler() { + } + @Override public void error(final Exception exception) { - throw new MetamorphException( - "Error while executing the Metamorph transformation pipeline: " + - exception.getMessage(), exception); + throw new MetamorphException("Error while executing the Metamorph transformation pipeline: " + exception.getMessage(), exception); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Entity.java b/metamorph/src/main/java/org/metafacture/metamorph/Entity.java index ac7bb92c9..016fbe9e6 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Entity.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Entity.java @@ -13,13 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Supplier; +package org.metafacture.metamorph; import org.metafacture.commons.StringUtil; import org.metafacture.flowcontrol.StreamBuffer; @@ -28,6 +23,12 @@ import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + /** * Corresponds to the <entity> tag. * @@ -64,29 +65,31 @@ protected void emit() { if (namedValueReceiver instanceof Entity) { final Entity parent = (Entity) namedValueReceiver; parent.receive(null, null, this, getRecordCount(), getEntityCount()); - } else { + } + else { write(receiver.get()); } } - private void write(final StreamReceiver receiver) { + private void write(final StreamReceiver currentReceiver) { if (!buffer.isEmpty()) { - receiver.startEntity(StringUtil.fallback(currentName, getName())); - buffer.setReceiver(receiver); + currentReceiver.startEntity(StringUtil.fallback(currentName, getName())); + buffer.setReceiver(currentReceiver); buffer.replay(); - receiver.endEntity(); + currentReceiver.endEntity(); } } @Override - protected void receive(final String name, final String value, - final NamedValueSource source) { + protected void receive(final String name, final String value, final NamedValueSource source) { if (source == nameSource) { currentName = value; - } else if (source instanceof Entity) { + } + else if (source instanceof Entity) { final Entity child = (Entity) source; child.write(buffer); - } else { + } + else { buffer.literal(name, value); } sourcesLeft.remove(source); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Filter.java b/metamorph/src/main/java/org/metafacture/metamorph/Filter.java index 9b990c58e..eafb1e22f 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Filter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Filter.java @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; +package org.metafacture.metamorph; import org.metafacture.flowcontrol.StreamBuffer; import org.metafacture.framework.FluxCommand; @@ -45,29 +45,22 @@ public final class Filter extends DefaultStreamPipe { private final SingleValue singleValue = new SingleValue(); private final Metamorph metamorph; - public Filter(final String morphDef) { - super(); metamorph = new Metamorph(morphDef); metamorph.setReceiver(singleValue); } public Filter(final Metamorph metamorph) { - super(); this.metamorph = metamorph; metamorph.setReceiver(singleValue); } public Filter(final String morphDef, final Map vars) { - - super(); metamorph = new Metamorph(morphDef, vars); metamorph.setReceiver(singleValue); } public Filter(final String morphDef, final InterceptorFactory interceptorFactory) { - - super(); metamorph = new Metamorph(morphDef, interceptorFactory); metamorph.setReceiver(singleValue); } @@ -77,10 +70,9 @@ protected void onSetReceiver() { buffer.setReceiver(getReceiver()); } - - private void dispatch(){ + private void dispatch() { final String key = singleValue.getValue(); - if(!key.isEmpty()){ + if (!key.isEmpty()) { buffer.replay(); } buffer.clear(); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Flush.java b/metamorph/src/main/java/org/metafacture/metamorph/Flush.java index 0d69bc00b..e23cd8a35 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Flush.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Flush.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import org.metafacture.metamorph.api.FlushListener; @@ -20,7 +21,6 @@ import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.SourceLocation; - /** * Flushes a {@link FlushListener} * diff --git a/metamorph/src/main/java/org/metafacture/metamorph/FunctionFactory.java b/metamorph/src/main/java/org/metafacture/metamorph/FunctionFactory.java index e24ae6193..383b3bcac 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/FunctionFactory.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/FunctionFactory.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; - -import java.io.IOException; +package org.metafacture.metamorph; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.reflection.ObjectFactory; import org.metafacture.framework.MetafactureException; import org.metafacture.metamorph.api.Function; +import java.io.IOException; + /** * Creates the functions available in Metamorph. * @@ -33,9 +33,9 @@ final class FunctionFactory extends ObjectFactory { FunctionFactory() { try { - loadClassesFromMap(ResourceUtil.loadProperties( - "morph-functions.properties"), Function.class); - } catch (IOException e) { + loadClassesFromMap(ResourceUtil.loadProperties("morph-functions.properties"), Function.class); + } + catch (final IOException e) { throw new MetafactureException("Failed to load functions list", e); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/InlineMorph.java b/metamorph/src/main/java/org/metafacture/metamorph/InlineMorph.java index a0ff8b92c..704bbb8b5 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/InlineMorph.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/InlineMorph.java @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.io.StringReader; -import java.net.URL; +package org.metafacture.metamorph; import org.metafacture.framework.StreamReceiver; + import org.xml.sax.InputSource; +import java.io.StringReader; +import java.net.URL; + /** * Helper for including Metamorph scripts directly in Java code. *

@@ -72,7 +74,7 @@ private InlineMorph() { * @param owner the object which contains the morph script * @return an instance of {@code InlineMorph} for continuation */ - public static InlineMorph in(Object owner) { + public static InlineMorph in(final Object owner) { return in(owner.getClass()); } @@ -86,11 +88,11 @@ public static InlineMorph in(Object owner) { * @param owner the class which contains the morph script * @return an instance of {@code InlineMorph} for continuation */ - public static InlineMorph in(Class owner) { + public static InlineMorph in(final Class owner) { return new InlineMorph().setClassAsSystemId(owner); } - private InlineMorph setClassAsSystemId(Class owner) { + private InlineMorph setClassAsSystemId(final Class owner) { final URL baseUrl = owner.getResource(""); systemId = baseUrl.toExternalForm(); return this; @@ -102,7 +104,7 @@ private InlineMorph setClassAsSystemId(Class owner) { * @param line the next line of the morph script * @return a reference to {@code this} for continuation */ - public InlineMorph with(String line) { + public InlineMorph with(final String line) { if (scriptBuilder.length() == 0) { appendBoilerplate(line); } @@ -112,7 +114,7 @@ public InlineMorph with(String line) { return this; } - private void appendBoilerplate(String line) { + private void appendBoilerplate(final String line) { final String trimmedLine = line.trim(); if (!trimmedLine.startsWith(""); + scriptBuilder.append(""); } /** @@ -169,7 +169,7 @@ private InputSource createScriptSource() { * send its output. * @return a Metamorph object initialised with the inline script */ - public Metamorph createConnectedTo(StreamReceiver receiver) { + public Metamorph createConnectedTo(final StreamReceiver receiver) { final Metamorph metamorph = create(); metamorph.setReceiver(receiver); return metamorph; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/MapFactory.java b/metamorph/src/main/java/org/metafacture/metamorph/MapFactory.java index 290efb8f2..89af4d789 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/MapFactory.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/MapFactory.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.io.IOException; -import java.util.Map; +package org.metafacture.metamorph; import org.metafacture.commons.ResourceUtil; import org.metafacture.commons.reflection.ObjectFactory; import org.metafacture.framework.MetafactureException; +import java.io.IOException; +import java.util.Map; + /** * Creates the maps available in Metamorph. * @@ -30,13 +31,13 @@ */ final class MapFactory extends ObjectFactory { - MapFactory() { - try { - loadClassesFromMap(ResourceUtil.loadProperties( - "morph-maps.properties"), Map.class); - } catch (IOException e) { - throw new MetafactureException("Failed to load maps list", e); - } - } + MapFactory() { + try { + loadClassesFromMap(ResourceUtil.loadProperties("morph-maps.properties"), Map.class); + } + catch (final IOException e) { + throw new MetafactureException("Failed to load maps list", e); + } + } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Metamorph.java b/metamorph/src/main/java/org/metafacture/metamorph/Metamorph.java index e38b9d052..a2feb6bce 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Metamorph.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Metamorph.java @@ -13,22 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.io.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; +package org.metafacture.metamorph; import org.metafacture.commons.ResourceUtil; import org.metafacture.framework.FluxCommand; @@ -49,26 +35,40 @@ import org.metafacture.metamorph.api.NamedValueReceiver; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.SourceLocation; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.InputSource; +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + /** - * Transforms a data stream send via the {@link StreamReceiver} interface. Use - * {@link MorphBuilder} to create an instance based on an xml description + * Transforms a data stream sent via the {@link StreamReceiver} interface. Use + * {@link MorphBuilder} to create an instance based on an XML description. * * @author Markus Michael Geipel * @author Christoph Böhme */ -@Description("applies a metamorph transformation to the event stream. Metamorph " - + "definition is given in brackets.") +@Description("Applies a metamorph transformation to the event stream. Metamorph definition is given in brackets.") // checkstyle-disable-line ClassDataAbstractionCoupling|ClassFanOutComplexity @In(StreamReceiver.class) @Out(StreamReceiver.class) @FluxCommand("morph") public final class Metamorph implements StreamPipe, NamedValuePipe, Maps { - private static final String ELSE_NESTED_KEYWORD = "_elseNested"; public static final String ELSE_KEYWORD = "_else"; + public static final String ELSE_NESTED_KEYWORD = "_elseNested"; public static final String ELSE_FLATTENED_KEYWORD = "_elseFlattened"; public static final char FEEDBACK_CHAR = '@'; public static final char ESCAPE_CHAR = '\\'; @@ -76,6 +76,8 @@ public final class Metamorph implements StreamPipe, NamedValuePi public static final String VAR_START = "$["; public static final String VAR_END = "]"; + private static final Logger LOG = LoggerFactory.getLogger(Metamorph.class); + private static final String ENTITIES_NOT_BALANCED = "Entity starts and ends are not balanced"; private static final String COULD_NOT_LOAD_MORPH_FILE = "Could not load morph file"; @@ -101,7 +103,6 @@ public final class Metamorph implements StreamPipe, NamedValuePi private boolean elseNested; private boolean elseNestedEntityStarted; private String currentLiteralName; - private static final Logger LOG = LoggerFactory.getLogger(Metamorph.class); protected Metamorph() { // package private @@ -177,23 +178,21 @@ public Metamorph(final InputSource inputSource, final Map vars, init(); } - private void buildPipeline(InputSource inputSource, Map vars, - InterceptorFactory interceptorFactory) { + private void buildPipeline(final InputSource inputSource, final Map vars, final InterceptorFactory interceptorFactory) { try { final MorphBuilder builder = new MorphBuilder(this, interceptorFactory); builder.walk(inputSource, vars); - } catch (RuntimeException e) { - throw new MetamorphException( - "Error while building the Metamorph transformation pipeline: " + - e.getMessage(), e); + } + catch (final RuntimeException e) { // checkstyle-disable-line IllegalCatch + throw new MetamorphException("Error while building the Metamorph transformation pipeline: " + e.getMessage(), e); } } private static InputSource getInputSource(final String morphDef) { try { - return new InputSource( - ResourceUtil.getUrl(morphDef).toExternalForm()); - } catch (final MalformedURLException e) { + return new InputSource(ResourceUtil.getUrl(morphDef).toExternalForm()); + } + catch (final MalformedURLException e) { throw new MorphBuildException(COULD_NOT_LOAD_MORPH_FILE, e); } } @@ -231,7 +230,8 @@ protected void registerNamedValueReceiver(final String source, final NamedValueR else { LOG.warn("Only one of '_else', '_elseFlattened' and '_elseNested' is allowed. Ignoring the superflous ones."); } - } else { + } + else { dataRegistry.register(source, data); } } @@ -257,7 +257,7 @@ public void startRecord(final String identifier) { @Override public void endRecord() { - for(final FlushListener listener: recordEndListener){ + for (final FlushListener listener : recordEndListener) { listener.flush(recordCount, currentEntityCount); } @@ -290,7 +290,6 @@ public void endEntity() { flattener.endEntity(); } - @Override public void literal(final String name, final String value) { currentLiteralName = name; @@ -308,7 +307,8 @@ public void closeStream() { for (final Closeable closeable : resources) { try { closeable.close(); - } catch (final IOException e) { + } + catch (final IOException e) { errorHandler.error(e); } } @@ -357,7 +357,8 @@ private void send(final String path, final String value, final List 1 && name.charAt(0) == ESCAPE_CHAR - && (name.charAt(1) == FEEDBACK_CHAR || name.charAt(1) == ESCAPE_CHAR)) { + if (name.length() > 1 && name.charAt(0) == ESCAPE_CHAR && (name.charAt(1) == FEEDBACK_CHAR || name.charAt(1) == ESCAPE_CHAR)) { unescapedName = name.substring(1); } outputStreamReceiver.literal(unescapedName, value); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/MetamorphException.java b/metamorph/src/main/java/org/metafacture/metamorph/MetamorphException.java index ee928e672..b22901920 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/MetamorphException.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/MetamorphException.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import org.metafacture.framework.MetafactureException; @@ -27,7 +28,7 @@ public class MetamorphException extends MetafactureException { private static final long serialVersionUID = 0L; - public MetamorphException(String message, Throwable cause) { + public MetamorphException(final String message, final Throwable cause) { super(message, cause); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/MorphBuilder.java b/metamorph/src/main/java/org/metafacture/metamorph/MorphBuilder.java index 5b5f5f9e4..bec9ba980 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/MorphBuilder.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/MorphBuilder.java @@ -13,12 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.util.Deque; -import java.util.LinkedList; -import java.util.Map; -import java.util.regex.Pattern; +package org.metafacture.metamorph; import org.metafacture.commons.reflection.ConfigurableClass; import org.metafacture.commons.reflection.ReflectionUtil; @@ -31,8 +27,14 @@ import org.metafacture.metamorph.api.MorphBuildException; import org.metafacture.metamorph.api.NamedValuePipe; import org.metafacture.metamorph.xml.Location; + import org.w3c.dom.Node; +import java.util.Deque; +import java.util.LinkedList; +import java.util.Map; +import java.util.regex.Pattern; + /** * Builds a {@link Metamorph} from an xml description * @@ -53,54 +55,7 @@ public final class MorphBuilder extends AbstractMetamorphDomWalker { private final InterceptorFactory interceptorFactory; private final Deque stack = new LinkedList(); - private static final class StackFrame { - - private final NamedValuePipe headPipe; - - private NamedValuePipe pipe; - private boolean inEntityName; - private boolean inCondition; - - public StackFrame(final NamedValuePipe headPipe) { - this.headPipe = headPipe; - this.pipe = headPipe; - } - - public NamedValuePipe getHeadPipe() { - return headPipe; - } - - public void setPipe(final NamedValuePipe pipe) { - this.pipe = pipe; - } - - public NamedValuePipe getPipe() { - return pipe; - } - - public void setInEntityName(final boolean inEntityName) { - this.inEntityName = inEntityName; - } - - public boolean isInEntityName() { - return inEntityName; - } - - public void setInCondition(final boolean inCondition) { - this.inCondition = inCondition; - } - - public boolean isInCondition() { - return inCondition; - } - - } - - protected MorphBuilder(final Metamorph metamorph, - final InterceptorFactory interceptorFactory) { - - super(); - + protected MorphBuilder(final Metamorph metamorph, final InterceptorFactory interceptorFactory) { this.metamorph = metamorph; this.interceptorFactory = interceptorFactory; stack.push(new StackFrame(metamorph)); @@ -142,9 +97,11 @@ protected void handleMapClass(final Node mapNode) { final ConfigurableClass mapClass = ReflectionUtil.loadClass(className, Map.class); map = mapClass.newInstance(attributes); - } else if (getMapFactory().containsKey(mapNode.getLocalName())) { + } + else if (getMapFactory().containsKey(mapNode.getLocalName())) { map = getMapFactory().newInstance(mapNode.getLocalName(), attributes); - } else { + } + else { throw new MorphBuildException("Map " + mapNode.getLocalName() + NOT_FOUND); } @@ -159,13 +116,15 @@ protected void handleFunctionDefinition(final Node functionDefNode) { final String className = resolvedAttribute(functionDefNode, AttributeName.CLASS); try { clazz = Thread.currentThread().getContextClassLoader().loadClass(className); - } catch (final ClassNotFoundException e) { + } + catch (final ClassNotFoundException e) { throw new MorphBuildException("Function " + className + NOT_FOUND, e); } if (Function.class.isAssignableFrom(clazz)) { getFunctionFactory().registerClass(resolvedAttribute(functionDefNode, AttributeName.NAME), (Class) clazz); - } else { + } + else { throw new MorphBuildException(className + " does not implement interface 'Function'"); } } @@ -195,7 +154,8 @@ protected void enterData(final Node dataNode) { final NamedValuePipe delegate; if (interceptor == null) { delegate = data; - } else { + } + else { delegate = interceptor; data.addNamedValueSource(delegate); } @@ -214,7 +174,8 @@ protected void exitData(final Node node) { final NamedValuePipe delegate; if (interceptor == null) { delegate = dataPipe; - } else { + } + else { delegate = interceptor; delegate.addNamedValueSource(dataPipe); } @@ -223,10 +184,12 @@ protected void exitData(final Node node) { if (parent.isInEntityName()) { // Protected xsd schema and by assertion in enterName: ((Entity) parent.getPipe()).setNameSource(delegate); - } else if (parent.isInCondition()) { + } + else if (parent.isInCondition()) { // Protected xsd schema and by assertion in enterIf: ((ConditionAware) parent.getPipe()).setConditionSource(delegate); - } else { + } + else { parent.getPipe().addNamedValueSource(delegate); } } @@ -272,7 +235,8 @@ protected void enterCollect(final Node node) { if (ENTITY.equals(node.getLocalName())) { collect = getCollectFactory().newInstance(node.getLocalName(), attributes, metamorph); - } else { + } + else { collect = getCollectFactory().newInstance(node.getLocalName(), attributes); } collect.setSourceLocation(getSourceLocation(node)); @@ -297,7 +261,8 @@ protected void exitCollect(final Node node) { // instances of Entity. If an interceptor is inserted between // entity elements this mechanism will break. delegate = tailPipe; - } else { + } + else { delegate = interceptor; delegate.addNamedValueSource(tailPipe); } @@ -306,10 +271,12 @@ protected void exitCollect(final Node node) { if (parent.isInEntityName()) { // Protected xsd schema and by assertion in enterName: ((Entity) parent.getPipe()).setNameSource(delegate); - } else if (parent.isInCondition()) { + } + else if (parent.isInCondition()) { // Protected xsd schema and by assertion in enterIf: ((ConditionAware) parent.getPipe()).setConditionSource(delegate); - } else { + } + else { parent.getPipe().addNamedValueSource(delegate); } @@ -328,12 +295,14 @@ private void registerFlush(final String flushWith, final FlushListener flushList final FlushListener delegate; if (interceptor == null) { delegate = flushListener; - } else { + } + else { delegate = interceptor; } if (key.equals(RECORD)) { metamorph.registerRecordEndFlush(delegate); - } else { + } + else { metamorph.registerNamedValueReceiver(key, new Flush(delegate)); } } @@ -350,13 +319,15 @@ protected void handleFunction(final Node functionNode) { final ConfigurableClass functionClass = ReflectionUtil.loadClass(className, Function.class); function = functionClass.newInstance(attributes); - } else if (getFunctionFactory().containsKey(functionNode.getLocalName())) { + } + else if (getFunctionFactory().containsKey(functionNode.getLocalName())) { final String flushWith = attributes.remove(AttributeName.FLUSH_WITH.getString()); function = getFunctionFactory().newInstance(functionNode.getLocalName(), attributes); if (null != flushWith) { registerFlush(flushWith, function); } - } else { + } + else { throw new MorphBuildException(functionNode.getLocalName() + NOT_FOUND); } @@ -378,7 +349,8 @@ protected void handleFunction(final Node functionNode) { final NamedValuePipe delegate; if (interceptor == null) { delegate = function; - } else { + } + else { delegate = interceptor; function.addNamedValueSource(delegate); } @@ -392,4 +364,47 @@ private XmlSourceLocation getSourceLocation(final Node node) { Location.USER_DATA_ID)); } + private static final class StackFrame { + + private final NamedValuePipe headPipe; + + private NamedValuePipe pipe; + private boolean inEntityName; + private boolean inCondition; + + StackFrame(final NamedValuePipe headPipe) { + this.headPipe = headPipe; + this.pipe = headPipe; + } + + public NamedValuePipe getHeadPipe() { + return headPipe; + } + + public void setPipe(final NamedValuePipe pipe) { + this.pipe = pipe; + } + + public NamedValuePipe getPipe() { + return pipe; + } + + public void setInEntityName(final boolean inEntityName) { + this.inEntityName = inEntityName; + } + + public boolean isInEntityName() { + return inEntityName; + } + + public void setInCondition(final boolean inCondition) { + this.inCondition = inCondition; + } + + public boolean isInCondition() { + return inCondition; + } + + } + } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/NullInterceptorFactory.java b/metamorph/src/main/java/org/metafacture/metamorph/NullInterceptorFactory.java index 360fc57aa..47c38aaf5 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/NullInterceptorFactory.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/NullInterceptorFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import org.metafacture.metamorph.api.FlushListener; @@ -29,6 +30,9 @@ */ final class NullInterceptorFactory implements InterceptorFactory { + NullInterceptorFactory() { + } + @Override public NamedValuePipe createNamedValueInterceptor() { return null; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Registry.java b/metamorph/src/main/java/org/metafacture/metamorph/Registry.java index 1095a47fd..cdc237d76 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Registry.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Registry.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import java.util.List; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/SimpleDataRegistry.java b/metamorph/src/main/java/org/metafacture/metamorph/SimpleDataRegistry.java index 0cc55dd96..b86dd6ba3 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/SimpleDataRegistry.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/SimpleDataRegistry.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import java.util.ArrayList; @@ -31,6 +32,9 @@ final class SimpleDataRegistry implements Registry { private final Map> map = new HashMap>(); + SimpleDataRegistry() { + } + @Override public void register(final String path, final T value) { List matchingData = map.get(path); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/Splitter.java b/metamorph/src/main/java/org/metafacture/metamorph/Splitter.java index 01d014a48..0646e38b7 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/Splitter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/Splitter.java @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.io.Reader; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.metamorph; import org.metafacture.flowcontrol.StreamBuffer; import org.metafacture.framework.StreamPipe; @@ -27,7 +24,9 @@ import org.metafacture.framework.annotations.Out; import org.metafacture.javaintegration.SingleValue; - +import java.io.Reader; +import java.util.HashMap; +import java.util.Map; /** * Splits a stream based on a morph definition. @@ -71,11 +70,11 @@ public R setReceiver(final String key, final R receiv return receiver; } - private void dispatch(){ + private void dispatch() { final String key = singleValue.getValue(); final StreamReceiver receiver = receiverMap.get(key); - if(null != receiver){ + if (null != receiver) { buffer.setReceiver(receiver); buffer.replay(); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/WildcardDataRegistry.java b/metamorph/src/main/java/org/metafacture/metamorph/WildcardRegistry.java similarity index 97% rename from metamorph/src/main/java/org/metafacture/metamorph/WildcardDataRegistry.java rename to metamorph/src/main/java/org/metafacture/metamorph/WildcardRegistry.java index b64330853..8d309c5db 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/WildcardDataRegistry.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/WildcardRegistry.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph; -import java.util.List; +package org.metafacture.metamorph; import org.metafacture.commons.tries.SimpleRegexTrie; import org.metafacture.commons.tries.WildcardTrie; +import java.util.List; + /** * Implements {@link Registry} with a {@link WildcardTrie}. * @@ -30,6 +31,9 @@ final class WildcardRegistry implements Registry { private final SimpleRegexTrie trie = new SimpleRegexTrie(); + WildcardRegistry() { + } + @Override public void register(final String path, final T value) { trie.put(path, value); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/XmlSourceLocation.java b/metamorph/src/main/java/org/metafacture/metamorph/XmlSourceLocation.java index ced83f902..f05dfd6ed 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/XmlSourceLocation.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/XmlSourceLocation.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import org.metafacture.metamorph.api.SourceLocation; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/All.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/All.java index f13bcfa96..8990a22a9 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/All.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/All.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.collectors; -import java.util.HashSet; -import java.util.Set; +package org.metafacture.metamorph.collectors; import org.metafacture.commons.StringUtil; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; +import java.util.HashSet; +import java.util.Set; + /** * Corresponds to the {@code } tag. * @@ -35,6 +36,9 @@ public final class All extends AbstractFlushingCollect { private final Set sources = new HashSet(); private final Set sourcesLeft = new HashSet(); + public All() { + } + @Override protected void receive(final String name, final String value, final NamedValueSource source) { sourcesLeft.remove(source); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Any.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Any.java index cfbdf1534..df3289813 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Any.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Any.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import org.metafacture.commons.StringUtil; @@ -32,6 +33,9 @@ public final class Any extends AbstractCollect { private boolean receivedInput; private boolean emittedResult; + public Any() { + } + @Override protected void receive(final String name, final String value, final NamedValueSource source) { receivedInput = true; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Choose.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Choose.java index ce622681f..8ea10b752 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Choose.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Choose.java @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.collectors; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.metamorph.collectors; import org.metafacture.commons.StringUtil; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; - +import java.util.HashMap; +import java.util.Map; /** * Corresponds to the {@code } tag. @@ -35,13 +34,15 @@ public final class Choose extends AbstractFlushingCollect { private String value; private String name; private int priority = Integer.MAX_VALUE; - private final Map priorities = - new HashMap(); + private final Map priorities = new HashMap(); private int nextPriority; + public Choose() { + } + @Override protected void emit() { - if(!isEmpty()){ + if (!isEmpty()) { getNamedValueReceiver().receive(StringUtil.fallback(getName(), name), StringUtil.fallback(getValue(), value), this, getRecordCount(), getEntityCount()); @@ -65,13 +66,12 @@ protected void clear() { } @Override - protected void receive(final String name, final String value, - final NamedValueSource source) { + protected void receive(final String newName, final String newValue, final NamedValueSource source) { final int sourcePriority = priorities.get(source).intValue(); if (sourcePriority <= priority) { - this.value = value; - this.name = name; - this.priority = sourcePriority; + name = newName; + value = newValue; + priority = sourcePriority; } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Combine.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Combine.java index 4074a6343..be9c4b85e 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Combine.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Combine.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; +import org.metafacture.commons.StringUtil; +import org.metafacture.metamorph.api.NamedValueSource; +import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.metafacture.commons.StringUtil; -import org.metafacture.metamorph.api.NamedValueSource; -import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; - /** * Corresponds to the <collect> tag. * @@ -35,12 +36,14 @@ public final class Combine extends AbstractFlushingCollect { private final Set sources = new HashSet(); private final Set sourcesLeft = new HashSet(); + public Combine() { + } + @Override protected void emit() { final String name = StringUtil.format(getName(), variables); final String value = StringUtil.format(getValue(), variables); - getNamedValueReceiver().receive(name, value, this, getRecordCount(), - getEntityCount()); + getNamedValueReceiver().receive(name, value, this, getRecordCount(), getEntityCount()); } @Override @@ -49,8 +52,7 @@ protected boolean isComplete() { } @Override - protected void receive(final String name, final String value, - final NamedValueSource source) { + protected void receive(final String name, final String value, final NamedValueSource source) { variables.put(name, value); sourcesLeft.remove(source); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Concat.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Concat.java index 4c17e6845..9e51eee71 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Concat.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Concat.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import org.metafacture.metamorph.api.NamedValueSource; @@ -30,9 +31,11 @@ public final class Concat extends AbstractFlushingCollect { private String prefix = ""; private String postfix = ""; private String delimiter = ""; - private boolean reverse = false; - private String currentDelimiter = ""; + private boolean reverse; + + public Concat() { + } public void setPrefix(final String prefix) { this.prefix = prefix; @@ -71,7 +74,8 @@ protected void receive(final String name, final String value, if (reverse) { builder.insert(0, currentDelimiter); builder.insert(0, value); - } else { + } + else { builder.append(currentDelimiter); builder.append(value); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/EqualsFilter.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/EqualsFilter.java index fc8820a5f..8aaf181a6 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/EqualsFilter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/EqualsFilter.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; +import org.metafacture.commons.StringUtil; +import org.metafacture.metamorph.api.NamedValueSource; +import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; + import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.metafacture.commons.StringUtil; -import org.metafacture.metamorph.api.NamedValueSource; -import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; - /** * Corresponds to the <equalsFilter-literal> tag. Emits data * if values in variables are all equal. @@ -37,42 +38,43 @@ public final class EqualsFilter extends AbstractFlushingCollect { private final Set sourcesLeft = new HashSet(); private boolean isEqual = true; + public EqualsFilter() { + } + @Override protected void emit() { - final String name = StringUtil.format(getName(), this.variables); - final String value = StringUtil.format(getValue(), this.variables); - if (this.isEqual) { - getNamedValueReceiver().receive(name, value, this, - getRecordCount(), getEntityCount()); + final String name = StringUtil.format(getName(), variables); + final String value = StringUtil.format(getValue(), variables); + if (isEqual) { + getNamedValueReceiver().receive(name, value, this, getRecordCount(), getEntityCount()); } } @Override protected boolean isComplete() { - return this.sourcesLeft.isEmpty(); + return sourcesLeft.isEmpty(); } @Override - protected void receive(final String name, final String value, - final NamedValueSource source) { - if (this.variables.size() > 0 && !this.variables.containsValue(value)) { - this.isEqual = false; + protected void receive(final String name, final String value, final NamedValueSource source) { + if (variables.size() > 0 && !variables.containsValue(value)) { + isEqual = false; } - this.variables.put(name, value); - this.sourcesLeft.remove(source); + variables.put(name, value); + sourcesLeft.remove(source); } @Override public void onNamedValueSourceAdded(final NamedValueSource namedValueSource) { - this.sources.add(namedValueSource); - this.sourcesLeft.add(namedValueSource); + sources.add(namedValueSource); + sourcesLeft.add(namedValueSource); } @Override protected void clear() { - this.sourcesLeft.addAll(this.sources); - this.variables.clear(); - this.isEqual = true; + sourcesLeft.addAll(sources); + variables.clear(); + isEqual = true; } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Group.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Group.java index a56a50bd4..a55992487 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Group.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Group.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import org.metafacture.commons.StringUtil; @@ -26,9 +27,11 @@ */ public final class Group extends AbstractFlushingCollect { + public Group() { + } + @Override - protected void receive(final String recName, final String recValue, - final NamedValueSource source) { + protected void receive(final String recName, final String recValue, final NamedValueSource source) { getNamedValueReceiver().receive( StringUtil.fallback(getName(), recName), StringUtil.fallback(getValue(), recValue), this, diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/None.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/None.java index 28f9de4e2..4e8f5a694 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/None.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/None.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import org.metafacture.commons.StringUtil; @@ -32,6 +33,9 @@ public final class None extends AbstractCollect { private boolean receivedInput; private boolean emittedResult; + public None() { + } + @Override protected void receive(final String name, final String value, final NamedValueSource source) { receivedInput = true; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Range.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Range.java index efa358672..486661c27 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Range.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Range.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.collectors; -import java.util.Comparator; -import java.util.SortedSet; -import java.util.TreeSet; +package org.metafacture.metamorph.collectors; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; +import java.util.Comparator; +import java.util.SortedSet; +import java.util.TreeSet; /** * Corresponds to the <range> tag. @@ -35,17 +35,7 @@ public final class Range extends AbstractFlushingCollect { private int increment; private Integer first; - /** - * A comparator which defines the sort order of the values in the range - * depending on the increment. - */ - private class IncrementDependingComparator implements Comparator { - - @Override - public int compare(final Integer o1, final Integer o2) { - return Integer.signum(increment) * (o1 - o2); - } - + public Range() { } public int getIncrement() { @@ -72,7 +62,8 @@ protected boolean isComplete() { protected void receive(final String name, final String value, final NamedValueSource source) { if (first == null) { first = Integer.valueOf(value); - } else { + } + else { final int last = Integer.valueOf(value).intValue(); for (int i = first.intValue(); (increment > 0 && i <= last) || (increment < 0 && i >= last); i += increment) { values.add(Integer.valueOf(i)); @@ -87,4 +78,20 @@ protected void clear() { first = null; } + /** + * A comparator which defines the sort order of the values in the range + * depending on the increment. + */ + private class IncrementDependingComparator implements Comparator { + + IncrementDependingComparator() { + } + + @Override + public int compare(final Integer o1, final Integer o2) { + return Integer.signum(increment) * (o1 - o2); + } + + } + } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Square.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Square.java index 3b455921a..3cc19888e 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Square.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Square.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; +import org.metafacture.metamorph.api.NamedValueSource; +import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.metafacture.metamorph.api.NamedValueSource; -import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; - /** * Corresponds to the <collect-literal> tag. * @@ -30,10 +31,14 @@ public final class Square extends AbstractFlushingCollect { private final List values = new ArrayList(); + private String prefix = ""; private String postfix = ""; private String delimiter = ""; + public Square() { + } + public void setPrefix(final String prefix) { this.prefix = prefix; } @@ -50,7 +55,7 @@ public void setDelimiter(final String delimiter) { protected void emit() { Collections.sort(values); final int size = values.size(); - for (int i = 0; i < size; i++) { + for (int i = 0; i < size; ++i) { final String last = values.remove(values.size() - 1); for (final String value : values) { getNamedValueReceiver().receive(getName(), @@ -66,8 +71,7 @@ protected boolean isComplete() { } @Override - protected void receive(final String name, final String value, - final NamedValueSource source) { + protected void receive(final String name, final String value, final NamedValueSource source) { values.add(value); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Tuples.java b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Tuples.java index 77a7d49ad..d36acbf85 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/collectors/Tuples.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/collectors/Tuples.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.collectors; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +package org.metafacture.metamorph.collectors; import org.metafacture.commons.types.ListMap; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFlushingCollect; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * Builds the cross product of the data sources. * @@ -32,9 +33,13 @@ public final class Tuples extends AbstractFlushingCollect { private final ListMap listMap = new ListMap(); + private int minN = 1; private String separator = ""; + public Tuples() { + } + public void setMinN(final int minN) { this.minN = minN; } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractCompose.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractCompose.java index 28acd6eaf..5b3808732 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractCompose.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractCompose.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.Function; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractLookup.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractLookup.java index 5193dfb37..3d03043fe 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractLookup.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/AbstractLookup.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; @@ -28,7 +29,8 @@ protected final String lookup(final String key) { final String returnValue; if (getMapName() == null) { returnValue = getLocalValue(key); - } else { + } + else { returnValue = getValue(getMapName(), key); } return returnValue; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/BlackList.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/BlackList.java index fa01c8206..7f1da50e7 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/BlackList.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/BlackList.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; - +package org.metafacture.metamorph.functions; /** * A function which checks whether the received value @@ -25,10 +24,13 @@ */ public final class BlackList extends AbstractLookup { + public BlackList() { + } + @Override public String process(final String key) { final String returnValue = lookup(key); - if(returnValue==null){ + if (returnValue == null) { return key; } return null; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Buffer.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Buffer.java index a8d7865f5..7e5af9f16 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Buffer.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Buffer.java @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; -import java.util.ArrayList; -import java.util.List; +package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.NamedValueReceiver; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFunction; +import java.util.ArrayList; +import java.util.List; /** * Stores all received values and only releases them on flush. @@ -34,23 +34,21 @@ public final class Buffer extends AbstractFunction { private final List receipts = new ArrayList(); private int currentRecord; - @Override - public void receive(final String name, final String value, - final NamedValueSource source, final int recordCount, - final int entityCount) { + public Buffer() { + } + @Override + public void receive(final String name, final String value, final NamedValueSource source, final int recordCount, final int entityCount) { if (currentRecord != recordCount) { receipts.clear(); currentRecord = recordCount; } receipts.add(new Receipt(name, value, this, recordCount, entityCount)); - } @Override public void flush(final int recordCount, final int entityCount) { - for (final Receipt receipt : receipts) { receipt.send(getNamedValueReceiver()); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Case.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Case.java index f4a9700f7..666132e4f 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Case.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Case.java @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; +import org.metafacture.metamorph.api.MorphBuildException; +import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; + import java.util.Collections; import java.util.HashSet; import java.util.Locale; import java.util.Set; -import org.metafacture.metamorph.api.MorphBuildException; -import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; - /** * Changes the the received value from upper to lower case * or vice versa. @@ -42,6 +43,9 @@ public final class Case extends AbstractSimpleStatelessFunction { LANGUAGES = Collections.unmodifiableSet(set); } + public Case() { + } + @Override public String process(final String value) { if (toUpper) { @@ -56,8 +60,7 @@ public void setTo(final String string) { public void setLanguage(final String language) { if (!LANGUAGES.contains(language)) { - throw new MorphBuildException("Language " + language - + " not supported."); + throw new MorphBuildException("Language " + language + " not supported."); } this.locale = new Locale(language); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Compose.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Compose.java index 8d188a4db..487499400 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Compose.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Compose.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; /** @@ -22,6 +23,9 @@ */ public final class Compose extends AbstractCompose { + public Compose() { + } + @Override public String process(final String value) { return getPrefix() + value + getPostfix(); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Constant.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Constant.java index 331115462..b031a4394 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Constant.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Constant.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; @@ -26,6 +27,9 @@ public final class Constant extends AbstractSimpleStatelessFunction { private String constValue; + public Constant() { + } + @Override public String process(final String value) { return constValue; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Contains.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Contains.java index 9c51f011b..eb497d649 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Contains.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Contains.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractFilter; @@ -24,6 +25,9 @@ */ public final class Contains extends AbstractFilter { + public Contains() { + } + @Override protected boolean accept(final String value) { diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Count.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Count.java index 43e443b27..2aea2b7aa 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Count.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Count.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractStatefulFunction; @@ -27,6 +28,9 @@ public final class Count extends AbstractStatefulFunction { private int count; + public Count() { + } + @Override public String process(final String value) { ++count; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/DateFormat.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/DateFormat.java index 498edab2d..0d240e669 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/DateFormat.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/DateFormat.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; +import org.metafacture.metamorph.api.MorphBuildException; +import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; + import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Collections; @@ -23,9 +27,6 @@ import java.util.Locale; import java.util.Set; -import org.metafacture.metamorph.api.MorphBuildException; -import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; - /** * Format date/time strings in Metamorph. By default the input format is * dd.MM.yyyy and the output format is {@link java.text.DateFormat.Field#LONG}. @@ -121,6 +122,9 @@ int getEraId() { SUPPORTED_LANGUAGES = Collections.unmodifiableSet(set); } + public DateFormat() { + } + @Override public final String process(final String value) { String result; @@ -130,7 +134,8 @@ public final String process(final String value) { c.setTime(sdf.parse(value)); if (era == Era.BC) { c.set(Calendar.ERA, GregorianCalendar.BC); - } else if (era == Era.AD) { + } + else if (era == Era.AD) { c.set(Calendar.ERA, GregorianCalendar.AD); } @@ -147,9 +152,11 @@ public final String process(final String value) { result = result.replaceAll("([0]{1,})([0-9]{1,})", "$2"); } - } catch (final IllegalArgumentException e) { + } + catch (final IllegalArgumentException e) { throw new MorphBuildException("The date/time format is not supported.", e); - } catch (final Exception e) { + } + catch (final Exception e) { // checkstyle-disable-line IllegalCatch result = value; } return result; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Equals.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Equals.java index 0b93e1617..0be5edcd8 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Equals.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Equals.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractFilter; @@ -24,6 +25,9 @@ */ public final class Equals extends AbstractFilter { + public Equals() { + } + @Override protected boolean accept(final String value) { return getString().equals(value); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/HtmlAnchor.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/HtmlAnchor.java index 08dc3ed2e..37df4cf29 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/HtmlAnchor.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/HtmlAnchor.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; /** @@ -25,21 +26,17 @@ public final class HtmlAnchor extends AbstractCompose { private String title; + public HtmlAnchor() { + } + public void setTitle(final String title) { this.title = title; } @Override public String process(final String value) { - final String title; - if (this.title == null) { - title = value; - } else { - title = this.title; - } - - return "" - + title + ""; + final String text = title == null ? value : title; + return "" + text + ""; } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/ISBN.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/ISBN.java index b510fe8c5..353ba1845 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/ISBN.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/ISBN.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; +import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; + import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; - /** * Offers ISBN conversions. * @@ -45,6 +46,9 @@ public final class ISBN extends AbstractSimpleStatelessFunction { private boolean verifyCheckDigit; private String errorString; + public ISBN() { + } + public void setErrorString(final String errorString) { this.errorString = errorString; } @@ -56,12 +60,15 @@ public String process(final String value) { if (verifyCheckDigit && !isValid(result)) { result = errorString; - } else if (!(size == ISBN10_SIZE || size == ISBN13_SIZE)) { + } + else if (!(size == ISBN10_SIZE || size == ISBN13_SIZE)) { result = errorString; - } else { + } + else { if (to10 && ISBN13_SIZE == size) { result = isbn13to10(result); - } else if (to13 && ISBN10_SIZE == size) { + } + else if (to13 && ISBN10_SIZE == size) { result = isbn10to13(result); } } @@ -103,7 +110,8 @@ private static char check13(final String isbn13Data) { final int digit = charToInt(isbn13Data.charAt(i)); if ((i % 2) == 0) { accumulator = accumulator + digit; - } else { + } + else { accumulator = accumulator + ISBN13_MAGIC * digit; } } @@ -146,7 +154,8 @@ public static boolean isValid(final String isbn) { if (isbn.length() == ISBN10_SIZE) { result = check10(isbn.substring(0, ISBN10_SIZE - 1)) == isbn .charAt(ISBN10_SIZE - 1); - } else if (isbn.length() == ISBN13_SIZE) { + } + else if (isbn.length() == ISBN13_SIZE) { result = check13(isbn.substring(0, ISBN13_SIZE - 1)) == isbn .charAt(ISBN13_SIZE - 1); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Lookup.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Lookup.java index 43bcbdb7a..e340c9b5d 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Lookup.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Lookup.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; /** @@ -25,8 +26,11 @@ public final class Lookup extends AbstractLookup { private String defaultValue; - public void setDefault(final String defaultValue) { - this.defaultValue = defaultValue; + public Lookup() { + } + + public void setDefault(final String newDefaultValue) { + defaultValue = newDefaultValue; } @Override diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/NormalizeUTF8.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/NormalizeUTF8.java index 8efe423b2..23c8b3880 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/NormalizeUTF8.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/NormalizeUTF8.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; -import java.text.Normalizer; -import java.text.Normalizer.Form; +package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; +import java.text.Normalizer.Form; +import java.text.Normalizer; + /** * Performs normalization of diacritics in utf-8 encoded strings. * @@ -27,6 +28,9 @@ */ public final class NormalizeUTF8 extends AbstractSimpleStatelessFunction { + public NormalizeUTF8() { + } + @Override public String process(final String value) { return Normalizer.normalize(value, Form.NFC); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/NotContains.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/NotContains.java index a3d84db79..15094f404 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/NotContains.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/NotContains.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractFilter; @@ -25,6 +26,9 @@ */ public final class NotContains extends AbstractFilter { + public NotContains() { + } + @Override protected boolean accept(final String value) { return !value.contains(getString()); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/NotEquals.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/NotEquals.java index 9f95facc0..5b5c67b99 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/NotEquals.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/NotEquals.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractFilter; @@ -25,6 +26,9 @@ */ public final class NotEquals extends AbstractFilter { + public NotEquals() { + } + @Override protected boolean accept(final String value) { return !getString().equals(value); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Occurrence.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Occurrence.java index ed652edf7..b3b26159a 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Occurrence.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Occurrence.java @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; -import java.util.HashMap; -import java.util.Map; +package org.metafacture.metamorph.functions; import org.metafacture.commons.StringUtil; import org.metafacture.metamorph.api.MorphBuildException; import org.metafacture.metamorph.api.helpers.AbstractStatefulFunction; +import java.util.HashMap; +import java.util.Map; + /** * Only outputs the received values in a certain range. * @@ -47,6 +48,9 @@ public boolean accept(final int value) { private final Map variables = new HashMap(); private boolean sameEntity; + public Occurrence() { + } + @Override public String process(final String value) { ++count; @@ -92,9 +96,11 @@ private static IntFilter parse(final String only) { if (only.startsWith(LESS_THAN)) { filter = createLessThanFilter(extractNumberFrom(only)); - } else if (only.startsWith(MORE_THAN)) { + } + else if (only.startsWith(MORE_THAN)) { filter = createGreaterThanFilter(extractNumberFrom(only)); - } else { + } + else { final int number = Integer.parseInt(only); filter = createEqualsFilter(number); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java index a2c192093..b7490eb6a 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Regexp.java @@ -13,17 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; +import org.metafacture.commons.StringUtil; +import org.metafacture.metamorph.api.NamedValueSource; +import org.metafacture.metamorph.api.helpers.AbstractFunction; + import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.metafacture.commons.StringUtil; -import org.metafacture.metamorph.api.NamedValueSource; -import org.metafacture.metamorph.api.helpers.AbstractFunction; - /** * Performs regexp matching. * @@ -35,10 +36,11 @@ public final class Regexp extends AbstractFunction { private String format; private final Map tempVars = new HashMap(); + public Regexp() { + } + @Override - public void receive(final String name, final String value, - final NamedValueSource source, final int recordCount, - final int entityCount) { + public void receive(final String name, final String value, final NamedValueSource source, final int recordCount, final int entityCount) { if (null == value) { return; } @@ -51,7 +53,8 @@ public void receive(final String name, final String value, recordCount, entityCount); } } - } else { + } + else { while (matcher.find()) { populateVars(); if (!tempVars.isEmpty()) { @@ -74,7 +77,7 @@ private void populateVars() { } public void setMatch(final String match) { - this.matcher = Pattern.compile(match).matcher(""); + matcher = Pattern.compile(match).matcher(""); } public void setFormat(final String format) { diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Replace.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Replace.java index 0363e54f4..518f8ad62 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Replace.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Replace.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; -import java.util.regex.Pattern; +package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; +import java.util.regex.Pattern; + /** * Replaces the matches of pattern with a set value. * @@ -29,13 +30,16 @@ public final class Replace extends AbstractSimpleStatelessFunction { private Pattern pattern; private String with; + public Replace() { + } + @Override public String process(final String value) { return pattern.matcher(value).replaceAll(with); } public void setPattern(final String string) { - this.pattern = Pattern.compile(string); + pattern = Pattern.compile(string); } public void setWith(final String with) { diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Script.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Script.java index e603d159c..e1110509f 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Script.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Script.java @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; -import java.io.FileNotFoundException; +import org.metafacture.commons.ResourceUtil; +import org.metafacture.metamorph.api.MorphBuildException; +import org.metafacture.metamorph.api.MorphExecutionException; +import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; +import java.io.FileNotFoundException; import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; -import org.metafacture.commons.ResourceUtil; -import org.metafacture.metamorph.api.MorphBuildException; -import org.metafacture.metamorph.api.MorphExecutionException; -import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; - /** * A function which executes a javascript function. * @@ -37,6 +37,9 @@ public final class Script extends AbstractSimpleStatelessFunction { private Invocable invocable; private String invoke; + public Script() { + } + public void setInvoke(final String invoke) { this.invoke = invoke; } @@ -48,9 +51,11 @@ public void setFile(final String file) { try { // TODO: The script file should be loaded relatively to the base URI engine.eval(ResourceUtil.getReader(file)); - } catch (final ScriptException e) { + } + catch (final ScriptException e) { throw new MorphBuildException("Error in script", e); - } catch (final FileNotFoundException e) { + } + catch (final FileNotFoundException e) { throw new MorphBuildException("Error loading script '" + file + "'", e); } @@ -63,10 +68,12 @@ public String process(final String value) { try { obj = invocable.invokeFunction(invoke, value); return obj.toString(); - } catch (final ScriptException e) { + } + catch (final ScriptException e) { throw new MorphExecutionException( "Error in script while evaluating 'process' method", e); - } catch (final NoSuchMethodException e) { + } + catch (final NoSuchMethodException e) { throw new MorphExecutionException("'process' method is missing in script", e); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/SetReplace.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/SetReplace.java index ef620684f..c699cc969 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/SetReplace.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/SetReplace.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.commons.tries.SetReplacer; @@ -26,6 +27,9 @@ public final class SetReplace extends AbstractSimpleStatelessFunction { private final SetReplacer setReplacer = new SetReplacer(); private boolean prepared; + public SetReplace() { + } + @Override public String process(final String text) { if (!prepared) { diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Split.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Split.java index 665b1288f..b18af6dbc 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Split.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Split.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; -import java.util.regex.Pattern; +package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.NamedValueSource; import org.metafacture.metamorph.api.helpers.AbstractFunction; +import java.util.regex.Pattern; + /** * Splits the received value and output each part separately. * @@ -29,10 +30,11 @@ public final class Split extends AbstractFunction { private Pattern delimiterPattern; + public Split() { + } + @Override - public void receive(final String name, final String value, - final NamedValueSource source, final int recordCount, - final int entityCount) { + public void receive(final String name, final String value, final NamedValueSource source, final int recordCount, final int entityCount) { final String[] parts = delimiterPattern.split(value); for (final String part : parts) { getNamedValueReceiver().receive(name, part, this, recordCount, diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Substring.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Substring.java index 21a701d95..5987b0852 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Substring.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Substring.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; @@ -27,6 +28,9 @@ public final class Substring extends AbstractSimpleStatelessFunction { private int start; private int end; + public Substring() { + } + @Override public String process(final String value) { final int length = value.length(); @@ -37,7 +41,8 @@ public String process(final String value) { final int adjEnd; if (end == 0 || end > length) { adjEnd = length; - } else { + } + else { adjEnd = end; } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/SwitchNameValue.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/SwitchNameValue.java index b84804e25..fc6f7abcb 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/SwitchNameValue.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/SwitchNameValue.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.NamedValueSource; @@ -25,14 +26,12 @@ */ public final class SwitchNameValue extends AbstractFunction { - @Override - public void receive(final String name, final String value, - final NamedValueSource source, final int recordCount, - final int entityCount) { - - getNamedValueReceiver().receive(value, name, this, recordCount, - entityCount); + public SwitchNameValue() { + } + @Override + public void receive(final String name, final String value, final NamedValueSource source, final int recordCount, final int entityCount) { + getNamedValueReceiver().receive(value, name, this, recordCount, entityCount); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Timestamp.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Timestamp.java index 9d9473780..3c25b5f5d 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Timestamp.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Timestamp.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; +import org.metafacture.metamorph.api.MorphBuildException; +import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collections; @@ -24,9 +28,6 @@ import java.util.Set; import java.util.TimeZone; -import org.metafacture.metamorph.api.MorphBuildException; -import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; - /** * This function creates a timestamp. By default it returns a unix * timestamp. Other formats are and different @@ -61,6 +62,9 @@ public final class Timestamp extends AbstractSimpleStatelessFunction { SUPPORTED_LANGUAGES = Collections.unmodifiableSet(set); } + public Timestamp() { + } + @Override public String process(final String value) { if (FORMAT_TIMESTAMP.equals(format)) { @@ -69,7 +73,8 @@ public String process(final String value) { final DateFormat dateFormat; try { dateFormat = new SimpleDateFormat(format, locale); - } catch (final IllegalArgumentException e) { + } + catch (final IllegalArgumentException e) { throw new MorphBuildException("The date/time format '" + format + "' is not supported. ", e); } dateFormat.setTimeZone(TimeZone.getTimeZone(timezone)); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Trim.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Trim.java index deaaec012..a4881c156 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Trim.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Trim.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; @@ -24,6 +25,9 @@ */ public final class Trim extends AbstractSimpleStatelessFunction { + public Trim() { + } + @Override public String process(final String value) { return value.trim(); diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/URLEncode.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/URLEncode.java index 3f7ca1446..3996b7e1f 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/URLEncode.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/URLEncode.java @@ -13,14 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.functions; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; +package org.metafacture.metamorph.functions; import org.metafacture.metamorph.api.MorphExecutionException; import org.metafacture.metamorph.api.helpers.AbstractSimpleStatelessFunction; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + /** * URL encodes the received value. * @@ -29,13 +30,16 @@ */ public final class URLEncode extends AbstractSimpleStatelessFunction { + public URLEncode() { + } + @Override public String process(final String value) { try { return URLEncoder.encode(value, "UTF-8"); - } catch (final UnsupportedEncodingException e) { - throw new MorphExecutionException("urlencode: unsupported encoding UTF-8", - e); + } + catch (final UnsupportedEncodingException e) { + throw new MorphExecutionException("urlencode: unsupported encoding UTF-8", e); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/Unique.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/Unique.java index 944aa14cf..572fca9f0 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/Unique.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/Unique.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; +import org.metafacture.metamorph.api.helpers.AbstractStatefulFunction; + import java.util.HashSet; import java.util.Set; -import org.metafacture.metamorph.api.helpers.AbstractStatefulFunction; - /** * Checks whether the received value was not received before. * @@ -43,6 +44,9 @@ public String createKey(final String name, final String value) { } }; + public Unique() { + } + @Override public String process(final String value) { final String key = keyGenerator.createKey(getLastName(), value); @@ -75,7 +79,8 @@ public String createKey(final String name, final String value) { return name; } }; - } else if (VALUE.equals(part)) { + } + else if (VALUE.equals(part)) { keyGenerator = new KeyGenerator() { @Override public String createKey(final String name, final String value) { diff --git a/metamorph/src/main/java/org/metafacture/metamorph/functions/WhiteList.java b/metamorph/src/main/java/org/metafacture/metamorph/functions/WhiteList.java index 4d9e149a1..30187ada9 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/functions/WhiteList.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/functions/WhiteList.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; /** @@ -22,14 +23,13 @@ */ public final class WhiteList extends AbstractLookup { + public WhiteList() { + } + @Override public String process(final String key) { final String returnValue = lookup(key); - - if (returnValue != null) { - return key; - } - return null; + return returnValue != null ? key : null; } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/maps/FileMap.java b/metamorph/src/main/java/org/metafacture/metamorph/maps/FileMap.java index a475ce3be..ff2782b8f 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/maps/FileMap.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/maps/FileMap.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.maps; +import org.metafacture.metamorph.api.MorphExecutionException; +import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; + import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -30,9 +34,6 @@ import java.util.Optional; import java.util.regex.Pattern; -import org.metafacture.metamorph.api.MorphExecutionException; -import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; - /** * Provides a {@link Map} based on a file. The file is supposed to be UTF-8 * encoded. The separator is by default \t. Important: Lines @@ -46,6 +47,9 @@ public final class FileMap extends AbstractReadOnlyMap { private Pattern split = Pattern.compile("\t", Pattern.LITERAL); + public FileMap() { + } + public void setFiles(final String files) { final String[] parts = files.split("\\s*,\\s*"); for (final String part : parts) { @@ -55,9 +59,8 @@ public void setFiles(final String files) { public void setFile(final String file) { try ( - final InputStream stream = openStream(file); - final BufferedReader reader = new BufferedReader( - new InputStreamReader(stream, StandardCharsets.UTF_8)) + InputStream stream = openStream(file); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)) ) { String line; while ((line = reader.readLine()) != null) { @@ -69,12 +72,13 @@ public void setFile(final String file) { map.put(parts[0], parts[1]); } } - } catch (final IOException | UncheckedIOException e) { + } + catch (final IOException | UncheckedIOException e) { throw new MorphExecutionException("filemap: cannot read map file", e); } } - private InputStream openStream(String file) { + private InputStream openStream(final String file) { return openAsFile(file) .orElseGet(() -> openAsResource(file) .orElseGet(() -> openAsUrl(file) @@ -82,29 +86,32 @@ private InputStream openStream(String file) { "File not found: " + file)))); } - private Optional openAsFile(String file) { + private Optional openAsFile(final String file) { try { return Optional.of(new FileInputStream(file)); - } catch (FileNotFoundException e) { + } + catch (final FileNotFoundException e) { return Optional.empty(); } } - private Optional openAsResource(String file) { + private Optional openAsResource(final String file) { return Optional.ofNullable(Thread.currentThread() .getContextClassLoader().getResourceAsStream(file)); } - private Optional openAsUrl(String file) { + private Optional openAsUrl(final String file) { final URL url; try { url = new URL(file); - } catch (MalformedURLException e) { + } + catch (final MalformedURLException e) { return Optional.empty(); } try { return Optional.of(url.openStream()); - } catch (IOException e) { + } + catch (final IOException e) { throw new UncheckedIOException(e); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/maps/JndiSqlMap.java b/metamorph/src/main/java/org/metafacture/metamorph/maps/JndiSqlMap.java index c9f3cf28c..05400ad53 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/maps/JndiSqlMap.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/maps/JndiSqlMap.java @@ -13,22 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.maps; +import org.metafacture.metamorph.api.MorphExecutionException; +import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; + import java.io.Closeable; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; - import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; -import org.metafacture.metamorph.api.MorphExecutionException; -import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; - /** * A map which queries an sql database provided as jndi * resource. @@ -36,18 +36,20 @@ * @author Daniel Schäfer * */ -public final class JndiSqlMap extends AbstractReadOnlyMap - implements Closeable { +public final class JndiSqlMap extends AbstractReadOnlyMap implements Closeable { private DataSource datasource; private String query; + public JndiSqlMap() { + } + public void setDatasource(final String name) { try { - this.datasource = (DataSource) new InitialContext().lookup(name); - } catch (final NamingException e) { - throw new MorphExecutionException( - "jndisqlmap: lookup of data source failed", e); + datasource = (DataSource) new InitialContext().lookup(name); + } + catch (final NamingException e) { + throw new MorphExecutionException("jndisqlmap: lookup of data source failed", e); } } @@ -58,20 +60,19 @@ public void setQuery(final String query) { @Override public String get(final Object key) { String resultString = null; - try( - final Connection connection = datasource.getConnection(); - final PreparedStatement statement = - connection.prepareStatement(query); + try ( + Connection connection = datasource.getConnection(); + PreparedStatement statement = connection.prepareStatement(query) ) { statement.setString(1, key.toString()); - try(final ResultSet resultSet = statement.executeQuery()) { + try (ResultSet resultSet = statement.executeQuery()) { if (resultSet.first()) { resultString = resultSet.getString(1); } } - } catch (final SQLException e) { - throw new MorphExecutionException( - "jndisqlmap: execution of sql query failed", e); + } + catch (final SQLException e) { + throw new MorphExecutionException("jndisqlmap: execution of sql query failed", e); } return resultString; } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/maps/RestMap.java b/metamorph/src/main/java/org/metafacture/metamorph/maps/RestMap.java index f7c6e9310..d69a78897 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/maps/RestMap.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/maps/RestMap.java @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.maps; +import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -26,8 +29,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; - /** * A map which resolves its keys by doing a REST request and returning the * response as value. @@ -44,7 +45,7 @@ public final class RestMap extends AbstractReadOnlyMap { public RestMap() { } - public RestMap(String url) { + public RestMap(final String url) { this.url = url; } @@ -52,27 +53,28 @@ public RestMap(String url) { public String get(final Object key) { final Matcher matcher = VAR_PATTERN.matcher(url); try { - String urlString = matcher.replaceAll(key.toString()); + final String urlString = matcher.replaceAll(key.toString()); return readFromUrl(urlString); - } catch (IOException | URISyntaxException e) { + } + catch (final IOException | URISyntaxException e) { // There was no data result for the given URL return null; } } - private String readFromUrl(final String url) throws IOException, URISyntaxException { - InputStream inputStream = new URL(new URI(url.replace(" ", "%20")).toASCIIString()).openConnection() + private String readFromUrl(final String targetUrl) throws IOException, URISyntaxException { + final InputStream inputStream = new URL(new URI(targetUrl.replace(" ", "%20")).toASCIIString()).openConnection() .getInputStream(); try { - BufferedReader reader = new BufferedReader( - new InputStreamReader(inputStream, Charset.forName(charsetName))); - StringBuilder stringBuffer = new StringBuilder(); + final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName(charsetName))); + final StringBuilder stringBuffer = new StringBuilder(); int value; while ((value = reader.read()) != -1) { stringBuffer.append((char) value); } return stringBuffer.toString(); - } finally { + } + finally { inputStream.close(); } } @@ -81,7 +83,7 @@ public void setUrl(final String url) { this.url = url; } - public void setCharsetName(String name) { + public void setCharsetName(final String name) { charsetName = name; } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/maps/SqlMap.java b/metamorph/src/main/java/org/metafacture/metamorph/maps/SqlMap.java index c56fcea28..8a8d53a6b 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/maps/SqlMap.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/maps/SqlMap.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.maps; +import org.metafacture.metamorph.api.MorphExecutionException; +import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; + import java.io.Closeable; import java.io.IOException; import java.sql.Connection; @@ -23,9 +27,6 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.metafacture.metamorph.api.MorphExecutionException; -import org.metafacture.metamorph.api.helpers.AbstractReadOnlyMap; - /** * A map implementation that queries an sql database. * @@ -33,8 +34,7 @@ * @author Markus Michael Geipel * */ -public final class SqlMap extends AbstractReadOnlyMap implements - Closeable { +public final class SqlMap extends AbstractReadOnlyMap implements Closeable { private boolean isUninitialized = true; @@ -48,13 +48,15 @@ public final class SqlMap extends AbstractReadOnlyMap implements private PreparedStatement preparedStatement; - public void init() { + public SqlMap() { + } + public void init() { try { preparedStatement = getMySqlConnection().prepareStatement(query); - } catch (final SQLException e) { - throw new MorphExecutionException( - "sqlmap: could not create prepared statement for query", e); + } + catch (final SQLException e) { + throw new MorphExecutionException("sqlmap: could not create prepared statement for query", e); } isUninitialized = false; } @@ -62,13 +64,12 @@ public void init() { @Override public void close() throws IOException { try { - if (conn != null) { conn.close(); } - } catch (final SQLException e) { - throw new MorphExecutionException("sqlmap: could not close db connection", - e); + } + catch (final SQLException e) { + throw new MorphExecutionException("sqlmap: could not close db connection", e); } } @@ -76,12 +77,11 @@ private Connection getMySqlConnection() { try { Class.forName(driver); - conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" - + database + "?" + "user=" + login + "&" + "password=" - + password); - } catch (final ClassNotFoundException | SQLException e) { - throw new MorphExecutionException("sqlmap: cannot create db connection", - e); + conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" + + database + "?" + "user=" + login + "&" + "password=" + password); + } + catch (final ClassNotFoundException | SQLException e) { + throw new MorphExecutionException("sqlmap: cannot create db connection", e); } return conn; } @@ -100,9 +100,9 @@ public String get(final Object key) { resultString = resultSet.getString(1); } resultSet.close(); - } catch (final SQLException e) { - throw new MorphExecutionException( - "sqlmap: execution of prepared statement failed", e); + } + catch (final SQLException e) { + throw new MorphExecutionException("sqlmap: execution of prepared statement failed", e); } return resultString; } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/CDataFilter.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/CDataFilter.java index be90a9f5a..136d0973b 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/CDataFilter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/CDataFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.xml; import org.xml.sax.SAXException; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/CommentsFilter.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/CommentsFilter.java index 1108158dc..b95016fd9 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/CommentsFilter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/CommentsFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.xml; import org.xml.sax.SAXException; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/DomLoader.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/DomLoader.java index 8ba91f906..8ed4d4f5f 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/DomLoader.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/DomLoader.java @@ -13,11 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.xml; +import org.metafacture.commons.ResourceUtil; +import org.metafacture.framework.MetafactureException; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.XMLReader; + import java.net.MalformedURLException; import java.net.URL; - import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -34,17 +45,6 @@ import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; -import org.metafacture.commons.ResourceUtil; -import org.metafacture.framework.MetafactureException; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xml.sax.ErrorHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.XMLReader; - - /** * Helper to load DOM {@link Document}s. * @@ -52,19 +52,17 @@ * @author Christoph Böhme * */ -public final class DomLoader { +public final class DomLoader { // checkstyle-disable-line ClassDataAbstractionCoupling|ClassFanOutComplexity - private static final ErrorHandler SAX_ERROR_HANDLER = - new SaxErrorHandler(); + private static final ErrorHandler SAX_ERROR_HANDLER = new SaxErrorHandler(); - private static final ErrorListener TRANSFORMER_ERROR_HANDLER = - new TransformerErrorHandler(); + private static final ErrorListener TRANSFORMER_ERROR_HANDLER = new TransformerErrorHandler(); private DomLoader() { throw new AssertionError("No instances allowed"); } - public static Document parse(String schemaFile, InputSource input) { + public static Document parse(final String schemaFile, final InputSource input) { final Document document = createEmptyDocument(); final XMLReader pipeline = createXmlFilterPipeline(schemaFile, document); process(new SAXSource(pipeline, input), new DOMResult(document)); @@ -81,15 +79,14 @@ public static Document parse(String schemaFile, InputSource input) { private static Document createEmptyDocument() { try { - return DocumentBuilderFactory.newInstance().newDocumentBuilder() - .newDocument(); - } catch (ParserConfigurationException e) { + return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + } + catch (final ParserConfigurationException e) { throw new MetafactureException(e); } } - private static XMLReader createXmlFilterPipeline(String schemaFile, - Document document) { + private static XMLReader createXmlFilterPipeline(final String schemaFile, final Document document) { XMLReader pipelineHead = createSaxReader(loadSchema(schemaFile)); pipelineHead = new LocationAnnotator(pipelineHead, document); pipelineHead = new IgnorableWhitespaceFilter(pipelineHead); @@ -99,51 +96,54 @@ private static XMLReader createXmlFilterPipeline(String schemaFile, return pipelineHead; } - private static Schema loadSchema(String schemaFile) { + private static Schema loadSchema(final String schemaFile) { try { - return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) - .newSchema(getSchemaUrl(schemaFile)); - } catch (SAXException e) { + return SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(getSchemaUrl(schemaFile)); + } + catch (final SAXException e) { throw new MetafactureException(e); } } - private static URL getSchemaUrl(String schemaFile) { + private static URL getSchemaUrl(final String schemaFile) { try { return ResourceUtil.getUrl(schemaFile); - } catch (final MalformedURLException e) { + } + catch (final MalformedURLException e) { throw new MetafactureException("'" + schemaFile + "' not found:", e); } } - private static XMLReader createSaxReader(Schema schema) { + private static XMLReader createSaxReader(final Schema schema) { final SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setSchema(schema); parserFactory.setNamespaceAware(true); parserFactory.setXIncludeAware(true); try { return parserFactory.newSAXParser().getXMLReader(); - } catch (ParserConfigurationException | SAXException e) { + } + catch (final ParserConfigurationException | SAXException e) { throw new MetafactureException(e); } } - private static void process(Source source, Result result) { + private static void process(final Source source, final Result result) { final Transformer transformer = createTransformer(); try { transformer.transform(source, result); - } catch (TransformerException e) { + } + catch (final TransformerException e) { throw new MetafactureException(e); } } private static Transformer createTransformer() { try { - final Transformer transformer = TransformerFactory.newInstance() - .newTransformer(); + final Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setErrorListener(TRANSFORMER_ERROR_HANDLER); return transformer; - } catch (TransformerConfigurationException e) { + } + catch (final TransformerConfigurationException e) { throw new MetafactureException(e); } } @@ -155,10 +155,11 @@ private static void removeEmptyTextNodes(final Node node) { final Node old = child; child = child.getNextSibling(); - if(old.getNodeValue().trim().isEmpty()) { + if (old.getNodeValue().trim().isEmpty()) { node.removeChild(old); } - } else { + } + else { removeEmptyTextNodes(child); child = child.getNextSibling(); } @@ -191,8 +192,7 @@ public void error(final SAXParseException exception) throws SAXException { } private void handle(final SAXParseException exception) { - throw new MetafactureException("Error parsing xml: " + - exception.getMessage(), exception); + throw new MetafactureException("Error parsing xml: " + exception.getMessage(), exception); } } @@ -208,26 +208,22 @@ private static class TransformerErrorHandler implements ErrorListener { } @Override - public void warning(final TransformerException exception) - throws TransformerException { + public void warning(final TransformerException exception) throws TransformerException { handle(exception); } @Override - public void error(final TransformerException exception) - throws TransformerException { + public void error(final TransformerException exception) throws TransformerException { handle(exception); } @Override - public void fatalError(final TransformerException exception) - throws TransformerException { + public void fatalError(final TransformerException exception) throws TransformerException { handle(exception); } private void handle(final TransformerException exception) { - throw new MetafactureException("Error during DOM creation: " + - exception.getMessage(), exception); + throw new MetafactureException("Error during DOM creation: " + exception.getMessage(), exception); } } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/IgnorableWhitespaceFilter.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/IgnorableWhitespaceFilter.java index 59eac1dce..9851cf8e3 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/IgnorableWhitespaceFilter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/IgnorableWhitespaceFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.xml; import org.xml.sax.SAXException; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/LexicalHandlerXmlFilter.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/LexicalHandlerXmlFilter.java index 76ce50b76..5acf2bcf6 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/LexicalHandlerXmlFilter.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/LexicalHandlerXmlFilter.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.xml; -import java.io.IOException; +package org.metafacture.metamorph.xml; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -25,6 +24,8 @@ import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.XMLFilterImpl; +import java.io.IOException; + /** * Extends {@link XMLFilterImpl} to also intercept events defined * in {@link LexicalHandler}. @@ -34,8 +35,7 @@ */ class LexicalHandlerXmlFilter extends XMLFilterImpl implements LexicalHandler { - private static final String LEXICAL_HANDLER_PROPERTY = - "http://xml.org/sax/properties/lexical-handler"; + private static final String LEXICAL_HANDLER_PROPERTY = "http://xml.org/sax/properties/lexical-handler"; private LexicalHandler lexicalHandler; @@ -60,20 +60,17 @@ public void parse(final String systemId) throws SAXException, IOException { } @Override - public void setProperty(final String name, final Object value) - throws SAXNotRecognizedException, SAXNotSupportedException { - + public void setProperty(final String name, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if (LEXICAL_HANDLER_PROPERTY.equals(name)) { lexicalHandler = (LexicalHandler) value; - } else { + } + else { super.setProperty(name, value); } } @Override - public void startDTD(final String name, final String publicId, final String systemId) - throws SAXException { - + public void startDTD(final String name, final String publicId, final String systemId) throws SAXException { if (lexicalHandler != null) { lexicalHandler.startDTD(name, publicId, systemId); } @@ -115,9 +112,7 @@ public void endCDATA() throws SAXException { } @Override - public void comment(final char[] ch, final int start, final int length) - throws SAXException { - + public void comment(final char[] ch, final int start, final int length) throws SAXException { if (lexicalHandler != null) { lexicalHandler.comment(ch, start, length); } diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/Location.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/Location.java index 26d6f1985..aaee029e6 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/Location.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/Location.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.xml; import org.w3c.dom.Node; diff --git a/metamorph/src/main/java/org/metafacture/metamorph/xml/LocationAnnotator.java b/metamorph/src/main/java/org/metafacture/metamorph/xml/LocationAnnotator.java index c384e0419..9b6ce7a6b 100644 --- a/metamorph/src/main/java/org/metafacture/metamorph/xml/LocationAnnotator.java +++ b/metamorph/src/main/java/org/metafacture/metamorph/xml/LocationAnnotator.java @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.metafacture.metamorph.xml; -import java.util.Deque; -import java.util.LinkedList; +package org.metafacture.metamorph.xml; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -30,6 +28,9 @@ import org.xml.sax.helpers.LocatorImpl; import org.xml.sax.helpers.XMLFilterImpl; +import java.util.Deque; +import java.util.LinkedList; + /** * Annotates a DOM with information about the location of * the elements in the input file. @@ -49,7 +50,7 @@ final class LocationAnnotator extends XMLFilterImpl { private Locator locator; - public LocationAnnotator(final XMLReader xmlReader, final Document document) { + LocationAnnotator(final XMLReader xmlReader, final Document document) { super(xmlReader); final EventListener listener = new EventListener() { @@ -68,28 +69,22 @@ public void handleEvent(final Event event) { } @Override - public void setDocumentLocator(final Locator locator) { - super.setDocumentLocator(locator); - this.locator = locator; + public void setDocumentLocator(final Locator newLocator) { + super.setDocumentLocator(newLocator); + locator = newLocator; } @Override - public void startElement(final String uri, final String localName, final String qName, - final Attributes atts) throws SAXException { - + public void startElement(final String uri, final String localName, final String qName, final Attributes atts) throws SAXException { super.startElement(uri, localName, qName, atts); - locatorsAtElementStart.push(new LocatorImpl(locator)); } @Override - public void endElement(final String uri, final String localName, final String qName) - throws SAXException { - + public void endElement(final String uri, final String localName, final String qName) throws SAXException { super.endElement(uri, localName, qName); final Locator elementStartLocator = locatorsAtElementStart.pop(); - final Location location = new Location(elementStartLocator, locator); final Node domNode = domNodes.pop(); diff --git a/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java b/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java index 88f659c39..96ecd854a 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/MetamorphTest.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import static org.junit.Assert.assertEquals; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java b/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java index 06ba3c9ea..ba9ab310e 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/SplitterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/TestHelpers.java b/metamorph/src/test/java/org/metafacture/metamorph/TestHelpers.java index 5617f8b0b..6d9694f94 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/TestHelpers.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/TestHelpers.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import org.metafacture.framework.StreamReceiver; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java b/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java index 7f551ba18..b21b4c2e0 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphBasics.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import static org.metafacture.metamorph.TestHelpers.assertMorph; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphMacros.java b/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphMacros.java index f0edadee3..0c5c3ba2e 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphMacros.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/TestMetamorphMacros.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph; import static org.metafacture.metamorph.TestHelpers.assertMorph; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java index 69138afa6..3ca2f5010 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AllTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java index c67807b27..8a697c650 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/AnyTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java index 9dabfa3bb..278066505 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ChooseTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java index fd71f4062..75d56ef87 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/CombineTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java index 5ca08b126..83821782b 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/ConcatTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java index 93e3f2ab5..83a53ffc4 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EntityTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java index 2f6c69351..998aada7e 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/EqualsFilterTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.ArgumentMatchers.any; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java index 469c1c010..c983b258b 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/GroupTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java index 6ef25ea12..4953222be 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/NoneTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java index d92a02c2c..8294d12b9 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/RangeTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java index 260d75b28..e5c022335 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/SquareTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java index d748ca6ee..7cf2cbd3c 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorBasics.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java index 9ee599e0f..ea8378eb2 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TestCollectorIf.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TuplesTest.java b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TuplesTest.java index 1909c9b09..654f03dad 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/collectors/TuplesTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/collectors/TuplesTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.collectors; import static org.metafacture.metamorph.TestHelpers.assertMorph; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java index c5a56a263..65801c706 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/DateFormatTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java index 2995c5e12..60c0fdc2c 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/ISBNTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.junit.Assert.assertEquals; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java index aaccb64c9..d50204c2c 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/LookupTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.junit.Assert.assertEquals; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java index b069db7e7..b4796eeda 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/NormalizeUTF8Test.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.junit.Assert.assertEquals; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java index f1643ff83..a1ca10813 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/RegexpTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java index e98c942c5..f51203b94 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/ScriptTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java index a0750cb56..414a05cf7 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/SplitTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.verify; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java index db278db57..03216f875 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/StringOperationsTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.junit.Assert.assertEquals; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java index 368dce16e..a5a4e3b1b 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/SwitchNameValueTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.verify; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java index b172ed7d8..112943317 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestFunctionBasics.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java index 5dc154f9d..484507f52 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/TestVariousFunctions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.mockito.Mockito.inOrder; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java b/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java index 2fcdf7c96..878baf3e3 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/functions/UniqueTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.functions; import static org.metafacture.metamorph.TestHelpers.assertMorph; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/maps/FileMapTest.java b/metamorph/src/test/java/org/metafacture/metamorph/maps/FileMapTest.java index 17b544d4f..35a1fc952 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/maps/FileMapTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/maps/FileMapTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.maps; import static org.metafacture.metamorph.TestHelpers.assertMorph; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/maps/JavaMapTest.java b/metamorph/src/test/java/org/metafacture/metamorph/maps/JavaMapTest.java index 59ef90b5a..ce019c287 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/maps/JavaMapTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/maps/JavaMapTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.maps; import static org.metafacture.metamorph.TestHelpers.assertMorph; diff --git a/metamorph/src/test/java/org/metafacture/metamorph/xml/DomLoaderTest.java b/metamorph/src/test/java/org/metafacture/metamorph/xml/DomLoaderTest.java index f26effdd0..0e2b1f191 100644 --- a/metamorph/src/test/java/org/metafacture/metamorph/xml/DomLoaderTest.java +++ b/metamorph/src/test/java/org/metafacture/metamorph/xml/DomLoaderTest.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.metafacture.metamorph.xml; import static org.junit.Assert.assertEquals;