Catalog
public class CatalogBase extends java.lang.Object implements Catalog
Simple in-memory implementation of Catalog
. This class can
also be used as the basis for more advanced implementations.
This implementation is thread-safe.
Modifier and Type | Field | Description |
---|---|---|
protected java.util.Map |
commands |
The map of named
Command s, keyed by name. |
CATALOG_KEY
Constructor | Description |
---|---|
CatalogBase() |
Create an empty catalog.
|
CatalogBase(java.util.Map commands) |
Create a catalog whose commands are those specified in the given
Map . |
Modifier and Type | Method | Description |
---|---|---|
void |
addCommand(java.lang.String name,
Command command) |
|
Command |
getCommand(java.lang.String name) |
Return the
Command associated with the
specified name, if any; otherwise, return null . |
java.util.Iterator |
getNames() |
Return an
Iterator over the set of named commands
known to this Catalog . |
java.lang.String |
toString() |
Converts this Catalog to a String.
|
protected java.util.Map commands
The map of named Command
s, keyed by name.
public CatalogBase()
public CatalogBase(java.util.Map commands)
Create a catalog whose commands are those specified in the given Map
.
All Map keys should be String
and all values should be Command
.
commands
- Map of Commands.public void addCommand(java.lang.String name, Command command)
Add a new name and associated Command
to the set of named commands known to this Catalog
,
replacing any previous command for that name.
addCommand
in interface Catalog
name
- Name of the new commandcommand
- Command
to be returned
for later lookups on this namepublic Command getCommand(java.lang.String name)
Return the Command
associated with the
specified name, if any; otherwise, return null
.
getCommand
in interface Catalog
name
- Name for which a Command
should be retrievedpublic java.util.Iterator getNames()
Return an Iterator
over the set of named commands
known to this Catalog
. If there are no known commands,
an empty Iterator is returned.
public java.lang.String toString()
toString
in class java.lang.Object