Package javassist

# Class ClassMap

java.lang.Object
java.util.AbstractMap<String,String>
java.util.HashMap<String,String>
javassist.ClassMap

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Map<String,String>`

public class ClassMap extends HashMap<String,String>
A hash table associating class names with different names.

This hashtable is used for replacing class names in a class definition or a method body. Define a subclass of this class if a more complex mapping algorithm is needed. For example,

    class MyClassMap extends ClassMap {
       public Object get(Object jvmClassName) {
         String name = toJavaName((String)jvmClassName);
         if (name.startsWith("java."))
             return toJvmName("java2." + name.substring(5));
         else
             return super.get(jvmClassName);
       }
     }

This subclass maps `java.lang.String` to `java2.lang.String`. Note that `get()` receives and returns the internal representation of a class name. For example, the internal representation of `java.lang.String` is `java/lang/String`.

Note that this is a map from `String` to `String`.

See Also:
  - `get(Object)`
  - `CtClass.replaceClassName(ClassMap)`
  - `CtNewMethod.copy(CtMethod,String,CtClass,ClassMap)`
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class java.util.AbstractMap

`AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K,V>`

## Constructor Summary

Constructors
Constructor
Description
`ClassMap()`
Constructs a hash table.

## Method Summary

Modifier and Type
Method
Description
`void`
`fix(String name)`
Prevents a mapping from the specified class name to another name.
`void`
`fix(CtClass clazz)`
Prevents a mapping from the specified class name to another name.
`String`
`get(Object jvmClassName)`
Returns the class name to wihch the given `jvmClassName` is mapped.
`String`
`put(String oldname, String newname)`
Maps a class name to another name in this hashtable.
`void`
`put(CtClass oldname, CtClass newname)`
Maps a class name to another name in this hashtable.
`void`
`putIfNone(String oldname, String newname)`
Is equivalent to `put()` except that the given mapping is not recorded into the hashtable if another mapping from `oldname` is already included.
`static String`
`toJavaName(String classname)`
Converts a class name from the internal representation used in the JVM to the normal one used in Java.
`static String`
`toJvmName(String classname)`
Converts a class name into the internal representation used in the JVM.

### Methods inherited from class java.util.HashMap

`clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, newHashMap, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values`

### Methods inherited from class java.util.AbstractMap

`equals, hashCode, toString`

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

`getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Map

`equals, hashCode`

## Constructor Details

### ClassMap

public ClassMap()
Constructs a hash table.

## Method Details

### put

public void put(CtClass oldname, CtClass newname)
Maps a class name to another name in this hashtable. The names are obtained with calling `Class.getName()`. This method translates the given class names into the internal form used in the JVM before putting it in the hashtable.

Parameters:
  `oldname` - the original class name
  `newname` - the substituted class name.

### put

public String put(String oldname, String newname)
Maps a class name to another name in this hashtable. If the hashtable contains another mapping from the same class name, the old mapping is replaced. This method translates the given class names into the internal form used in the JVM before putting it in the hashtable.

If `oldname` is identical to `newname`, then this method does not perform anything; it does not record the mapping from `oldname` to `newname`. See `fix` method.

Specified by:
  `put` in interface `Map<String,String>`
Overrides:
  `put` in class `HashMap<String,String>`
Parameters:
  `oldname` - the original class name.
  `newname` - the substituted class name.
See Also:
  - `fix(String)`

### putIfNone

public void putIfNone(String oldname, String newname)
Is equivalent to `put()` except that the given mapping is not recorded into the hashtable if another mapping from `oldname` is already included.

Parameters:
  `oldname` - the original class name.
  `newname` - the substituted class name.

### get

public String get(Object jvmClassName)
Returns the class name to wihch the given `jvmClassName` is mapped. A subclass of this class should override this method.

This method receives and returns the internal representation of class name used in the JVM.

Specified by:
  `get` in interface `Map<String,String>`
Overrides:
  `get` in class `HashMap<String,String>`
See Also:
  - `toJvmName(String)`
  - `toJavaName(String)`

### fix

public void fix(CtClass clazz)
Prevents a mapping from the specified class name to another name.

### fix

public void fix(String name)
Prevents a mapping from the specified class name to another name.

### toJvmName

public static String toJvmName(String classname)
Converts a class name into the internal representation used in the JVM.

### toJavaName

public static String toJavaName(String classname)
Converts a class name from the internal representation used in the JVM to the normal one used in Java.