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
Symbol
s.
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 Namespace
The Namespace with the empty name.protected static final Hashtable
Map namepsace names (and nick-names) to Namespaces.protected String
static final String
Fields 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 Namespace
create()
static Namespace
create
(int capacity) Find value for given key.static Namespace
static Symbol
getDefaultSymbol
(String name) protected int
getEntryHashCode
(gnu.mapping.SymbolRef entry) Extract hash-code from Entry.protected gnu.mapping.SymbolRef
getEntryNext
(gnu.mapping.SymbolRef entry) Extract next Entry in same hash-bucket.final String
getName()
Get the name of this Namespace.final String
Get a Symbol matching the given name.boolean
isConstant
(String key) boolean
A namespace with known prefix but unknown uri.Get a Symbol matching the given name.protected final Symbol
lookupInternal
(String key, int hash) Search for an existing Symbol with the give name.protected gnu.mapping.SymbolRef
Allocate a new node in the hash table.static Namespace
makeUnknownNamespace
(String prefix) Create a "placeholder" for a namespace with a known prefix but unknown uri.void
boolean
protected void
setEntryNext
(gnu.mapping.SymbolRef entry, gnu.mapping.SymbolRef next) Set next Entry in same hash-bucket.final void
Set the name of this Namespace.toString()
static Namespace
valueOf()
static Namespace
Return Namespace with the given name (namespace-URI).static Namespace
valueOf
(String uri, SimpleSymbol prefix) static Namespace
static Namespace
valueOfNoCreate
(String name) Return Namespace with the given name (namespace-URI), if it exists.void
Methods inherited from class gnu.kawa.util.AbstractHashTable
clear, entrySet, get, getNode, getOrDefault, hash, hashToIndex, matches, matches, put, put, rehash, remove, size
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
get
in interfaceHasNamedParts
-
isConstant
- Specified by:
isConstant
in 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:AbstractHashTable
Find value for given key. Return defaultValue if not found.- Overrides:
get
in classAbstractHashTable<gnu.mapping.SymbolRef,
String, Symbol>
-
lookup
-
remove
-
getEntryHashCode
protected int getEntryHashCode(gnu.mapping.SymbolRef entry) Description copied from class:AbstractHashTable
Extract hash-code from Entry.- Specified by:
getEntryHashCode
in 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:
getEntryNext
in 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:
setEntryNext
in classAbstractHashTable<gnu.mapping.SymbolRef,
String, Symbol>
-
allocEntries
protected gnu.mapping.SymbolRef[] allocEntries(int n) Allocate Entry[n].- Specified by:
allocEntries
in classAbstractHashTable<gnu.mapping.SymbolRef,
String, Symbol>
-
makeEntry
Description copied from class:AbstractHashTable
Allocate a new node in the hash table.- Specified by:
makeEntry
in classAbstractHashTable<gnu.mapping.SymbolRef,
String, Symbol>
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
readResolve
- Throws:
ObjectStreamException
-
toString
- Overrides:
toString
in classAbstractMap<String,
Symbol>
-