commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [2/2] incubator-commonsrdf git commit: RDFSyntax - Java 8 style stream in byMediaType/byFileExtension
Date Mon, 28 Mar 2016 17:45:51 GMT
RDFSyntax - Java 8 style stream in byMediaType/byFileExtension

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

Branch: refs/heads/rdfsyntax-enum
Commit: 2ef97f1627d3c3d11865abb4a533d55f487699d9
Parents: c896bf7
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Mon Mar 28 18:42:04 2016 +0100
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Mon Mar 28 18:45:17 2016 +0100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/api/RDFSyntax.java   | 26 +++++++-------------
 1 file changed, 9 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/2ef97f16/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 9148cd2..84e1ca7 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
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.rdf.api;
 
+import java.util.Arrays;
 import java.util.Locale;
 import java.util.Optional;
 
@@ -153,15 +154,10 @@ public enum RDFSyntax {
 	 *         no matching syntax was found.
 	 */
 	public static Optional<RDFSyntax> byMediaType(String mediaType) {
-		mediaType = mediaType.toLowerCase(Locale.ENGLISH);
-		mediaType = mediaType.split("\\s*[;,]")[0];
-		
-		for (RDFSyntax syntax : RDFSyntax.values()) {
-			if (mediaType.equals(syntax.mediaType)) { 
-				return Optional.of(syntax);
-			}
-		}
-		return Optional.empty();
+		final String type = mediaType.toLowerCase(Locale.ENGLISH).
+				split("\\s*[;,]", 2)[0];
+		return Arrays.stream(RDFSyntax.values()).filter(
+				t -> t.mediaType.equals(type)).findAny();		
 	}
 
 	/**
@@ -178,14 +174,10 @@ public enum RDFSyntax {
 	 *         {@link Optional#empty()} indicating that no matching file
 	 *         extension was found.
 	 */
-	public static Optional<RDFSyntax> byFileExtension(String fileExtension) {
-		fileExtension = fileExtension.toLowerCase(Locale.ENGLISH);
-		for (RDFSyntax syntax : RDFSyntax.values()) {
-			if (fileExtension.equals(syntax.fileExtension)) {
-				return Optional.of(syntax);
-			}
-		}
-		return Optional.empty();
+	public static Optional<RDFSyntax> byFileExtension(String fileExtension) {		
+		final String ext = fileExtension.toLowerCase(Locale.ENGLISH);
+		return Arrays.stream(RDFSyntax.values()).filter(
+				t -> t.fileExtension.equals(ext)).findAny();		
 	}
 
 }


Mime
View raw message