Package gnu.mapping

Class Namespace

  • All Implemented Interfaces:
    HasNamedParts, java.io.Externalizable, java.io.Serializable, java.util.Map<java.lang.String,​Symbol>
    Direct Known Subclasses:
    ClassNamespace, LispPackage, XmlNamespace

    public class Namespace
    extends AbstractHashTable<gnu.mapping.SymbolRef,​java.lang.String,​Symbol>
    implements java.io.Externalizable, HasNamedParts
    A mapping from strings ("print names") to Symbols. Namespaces are normally named and can be accessed from a global table. They correspond to Common Lisp "packages" (which are implemented using gnu.kawa.lispexpr.LispPackage, which extends Namespace). A Namespace is a "weak" mapping in the sense that a Symbol can be garbage collected even though it is referenced from a Namespace.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        Namespace()  
      protected Namespace​(int capacity)  
    • Field Detail

      • nsTable

        protected static final java.util.Hashtable nsTable
        Map namepsace names (and nick-names) to Namespaces.
      • EmptyNamespace

        public static final Namespace EmptyNamespace
        The Namespace with the empty name.
      • prefix

        protected java.lang.String prefix
      • UNKNOWN_NAMESPACE

        public static final java.lang.String UNKNOWN_NAMESPACE
    • Constructor Detail

      • Namespace

        public Namespace()
      • Namespace

        protected Namespace​(int capacity)
    • Method Detail

      • getName

        public final java.lang.String getName()
        Get the name of this Namespace.
      • setName

        public final void setName​(java.lang.String name)
        Set the name of this Namespace.
      • getPrefix

        public final java.lang.String getPrefix()
      • create

        public static Namespace create​(int capacity)
      • getDefault

        public static Namespace getDefault()
      • getDefaultSymbol

        public static Symbol getDefaultSymbol​(java.lang.String name)
      • valueOf

        public static Namespace valueOf()
      • valueOf

        public static Namespace valueOf​(java.lang.String name)
        Return Namespace with the given name (namespace-URI). Create it if needed.
      • valueOfNoCreate

        public static Namespace valueOfNoCreate​(java.lang.String name)
        Return Namespace with the given name (namespace-URI), if it exists. Return null if no such namespace exists.
      • valueOf

        public static Namespace valueOf​(java.lang.String uri,
                                        java.lang.String prefix)
      • isUnknownNamespace

        public boolean isUnknownNamespace()
        A namespace with known prefix but unknown uri.
      • get

        public java.lang.Object get​(java.lang.String key)
        Specified by:
        get in interface HasNamedParts
      • isConstant

        public boolean isConstant​(java.lang.String key)
        Specified by:
        isConstant in interface HasNamedParts
      • getSymbol

        public Symbol getSymbol​(java.lang.String key)
        Get a Symbol matching the given name. Creates a new Symbol if one is not found. Equivalent to Common Lisp's "intern" function.
      • lookup

        public Symbol lookup​(java.lang.String key)
        Get a Symbol matching the given name. Returns null if one is not found.
      • lookupInternal

        protected final Symbol lookupInternal​(java.lang.String key,
                                              int hash)
        Search for an existing Symbol with the give name.
        Parameters:
        key - String - does not need to be interned.
      • get

        public Symbol get​(java.lang.Object key,
                          Symbol defaultValue)
        Description copied from class: AbstractHashTable
        Find value for given key. Return defaultValue if not found.
        Overrides:
        get in class AbstractHashTable<gnu.mapping.SymbolRef,​java.lang.String,​Symbol>
      • lookup

        public Symbol lookup​(java.lang.String key,
                             int hash,
                             boolean create)
      • remove

        public boolean remove​(Symbol symbol)
      • getEntryNext

        protected gnu.mapping.SymbolRef getEntryNext​(gnu.mapping.SymbolRef entry)
        Extract next Entry in same hash-bucket.
        Specified by:
        getEntryNext in class AbstractHashTable<gnu.mapping.SymbolRef,​java.lang.String,​Symbol>
      • setEntryNext

        protected void setEntryNext​(gnu.mapping.SymbolRef entry,
                                    gnu.mapping.SymbolRef next)
        Set next Entry in same hash-bucket.
        Specified by:
        setEntryNext in class AbstractHashTable<gnu.mapping.SymbolRef,​java.lang.String,​Symbol>
      • allocEntries

        protected gnu.mapping.SymbolRef[] allocEntries​(int n)
        Allocate Entry[n].
        Specified by:
        allocEntries in class AbstractHashTable<gnu.mapping.SymbolRef,​java.lang.String,​Symbol>
      • makeEntry

        protected gnu.mapping.SymbolRef makeEntry​(java.lang.String key,
                                                  int hash,
                                                  Symbol value)
        Description copied from class: AbstractHashTable
        Allocate a new node in the hash table.
        Specified by:
        makeEntry in class AbstractHashTable<gnu.mapping.SymbolRef,​java.lang.String,​Symbol>
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readResolve

        public java.lang.Object readResolve()
                                     throws java.io.ObjectStreamException
        Throws:
        java.io.ObjectStreamException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,​Symbol>