You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/05/17 09:51:40 UTC

[09/14] jena git commit: ConcurrentHashMap

ConcurrentHashMap

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/204f2530
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/204f2530
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/204f2530

Branch: refs/heads/master
Commit: 204f2530937dbdf8d78c64839436b0a2aaf4518f
Parents: af370df
Author: Andy Seaborne <an...@apache.org>
Authored: Mon May 16 10:14:37 2016 +0100
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon May 16 10:14:37 2016 +0100

----------------------------------------------------------------------
 .../org/apache/jena/sparql/util/Context.java    | 57 ++++++++++++--------
 1 file changed, 35 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/204f2530/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
index ce911a8..0267510 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/Context.java
@@ -19,6 +19,7 @@
 package org.apache.jena.sparql.util ;
 
 import java.util.* ;
+import java.util.concurrent.ConcurrentHashMap ;
 
 import org.apache.jena.atlas.lib.Callback ;
 import org.apache.jena.atlas.lib.Lib ;
@@ -35,7 +36,7 @@ import org.apache.jena.sparql.core.DatasetGraph ;
 public class Context {
     public static final Context      emptyContext = new Context(true) ;
 
-    protected Map<Symbol, Object>    context      = new HashMap<>() ;
+    protected Map<Symbol, Object>    context      = new ConcurrentHashMap<>() ;
     protected List<Callback<Symbol>> callbacks    = new ArrayList<>() ;
     protected boolean                readonly     = false ;
 
@@ -307,36 +308,20 @@ public class Context {
         return context.size() ;
     }
 
-    // @Override
-    // public int hashCode()
-    // {
-    // return context.hashCode() ;
-    // }
-    //
-    // @Override
-    // public boolean equals(Object other)
-    // {
-    // if ( this == other ) return true ;
-    //
-    // if ( ! ( other instanceof Context ) ) return false ;
-    // Context cxt = (Context)other ;
-    // return context.equals(cxt.context) ;
-    // }
-
     // ---- Callbacks
-    public void addCallback(Callback<Symbol> m) {
+    public synchronized void addCallback(Callback<Symbol> m) {
         callbacks.add(m) ;
     }
 
-    public void removeCallback(Callback<Symbol> m) {
+    public synchronized void removeCallback(Callback<Symbol> m) {
         callbacks.remove(m) ;
     }
 
-    public List<Callback<Symbol>> getCallbacks() {
-        return callbacks ;
+    public synchronized List<Callback<Symbol>> getCallbacks() {
+        return Collections.unmodifiableList(callbacks) ;
     }
 
-    private void doCallbacks(Symbol symbol) {
+    private synchronized void doCallbacks(Symbol symbol) {
         for ( Callback<Symbol> c : callbacks ) {
             c.apply(symbol) ;
         }
@@ -378,4 +363,32 @@ public class Context {
         return context ;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31 ;
+        int result = 1 ;
+        result = prime * result + ((context == null) ? 0 : context.hashCode()) ;
+        result = prime * result + (readonly ? 1231 : 1237) ;
+        return result ;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if ( this == obj )
+            return true ;
+        if ( obj == null )
+            return false ;
+        if ( getClass() != obj.getClass() )
+            return false ;
+        Context other = (Context)obj ;
+        if ( context == null ) {
+            if ( other.context != null )
+                return false ;
+        } else if ( !context.equals(other.context) )
+            return false ;
+        if ( readonly != other.readonly )
+            return false ;
+        return true ;
+    }
+
 }