mirror of
https://github.com/zaaarf/lillero-mapper.git
synced 2024-11-22 04:44:48 +01:00
fix: removed unnecessary reflection
This commit is contained in:
parent
9816a595b3
commit
c48450085b
1 changed files with 3 additions and 9 deletions
|
@ -8,7 +8,6 @@ import java.net.URISyntaxException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The main class of the mapper library. It loads all the
|
||||
|
@ -30,7 +29,7 @@ public class MapperProvider {
|
|||
/**
|
||||
* A {@link Set} containing all the loaded mapper classes.
|
||||
*/
|
||||
private Set<Class<? extends IMappingFormat>> loadedMappers = null;
|
||||
private Set<IMappingFormat> loadedMappers = null;
|
||||
|
||||
/**
|
||||
* Loads the mapper classes into a {@link Set}.
|
||||
|
@ -38,7 +37,7 @@ public class MapperProvider {
|
|||
private void loadMappers() {
|
||||
this.loadedMappers = new HashSet<>();
|
||||
for(IMappingFormat mapper: ServiceLoader.load(IMappingFormat.class))
|
||||
this.loadedMappers.add(mapper.getClass());
|
||||
this.loadedMappers.add(mapper);
|
||||
if(this.loadedMappers.isEmpty())
|
||||
throw new RuntimeException("Something went wrong: no mapper types were loaded successfully!");
|
||||
}
|
||||
|
@ -54,12 +53,7 @@ public class MapperProvider {
|
|||
if(getInstance().loadedMappers == null)
|
||||
getInstance().loadMappers();
|
||||
return getInstance().loadedMappers.stream()
|
||||
.flatMap(clazz -> {
|
||||
try {
|
||||
return Stream.of(clazz.newInstance());
|
||||
} catch(ReflectiveOperationException ignored) {}
|
||||
return Stream.empty();
|
||||
}).filter(m -> m.claim(data))
|
||||
.filter(m -> m.claim(data))
|
||||
.max(Comparator.comparingInt(IMappingFormat::priority))
|
||||
.orElseThrow(InvalidResourceException::new);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue