commonsrdf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ans...@apache.org
Subject [17/18] incubator-commonsrdf git commit: Use hash check before iterating over ALL_TYPES
Date Mon, 30 Mar 2015 01:10:11 GMT
Use hash check before iterating over ALL_TYPES

No simple way with Set to get the actual object that we want to return
as the replacement, so still need to iterate if we think we have it.

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

Branch: refs/heads/master
Commit: 1cb8056b07261c5586d21c7ff87b19ad519c5fb1
Parents: 21207cb
Author: Peter Ansell <p_ansell@yahoo.com>
Authored: Sat Mar 28 21:57:51 2015 +1100
Committer: Peter Ansell <p_ansell@yahoo.com>
Committed: Sat Mar 28 21:57:51 2015 +1100

----------------------------------------------------------------------
 .../main/java/org/apache/commons/rdf/simple/Types.java  | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/1cb8056b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
index a8e9f52..45ee85e 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/Types.java
@@ -273,7 +273,7 @@ public final class Types implements IRI {
 	public int hashCode() {
 		return this.field.hashCode();
 	}
-	
+
 	@Override
 	public String toString() {
 		return this.field.toString();
@@ -299,9 +299,13 @@ public final class Types implements IRI {
 	 *         {@link Optional#empty()} if it is not present here.
 	 */
 	public static Optional<IRI> get(IRI nextIRI) {
-		for (IRI nextType : values()) {
-			if (nextType.equals(nextIRI)) {
-				return Optional.of(nextType);
+		if (ALL_TYPES.contains(nextIRI)) {
+			// If we know about this IRI, then look through our set to find the
+			// object that matches and return it
+			for (IRI nextType : ALL_TYPES) {
+				if (nextType.equals(nextIRI)) {
+					return Optional.of(nextType);
+				}
 			}
 		}
 		return Optional.empty();


Mime
View raw message