com.buger.patcher.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of object-patcher Show documentation
Show all versions of object-patcher Show documentation
Java Object Patcher is simple,
dependency-free and fast library
which makes patching/merging objects simple.
The newest version!
package com.buger.patcher;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @author Created by Buheria Oleksii {@literal [email protected]}
* @version 1.0
* @since 29-09-2020
*/
public class Utils {
public static Set getAllFields(Class> type) {
Set fields = new HashSet();
for (Class> c = type; c != null; c = c.getSuperclass()) {
fields.addAll(Arrays.asList(c.getDeclaredFields()));
}
return fields;
}
public static Set getCommonFields(Class> class1, Class> class2) {
Set class1Fields = getAllFields(class1);
Set class2Fields = getAllFields(class2);
Set result = new HashSet();
for (Field class1Field : class1Fields) {
if (class2Fields.contains(class1Field)) {
result.add(class1Field);
}
}
return result;
}
}