commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [2/3] incubator-commonsrdf git commit: RDFSyntax as interface with getMediaType()
Date Sun, 27 Mar 2016 18:45:27 GMT
RDFSyntax as interface with getMediaType()

.. adding the standard under the .Standard enum

.. but remember enums can't override their hashCode() or equals() -
so we then can't require that an RDFSyntax is equals based on its
getContentType()


Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/b517778c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/b517778c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/b517778c

Branch: refs/heads/rdfsyntax-interface
Commit: b517778cb63d56bb336f686aad056e1d6788cf71
Parents: 1a63f48
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Sun Mar 27 19:42:16 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Sun Mar 27 19:43:15 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/RDFSyntax.java   | 43 ++++++++++++------
 .../apache/commons/rdf/api/RDFSyntaxTest.java   | 48 ++++++++++----------
 2 files changed, 54 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b517778c/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
index c1b5ea1..3e4ed26 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java
@@ -31,7 +31,20 @@ import java.util.Optional;
  * @see <a href="https://www.w3.org/TR/rdf11-primer/#section-graph-syntax">RDF 1.1
Primer</a>
  *
  */
-public enum RDFSyntax {
+public interface RDFSyntax {
+	
+	/** 
+	 * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for
the RDF syntax.
+	 * <p> 
+	 * The media type can be used as part of 
+	 * <code>Content-Type</code> 
+	 * and <code>Accept</code> for <em>content negotiation</em> in the

+	 * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP protocol</a>.

+	 */
+	public String getMediaType();
+	
+	
+	public enum Standard implements RDFSyntax {
 	
 	/**
 	 * JSON-LD 1.0
@@ -91,15 +104,8 @@ public enum RDFSyntax {
 	 */
 	TRIG("RDF 1.1 TriG", "application/trig");
 
-	/** 
-	 * The <a href="https://tools.ietf.org/html/rfc2046">IANA media type</a> for
the RDF syntax.
-	 * <p> 
-	 * The media type can be used as part of 
-	 * <code>Content-Type</code> 
-	 * and <code>Accept</code> for <em>content negotiation</em> in the

-	 * <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP protocol</a>.

-	 */
-	public final String mediaType;
+
+	private final String mediaType;
 		
 	private final String name;
 	
@@ -113,7 +119,8 @@ public enum RDFSyntax {
 		return name;
 	}
 	
-	private RDFSyntax(String name, String mediaType) {
+	
+	private Standard(String name, String mediaType) {
 		this.name = name;
 		this.mediaType = mediaType;
 	}
@@ -137,11 +144,11 @@ public enum RDFSyntax {
 	 *         {@link Optional#empty()} indicating that 
 	 *         no matching syntax was found.
 	 */
-	public static Optional<RDFSyntax> byMediaType(String mediaType) {
+	public static Optional<Standard> byMediaType(String mediaType) {
 		mediaType = mediaType.toLowerCase(Locale.ENGLISH);
 		mediaType = mediaType.split("\\s*[;,]")[0];
 		
-		for (RDFSyntax syntax : RDFSyntax.values()) {
+		for (Standard syntax : Standard.values()) {
 			if (mediaType.equals(syntax.mediaType)) { 
 				return Optional.of(syntax);
 			}
@@ -149,4 +156,14 @@ public enum RDFSyntax {
 		return Optional.empty();
 	}
 
+	@Override
+	public String getMediaType() {
+		return mediaType;
+	}
+	
+	
+	
+	
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/b517778c/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java b/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
index 701545f..c0b5b85 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java
@@ -27,50 +27,50 @@ public class RDFSyntaxTest {
 
 	@Test
 	public void mediaType() throws Exception {
-		assertEquals("application/ld+json", RDFSyntax.JSONLD.mediaType);
-		assertEquals("application/n-quads", RDFSyntax.NQUADS.mediaType);
-		assertEquals("application/n-triples", RDFSyntax.NTRIPLES.mediaType);
-		assertEquals("text/html", RDFSyntax.RDFA_HTML.mediaType);
-		assertEquals("application/xhtml+xml", RDFSyntax.RDFA_XHTML.mediaType);
-		assertEquals("application/rdf+xml", RDFSyntax.RDFXML.mediaType);
-		assertEquals("application/trig", RDFSyntax.TRIG.mediaType);
-		assertEquals("text/turtle", RDFSyntax.TURTLE.mediaType);
+		assertEquals("application/ld+json", RDFSyntax.Standard.JSONLD.getMediaType());
+		assertEquals("application/n-quads", RDFSyntax.Standard.NQUADS.getMediaType());
+		assertEquals("application/n-triples", RDFSyntax.Standard.NTRIPLES.getMediaType());
+		assertEquals("text/html", RDFSyntax.Standard.RDFA_HTML.getMediaType());
+		assertEquals("application/xhtml+xml", RDFSyntax.Standard.RDFA_XHTML.getMediaType());
+		assertEquals("application/rdf+xml", RDFSyntax.Standard.RDFXML.getMediaType());
+		assertEquals("application/trig", RDFSyntax.Standard.TRIG.getMediaType());
+		assertEquals("text/turtle", RDFSyntax.Standard.TURTLE.getMediaType());
 	}
 
 	@Test
 	public void byMediaType() throws Exception {
-		assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("application/ld+json").get());
-		assertEquals(RDFSyntax.NQUADS, RDFSyntax.byMediaType("application/n-quads").get());
-		assertEquals(RDFSyntax.NTRIPLES, RDFSyntax.byMediaType("application/n-triples").get());
-		assertEquals(RDFSyntax.RDFA_HTML, RDFSyntax.byMediaType("text/html").get());
-		assertEquals(RDFSyntax.RDFA_XHTML, RDFSyntax.byMediaType("application/xhtml+xml").get());
-		assertEquals(RDFSyntax.RDFXML, RDFSyntax.byMediaType("application/rdf+xml").get());
-		assertEquals(RDFSyntax.TRIG, RDFSyntax.byMediaType("application/trig").get());
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle").get());
+		assertEquals(RDFSyntax.Standard.JSONLD, RDFSyntax.Standard.byMediaType("application/ld+json").get());
+		assertEquals(RDFSyntax.Standard.NQUADS, RDFSyntax.Standard.byMediaType("application/n-quads").get());
+		assertEquals(RDFSyntax.Standard.NTRIPLES, RDFSyntax.Standard.byMediaType("application/n-triples").get());
+		assertEquals(RDFSyntax.Standard.RDFA_HTML, RDFSyntax.Standard.byMediaType("text/html").get());
+		assertEquals(RDFSyntax.Standard.RDFA_XHTML, RDFSyntax.Standard.byMediaType("application/xhtml+xml").get());
+		assertEquals(RDFSyntax.Standard.RDFXML, RDFSyntax.Standard.byMediaType("application/rdf+xml").get());
+		assertEquals(RDFSyntax.Standard.TRIG, RDFSyntax.Standard.byMediaType("application/trig").get());
+		assertEquals(RDFSyntax.Standard.TURTLE, RDFSyntax.Standard.byMediaType("text/turtle").get());
 	}
 
 	@Test
 	public void name() throws Exception {
-		assertEquals("JSON-LD 1.0", RDFSyntax.JSONLD.toString());
-		assertEquals("RDF 1.1 Turtle", RDFSyntax.TURTLE.toString());
+		assertEquals("JSON-LD 1.0", RDFSyntax.Standard.JSONLD.toString());
+		assertEquals("RDF 1.1 Turtle", RDFSyntax.Standard.TURTLE.toString());
 	}
 
 	@Test
 	public void byMediaTypeUnknown() throws Exception {
-		assertEquals(Optional.empty(), RDFSyntax.byMediaType("application/octet-stream"));
+		assertEquals(Optional.empty(), RDFSyntax.Standard.byMediaType("application/octet-stream"));
 	}
 
 	@Test
 	public void byMediaTypeLowerCase() throws Exception {
-		assertEquals(RDFSyntax.JSONLD, RDFSyntax.byMediaType("APPLICATION/ld+JSON").get());
+		assertEquals(RDFSyntax.Standard.JSONLD, RDFSyntax.Standard.byMediaType("APPLICATION/ld+JSON").get());
 	}
 
 	@Test
 	public void byMediaTypeContentType() throws Exception {
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle; charset=\"UTF-8\"").get());
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle ; charset=\"UTF-8\"").get());
-		assertEquals(RDFSyntax.TURTLE, RDFSyntax.byMediaType("text/turtle, text/plain").get());
-		assertEquals(Optional.empty(), RDFSyntax.byMediaType(" text/turtle"));
+		assertEquals(RDFSyntax.Standard.TURTLE, RDFSyntax.Standard.byMediaType("text/turtle; charset=\"UTF-8\"").get());
+		assertEquals(RDFSyntax.Standard.TURTLE, RDFSyntax.Standard.byMediaType("text/turtle ; charset=\"UTF-8\"").get());
+		assertEquals(RDFSyntax.Standard.TURTLE, RDFSyntax.Standard.byMediaType("text/turtle, text/plain").get());
+		assertEquals(Optional.empty(), RDFSyntax.Standard.byMediaType(" text/turtle"));
 	}
 
 }


Mime
View raw message