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

org.cobraparser.util.Items Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package org.cobraparser.util;

import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;

public class Items {
  private Items() {
  }

  private static Map> sourceMap = new WeakHashMap<>();

  public static Object getItem(final Object source, final String name) {
    final Map> sm = sourceMap;
    synchronized (sm) {
      final Map itemMap = sm.get(source);
      if (itemMap == null) {
        return null;
      }
      return itemMap.get(name);
    }
  }

  public static void setItem(final Object source, final String name, final Object value) {
    final Map> sm = sourceMap;
    synchronized (sm) {
      Map itemMap = sm.get(source);
      if (itemMap == null) {
        itemMap = new HashMap<>(1);
        sm.put(source, itemMap);
      }
      itemMap.put(name, value);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy