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

org.umlg.runtime.adaptor.UmlgAssociationClassManager Maven / Gradle / Ivy

There is a newer version: 2.0.15
Show newest version
package org.umlg.runtime.adaptor;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Date: 2013/07/26
 * Time: 8:07 AM
 */
public class UmlgAssociationClassManager {

    public static UmlgAssociationClassManager INSTANCE = new UmlgAssociationClassManager();

    private UmlgAssociationClassManager() {
    }

    private static ThreadLocal>> associationClassMap = new ThreadLocal>>() {
        @Override
        protected Map> initialValue() {
            return new HashMap>();
        }
    };

    public synchronized void put(String associationClassName, Object associationToObjectId) {
        if (UmlgAssociationClassManager.associationClassMap.get().get(associationClassName) == null) {
            UmlgAssociationClassManager.associationClassMap.get().put(associationClassName, new HashSet());
        }
        UmlgAssociationClassManager.associationClassMap.get().get(associationClassName).add(associationToObjectId);
    }

    public boolean has(String associationClassName, Object associationToObjectId) {
        return UmlgAssociationClassManager.associationClassMap.get().get(associationClassName) != null &&
                UmlgAssociationClassManager.associationClassMap.get().get(associationClassName).contains(associationToObjectId);
    }

    public static void remove() {
        UmlgAssociationClassManager.associationClassMap.remove();
    }

}