jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [4/8] jena git commit: JENA-1249 - Add PrefixMapping.numPrefixes and PrefixMapping.noMappings
Date Wed, 26 Oct 2016 21:43:31 GMT
JENA-1249 - Add PrefixMapping.numPrefixes and PrefixMapping.noMappings

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

Branch: refs/heads/master
Commit: 4573a430e7b05c9a3e669e53f128507461f03bf3
Parents: 7df4d4c
Author: Andy Seaborne <andy@apache.org>
Authored: Tue Oct 25 12:49:06 2016 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Tue Oct 25 12:49:06 2016 +0100

----------------------------------------------------------------------
 .../jena/query/ParameterizedSparqlString.java      | 10 ++++++++++
 .../apache/jena/sparql/util/PrefixMapping2.java    | 17 +++++++++++++++++
 .../java/org/apache/jena/shared/PrefixMapping.java | 15 ++++++++++++++-
 .../apache/jena/shared/impl/PrefixMappingImpl.java |  8 ++++++++
 .../jena/shared/AbstractTestPrefixMapping.java     | 15 +++++++++++++++
 .../graph/impl/SecuredPrefixMappingImpl.java       | 12 ++++++++++++
 .../permissions/model/impl/SecuredModelImpl.java   |  4 ++--
 .../apache/jena/permissions/MockPrefixMapping.java |  5 +++++
 .../permissions/model/SecuredModelDetailTest.java  |  6 ++++--
 9 files changed, 87 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-arq/src/main/java/org/apache/jena/query/ParameterizedSparqlString.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/ParameterizedSparqlString.java b/jena-arq/src/main/java/org/apache/jena/query/ParameterizedSparqlString.java
index 928b728..db173f9 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/ParameterizedSparqlString.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/ParameterizedSparqlString.java
@@ -1508,6 +1508,16 @@ public class ParameterizedSparqlString implements PrefixMapping {
     }
 
     @Override
+    public boolean hasNoMappings() {
+        return this.prefixes.hasNoMappings();
+    }
+    
+    @Override
+    public int numPrefixes() {
+        return this.prefixes.numPrefixes();
+    }    
+    
+    @Override
     public PrefixMapping lock() {
         return this.prefixes.lock();
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-arq/src/main/java/org/apache/jena/sparql/util/PrefixMapping2.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/util/PrefixMapping2.java b/jena-arq/src/main/java/org/apache/jena/sparql/util/PrefixMapping2.java
index f837300..cc730ef 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/util/PrefixMapping2.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/util/PrefixMapping2.java
@@ -18,6 +18,7 @@
 
 package org.apache.jena.sparql.util;
 
+import java.util.HashMap;
 import java.util.Map ;
 
 import org.apache.jena.shared.PrefixMapping ;
@@ -180,6 +181,22 @@ public class PrefixMapping2 implements PrefixMapping
         return null ;
     }
 
+    @Override
+    public boolean hasNoMappings() {
+        return pmapLocal.hasNoMappings() && pmapGlobal.hasNoMappings();
+    }
+    
+    @Override
+    public int numPrefixes() {
+        // Expensive but gets the right answer.
+        Map<String, String> x = new HashMap<>() ;
+        x.putAll(pmapLocal.getNsPrefixMap()) ;
+        x.putAll(pmapGlobal.getNsPrefixMap()) ;
+        return x.size() ;
+    }    
+    
+
+    
     /** @see org.apache.jena.shared.PrefixMapping#lock() */
     @Override
     public PrefixMapping lock()

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-core/src/main/java/org/apache/jena/shared/PrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/shared/PrefixMapping.java b/jena-core/src/main/java/org/apache/jena/shared/PrefixMapping.java
index 2ff26de..404cd90 100644
--- a/jena-core/src/main/java/org/apache/jena/shared/PrefixMapping.java
+++ b/jena-core/src/main/java/org/apache/jena/shared/PrefixMapping.java
@@ -174,7 +174,20 @@ public interface PrefixMapping
          @return this mapping, locked against changes
     */
     PrefixMapping lock();
-
+    
+    // These can not be called the usual "isEmpty" and "size" because this interface is inherited
+    // in places where those names are in use for the main putrpose of the interface (e.g.
Model).  
+    
+    /**
+        Return whether the prefix mapping has any defined prefixes.
+     */
+    default boolean hasNoMappings() { return numPrefixes() == 0 ; }
+    
+    /**
+         Return the number of defined prefixes.
+     */
+    int numPrefixes() ;
+    
     /**
         Exception to throw when the prefix argument to setNsPrefix is
         illegal for some reason.

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java b/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
index 4a492a1..d601bba 100644
--- a/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
+++ b/jena-core/src/main/java/org/apache/jena/shared/impl/PrefixMappingImpl.java
@@ -253,6 +253,14 @@ public class PrefixMappingImpl implements PrefixMapping
             ;
         }
     
+    @Override
+    public boolean hasNoMappings()
+        { return prefixToURI.isEmpty(); }
+
+    @Override
+    public int numPrefixes()
+        { return prefixToURI.size(); }
+    
     protected boolean equals( PrefixMappingImpl other )
         { return other.sameAs( this ); }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-core/src/test/java/org/apache/jena/shared/AbstractTestPrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-core/src/test/java/org/apache/jena/shared/AbstractTestPrefixMapping.java
b/jena-core/src/test/java/org/apache/jena/shared/AbstractTestPrefixMapping.java
index e49271e..ae90e8b 100644
--- a/jena-core/src/test/java/org/apache/jena/shared/AbstractTestPrefixMapping.java
+++ b/jena-core/src/test/java/org/apache/jena/shared/AbstractTestPrefixMapping.java
@@ -416,7 +416,22 @@ public abstract class AbstractTestPrefixMapping extends GraphTestBase
         assertEquals( null, A.getNsURIPrefix(bURI) ) ;
     }
 
+    public void testNoMapping() {
+        String hURI = "http://test.prefixes/prefix#";
+        PrefixMapping A = getMapping();
+        assertTrue(A.hasNoMappings()) ;
+        A.setNsPrefix( "hr", hURI );
+        assertFalse(A.hasNoMappings()) ;
+    }
     
+    public void testNumPrefixes() {
+        String hURI = "http://test.prefixes/prefix#";
+        PrefixMapping A = getMapping();
+        assertEquals(0, A.numPrefixes()) ;
+        A.setNsPrefix( "hr", hURI );
+        assertEquals(1, A.numPrefixes()) ;
+    }
+
     public void testEquality()
         {
         testEquals( "" );

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-permissions/src/main/java/org/apache/jena/permissions/graph/impl/SecuredPrefixMappingImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/graph/impl/SecuredPrefixMappingImpl.java
b/jena-permissions/src/main/java/org/apache/jena/permissions/graph/impl/SecuredPrefixMappingImpl.java
index 0f4d36d..da27768 100644
--- a/jena-permissions/src/main/java/org/apache/jena/permissions/graph/impl/SecuredPrefixMappingImpl.java
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/graph/impl/SecuredPrefixMappingImpl.java
@@ -148,6 +148,18 @@ public class SecuredPrefixMappingImpl extends SecuredItemImpl implements
 		checkRead();
 		return holder.getBaseItem().shortForm(uri);
 	}
+	
+    @Override
+    public boolean hasNoMappings() {
+        checkRead();
+        return holder.getBaseItem().hasNoMappings();
+    }
+
+    @Override
+    public int numPrefixes() {
+        checkRead();
+        return holder.getBaseItem().numPrefixes();
+    }
 
 	@Override
 	public SecuredPrefixMapping withDefaultMappings(final PrefixMapping map)

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredModelImpl.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredModelImpl.java
b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredModelImpl.java
index 794c8d1..e0024f4 100644
--- a/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredModelImpl.java
+++ b/jena-permissions/src/main/java/org/apache/jena/permissions/model/impl/SecuredModelImpl.java
@@ -1954,9 +1954,9 @@ public class SecuredModelImpl extends SecuredItemImpl implements SecuredModel
{
 	}
 	
     @Override
-    public boolean noMappings() {
+    public boolean hasNoMappings() {
         checkRead();
-        return holder.getBaseItem().noMappings();
+        return holder.getBaseItem().hasNoMappings();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-permissions/src/test/java/org/apache/jena/permissions/MockPrefixMapping.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/MockPrefixMapping.java
b/jena-permissions/src/test/java/org/apache/jena/permissions/MockPrefixMapping.java
index 21ecee2..e0c9ecc 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/MockPrefixMapping.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/MockPrefixMapping.java
@@ -108,4 +108,9 @@ public class MockPrefixMapping implements PrefixMapping
 	{
 		throw new UnsupportedOperationException();
 	}
+
+    @Override
+    public int numPrefixes() {
+        return getNsPrefixMap().size() ;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/jena/blob/4573a430/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
index e17d2dd..382ffad 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
@@ -275,9 +275,11 @@ public class SecuredModelDetailTest {
 		private Model model;
 		private RDFNode msgType = ResourceFactory
 				.createResource("http://example.com/msg");
-		private Property pTo = ResourceFactory
+		@SuppressWarnings("hiding")
+        private Property pTo = ResourceFactory
 				.createProperty("http://example.com/to");
-		private Property pFrom = ResourceFactory
+		@SuppressWarnings("hiding")
+        private Property pFrom = ResourceFactory
 				.createProperty("http://example.com/from");
 
 		/**


Mime
View raw message