Small amount of code cleanup

This commit is contained in:
Rsl1122 2019-03-14 16:57:10 +02:00
parent b52d113e2e
commit 41f5ce4853
2 changed files with 14 additions and 11 deletions

View File

@ -54,6 +54,9 @@ public class DataProviderExtractor {
extensionExtractor = new ExtensionExtractor(extension);
extensionExtractor.extractAnnotationInformation();
dataProviders = new DataProviders();
extractAllDataProviders();
}
public String getPluginName() {
@ -69,6 +72,7 @@ public class DataProviderExtractor {
Map<String, TabInfo> tabInformation = extensionExtractor.getTabInformation()
.stream().collect(Collectors.toMap(TabInfo::tab, Function.identity(), (one, two) -> one));
// Extracts PluginTabs
return extensionExtractor.getMethodAnnotations().getAnnotations(Tab.class).stream()
.map(Tab::value)
.distinct()
@ -92,14 +96,16 @@ public class DataProviderExtractor {
.collect(Collectors.toSet());
}
public DataProviders getDataProviders() {
return dataProviders;
}
private Optional<Class> extractParameterClass(Method method) {
Class<?>[] parameterTypes = method.getParameterTypes();
return parameterTypes.length == 1 ? Optional.of(parameterTypes[0]) : Optional.empty();
}
public DataProviders getDataProviders() {
dataProviders = new DataProviders();
private void extractAllDataProviders() {
PluginInfo pluginInfo = extensionExtractor.getPluginInfo();
MethodAnnotations methodAnnotations = extensionExtractor.getMethodAnnotations();
Map<Method, Tab> tabs = methodAnnotations.getMethodAnnotations(Tab.class);
@ -110,8 +116,6 @@ public class DataProviderExtractor {
extractDataProviders(pluginInfo, tabs, conditions, PercentageProvider.class, PercentageDataProvider::placeToDataProviders);
extractDataProviders(pluginInfo, tabs, conditions, NumberProvider.class, NumberDataProvider::placeToDataProviders);
extractDataProviders(pluginInfo, tabs, conditions, StringProvider.class, StringDataProvider::placeToDataProviders);
return dataProviders;
}
private <T extends Annotation> void extractDataProviders(PluginInfo pluginInfo, Map<Method, Tab> tabs, Map<Method, Conditional> conditions, Class<T> ofKind, DataProviderFactory<T> factory) {

View File

@ -28,24 +28,23 @@ import java.util.Map;
*/
public class DataProviders {
// Return type, Parameter type, DataProvider
private Map<Class, Map<Class, List<DataProvider>>> providers;
private Map<Class, Map<Class, List<DataProvider>>> byReturnType;
public DataProviders() {
providers = new HashMap<>();
byReturnType = new HashMap<>();
}
public <T, K> void put(Class<T> parameterType, Class<K> returnType, DataProvider<T, K> provider) {
Map<Class, List<DataProvider>> byParameterType = providers.getOrDefault(returnType, new HashMap<>());
Map<Class, List<DataProvider>> byParameterType = byReturnType.getOrDefault(returnType, new HashMap<>());
List<DataProvider> dataProviders = byParameterType.getOrDefault(parameterType, new ArrayList<>());
dataProviders.add(provider);
byParameterType.put(parameterType, dataProviders);
providers.put(returnType, byParameterType);
byReturnType.put(returnType, byParameterType);
}
public <T, K> List<DataProvider> get(Class<T> parameterType, Class<K> returnType) {
return this.providers.getOrDefault(returnType, new HashMap<>()).getOrDefault(parameterType, new ArrayList<>());
return byReturnType.getOrDefault(returnType, new HashMap<>()).getOrDefault(parameterType, new ArrayList<>());
}
}