All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.buger.patcher.Utils Maven / Gradle / Ivy

Go to download

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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy