From 8d157d91921d7715b23042589e2ece651f994779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Sun, 13 Nov 2016 22:55:51 +0100 Subject: [PATCH] fixing RdfContentParameter generic type settings --- build.gradle | 2 +- .../java/org/xbib/content/rdf/RdfContent.java | 3 +-- .../xbib/content/rdf/RdfContentParser.java | 4 ++-- .../org/xbib/content/rdf/RdfXContent.java | 2 +- .../xbib/content/rdf/RouteRdfXContent.java | 6 ++--- .../xbib/content/rdf/io/json/JsonContent.java | 4 ++-- .../rdf/io/json/JsonContentParser.java | 18 ++++++++------- .../rdf/io/ntriple/NTripleContent.java | 4 ++-- .../rdf/io/ntriple/NTripleContentParser.java | 10 +++++---- .../content/rdf/io/rdfxml/RdfXmlContent.java | 4 ++-- .../rdf/io/rdfxml/RdfXmlContentParser.java | 2 +- .../content/rdf/io/turtle/TurtleContent.java | 4 ++-- .../rdf/io/turtle/TurtleContentParser.java | 22 ++++++++++--------- .../xbib/content/rdf/io/xml/XmlContent.java | 2 +- .../content/rdf/io/xml/XmlContentParser.java | 2 +- .../content/rdf/io/json/JsonReaderTest.java | 2 +- .../rdf/io/ntriple/NTripleReaderTest.java | 2 +- .../rdf/io/turtle/TurtleConformanceTest.java | 2 +- .../content/rdf/io/turtle/TurtleTest.java | 6 ++--- .../xbib/content/rdf/util/MultiMapTest.java | 10 ++++----- 20 files changed, 58 insertions(+), 53 deletions(-) diff --git a/build.gradle b/build.gradle index 0d98775..05ab537 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ ext { allprojects { group = 'org.xbib' - version = '1.0.4' + version = '1.0.5' apply plugin: 'java' apply plugin: 'maven' diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/RdfContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/RdfContent.java index 2034970..8e3962b 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/RdfContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/RdfContent.java @@ -13,6 +13,5 @@ public interface RdfContent

{ RdfContentGenerator

createGenerator(OutputStream out) throws IOException; - RdfContentParser createParser(InputStream in) throws IOException; - + RdfContentParser

createParser(InputStream in) throws IOException; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/RdfContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/RdfContentParser.java index e2d8975..830e4e0 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/RdfContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/RdfContentParser.java @@ -5,10 +5,10 @@ import java.io.IOException; /** * */ -public interface RdfContentParser { +public interface RdfContentParser { RdfContentType contentType(); - RdfContentParser parse() throws IOException; + RdfContentParser parse() throws IOException; } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/RdfXContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/RdfXContent.java index c274623..7f8998b 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/RdfXContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/RdfXContent.java @@ -33,7 +33,7 @@ public class RdfXContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream in) throws IOException { + public RdfContentParser createParser(InputStream in) throws IOException { throw new UnsupportedOperationException(); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/RouteRdfXContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/RouteRdfXContent.java index ea17b4f..b9ca2e8 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/RouteRdfXContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/RouteRdfXContent.java @@ -14,7 +14,7 @@ public class RouteRdfXContent implements RdfContent { private RouteRdfXContent() { } - public static final RouteRdfXContent routeRdfXContent() { + public static RouteRdfXContent routeRdfXContent() { return ROUTE_RDF_X_CONTENT; } @@ -33,8 +33,8 @@ public class RouteRdfXContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream in) throws IOException { - return null; + public RdfContentParser createParser(InputStream in) throws IOException { + throw new UnsupportedOperationException(); } /** diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContent.java index be9661f..02d0401 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContent.java @@ -44,7 +44,7 @@ public class JsonContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream in) throws IOException { - return new JsonContentParser(in); + public RdfContentParser createParser(InputStream in) throws IOException { + return new JsonContentParser<>(in); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentParser.java index 1ce19fd..2f3e601 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/json/JsonContentParser.java @@ -1,6 +1,7 @@ package org.xbib.content.rdf.io.json; import org.xbib.content.rdf.RdfContentBuilder; +import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParser; import org.xbib.content.rdf.RdfContentType; import org.xbib.content.rdf.StandardRdfContentType; @@ -18,14 +19,15 @@ import javax.xml.namespace.QName; /** * A parser for generic JSON (not JSON-LD) via JSON SaX adapter. + * @param parameterized type */ -public class JsonContentParser implements RdfContentParser { +public class JsonContentParser implements RdfContentParser { private final Reader reader; - private XmlHandler handler; + private XmlHandler handler; - private RdfContentBuilder builder; + private RdfContentBuilder builder; private QName root; @@ -42,27 +44,27 @@ public class JsonContentParser implements RdfContentParser { return StandardRdfContentType.JSON; } - public XmlHandler getHandler() { + public XmlHandler getHandler() { return handler; } - public JsonContentParser setHandler(XmlHandler handler) { + public JsonContentParser setHandler(XmlHandler handler) { this.handler = handler; return this; } - public JsonContentParser root(QName root) { + public JsonContentParser root(QName root) { this.root = root; return this; } - public JsonContentParser builder(RdfContentBuilder builder) { + public JsonContentParser builder(RdfContentBuilder builder) { this.builder = builder; return this; } @Override - public JsonContentParser parse() throws IOException { + public JsonContentParser parse() throws IOException { if (handler != null) { if (builder != null) { handler.setBuilder(builder); diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContent.java index 8045373..4377d16 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContent.java @@ -44,7 +44,7 @@ public class NTripleContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream in) throws IOException { - return new NTripleContentParser(in); + public RdfContentParser createParser(InputStream in) throws IOException { + return new NTripleContentParser<>(in); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentParser.java index 4e96653..b6f853f 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentParser.java @@ -1,6 +1,7 @@ package org.xbib.content.rdf.io.ntriple; import org.xbib.content.rdf.RdfContentBuilder; +import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParser; import org.xbib.content.rdf.RdfContentType; import org.xbib.content.rdf.Resource; @@ -24,8 +25,9 @@ import java.util.regex.PatternSyntaxException; * Parser for NTriple RDF format. * See also the NTriple * specification. + * @param RDF content parameter type */ -public class NTripleContentParser implements RdfContentParser { +public class NTripleContentParser implements RdfContentParser { private static final Resource resource = new DefaultAnonymousResource(); @@ -48,7 +50,7 @@ public class NTripleContentParser implements RdfContentParser { private boolean eof; - private RdfContentBuilder builder; + private RdfContentBuilder builder; public NTripleContentParser(InputStream in) throws IOException { this(new InputStreamReader(in, StandardCharsets.UTF_8)); @@ -63,13 +65,13 @@ public class NTripleContentParser implements RdfContentParser { return StandardRdfContentType.NTRIPLE; } - public NTripleContentParser setBuilder(RdfContentBuilder builder) { + public NTripleContentParser setBuilder(RdfContentBuilder builder) { this.builder = builder; return this; } @Override - public NTripleContentParser parse() throws IOException { + public NTripleContentParser parse() throws IOException { this.eof = false; try (BufferedReader br = new BufferedReader(reader)) { while (!eof) { diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContent.java index 880501b..5fba803 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContent.java @@ -44,7 +44,7 @@ public class RdfXmlContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream in) throws IOException { - return new RdfXmlContentParser(in); + public RdfContentParser createParser(InputStream in) throws IOException { + return new RdfXmlContentParser<>(in); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java index cb95be1..a489fa7 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/rdfxml/RdfXmlContentParser.java @@ -52,7 +52,7 @@ import java.util.logging.Logger; * Note that the XMLLiteral datatype is not fully supported. * @param parameter type */ -public class RdfXmlContentParser implements RdfConstants, RdfContentParser { +public class RdfXmlContentParser implements RdfConstants, RdfContentParser { private static final Logger logger = Logger.getLogger(RdfXmlContentParser.class.getName()); diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContent.java index 4626bf2..a566cfa 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContent.java @@ -44,8 +44,8 @@ public class TurtleContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream inputStream) throws IOException { - return new TurtleContentParser(inputStream); + public RdfContentParser createParser(InputStream inputStream) throws IOException { + return new TurtleContentParser<>(inputStream); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java index 83d4954..61d11d9 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/turtle/TurtleContentParser.java @@ -4,6 +4,7 @@ import org.xbib.content.rdf.Literal; import org.xbib.content.rdf.RdfContentBuilder; import org.xbib.content.rdf.RdfContentBuilderHandler; import org.xbib.content.rdf.RdfContentBuilderProvider; +import org.xbib.content.rdf.RdfContentParams; import org.xbib.content.rdf.RdfContentParser; import org.xbib.content.rdf.RdfContentType; import org.xbib.content.rdf.Resource; @@ -36,8 +37,9 @@ import java.util.logging.Logger; * * @see Turtle - Terse RDF * Triple Language + * @param RDF content type parameter */ -public class TurtleContentParser implements RdfContentParser { +public class TurtleContentParser implements RdfContentParser { private static final Logger logger = Logger.getLogger(TurtleContentParser.class.getName()); @@ -45,11 +47,11 @@ public class TurtleContentParser implements RdfContentParser { private final HashMap bnodes = new HashMap<>(); - private RdfContentBuilderProvider provider; + private RdfContentBuilderProvider provider; - private RdfContentBuilderHandler rdfContentBuilderHandler; + private RdfContentBuilderHandler rdfContentBuilderHandler; - private RdfContentBuilder builder; + private RdfContentBuilder builder; /** * The base IRI. @@ -136,29 +138,29 @@ public class TurtleContentParser implements RdfContentParser { return StandardRdfContentType.TURTLE; } - public TurtleContentParser setRdfContentBuilderProvider(RdfContentBuilderProvider provider) { + public TurtleContentParser setRdfContentBuilderProvider(RdfContentBuilderProvider provider) { this.provider = provider; return this; } - public TurtleContentParser setRdfContentBuilderHandler(RdfContentBuilderHandler + public TurtleContentParser setRdfContentBuilderHandler(RdfContentBuilderHandler rdfContentBuilderHandler) { this.rdfContentBuilderHandler = rdfContentBuilderHandler; return this; } - public TurtleContentParser setBaseIRI(IRI baseIRI) { + public TurtleContentParser setBaseIRI(IRI baseIRI) { this.baseIRI = baseIRI; return this; } - public TurtleContentParser context(XmlNamespaceContext context) { + public TurtleContentParser context(XmlNamespaceContext context) { this.context = context; return this; } @Override - public TurtleContentParser parse() throws IOException { + public TurtleContentParser parse() throws IOException { if (provider != null) { builder = provider.newContentBuilder(); builder.startStream(); @@ -218,7 +220,7 @@ public class TurtleContentParser implements RdfContentParser { * relative URIs. It takes, itself, a relative URI, so it can be used to * change the base URI relative to the previous one. * - * @throws IOException + * @throws IOException if directive could not be parsed */ private void parseDirective() throws IOException { String directive; diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContent.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContent.java index b0c31ba..815c442 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContent.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContent.java @@ -44,7 +44,7 @@ public class XmlContent implements RdfContent { } @Override - public RdfContentParser createParser(InputStream inputStream) throws IOException { + public RdfContentParser createParser(InputStream inputStream) throws IOException { return new XmlContentParser<>(inputStream); } } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java index 9715c86..b167ee4 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/XmlContentParser.java @@ -20,7 +20,7 @@ import java.nio.charset.StandardCharsets; * An XML reader for parsing XML into triples. * @param

parameter type */ -public class XmlContentParser

implements RdfContentParser { +public class XmlContentParser

implements RdfContentParser

{ private final Reader reader; diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java index 5c488c8..af6d505 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/json/JsonReaderTest.java @@ -66,7 +66,7 @@ public class JsonReaderTest extends StreamTester { }; RdfContentBuilder builder = jsonBuilder(); jsonHandler.setBuilder(builder); - new JsonContentParser(in) + new JsonContentParser(in) .setHandler(jsonHandler) .root(new QName("http://purl.org/dc/elements/1.1/", "root", "dc")) .parse(); diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java index af60e4c..98b15fc 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/ntriple/NTripleReaderTest.java @@ -22,7 +22,7 @@ public class NTripleReaderTest extends StreamTester { throw new IOException("file " + filename + " not found"); } RdfContentBuilder builder = ntripleBuilder(); - NTripleContentParser reader = new NTripleContentParser(in); + NTripleContentParser reader = new NTripleContentParser<>(in); reader.setBuilder(builder); reader.parse(); //assertStream(getClass().getResource("rdfxml.ttl").openStream(), diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java index 975f6ea..5220125 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleConformanceTest.java @@ -22,7 +22,7 @@ public class TurtleConformanceTest extends StreamTester { for (int n = 0; n < 30; n++) { String testNum = String.format("%02d", n); InputStream in = getClass().getResource("/turtle/test-" + testNum + ".ttl").openStream(); - TurtleContentParser turtleParser = new TurtleContentParser(in) + TurtleContentParser turtleParser = new TurtleContentParser(in) .setBaseIRI(IRI.create("http://example/base/")); turtleParser.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder); turtleParser.setRdfContentBuilderHandler(b -> { diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java index 5dfb28d..4295ea2 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/io/turtle/TurtleTest.java @@ -29,7 +29,7 @@ public class TurtleTest extends StreamTester { IRINamespaceContext context = IRINamespaceContext.newInstance(); context.addNamespace("gnd", "http://d-nb.info/gnd/"); InputStream in = getClass().getResourceAsStream("GND.ttl"); - TurtleContentParser reader = new TurtleContentParser(in) + TurtleContentParser reader = new TurtleContentParser(in) .setBaseIRI(IRI.create("http://d-nb.info/gnd/")) .context(context); reader.parse(); @@ -40,7 +40,7 @@ public class TurtleTest extends StreamTester { public void testTurtleGND2() throws Exception { IRINamespaceContext context = IRINamespaceContext.newInstance(); InputStream in = getClass().getResourceAsStream("gnd2.ttl"); - TurtleContentParser reader = new TurtleContentParser(in) + TurtleContentParser reader = new TurtleContentParser(in) .setBaseIRI(IRI.create("http://d-nb.info/gnd/")) .context(context); reader.parse(); @@ -51,7 +51,7 @@ public class TurtleTest extends StreamTester { public void testTurtleGND3() throws Exception { IRINamespaceContext context = IRINamespaceContext.newInstance(); InputStream in = getClass().getResourceAsStream("gnd2.ttl"); - TurtleContentParser reader = new TurtleContentParser(in) + TurtleContentParser reader = new TurtleContentParser(in) .setBaseIRI(IRI.create("http://d-nb.info/gnd/")) .context(context); reader.setRdfContentBuilderProvider(RdfContentFactory::turtleBuilder); diff --git a/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java b/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java index a6a6af0..249ed57 100644 --- a/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java +++ b/content-rdf/src/test/java/org/xbib/content/rdf/util/MultiMapTest.java @@ -1,12 +1,12 @@ package org.xbib.content.rdf.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.junit.Test; import java.util.Arrays; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /** * */ @@ -14,7 +14,7 @@ public class MultiMapTest { @Test public void testLinkedHashMultiMap() { - LinkedHashMultiMap map = new LinkedHashMultiMap<>(); + LinkedHashMultiMap map = new LinkedHashMultiMap<>(); map.put("a", "b"); map.put("b", "c"); map.put("a", "c"); @@ -28,7 +28,7 @@ public class MultiMapTest { @Test public void testTreeMultiMap() { - TreeMultiMap map = new TreeMultiMap<>(); + TreeMultiMap map = new TreeMultiMap<>(); map.put("a", "b"); map.put("b", "c"); map.put("a", "c");