jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1443363 - in /jena/trunk/jena-arq/src: main/java/org/apache/jena/riot/system/ test/java/org/apache/jena/riot/system/
Date Thu, 07 Feb 2013 09:17:15 GMT
Author: andy
Date: Thu Feb  7 09:17:14 2013
New Revision: 1443363

URL: http://svn.apache.org/viewvc?rev=1443363&view=rev
Log:
Convenience operations.
Add PrefixMap.isEmpty, PrefixMap.size, PrefixMap.putAll(Map<String, String>)
Add PrefixMapFactory.create(Map<String, String>)

Modified:
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/FastAbbreviatingPrefixMap.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapBase.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapExtended.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java
    jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapStd.java
    jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/AbstractTestPrefixMap.java

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/FastAbbreviatingPrefixMap.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/FastAbbreviatingPrefixMap.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/FastAbbreviatingPrefixMap.java
(original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/FastAbbreviatingPrefixMap.java
Thu Feb  7 09:17:14 2013
@@ -180,4 +180,15 @@ public class FastAbbreviatingPrefixMap e
         return x.toString() + localName;
     }
 
+    @Override
+    public boolean isEmpty()
+    {
+        return prefixes.isEmpty() ;
+    }
+
+    @Override
+    public int size()
+    {
+        return prefixes.size() ;
+    }
 }

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMap.java Thu Feb 
7 09:17:14 2013
@@ -109,6 +109,13 @@ public interface PrefixMap {
     public abstract void putAll(PrefixMapping pmap);
 
     /**
+     * Add a prefix, overwrites any existing association
+     * 
+     * @param mapping A Map of prefix name to IRI string 
+     */
+    public abstract void putAll(Map<String, String> mapping) ;
+
+    /**
      * Delete a prefix
      * 
      * @param prefix
@@ -163,5 +170,18 @@ public interface PrefixMap {
      * @return Expanded URI if possible, null otherwise
      */
     public abstract String expand(String prefix, String localName);
+    
+    /**
+     * return whether the 
+     * @return boolean
+     */
+
+    public boolean isEmpty();
+    
+    /**
+     * Return the number of entries in the prefix map.
+     * @return Size of the prefix mapping
+     */
 
+    public int size();
 }
\ No newline at end of file

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapBase.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapBase.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapBase.java Thu Feb
 7 09:17:14 2013
@@ -80,7 +80,12 @@ public abstract class PrefixMapBase impl
 
     @Override
     public void putAll(PrefixMapping pmap) {
-        for (Map.Entry<String, String> e : pmap.getNsPrefixMap().entrySet()) {
+        putAll(pmap.getNsPrefixMap()) ;
+    }
+
+    @Override
+    public void putAll(Map<String, String> mapping) {
+        for (Map.Entry<String, String> e : mapping.entrySet()) {
             this.add(e.getKey(), e.getValue());
         }
     }

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapExtended.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapExtended.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapExtended.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapExtended.java Thu
Feb  7 09:17:14 2013
@@ -106,4 +106,16 @@ public class PrefixMapExtended extends P
             return p;
         return parent.abbrev(uriStr);
     }
+    
+    @Override
+    public boolean isEmpty()
+    {
+        return parent.isEmpty() && local.isEmpty() ;
+    }
+
+    @Override
+    public int size()
+    {
+        return parent.size() + local.size() ;
+    }
 }

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapFactory.java Thu
Feb  7 09:17:14 2013
@@ -18,6 +18,8 @@
 
 package org.apache.jena.riot.system;
 
+import java.util.Map ;
+
 import com.hp.hpl.jena.shared.PrefixMapping;
 
 /**
@@ -27,7 +29,7 @@ import com.hp.hpl.jena.shared.PrefixMapp
 public class PrefixMapFactory {
 
     /**
-     * Creates a new prefix map
+     * Creates a new prefix map.
      * <p>
      * Will use whatever the version of ARQ you are using considers the default
      * implementation, this may change from release to release.
@@ -41,7 +43,7 @@ public class PrefixMapFactory {
 
     /**
      * Creates a new prefix map which starts with a copy of an existing prefix
-     * map
+     * map.
      * <p>
      * Will use whatever the version of ARQ you are using considers the default
      * implementation, this may change from release to release.
@@ -57,15 +59,15 @@ public class PrefixMapFactory {
     }
 
     /**
-     * Creates a new prefix map which is intended for use in output which starts
-     * with a copy of an existing map
+     * Creates a new prefix map which starts
+     * with a copy of an existing map.
      * <p>
      * Will use whatever the version of ARQ you are using considers the default
      * implementation, this may change from release to release.
      * </p>
      * 
      * @param pmap
-     *            Prefix Map to copy
+     *            PrefixMapping to copy
      * 
      * @return Prefix Map
      */
