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

org.openl.rules.ui.ObjectRegistry Maven / Gradle / Ivy

There is a newer version: 5.27.9
Show newest version
package org.openl.rules.ui;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;

public class ObjectRegistry {
    private final IdentityHashMap value2id = new IdentityHashMap<>();
    private final Map id2value = new HashMap<>();

    private int uniqueId = 0;

    public Integer getId(T value) {
        return value2id.get(value);
    }

    public T getValue(Integer id) {
        return id2value.get(id);
    }

    public Integer putIfAbsent(T value) {
        Integer id = getId(value);
        if (id != null) {
            return id;
        }

        id = ++uniqueId;
        value2id.put(value, id);
        id2value.put(id, value);
        return id;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy