Package gnu.mapping
Class Namespace
java.lang.Object
java.util.AbstractMap<String,Symbol>
gnu.kawa.util.AbstractHashTable<gnu.mapping.SymbolRef,String,Symbol>
gnu.mapping.Namespace
- All Implemented Interfaces:
HasNamedParts,Externalizable,Serializable,Map<String,Symbol>
- Direct Known Subclasses:
ClassNamespace,LispPackage,XmlNamespace
public class Namespace
extends AbstractHashTable<gnu.mapping.SymbolRef,String,Symbol>
implements 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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NamespaceThe Namespace with the empty name.protected static final HashtableMap namepsace names (and nick-names) to Namespaces.protected Stringstatic final StringFields inherited from class gnu.kawa.util.AbstractHashTable
DEFAULT_INITIAL_SIZE, mask, num_bindings, table -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected gnu.mapping.SymbolRef[]allocEntries(int n) Allocate Entry[n].static Namespacecreate()static Namespacecreate(int capacity) Find value for given key.static Namespacestatic SymbolgetDefaultSymbol(String name) protected intgetEntryHashCode(gnu.mapping.SymbolRef entry) Extract hash-code from Entry.protected gnu.mapping.SymbolRefgetEntryNext(gnu.mapping.SymbolRef entry) Extract next Entry in same hash-bucket.final StringgetName()Get the name of this Namespace.final StringGet a Symbol matching the given name.booleanisConstant(String key) booleanA namespace with known prefix but unknown uri.Get a Symbol matching the given name.protected final SymbollookupInternal(String key, int hash) Search for an existing Symbol with the give name.protected gnu.mapping.SymbolRefAllocate a new node in the hash table.static NamespacemakeUnknownNamespace(String prefix) Create a "placeholder" for a namespace with a known prefix but unknown uri.voidbooleanprotected voidsetEntryNext(gnu.mapping.SymbolRef entry, gnu.mapping.SymbolRef next) Set next Entry in same hash-bucket.final voidSet the name of this Namespace.toString()static NamespacevalueOf()static NamespaceReturn Namespace with the given name (namespace-URI).static NamespacevalueOf(String uri, SimpleSymbol prefix) static Namespacestatic NamespacevalueOfNoCreate(String name) Return Namespace with the given name (namespace-URI), if it exists.voidMethods inherited from class gnu.kawa.util.AbstractHashTable
clear, entrySet, get, getNode, getOrDefault, hash, hashToIndex, matches, matches, put, put, rehash, remove, sizeMethods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
nsTable
Map namepsace names (and nick-names) to Namespaces. -
EmptyNamespace
The Namespace with the empty name. -
prefix
-
UNKNOWN_NAMESPACE
-
-
Constructor Details
-
Namespace
public Namespace() -
Namespace
protected Namespace(int capacity)
-
-
Method Details
-
getName
Get the name of this Namespace. -
setName
Set the name of this Namespace. -
getPrefix
-
create
-
create
-
getDefault
-
getDefaultSymbol
-
valueOf
-
valueOf
Return Namespace with the given name (namespace-URI). Create it if needed. -
valueOfNoCreate
Return Namespace with the given name (namespace-URI), if it exists. Return null if no such namespace exists. -
valueOf
-
valueOf
-
isUnknownNamespace
public boolean isUnknownNamespace()A namespace with known prefix but unknown uri. -
makeUnknownNamespace
Create a "placeholder" for a namespace with a known prefix but unknown uri.- See Also:
-
get
- Specified by:
getin interfaceHasNamedParts
-
isConstant
- Specified by:
isConstantin interfaceHasNamedParts
-
getSymbol
Get a Symbol matching the given name. Creates a new Symbol if one is not found. Equivalent to Common Lisp's "intern" function. -
lookup
Get a Symbol matching the given name. Returns null if one is not found. -
lookupInternal
Search for an existing Symbol with the give name.- Parameters:
key- String - does not need to be interned.
-
add
-
get
Description copied from class:AbstractHashTableFind value for given key. Return defaultValue if not found.- Overrides:
getin classAbstractHashTable<gnu.mapping.SymbolRef,String, Symbol>
-
lookup
-
remove
-
getEntryHashCode
protected int getEntryHashCode(gnu.mapping.SymbolRef entry) Description copied from class:AbstractHashTableExtract hash-code from Entry.- Specified by:
getEntryHashCodein classAbstractHashTable<gnu.mapping.SymbolRef,String, Symbol>
-
getEntryNext
protected gnu.mapping.SymbolRef getEntryNext(gnu.mapping.SymbolRef entry) Extract next Entry in same hash-bucket.- Specified by:
getEntryNextin classAbstractHashTable<gnu.mapping.SymbolRef,String, Symbol>
-
setEntryNext
protected void setEntryNext(gnu.mapping.SymbolRef entry, gnu.mapping.SymbolRef next) Set next Entry in same hash-bucket.- Specified by:
setEntryNextin classAbstractHashTable<gnu.mapping.SymbolRef,String, Symbol>
-
allocEntries
protected gnu.mapping.SymbolRef[] allocEntries(int n) Allocate Entry[n].- Specified by:
allocEntriesin classAbstractHashTable<gnu.mapping.SymbolRef,String, Symbol>
-
makeEntry
Description copied from class:AbstractHashTableAllocate a new node in the hash table.- Specified by:
makeEntryin classAbstractHashTable<gnu.mapping.SymbolRef,String, Symbol>
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
readResolve
- Throws:
ObjectStreamException
-
toString
- Overrides:
toStringin classAbstractMap<String,Symbol>
-