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

eu.maveniverse.maven.mima.runtime.standalonesisu.internal.SisuLookup Maven / Gradle / Ivy

There is a newer version: 3.0.0-alpha-3
Show newest version
package eu.maveniverse.maven.mima.runtime.standalonesisu.internal;

import com.google.inject.Key;
import com.google.inject.name.Names;
import eu.maveniverse.maven.mima.context.Lookup;
import java.util.Iterator;
import java.util.Optional;
import javax.inject.Named;
import javax.inject.Provider;
import org.eclipse.sisu.BeanEntry;
import org.eclipse.sisu.inject.MutableBeanLocator;

public class SisuLookup implements Lookup {
    private final MutableBeanLocator locator;

    public SisuLookup(MutableBeanLocator locator) {
        this.locator = locator;
    }

    private  Optional lookupInternal(Key key) {
        final Iterable> entries = locator.locate(key);
        final Iterator> iterator = entries.iterator();
        final Provider provider = iterator.hasNext() ? iterator.next().getProvider() : null;
        if (provider == null) {
            return Optional.empty();
        }
        return Optional.of(provider.get());
    }

    @Override
    public  Optional lookup(Class type) {
        return lookupInternal(Key.get(type, Named.class));
    }

    @Override
    public  Optional lookup(Class type, String name) {
        return lookupInternal(Key.get(type, Names.named(name)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy