Skip to content

Commit

Permalink
Merge branch 'feature/transformer-generator' into feature/transformer…
Browse files Browse the repository at this point in the history
…-generator-jdk8
  • Loading branch information
fborriello committed Aug 22, 2020
2 parents 46f8920 + 10a636f commit 2cafbe4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -733,45 +733,43 @@ public ClassType getClassType(final Class<?> clazz) {

/**
* Retrieves all the setters method for the given class.
* @param clazz the clazz containing the methods.
* @param clazz the class containing the methods.
* @return all the class setter methods
*/
@SuppressWarnings("unchecked")
public List<Method> getSetterMethods(final Class<?> clazz) {
notNull(clazz, CLAZZ_CANNOT_BE_NULL);
final String cacheKey = "SetterMethods-" + clazz.getName();
return CACHE_MANAGER.getFromCache(cacheKey, List.class).orElseGet(() -> {
final List<Method> setterMethods = new LinkedList<>();
if (hasSuperclass(clazz.getSuperclass())) {
setterMethods.addAll(getSetterMethods(clazz.getSuperclass()));
}
setterMethods.addAll(stream(getDeclaredMethods(clazz))
.filter(reflectionUtils::isSetter)
.collect(toList()));
CACHE_MANAGER.cacheObject(cacheKey, setterMethods);
return setterMethods;
});
return getMethods(clazz, "SetterMethods", reflectionUtils::isSetter);
}

/**
* Retrieves all the setters method for the given class.
* @param clazz the clazz containing the methods.
* @return all the class setter methods
* Retrieves all the getters method for the given class.
* @param clazz the class containing the methods.
* @return all the class getter methods
*/
@SuppressWarnings("unchecked")
public List<Method> getGetterMethods(final Class<?> clazz) {
return getMethods(clazz, "GetterMethods", reflectionUtils::isGetter);
}

/**
* Retrieves all the class methods matching to the the given filter.
* @param clazz the class containing the methods.
* @param cacheKeyPrefix the prefix to adopt for the cache key
* @param methodFilter the filter to apply to the retrieved methods
* @return the class methods matching the filter
*/
@SuppressWarnings("unchecked")
private List<Method> getMethods(final Class<?> clazz, final String cacheKeyPrefix, final Predicate<Method> methodFilter) {
notNull(clazz, CLAZZ_CANNOT_BE_NULL);
final String cacheKey = "GetterMethods-" + clazz.getName();
final String cacheKey = cacheKeyPrefix + "-" + clazz.getName();
return CACHE_MANAGER.getFromCache(cacheKey, List.class).orElseGet(() -> {
final List<Method> setterMethods = new LinkedList<>();
final List<Method> methods = new LinkedList<>();
if (hasSuperclass(clazz.getSuperclass())) {
setterMethods.addAll(getGetterMethods(clazz.getSuperclass()));
methods.addAll(getMethods(clazz.getSuperclass(), cacheKeyPrefix, methodFilter));
}
setterMethods.addAll(stream(getDeclaredMethods(clazz))
.filter(reflectionUtils::isGetter)
methods.addAll(stream(getDeclaredMethods(clazz))
.filter(methodFilter)
.collect(toList()));
CACHE_MANAGER.cacheObject(cacheKey, setterMethods);
return setterMethods;
CACHE_MANAGER.cacheObject(cacheKey, methods);
return methods;
});
}

Expand Down
5 changes: 0 additions & 5 deletions bull-map-transformer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
</parent>

<dependencies>
<dependency>
<groupId>com.hotels.beans</groupId>
<artifactId>bull-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.hotels.beans</groupId>
<artifactId>bull-bean-transformer</artifactId>
Expand Down

0 comments on commit 2cafbe4

Please sign in to comment.