Package gnu.mapping
Class Namespace
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- 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") toSymbol
s. Namespaces are normally named and can be accessed from a global table. They correspond to Common Lisp "packages" (which are implemented usinggnu.kawa.lispexpr.LispPackage
, which extendsNamespace
). ANamespace
is a "weak" mapping in the sense that aSymbol
can be garbage collected even though it is referenced from aNamespace
.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description static Namespace
EmptyNamespace
The Namespace with the empty name.protected static Hashtable
nsTable
Map namepsace names (and nick-names) to Namespaces.protected String
prefix
static String
UNKNOWN_NAMESPACE
-
Fields inherited from class gnu.kawa.util.AbstractHashTable
DEFAULT_INITIAL_SIZE, mask, num_bindings, table
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Symbol
add(Symbol sym, int hash)
protected gnu.mapping.SymbolRef[]
allocEntries(int n)
Allocate Entry[n].static Namespace
create()
static Namespace
create(int capacity)
Symbol
get(Object key, Symbol defaultValue)
Find value for given key.Object
get(String key)
static Namespace
getDefault()
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.String
getName()
Get the name of this Namespace.String
getPrefix()
Symbol
getSymbol(String key)
Get a Symbol matching the given name.boolean
isConstant(String key)
boolean
isUnknownNamespace()
A namespace with known prefix but unknown uri.Symbol
lookup(String key)
Get a Symbol matching the given name.Symbol
lookup(String key, int hash, boolean create)
protected Symbol
lookupInternal(String key, int hash)
Search for an existing Symbol with the give name.protected gnu.mapping.SymbolRef
makeEntry(String key, int hash, Symbol value)
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
readExternal(ObjectInput in)
Object
readResolve()
boolean
remove(Symbol symbol)
protected void
setEntryNext(gnu.mapping.SymbolRef entry, gnu.mapping.SymbolRef next)
Set next Entry in same hash-bucket.void
setName(String name)
Set the name of this Namespace.String
toString()
static Namespace
valueOf()
static Namespace
valueOf(String name)
Return Namespace with the given name (namespace-URI).static Namespace
valueOf(String uri, SimpleSymbol prefix)
static Namespace
valueOf(String uri, String prefix)
static Namespace
valueOfNoCreate(String name)
Return Namespace with the given name (namespace-URI), if it exists.void
writeExternal(ObjectOutput out)
-
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 Detail
-
nsTable
protected static final Hashtable nsTable
Map namepsace names (and nick-names) to Namespaces.
-
EmptyNamespace
public static final Namespace EmptyNamespace
The Namespace with the empty name.
-
prefix
protected String prefix
-
UNKNOWN_NAMESPACE
public static final String UNKNOWN_NAMESPACE
-
-
Method Detail
-
getName
public final String getName()
Get the name of this Namespace.
-
setName
public final void setName(String name)
Set the name of this Namespace.
-
getPrefix
public final String getPrefix()
-
create
public static Namespace create(int capacity)
-
create
public static Namespace create()
-
getDefault
public static Namespace getDefault()
-
valueOf
public static Namespace valueOf()
-
valueOf
public static Namespace valueOf(String name)
Return Namespace with the given name (namespace-URI). Create it if needed.
-
valueOfNoCreate
public static Namespace valueOfNoCreate(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(String uri, SimpleSymbol prefix)
-
isUnknownNamespace
public boolean isUnknownNamespace()
A namespace with known prefix but unknown uri.
-
makeUnknownNamespace
public static Namespace makeUnknownNamespace(String prefix)
Create a "placeholder" for a namespace with a known prefix but unknown uri.
-
get
public Object get(String key)
- Specified by:
get
in interfaceHasNamedParts
-
isConstant
public boolean isConstant(String key)
- Specified by:
isConstant
in interfaceHasNamedParts
-
getSymbol
public Symbol getSymbol(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(String key)
Get a Symbol matching the given name. Returns null if one is not found.
-
lookupInternal
protected final Symbol lookupInternal(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(Object key, Symbol defaultValue)
Description copied from class:AbstractHashTable
Find value for given key. Return defaultValue if not found.- Overrides:
get
in classAbstractHashTable<gnu.mapping.SymbolRef,String,Symbol>
-
remove
public boolean remove(Symbol symbol)
-
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
protected gnu.mapping.SymbolRef makeEntry(String key, int hash, Symbol value)
Description copied from class:AbstractHashTable
Allocate a new node in the hash table.- Specified by:
makeEntry
in classAbstractHashTable<gnu.mapping.SymbolRef,String,Symbol>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
readResolve
public Object readResolve() throws ObjectStreamException
- Throws:
ObjectStreamException
-
toString
public String toString()
- Overrides:
toString
in classAbstractMap<String,Symbol>
-
-