com.softicar.platform.common.core.constant.container.field.ConstantContainerFieldExtractor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.constant.container.field;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Collectors;
public class ConstantContainerFieldExtractor {
private final Class containerClass;
private final Class expectedFieldType;
public ConstantContainerFieldExtractor(Class containerClass, Class expectedFieldType) {
this.containerClass = Objects.requireNonNull(containerClass);
this.expectedFieldType = Objects.requireNonNull(expectedFieldType);
}
public Collection> extractFields() {
return Arrays//
.asList(containerClass.getDeclaredFields())
.stream()
.filter(this::isRelevant)
.map(this::createContainerField)
.collect(Collectors.toList());
}
private ConstantContainerField createContainerField(Field field) {
return new ConstantContainerField<>(containerClass, expectedFieldType, field);
}
private boolean isRelevant(Field field) {
return expectedFieldType.isAssignableFrom(field.getType());
}
}