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

org.weakref.jmx.guice.MapMapping Maven / Gradle / Ivy

There is a newer version: 1.26
Show newest version
package org.weakref.jmx.guice;

import org.weakref.jmx.internal.guava.reflect.TypeParameter;
import org.weakref.jmx.internal.guava.reflect.TypeToken;
import com.google.inject.Key;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.Map.Entry;

class MapMapping
{
    private final ObjectNameFunction> objectNameFunction;
    private final Class keyClass;
    private final Class valueClass;

    MapMapping(Class keyClass, Class valueClass, ObjectNameFunction> objectNameFunction)
    {
        this.keyClass = keyClass;
        this.valueClass = valueClass;
        this.objectNameFunction = objectNameFunction;
    }

    public ObjectNameFunction> getObjectNameFunction()
    {
        return objectNameFunction;
    }

    public Key> getKey()
    {
        return (Key>) Key.get(mapOf(keyClass, valueClass));
    }

    private static  Type mapOf(Class keyClass, Class valueClass)
    {
        return new TypeToken>() {}
                .where(new TypeParameter() {}, TypeToken.of(keyClass))
                .where(new TypeParameter() {}, TypeToken.of(valueClass))
                .getType();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy