Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## avrora.util
Class ClassMap

    java.lang.Object
      avrora.util.ClassMap

public class ClassMap
extends java.lang.Object

The `ClassMap` is a class that maps short names (i.e. short, lower case strings) to java classes and can instantiate them. This is useful for dynamic resolution of classes but with a small set of known defaults that have a short name. If the short name is not in the default set, this class will treat the short name as a fully qualified Java class name and load it. This class does the requisite checking--that the class exists, that it can be loaded, that it is of the appropriate type, that it can be instantiated, etc.

Field Summary
`protected java.util.HashMap` | `classMap` The `classMap` field is a hash map that maps a string to a Java class.
`protected java.lang.Class` | `clazz` The `clazz` field stores a reference to the Java class of which the objects stored in this map are instances of.
`protected java.util.HashMap` | `objMap` The `objMap` field is a hash map that maps a string to an instance of a particular class, i.e. an object.
`protected java.lang.String` | `type` The `type` field stores a string that represents the name of the "type" that this map contains.

Constructor Summary
`ClassMap(java.lang.String t, java.lang.Class clz)` The constructor for the `ClassMap` class creates a new class map with the specified type, which maps strings to instances of the specified class.

Method Summary
`void` | `addClass(java.lang.String alias, java.lang.Class clz)` The `addClass()` method adds a short name (alias) for the specified class to the set of default class names.
`void` | `addInstance(java.lang.String alias, java.lang.Object o)` The `addInstance()` method adds a mapping between a short name (alias) and an object that is the instance of the class represented by that short name.
`java.lang.Class` | `getClass(java.lang.String shortName)` The `getClass()` method gets the Java class representing the class returned for a given short name.
`java.util.Iterator` | `getIterator()` The `getIterator()` method returns an interator over all of the key values (short names or aliases) of this class map.
`java.lang.Object` | `getObjectOfClass(java.lang.String name)` The `getObjectOfClass()` method looks up the string name of the class in the alias map first, and if not found, attempts to load the class using `Class.forName()` and instantiates one object.
`java.util.List` | `getSortedList()` The `getSortedList()` method returns a sorted list of the short names (aliases) stored in this class map.
`java.util.Iterator` | `iterator()` The `iterator()` method returns an interator over the short names (aliases) stored in this map.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### type

    protected final java.lang.String type

  The `type` field stores a string that represents the name of the "type" that this map contains. For example, a class map for actions might be called "Action" and for input formats might be called "Input Format".

### clazz

    protected final java.lang.Class clazz

  The `clazz` field stores a reference to the Java class of which the objects stored in this map are instances of.

### classMap

    protected final java.util.HashMap classMap

  The `classMap` field is a hash map that maps a string to a Java class.

### objMap

    protected final java.util.HashMap objMap

  The `objMap` field is a hash map that maps a string to an instance of a particular class, i.e. an object.

Constructor Detail

### ClassMap

    public ClassMap(java.lang.String t,
                    java.lang.Class clz)

  The constructor for the `ClassMap` class creates a new class map with the specified type, which maps strings to instances of the specified class.

Parameters:
  `t` - the name of the type of this class as a string
  `clz` - the class which objects should be instances of

Method Detail

### addClass

    public void addClass(java.lang.String alias,
                         java.lang.Class clz)

  The `addClass()` method adds a short name (alias) for the specified class to the set of default class names.

  Parameters:
    `alias` - the string representation of the alias of the class
    `clz` - the class to which the alias maps

### addInstance

    public void addInstance(java.lang.String alias,
                            java.lang.Object o)

  The `addInstance()` method adds a mapping between a short name (alias) and an object that is the instance of the class represented by that short name.

  Parameters:
    `alias` - the alias for the instance
    `o` - the actual object that will be returned from `getObjectOfClass()` when the parameters is equal to the alias.

### getClass

    public java.lang.Class getClass(java.lang.String shortName)

  The `getClass()` method gets the Java class representing the class returned for a given short name. If there is no short name (alias) for the passed argument, this method will assume that the parameter is the fully qualified name of a class. It will then load that class and instantiate an instance of that class. That instance will be returned in subsequent calls to `getObjectOfClass()`.

  Parameters:
    `shortName` - the short name of the class
  Returns:
    a Java class representing the class for that alias or fully qualified name

### getObjectOfClass

    public java.lang.Object getObjectOfClass(java.lang.String name)

  The `getObjectOfClass()` method looks up the string name of the class in the alias map first, and if not found, attempts to load the class using `Class.forName()` and instantiates one object.

  Parameters:
    `name` - the name of the class or alias
  Returns:
    an instance of the specified class
  Throws:
    `Avrora.Error` - if there is a problem finding or instantiating the class

### getSortedList

    public java.util.List getSortedList()

  The `getSortedList()` method returns a sorted list of the short names (aliases) stored in this class map.

  Returns:
    an alphabetically sorted list that contains all the aliases in this map

### getIterator

    public java.util.Iterator getIterator()

  The `getIterator()` method returns an interator over all of the key values (short names or aliases) of this class map.

  Returns:
    an iterator over all the short names in this map

### iterator

    public java.util.Iterator iterator()

  The `iterator()` method returns an interator over the short names (aliases) stored in this map.

  Returns:
    an instance of `java.util.Iterator` which can be used to iterate over each alias in this map.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD