de.skuzzle.test.snapshots.normalize.FieldObjectMembers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snapshot-tests-normalize Show documentation
Show all versions of snapshot-tests-normalize Show documentation
Travers/Clean/Normalize object instances
package de.skuzzle.test.snapshots.normalize;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
class FieldObjectMembers implements ObjectMembers {
private static final ObjectMembers INSTANCE = new FieldObjectMembers();
private FieldObjectMembers() {
// hidden
}
public static ObjectMembers getInstance() {
return INSTANCE;
}
@Override
public Stream directMembersOf(Object root, Object collectionParent, VisitorContext visitorContext) {
final Class extends Object> valueType = root.getClass();
return Reflection.superClassHierarchy(valueType)
.map(Class::getDeclaredFields)
.flatMap(Arrays::stream)
.filter(field -> !Modifier.isStatic(field.getModifiers()))
.map(field -> new FieldObjectMember(field, root, collectionParent));
}
private static final class FieldObjectMember implements ObjectMember {
private final Object parent;
private final Object collectionParent;
private final Field field;
public FieldObjectMember(Field field, Object parent, Object collectionParent) {
this.parent = parent;
this.collectionParent = collectionParent;
this.field = field;
}
@Override
public Object parent() {
return parent;
}
@Override
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy