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") toSymbols. 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). ANamespaceis a "weak" mapping in the sense that aSymbolcan 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 NamespaceEmptyNamespaceThe Namespace with the empty name.protected static HashtablensTableMap namepsace names (and nick-names) to Namespaces.protected Stringprefixstatic StringUNKNOWN_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 Symboladd(Symbol sym, int hash)protected gnu.mapping.SymbolRef[]allocEntries(int n)Allocate Entry[n].static Namespacecreate()static Namespacecreate(int capacity)Symbolget(Object key, Symbol defaultValue)Find value for given key.Objectget(String key)static NamespacegetDefault()static 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.StringgetName()Get the name of this Namespace.StringgetPrefix()SymbolgetSymbol(String key)Get a Symbol matching the given name.booleanisConstant(String key)booleanisUnknownNamespace()A namespace with known prefix but unknown uri.Symbollookup(String key)Get a Symbol matching the given name.Symbollookup(String key, int hash, boolean create)protected SymbollookupInternal(String key, int hash)Search for an existing Symbol with the give name.protected gnu.mapping.SymbolRefmakeEntry(String key, int hash, Symbol value)Allocate a new node in the hash table.static NamespacemakeUnknownNamespace(String prefix)Create a "placeholder" for a namespace with a known prefix but unknown uri.voidreadExternal(ObjectInput in)ObjectreadResolve()booleanremove(Symbol symbol)protected voidsetEntryNext(gnu.mapping.SymbolRef entry, gnu.mapping.SymbolRef next)Set next Entry in same hash-bucket.voidsetName(String name)Set the name of this Namespace.StringtoString()static NamespacevalueOf()static NamespacevalueOf(String name)Return Namespace with the given name (namespace-URI).static NamespacevalueOf(String uri, SimpleSymbol prefix)static NamespacevalueOf(String uri, String prefix)static NamespacevalueOfNoCreate(String name)Return Namespace with the given name (namespace-URI), if it exists.voidwriteExternal(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:
getin interfaceHasNamedParts
-
isConstant
public boolean isConstant(String key)
- Specified by:
isConstantin 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:AbstractHashTableFind value for given key. Return defaultValue if not found.- Overrides:
getin classAbstractHashTable<gnu.mapping.SymbolRef,String,Symbol>
-
remove
public boolean remove(Symbol symbol)
-
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
protected gnu.mapping.SymbolRef makeEntry(String key, int hash, Symbol value)
Description copied from class:AbstractHashTableAllocate a new node in the hash table.- Specified by:
makeEntryin classAbstractHashTable<gnu.mapping.SymbolRef,String,Symbol>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
readResolve
public Object readResolve() throws ObjectStreamException
- Throws:
ObjectStreamException
-
toString
public String toString()
- Overrides:
toStringin classAbstractMap<String,Symbol>
-
-