Skip to content

Commit

Permalink
Delete unused method (#1744)
Browse files Browse the repository at this point in the history
* Delete unused method

* Delete unused property "typeMapping"

* Delete unused "import" declaration
  • Loading branch information
ackintosh authored and wing328 committed Dec 31, 2018
1 parent 0fca901 commit 5730f62
Showing 1 changed file with 1 addition and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,12 @@
package org.openapitools.codegen;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public final class CodegenModelFactory {

private static final Map<CodegenModelType, Class<?>> typeMapping = new HashMap<CodegenModelType, Class<?>>();

/**
* Configure a different implementation class.
*
* @param type the type that shall be replaced
* @param implementation the implementation class must extend the default class and must provide a public no-arg constructor
*/
public static void setTypeMapping(CodegenModelType type, Class<?> implementation) {
if (!type.getDefaultImplementation().isAssignableFrom(implementation)) {
throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend " + type.getDefaultImplementation().getSimpleName());
}
try {
implementation.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
typeMapping.put(type, implementation);
}

@SuppressWarnings("unchecked")
public static <T> T newInstance(CodegenModelType type) {
Class<?> classType = typeMapping.get(type);
try {
return (T) (classType != null ? classType : type.getDefaultImplementation()).getDeclaredConstructor().newInstance();
return (T) type.getDefaultImplementation().getDeclaredConstructor().newInstance();
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 5730f62

Please sign in to comment.