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

io.github.xuyao5.dkl.eskits.util.FieldUtilsPlus Maven / Gradle / Ivy

There is a newer version: 0.14
Show newest version
package io.github.xuyao5.dkl.eskits.util;

import com.google.gson.reflect.TypeToken;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.NonNull;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Thomas.XU(xuyao)
 * @version 7/03/21 21:09
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class FieldUtilsPlus {

    public static Map getDeclaredFieldsMap(@NonNull Class clz) {
        return Arrays.stream(clz.getDeclaredFields()).collect(Collectors.toConcurrentMap(Field::getName, Field::getGenericType));
    }

    public static Map getDeclaredFieldsMap(@NonNull Type type) {
        return getDeclaredFieldsMap(TypeToken.get(type).getRawType());
    }

    public static boolean isSameType(@NonNull TypeToken typeToken, @NonNull Type type) {
        return typeToken.getType().equals(type);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy