io.dinject.core.DContextEntry Maven / Gradle / Ivy
package io.dinject.core;
import io.dinject.BeanEntry;
import java.util.ArrayList;
import java.util.List;
/**
* Entry for a given key (bean class, interface class or annotation class).
*
* This holds a list of managed beans (which might be named).
*/
class DContextEntry {
private final List entries = new ArrayList<>();
@SuppressWarnings("unchecked")
BeanEntry candidate(String name) {
if (entries.isEmpty()) {
return null;
}
if (entries.size() == 1) {
DContextEntryBean entry = entries.get(0);
return entry.candidate(name);
}
EntryMatcher matcher = new EntryMatcher(name);
matcher.match(entries);
return matcher.candidate();
}
/**
* Get a single bean given the name.
*/
Object get(String name) {
if (entries.isEmpty()) {
return null;
}
if (entries.size() == 1) {
DContextEntryBean entry = entries.get(0);
return entry.getIfMatchWithDefault(name);
}
EntryMatcher matcher = new EntryMatcher(name);
matcher.match(entries);
return matcher.getBean();
}
/**
* Add all the managed beans to the given list.
*/
void addAll(List