@@ -76,12 +78,24 @@ public class PrefixMapFactory {
     }
 
     /**
-     * Creates a new prefix map which is intended for use in input
+     * Creates a new prefix map,initialized from a Map of prefix to IRI string.
      * <p>
-     * Will use whatever the version of ARQ you are using considers the best
-     * implementation for input, this may change from release to release.
+     * Will use whatever the version of ARQ you are using considers the default
+     * implementation, this may change from release to release.
      * </p>
      * 
+     * @param pmap Mapping from prefix to IRI string
+     * @return Prefix Map
+     */
+    public static PrefixMap create(Map<String, String> pmap) {
+        PrefixMap created = create();
+        created.putAll(pmap);
+        return created;
+    }
+
+    /**
+     * Creates a new prefix map which is intended for use in input.
+     * 
      * @return Prefix map
      */
     public static PrefixMap createForInput() {
@@ -109,7 +123,7 @@ public class PrefixMapFactory {
      * with a copy of an existing map
      * <p>
      * Will use whatever the version of ARQ you are using considers the best
-     * implementation for iput, this may change from release to release.
+     * implementation for input, this may change from release to release.
      * </p>
      * 
      * @param pmap
@@ -124,6 +138,19 @@ public class PrefixMapFactory {
     }
 
     /**
+     * Creates a new prefix map, initialized from a Map of prefix to IRI string.
+     * 
+     * @param pmap Mapping from prefix to IRI string
+     * @return Prefix Map
+     */
+    public static PrefixMap createForInput(Map<String, String> pmap) {
+        PrefixMap created = createForInput();
+        created.putAll(pmap);
+        return created;
+    }
+
+    
+    /**
      * Creates a new prefix map which is intended for use in output
      * <p>
      * Will use whatever the version of ARQ you are using considers the best
@@ -173,17 +200,25 @@ public class PrefixMapFactory {
     }
 
     /**
+     * Creates a new prefix map, initialized from a Map of prefix to IRI string.
+     * 
+     * @param pmap Mapping from prefix to IRI string
+     * @return Prefix Map
+     */
+    public static PrefixMap createForOutput(Map<String, String> pmap) {
+        PrefixMap created = createForOutput();
+        created.putAll(pmap);
+        return created;
+    }
+
+    /**
      * Creates a new prefix map which is an extension of an existing prefix map
      * <p>
-     * This differs from using one of the various {@code create()} methods since
+     * This differs from using one of the various {@code create} methods since
      * it does not copy the existing prefix map, rather it maintains both a
      * local map and the existing map. All operations favour the local map but
      * defer to the existing map if the local map cannot fulfil a request.
      * </p>
-     * <p>
-     * Will use whatever the version of ARQ you are using considers the default
-     * extending implementation, this may change from release to release.
-     * </p>
      * 
      * @param pmap
      *            Prefix Map to extend
@@ -192,5 +227,4 @@ public class PrefixMapFactory {
     public static PrefixMap extend(PrefixMap pmap) {
         return new PrefixMapExtended(pmap);
     }
-
 }

Modified: jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapStd.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapStd.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapStd.java (original)
+++ jena/trunk/jena-arq/src/main/java/org/apache/jena/riot/system/PrefixMapStd.java Thu Feb
 7 09:17:14 2013
@@ -139,4 +139,16 @@ public class PrefixMapStd extends Prefix
             return null;
         return x.toString() + localName;
     }
+
+    @Override
+    public boolean isEmpty()
+    {
+        return prefixes.isEmpty() ;
+    }
+
+    @Override
+    public int size()
+    {
+        return prefixes.size() ;
+    }
 }

Modified: jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/AbstractTestPrefixMap.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/AbstractTestPrefixMap.java?rev=1443363&r1=1443362&r2=1443363&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/AbstractTestPrefixMap.java
(original)
+++ jena/trunk/jena-arq/src/test/java/org/apache/jena/riot/system/AbstractTestPrefixMap.java
Thu Feb  7 09:17:14 2013
@@ -42,6 +42,8 @@ public abstract class AbstractTestPrefix
     public void prefixMap_basic_01()
     {
         PrefixMap pmap = getPrefixMap();
+        assertTrue(pmap.isEmpty()) ;
+        assertEquals(0, pmap.size()) ;
         assertTrue(pmap.getMapping().isEmpty()) ;
         assertTrue(pmap.getMappingCopy().isEmpty()) ;
         assertTrue(pmap.getMappingCopyStr().isEmpty()) ;
@@ -52,6 +54,8 @@ public abstract class AbstractTestPrefix
     {
         PrefixMap pmap = getPrefixMap();
         pmap.add("", "http://example/") ;
+        assertFalse(pmap.isEmpty()) ;
+        assertEquals(1, pmap.size()) ;
         assertTrue(pmap.contains("")) ;
         assertTrue(pmap.getMapping().containsKey("")) ;
         assertTrue(pmap.getMappingCopy().containsKey("")) ;
@@ -66,6 +70,8 @@ public abstract class AbstractTestPrefix
         pmap.add("org", "http://example.org/") ;
         assertTrue(pmap.contains("")) ;
         assertTrue(pmap.contains("org")) ;
+        assertFalse(pmap.isEmpty()) ;
+        assertEquals(2, pmap.size()) ;
     }
     
     @Test
@@ -79,6 +85,8 @@ public abstract class AbstractTestPrefix
 
         assertTrue(pmap2.contains("")) ;
         assertTrue(pmap2.contains("org")) ;
+        assertFalse(pmap2.isEmpty()) ;
+        assertEquals(2, pmap2.size()) ;
     }
     
     



Mime
View raw message