com.flextrade.builder.model.FieldFinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pojobuilder-maven-plugin Show documentation
Show all versions of pojobuilder-maven-plugin Show documentation
Maven Plugin which generates Builders and matchers
package com.flextrade.builder.model;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;
public class FieldFinder {
private final HashMap getters = new HashMap<>();
private final HashMap setters = new HashMap<>();
private final Stream fields;
public FieldFinder(Class clazz) {
fields = createFields(clazz);
}
private Stream createFields(Class clazz) {
Arrays.asList(clazz.getMethods()).stream().map(MethodWrapper::new).forEach(this::findGettersAndSetters);
Set fieldNames = new HashSet<>(getters.keySet());
fieldNames.retainAll(setters.keySet());
return fieldNames.stream().map(fieldName -> new Property(getters.get(fieldName), setters.get(fieldName)));
}
private void findGettersAndSetters(MethodWrapper methodWrapper) {
if(methodWrapper.isGetter())
getters.put(methodWrapper.getFieldName(), methodWrapper);
else if(methodWrapper.isSetter())
setters.put(methodWrapper.getFieldName(), methodWrapper);
}
public Stream getFields() {
return fields;
}
}