commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject [15/50] [abbrv] incubator-commonsrdf git commit: Reuse IRI objects in Types
Date Fri, 27 Mar 2015 18:15:13 GMT
Reuse IRI objects in Types

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

Branch: refs/heads/master
Commit: da9c4df578f412b229a5218f0d5700e8d9fbf5b7
Parents: ed963c1
Author: Peter Ansell <p_ansell@yahoo.com>
Authored: Mon Jan 26 18:03:57 2015 +1100
Committer: Peter Ansell <p_ansell@yahoo.com>
Committed: Mon Jan 26 18:03:57 2015 +1100

----------------------------------------------------------------------
 .../github/commonsrdf/simple/SimpleRDFTermFactory.java   |  4 +++-
 .../main/java/com/github/commonsrdf/simple/Types.java    | 11 +++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/da9c4df5/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java b/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
index 1825c66..1e4d307 100644
--- a/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
+++ b/simple/src/main/java/com/github/commonsrdf/simple/SimpleRDFTermFactory.java
@@ -51,7 +51,9 @@ public class SimpleRDFTermFactory implements RDFTermFactory {
 
 	@Override
 	public IRI createIRI(String iri) {
-		return new IRIImpl(iri);
+		IRI result = new IRIImpl(iri);
+		// Reuse any IRI objects already created in Types
+		return Types.get(result).orElse(result);
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/da9c4df5/simple/src/main/java/com/github/commonsrdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/com/github/commonsrdf/simple/Types.java b/simple/src/main/java/com/github/commonsrdf/simple/Types.java
index 7e8a76b..e135551 100644
--- a/simple/src/main/java/com/github/commonsrdf/simple/Types.java
+++ b/simple/src/main/java/com/github/commonsrdf/simple/Types.java
@@ -13,6 +13,8 @@
  */
 package com.github.commonsrdf.simple;
 
+import java.util.Optional;
+
 import com.github.commonsrdf.api.IRI;
 
 /**
@@ -169,4 +171,13 @@ public enum Types implements IRI {
 	public String ntriplesString() {
 		return this.field.ntriplesString();
 	}
+	
+	public static Optional<IRI> get(IRI nextIRI) {
+		for(IRI nextType : values()) {
+			if(nextType.equals(nextIRI)) {
+				return Optional.of(nextType); 
+			}
+		}
+		return Optional.empty();
+	}
 }


Mime
View raw message