commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject commons-rdf git commit: Added byName()
Date Thu, 12 Jan 2017 17:39:46 GMT
Repository: commons-rdf
Updated Branches:
  refs/heads/COMMONSRDF-47 dc082d141 -> c04864bf8


Added byName()


Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/c04864bf
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/c04864bf
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/c04864bf

Branch: refs/heads/COMMONSRDF-47
Commit: c04864bf866131fcd4fa2c00d4782864c2b7fe44
Parents: dc082d1
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Jan 12 17:39:42 2017 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Jan 12 17:39:42 2017 +0000

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/RDFSyntax.java   | 21 ++++++++++++++++++--
 .../apache/commons/rdf/api/RDFSyntaxTest.java   |  3 +--
 2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/c04864bf/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 0d2f0b0..70048e1 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
@@ -190,7 +190,7 @@ public interface RDFSyntax {
      * @param mediaType
      *            The media type to match
      * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
-     *         a matching {@link RDFSyntax#mediaType}, otherwise
+     *         a matching {@link RDFSyntax#mediaType()}, otherwise
      *         {@link Optional#empty()} indicating that no matching syntax was
      *         found.
      */
@@ -213,7 +213,7 @@ public interface RDFSyntax {
      * @param fileExtension
      *            The fileExtension to match, starting with <code>.</code>
      * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
-     *         a matching {@link RDFSyntax#fileExtension}, otherwise
+     *         a matching {@link RDFSyntax#fileExtension()}, otherwise
      *         {@link Optional#empty()} indicating that no matching file
      *         extension was found.
      */
@@ -224,6 +224,22 @@ public interface RDFSyntax {
     }
     
     /**
+     * Return the RDFSyntax with the specified {@link #name()}.
+     * <p>
+     * The list of syntaxes supported is at least those returned by
+     * {@link #w3cSyntaxes()}
+     * 
+     * @param name
+     *            The name to match, , e.g. <code>"JSONLD"</code>
+     * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} which has
+     *         a matching {@link RDFSyntax#name()}, otherwise
+     *         {@link Optional#empty()} indicating that no matching name was found.
+     */    
+    public static Optional<RDFSyntax> byName(final String name) {
+        return w3cSyntaxes().stream().filter(t -> t.name().equals(name)).findAny();
+    }
+    
+    /**
      * Compare this RDFSyntax with another object.
      * <p>
      * Two {@link RDFSyntax}es are considered equal if their
@@ -247,4 +263,5 @@ public interface RDFSyntax {
      */
     @Override
     int hashCode();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/c04864bf/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 8fc79e4..edf68af 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
@@ -116,8 +116,7 @@ public class RDFSyntaxTest {
 
     @Test
     public void valueOf() throws Exception {
-        assertEquals(RDFSyntax.TURTLE, RDFSyntax.valueOf("TURTLE"));
-        // No need to test all of them, we'll trust Enum
+        assertEquals(RDFSyntax.TURTLE, RDFSyntax.byName("TURTLE"));
     }
     
 }


Mime
View raw message