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

com.litongjava.tio.utils.prop.MapWithLockPropSupport Maven / Gradle / Ivy

There is a newer version: 3.7.3.v202400213-RELEASE
Show newest version
package com.litongjava.tio.utils.prop;

import java.util.HashMap;

import com.litongjava.tio.utils.lock.MapWithLock;

/**
 * @author tanyaowu
 * 2017年8月18日 下午5:36:02
 */
public class MapWithLockPropSupport implements IPropSupport {

  private final MapWithLock props = new MapWithLock<>(new HashMap(8));

  /**
   *
   * @author tanyaowu
   */
  public MapWithLockPropSupport() {
  }

  @Override
  public void clearAttribute() {
    props.clear();
  }

  /**
   * 同:clearAttribute()
   */
  public void clear() {
    clearAttribute();
  }

  /**
   *
   * @param key
   * @return
   * @author tanyaowu
   */
  @Override
  public Object getAttribute(String key) {
    return get(key);
  }

  /**
   * 同:getAttribute(String key)
   * @param key
   * @return
   */
  public Object get(String key) {
    return props.getObj().get(key);
  }

  // private void initProps() {
  // if (props == null) {
  // synchronized (this) {
  // if (props == null) {
  // props = new MapWithLock<>(new HashMap(10));
  // }
  // }
  // }
  // }

  /**
   * @param key
   * @author tanyaowu
   */
  @Override
  public void removeAttribute(String key) {
    remove(key);
  }

  /**
   * 同:removeAttribute(String key)
   * @param key
   */
  public void remove(String key) {
    props.remove(key);
  }

  /**
   *
   * @param key
   * @param value
   * @author tanyaowu
   */
  @Override
  public void setAttribute(String key, Object value) {
    set(key, value);
  }

  /**
   * 同:setAttribute(String key, Object value)
   * @param key
   * @param value
   */
  public void set(String key, Object value) {
    props.put(key, value);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy