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

org.voovan.tools.collection.Attributes Maven / Gradle / Ivy

package org.voovan.tools.collection;

import org.voovan.tools.reflect.annotation.NotSerialization;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 属性存储器
 *
 * @author: helyho
 * voovan Framework.
 * WebSite: https://github.com/helyho/voovan
 * Licence: Apache v2 License
 */
public class Attributes {

    private Map attr;

    @NotSerialization
    private transient boolean modifyed = false;

    public Attributes() {
        attr = new ConcurrentHashMap();
    }

    public boolean isModifyed() {
        return modifyed;
    }

    public void setModifyed(boolean modifyed) {
        this.modifyed = modifyed;
    }

    /**
     * 获取全部属性参数
     * @return 属性参数Map
     */
    public Map attributes(){
        return this.attr;
    }

    /**
     * 获取属性参数
     * @param key 参数名
     * @return    参数对象
     */
    public Object getAttribute(Object key) {
        return attr.get(key);
    }

    /**
     * 设置属性参数
     * @param key     参数名
     * @param value   参数对象
     * @param      范型
     * @return 对象自身
     */
    public  T setAttribute(Object key, Object value) {
        this.attr.put(key, value);
        modifyed = true;
        return (T)this;
    }

    /**
     * 移除属性参数
     * @param key     参数名
     * @param      范型
     * @return 对象自身
     */
    public   T  removeAttribute(Object key) {
        this.attr.remove(key);
        modifyed = true;
        return (T)this;
    }

    /**
     * 检查属性参数是否存在
     * @param key     参数名
     * @return 是否包含
     */
    public boolean containAttribute(Object key) {
        return this.attr.containsKey(key);
    }

    /**
     * 清空 session 的缓存配置
     * @param      范型
     * @return 对象自身
     */
    public   T clearAttribute() {
        attr.clear();
        modifyed = true;
        return (T)this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy