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

com.alachisoft.ncache.common.caching.statistics.monitoring.CounterIDMap Maven / Gradle / Ivy

package com.alachisoft.ncache.common.caching.statistics.monitoring;

import com.alachisoft.ncache.common.monitoring.CounterDataCollection;
import com.alachisoft.ncache.common.monitoring.CounterMetadata;

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

public class CounterIDMap
{

    private java.util.ArrayList counterMetadata = new java.util.ArrayList();
    private java.util.ArrayList counterNames = new java.util.ArrayList();
    private java.util.HashMap counterIDMap = new java.util.HashMap();


    private java.util.ArrayList privateCounterIds;
    public final java.util.ArrayList getCounterIds()
    {
        return privateCounterIds;
    }
    public final void setCounterIds(java.util.ArrayList value)
    {
        privateCounterIds = value;
    }
    private String privateVersion;
    public final String getVersion()
    {
        return privateVersion;
    }
    public final void setVersion(String value)
    {
        privateVersion = value;
    }
    private String privateCategory;
    public final String getCategory()
    {
        return privateCategory;
    }
    public final void setCategory(String value)
    {
        privateCategory = value;
    }


    public final void assignAndAddCounters(java.util.ArrayList counters)
    {
        // sort by name
        // assign ids

        int counterId = 0;
        java.util.ArrayList ids = new java.util.ArrayList();

        for (CounterMetadata counterMeta : counters)
        {
            if (!counterNames.contains(counterMeta.getName()))
            {
                counterNames.add(counterMeta.getName());
            }
        }

        for (String name : counterNames)
        {
            if (!counterIDMap.containsKey((short)counterId))
            {
                counterIDMap.put((short)counterId, name);
            }
            if (!ids.contains((short)counterId))
            {
                ids.add((short)counterId);
            }
            counterId++;
        }
        setCounterIds(ids);
    }

    public final short getCounterID(String counter)
    {

        if (counterIDMap != null)
        {
            if (counterIDMap.values().contains(counter))
            {
                for (Map.Entry entry : counterIDMap.entrySet()) {
                    if (counter.equals(entry.getValue())) {
                        return entry.getKey();
                    }
                }
            }
        }
        return -10;
    }

    public final String getCounterName(short id)
    {

        String name = "";
        if (counterIDMap != null)
        {
            if ((name = counterIDMap.get(id)) != null)
            {
                return name;
            }
        }

        return name;

    }


    public final java.util.Map convertToNameMap(CounterDataCollection collection)
    {

        HashMap nameMap = new HashMap();
        if (counterIDMap != null)
        {
            for (HashMap.Entry val : counterIDMap.entrySet())
            {
                nameMap.put(val.getValue(), val.getKey());
            }

        }

        return nameMap;
    }
    public final void Clear()
    {
        counterNames.clear();
        counterIDMap.clear();
        getCounterIds().clear();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy