net.sourceforge.pmd.util

## Class TypeMap

- java.lang.Object
- - net.sourceforge.pmd.util.TypeMap

    public class TypeMap
    extends Object

A specialized map that stores types by both their full and short (without package prefixes) names. If an incoming type shares the same name (but different package/prefix) with a type already in the map then an IllegalArgumentException will be thrown since any subsequent retrievals by said short name could be in error.

Author:
  Brian Remedios

### Constructor Summary

Constructors
Constructor and Description
`TypeMap(Class<?>... types)` Constructor for TypeMap that takes in an initial set of types.
`TypeMap(int initialSize)` Constructor for TypeMap.

### Method Summary

Methods
`void` `add(Class<?>... types)` Adds an array of types to the receiver at once.
`void` `add(Class<?> type)` Adds a type to the receiver and stores it keyed by both its full and short names.
`Map<Class<?>,String>` `asInverseWithShortName()` Creates and returns a map of short type names (without the package prefixes) keyed by the classes themselves.
`boolean` `contains(Class<?> type)` Returns whether the type is known to the receiver.
`boolean` `contains(String typeName)` Returns whether the typeName is known to the receiver.
`int` `size()` Returns the total number of entries in the receiver.
`Class<?>` `typeFor(String typeName)` Returns the type for the typeName specified.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### TypeMap

    public TypeMap(int initialSize)

Constructor for TypeMap.

Parameters:
  `initialSize` - int

#### TypeMap

    public TypeMap(Class<?>... types)

Constructor for TypeMap that takes in an initial set of types.

Parameters:
  `types` - Class[]

### Method Detail

#### add

    public void add(Class<?> type)

Adds a type to the receiver and stores it keyed by both its full and short names. Throws an exception if the short name of the argument matches an existing one already in the map for a different class.

Parameters:
  `type` - Class
Throws:
  `IllegalArgumentException`

#### contains

    public boolean contains(Class<?> type)

Returns whether the type is known to the receiver.

Parameters:
  `type` - Class
Returns:
  boolean

#### contains

    public boolean contains(String typeName)

Returns whether the typeName is known to the receiver.

Parameters:
  `typeName` - String
Returns:
  boolean

#### typeFor

    public Class<?> typeFor(String typeName)

Returns the type for the typeName specified.

Parameters:
  `typeName` - String
Returns:
  Class

#### add

    public void add(Class<?>... types)

Adds an array of types to the receiver at once.

Parameters:
  `types` - Class[]

#### asInverseWithShortName

    public Map<Class<?>,String> asInverseWithShortName()

Creates and returns a map of short type names (without the package prefixes) keyed by the classes themselves.

Returns:
  Map

#### size

    public int size()

Returns the total number of entries in the receiver. This will be exactly twice the number of types added.

Returns:
  the total number of entries in the receiver