Fix test bug: use reset prefixes

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

Branch: refs/heads/master
Commit: 55ba0e807b6ebd4f89b16ae6c621e226b1452e38
Parents: 2377f47
Author: Andy Seaborne <a...@apache.org>
Authored: Sat Jun 9 15:09:40 2018 +0100
Committer: Andy Seaborne <a...@apache.org>
Committed: Mon Jun 11 14:35:08 2018 +0100

----------------------------------------------------------------------
 .../jena/sparql/graph/PrefixMappingAdapter.java | 99 ++++++++++++++++++++
 .../jena/sparql/graph/PrefixMappingBase.java    | 26 +++--
 .../jena/sparql/graph/PrefixMappingMem.java     | 11 ++-
 .../jena/sparql/graph/PrefixMappingOver.java    | 97 -------------------
 .../jena/sparql/graph/PrefixMappingSink.java    |  4 +-
 .../jena/sparql/graph/PrefixMappingZero.java    |  4 +-
 .../graph/TestPrefixMappingPrefixMap.java       |  4 +-
 .../jena/tdb/graph/TestPrefixMappingTDB.java    |  4 +-
 8 files changed, 132 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingAdapter.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingAdapter.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingAdapter.java
new file mode 100644
index 0000000..f48c6b5
--- /dev/null
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingAdapter.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.graph;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+
+import org.apache.jena.iri.IRI;
+import org.apache.jena.riot.system.PrefixMap;
+import org.apache.jena.shared.PrefixMapping;
+
+/** Provided {@link PrefixMapping} for a {@link PrefixMap}. */
+public class PrefixMappingAdapter extends PrefixMappingBase {
+
+    private final PrefixMap pmap;
+    
+    public PrefixMappingAdapter(PrefixMap pmap) {
+        this.pmap = pmap;
+    }
+    
+    @Override
+    protected void add(String prefix, String uri) {
+        pmap.add(prefix, uri);
+    }
+
+    @Override
+    protected void remove(String prefix) {
+        pmap.delete(prefix);
+    }
+
+    @Override
+    protected void clear() {
+        pmap.clear();
+    }
+
+    @Override
+    protected boolean isEmpty() {
+        return pmap.isEmpty();
+    }
+
+    @Override
+    protected int size() {
+        return pmap.size();
+    }
+
+    @Override
+    protected String prefixToUri(String prefix) {
+        IRI iri = pmap.getMapping().get(prefix);
+        if ( iri == null )
+            return null;
+        return iri.toString();
+    }
+
+    @Override
+    protected String uriToPrefix(String uri) {
+       return pmap.getMapping().entrySet().stream()
+           .filter(e->Objects.equals(uri, e.getValue().toString()))
+           .map(Entry::getKey)
+           .findFirst()
+           .orElse(null);
+    }
+
+    @Override
+    protected Map<String, String> asMap() {
+        return pmap.getMappingCopyStr();
+    }
+
+    @Override
+    protected Map<String, String> asMapCopy() {
+        return pmap.getMappingCopyStr();
+    }
+
+    @Override
+    protected void apply(BiConsumer<String, String> action) {
+        BiConsumer<String, IRI> a = (p, iri)->action.accept(p, iri.toString());
+        pmap.forEach(a);
+    }
+
+    
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java
index a9e1e7c..8c927c6 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingBase.java
@@ -33,15 +33,13 @@ import org.apache.jena.util.SplitIRI;
  * {@code PrefixMappingImpl}) and implements the contract of {@link 
PrefixMapping},
  * providing the key algorithm and delegating storage to the subclasses.
  * <p>
- * Reverse mapping, looking up a URI to find a prefix is complex. There may be 
several
- * possibilities. Applications should not reliy on every implementat being 
consistent,
- * espeically when writing data when there has to be a choice on on prefix to 
use to
- * shorten a URI.
- * 
+ * Reverse mapping, looking up a URI to find a prefix is complex because there 
may be several
+ * possibilities. Applications should not rely on every implementation being 
consistent
+ * when there is a choice of which prefix to use to shorten a URI.
  */
 public abstract class PrefixMappingBase implements PrefixMapping {
     /* Reverse mappings.
-     * The strict contract of PrefixMapping requires a separate reversemapping 
to be storoed and manipuated
+     * The strict contract of PrefixMapping requires a separate reverse 
mapping to be stored and manipulated,
      * which in turn adds complexity to the storage implementations.
      * However, applications removing prefixes is unusual so we end up with a 
lot of complexity with little value.
      * 
@@ -92,8 +90,8 @@ public abstract class PrefixMappingBase implements 
PrefixMapping {
     
     /** Return as a map. This map is only used within this class.
      * It can be as efficient as possible.
-     * It will not be modifed.
-     * It wil not be retuned to a caller of {@code PrefixMappingBase}.
+     * It will not be modified.
+     * It will not be returned to a caller of {@code PrefixMappingBase}.
      */
     abstract protected Map<String, String> asMap();
 
@@ -107,7 +105,7 @@ public abstract class PrefixMappingBase implements 
PrefixMapping {
     abstract protected void apply(BiConsumer<String, String> action);
     
     /**
-     * This part of the subclass API and may be overriden if an implementation 
can do
+     * This part of the subclass API and may be overridden if an 
implementation can do
      * better This general implementation is based on asMap() which may be a 
copy or may
      * be a view of the storage directly.
      */
@@ -122,7 +120,7 @@ public abstract class PrefixMappingBase implements 
PrefixMapping {
 
     @Override
     public PrefixMapping setNsPrefix(String prefix, String uri) {
-        checkLegal(prefix); 
+        checkLegalPrefix(prefix); 
         add(prefix, uri);
         return this;
     }
@@ -150,7 +148,7 @@ public abstract class PrefixMappingBase implements 
PrefixMapping {
      * <p>
      * See also {@link #qnameFor}.
      */
-    private void checkLegal(String prefix) {
+    public static void checkLegalPrefix(String prefix) {
         if ( prefix == null )
             throw new PrefixMapping.IllegalPrefixException("null for prefix");
         if ( prefix.length() > 0 && !XMLChar.isValidNCName(prefix) )
@@ -177,13 +175,13 @@ public abstract class PrefixMappingBase implements 
PrefixMapping {
 
     /* Not javadoc.
         This is the unusual contract as defined by the interface:
-        Update this PrefixMapping with the bindings in <code>map</code>, only
-        adding those (p, u) pairs for which neither p nor u appears in this 
mapping.
+      Update this PrefixMapping with the bindings in <code>map</code>, only
+      adding those (p, u) pairs for which neither p nor u appears in this 
mapping.
      */
     @Override
     public PrefixMapping withDefaultMappings(PrefixMapping pmap) {
         if ( pmap instanceof PrefixMappingBase ) {
-            // Direct. No intemediate Map<> object created,
+            // Direct. No intermediate Map<> object created,
             PrefixMappingBase pmap2 = (PrefixMappingBase)pmap;
             pmap2.apply(this::addWith);
             return this;

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingMem.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingMem.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingMem.java
index e4a8e0e..07c6809 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingMem.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingMem.java
@@ -24,7 +24,16 @@ import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.BiConsumer;
 
-/** In-memory pair of maps */ 
+import org.apache.jena.shared.PrefixMapping;
+import org.apache.jena.shared.impl.PrefixMappingImpl;
+
+/** 
+ * A {@link PrefixMapping} implemented as a pair of in-memory maps.
+ * 
+ * @implNote
+ * {@link PrefixMappingImpl} is the long time implementation.
+ * This class should be exactly the same within the {@link PrefixMappingBase} 
framework.  
+ */ 
 public class PrefixMappingMem extends PrefixMappingBase {
 
     private Map<String, String> prefixToUri = new ConcurrentHashMap<>();

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java
deleted file mode 100644
index c933d04..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingOver.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.graph;
-
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.function.BiConsumer;
-
-import org.apache.jena.iri.IRI;
-import org.apache.jena.riot.system.PrefixMap;
-
-public class PrefixMappingOver extends PrefixMappingBase {
-
-    private final PrefixMap pmap;
-    
-    public PrefixMappingOver(PrefixMap pmap) {
-        this.pmap = pmap;
-    }
-    
-    @Override
-    protected void add(String prefix, String uri) {
-        pmap.add(prefix, uri);
-    }
-
-    @Override
-    protected void remove(String prefix) {
-        pmap.delete(prefix);
-    }
-
-    @Override
-    protected void clear() {
-        pmap.clear();
-    }
-
-    @Override
-    protected boolean isEmpty() {
-        return pmap.isEmpty();
-    }
-
-    @Override
-    protected int size() {
-        return pmap.size();
-    }
-
-    @Override
-    protected String prefixToUri(String prefix) {
-        IRI iri = pmap.getMapping().get(prefix);
-        if ( iri == null )
-            return null;
-        return iri.toString();
-    }
-
-    @Override
-    protected String uriToPrefix(String uri) {
-       return pmap.getMapping().entrySet().stream()
-           .filter(e->Objects.equals(uri, e.getValue().toString()))
-           .map(Entry::getKey)
-           .findFirst()
-           .orElse(null);
-    }
-
-    @Override
-    protected Map<String, String> asMap() {
-        return pmap.getMappingCopyStr();
-    }
-
-    @Override
-    protected Map<String, String> asMapCopy() {
-        return pmap.getMappingCopyStr();
-    }
-
-    @Override
-    protected void apply(BiConsumer<String, String> action) {
-        BiConsumer<String, IRI> a = (p, iri)->action.accept(p, iri.toString());
-        pmap.forEach(a);
-    }
-
-    
-    
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingSink.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingSink.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingSink.java
index 03dfb2b..b23a10d 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingSink.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingSink.java
@@ -24,7 +24,9 @@ import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.function.BiConsumer;
 
-/** Sink PrefixMapping. Accepts changes but does not retain state. */ 
+import org.apache.jena.shared.PrefixMapping;
+
+/** Sink {@link PrefixMapping}. Accepts changes but does not retain state. */ 
 public class PrefixMappingSink extends PrefixMappingBase {
     @Override
     protected void add(String prefix, String uri) { }

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingZero.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingZero.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingZero.java
index 0953c4e..f329ff4 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingZero.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/graph/PrefixMappingZero.java
@@ -18,7 +18,9 @@
 
 package org.apache.jena.sparql.graph;
 
-/** Immutable empty PrefixMapping. */
+import org.apache.jena.shared.PrefixMapping;
+
+/** Immutable empty {@link PrefixMapping}. */
 public class PrefixMappingZero extends PrefixMappingSink {
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestPrefixMappingPrefixMap.java
----------------------------------------------------------------------
diff --git 
a/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestPrefixMappingPrefixMap.java
 
b/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestPrefixMappingPrefixMap.java
index 856e6f6..176fd3e4 100644
--- 
a/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestPrefixMappingPrefixMap.java
+++ 
b/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestPrefixMappingPrefixMap.java
@@ -24,7 +24,7 @@ import org.apache.jena.riot.system.PrefixMap;
 import org.apache.jena.riot.system.PrefixMapFactory;
 import org.apache.jena.shared.AbstractTestPrefixMapping;
 import org.apache.jena.shared.PrefixMapping;
-import org.apache.jena.sparql.graph.PrefixMappingOver;
+import org.apache.jena.sparql.graph.PrefixMappingAdapter;
 
 /** Test a {@link PrefixMapping} backed by a {@link PrefixMap} */
 public class TestPrefixMappingPrefixMap extends AbstractTestPrefixMapping {
@@ -36,7 +36,7 @@ public class TestPrefixMappingPrefixMap extends 
AbstractTestPrefixMapping {
     @Override
     protected PrefixMapping getMapping() {
         PrefixMap pmap = PrefixMapFactory.create();
-        return new PrefixMappingOver(pmap);
+        return new PrefixMappingAdapter(pmap);
     }
     
     // PrefixMaps only keep the prefix -> URI direction mapping.

http://git-wip-us.apache.org/repos/asf/jena/blob/55ba0e80/jena-tdb/src/test/java/org/apache/jena/tdb/graph/TestPrefixMappingTDB.java
----------------------------------------------------------------------
diff --git 
a/jena-tdb/src/test/java/org/apache/jena/tdb/graph/TestPrefixMappingTDB.java 
b/jena-tdb/src/test/java/org/apache/jena/tdb/graph/TestPrefixMappingTDB.java
index e226421..de26fb2 100644
--- a/jena-tdb/src/test/java/org/apache/jena/tdb/graph/TestPrefixMappingTDB.java
+++ b/jena-tdb/src/test/java/org/apache/jena/tdb/graph/TestPrefixMappingTDB.java
@@ -111,7 +111,9 @@ public class TestPrefixMappingTDB extends 
AbstractTestPrefixMapping2
         prefixes.close() ;
 
         prefixes = createTesting(Location.create(dir), new 
DatasetControlMRSW()) ;
-        assertEquals("http://foo/";, pmap1.getNsPrefixURI("x")) ;
+        PrefixMapping pmap2 = prefixes.getPrefixMapping() ;
+        String uri = pmap2.getNsPrefixURI("x");
+        assertEquals("http://foo/";, uri) ;
         prefixes.close() ;
     }
     

Reply via email to