public class Namespace extends Object implements Serializable
Name
s and the objects
carrying these names. These objects have to implement the interface
Named
. It is possible to have nested namespaces in order to
represent different visibility scopes. An instance of Namespace can
operate in normal and protocoled mode, where the protocoled mode
keeps track of all new added names since the last call of startProtocol()
.Modifier and Type | Field and Description |
---|---|
protected Named |
localSym
One defined symbol.
|
protected int |
numLocalSyms
The number of symbols defined in this namespace.
|
protected Namespace |
parent
The fall-back namespace for symbols not present in this
Namespace.
|
protected HashMap<Name,Named> |
protocol
Additions can be "recorded" here
|
private static long |
serialVersionUID |
protected HashMap<Name,Named> |
symbols
The hashmap that maps a name to a symbols of that name if it
is defined in this Namespace.
|
Constructor and Description |
---|
Namespace()
Construct an empty Namespace without a parent namespace.
|
Namespace(HashMap<Name,Named> protocol)
Construct an empty Namespace with protocol
protocol
and without a parent namespace. |
Namespace(Namespace parent)
Construct a Namespace that uses
parent as a fallback
for finding symbols not defined in this one. |
Namespace(Namespace parent,
Named sym)
Construct a Namespace that uses
parent as a fallback
for finding symbols not defined in this one. |
Modifier and Type | Method and Description |
---|---|
void |
add(Iterable<? extends Named> l) |
void |
add(Named sym)
Adds the object
sym to this Namespace. |
void |
add(Namespace source) |
<T extends Named> |
addSafely(Iterable<T> names) |
void |
addSafely(Named sym)
Adds the object
sym to this namespace. |
ImmutableList<Named> |
allElements() |
Namespace |
copy() |
ImmutableList<Named> |
elements()
returns list of the elements (not the keys) in this
namespace (not about the one of the parent)
|
Namespace |
extended(Iterable<? extends Named> ext) |
Namespace |
extended(Named sym)
creates a new Namespace that has this as parent, and contains
an entry for
sym . |
Iterator<Named> |
getProtocolled()
gets symbols added since last
startProtocol() ;
resets the protocol |
Named |
lookup(Name name)
looks if a registered object is declared in this namespace, if
negative it asks its parent
|
Named |
lookup(String name)
Convenience method to look up.
|
protected Named |
lookupLocally(Name name) |
Namespace |
parent()
returns the fall-back Namespace of this Namespace, i.e.
|
void |
remove(Name name) |
void |
reset() |
<T extends Named> |
set(ImmutableSet<T> names) |
void |
startProtocol()
"remember" all additions from now on
|
String |
toString() |
private static final long serialVersionUID
protected Namespace parent
protected HashMap<Name,Named> symbols
protected Named localSym
symbols
is only initialized when there is more than one
symbol in this namespace. Otherwise, localSym
contains
that symbol.protected int numLocalSyms
symbols.size()
because symbols might be null if
there is only one symbol in this Namespace.public Namespace()
public Namespace(HashMap<Name,Named> protocol)
protocol
and without a parent namespace.public Namespace(Namespace parent)
parent
as a fallback
for finding symbols not defined in this one.public void add(Named sym)
sym
to this Namespace.
If an object with the same name is already there, it is quietly
replaced by sym
. Use addSafely() instead if possible.
TODO:The problem of saving to localSym, symbols, and symbolRefs is not solved yet.public void remove(Name name)
public void addSafely(Named sym)
sym
to this namespace.
Throws a runtime exception if an object with the same name is
already there.public void startProtocol()
public Iterator<Named> getProtocolled()
startProtocol()
;
resets the protocolpublic Namespace extended(Named sym)
sym
.public Named lookup(Name name)
name
- a Name representing the name of the symbol to look forpublic ImmutableList<Named> elements()
public ImmutableList<Named> allElements()
public Namespace parent()
public void add(Namespace source)
public Namespace copy()
public void reset()
public <T extends Named> void set(ImmutableSet<T> names)