Class PrefixMapStd

  • All Implemented Interfaces:
    PrefixMap

    public class PrefixMapStd
    extends PrefixMapBase
    In-memory implementation of a PrefixMap.

    This also provides fast URI to prefix name calculation suitable for output. For output, calculating possible prefix names from a URI happens on every URI so this operations needs to be efficient. Normally, a prefix map is "prefix to URI" and the abbreviation is a reverse lookup, which is a scan of the value of the map. This class keeps a reverse lookup map of URI to prefix which combined with a fast, approximate for determining the split point exploiting the most common use cases, provides efficient abbreviation.

    Usage for abbreviation: call PrefixMapFactory.createForOutput(PrefixMap) which copies the argument prefix map into an instance of this class, setting up the reverse lookup. This copy is cheaper than repeated reverse lookups would be.

    • Constructor Summary

      Constructors 
      Constructor Description
      PrefixMapStd()
      Creates a new empty prefix mapping
      PrefixMapStd​(PrefixMap prefixMap)
      Creates a new prefix mapping copied from an existing map
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.jena.atlas.lib.Pair<java.lang.String,​java.lang.String> abbrev​(java.lang.String uriStr)
      Abbreviate an IRI and return a pair of prefix and local parts, or null.
      java.lang.String abbreviate​(java.lang.String uriStr)
      Abbreviate an IRI or return null
      void add​(java.lang.String prefix, java.lang.String iri)
      Add a prefix, overwrites any existing association
      void clear()
      Clear all prefixes.
      boolean containsPrefix​(java.lang.String prefix)
      Gets whether the map contains a given prefix
      void delete​(java.lang.String prefix)
      Delete a prefix
      java.lang.String get​(java.lang.String prefix)
      Return the URI for the prefix, or null if there is no entry for this prefix.
      java.util.Map<java.lang.String,​java.lang.String> getMapping()
      Return the underlying mapping, this is generally unsafe to modify and implementations may opt to return an unmodifiable view of the mapping if they wish.
      boolean isEmpty()
      Return whether the prefix map is empty or not.
      int size()
      Return the number of entries in the prefix map.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • PrefixMapStd

        public PrefixMapStd()
        Creates a new empty prefix mapping
      • PrefixMapStd

        public PrefixMapStd​(PrefixMap prefixMap)
        Creates a new prefix mapping copied from an existing map
        Parameters:
        prefixMap - Prefix Map
    • Method Detail

      • getMapping

        public java.util.Map<java.lang.String,​java.lang.String> getMapping()
        Description copied from interface: PrefixMap
        Return the underlying mapping, this is generally unsafe to modify and implementations may opt to return an unmodifiable view of the mapping if they wish.
        Returns:
        Underlying mapping
        See Also:
        PrefixMap.getMappingCopy()
      • get

        public java.lang.String get​(java.lang.String prefix)
        Description copied from interface: PrefixMap
        Return the URI for the prefix, or null if there is no entry for this prefix.
      • add

        public void add​(java.lang.String prefix,
                        java.lang.String iri)
        Description copied from interface: PrefixMap
        Add a prefix, overwrites any existing association
        Parameters:
        prefix - Prefix
        iri - Namespace IRI
      • delete

        public void delete​(java.lang.String prefix)
        Description copied from interface: PrefixMap
        Delete a prefix
        Parameters:
        prefix - Prefix to delete
      • clear

        public void clear()
        Description copied from interface: PrefixMap
        Clear all prefixes.
      • containsPrefix

        public boolean containsPrefix​(java.lang.String prefix)
        Description copied from interface: PrefixMap
        Gets whether the map contains a given prefix
        Parameters:
        prefix - Prefix
        Returns:
        True if the prefix is contained in the map, false otherwise
      • abbreviate

        public java.lang.String abbreviate​(java.lang.String uriStr)
        Description copied from interface: PrefixMap
        Abbreviate an IRI or return null
        Specified by:
        abbreviate in interface PrefixMap
        Overrides:
        abbreviate in class PrefixMapBase
        Parameters:
        uriStr - URI to abbreviate
        Returns:
        URI in prefixed name form if possible, null otherwise
      • abbrev

        public org.apache.jena.atlas.lib.Pair<java.lang.String,​java.lang.String> abbrev​(java.lang.String uriStr)
        Description copied from interface: PrefixMap
        Abbreviate an IRI and return a pair of prefix and local parts, or null.
        Specified by:
        abbrev in interface PrefixMap
        Overrides:
        abbrev in class PrefixMapBase
        Parameters:
        uriStr - URI string to abbreviate
        Returns:
        Pair of prefix and local name
        See Also:
        PrefixMap.abbreviate(java.lang.String)
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: PrefixMap
        Return whether the prefix map is empty or not.
      • size

        public int size()
        Description copied from interface: PrefixMap
        Return the number of entries in the prefix map.