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

com.anwen.mongo.cache.global.FieldCache Maven / Gradle / Ivy

There is a newer version: 2.1.5
Show newest version
package com.anwen.mongo.cache.global;

import com.anwen.mongo.annotation.collection.CollectionField;

import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 通用的缓存
 *
 * @author anwen
 */
public class FieldCache {

    private static final Map genericTypeMapCache = new ConcurrentHashMap<>();

    private static final Map collectionFieldMapCache = new ConcurrentHashMap<>();

    public static Type getGenericType(Field field) {
        return genericTypeMapCache.getOrDefault(field,null);
    }

    public static Map getGenericTypeMapCache() {
        return genericTypeMapCache;
    }

    public static void setGenericTypeMapCache(Map genericTypeMapCache) {
        FieldCache.genericTypeMapCache.putAll(genericTypeMapCache);
    }

    public static void setGenericTypeMapCache(Field field,Type type) {
        FieldCache.genericTypeMapCache.put(field,type);
    }

    public static CollectionField getCollectionField(Field field) {
        return collectionFieldMapCache.getOrDefault(field,null);
    }

    public static Map getCollectionFieldMapCache() {
        return collectionFieldMapCache;
    }

    public static void setCollectionFieldMapCache(Map collectionFieldMapCache) {
        FieldCache.collectionFieldMapCache.putAll(collectionFieldMapCache);
    }

    public static void setCollectionFieldMapCache(Field field,CollectionField collectionField) {
        FieldCache.collectionFieldMapCache.put(field,collectionField);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy