com.softicar.platform.common.code.java.reflection.DeclaredFieldFinder 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.code.java.reflection;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class DeclaredFieldFinder {
private final Class declaringClass;
private Predicate predicate;
public DeclaredFieldFinder(Class declaringClass) {
this.declaringClass = Objects.requireNonNull(declaringClass);
this.predicate = dummy -> true;
}
public DeclaredFieldFinder setFilter(Predicate predicate) {
this.predicate = Objects.requireNonNull(predicate);
return this;
}
public Collection findDeclaredFields() {
return Arrays//
.asList(declaringClass.getDeclaredFields())
.stream()
.filter(predicate)
.collect(Collectors.toList());
}
}