Skip to content

Commit cdcdc91

Browse files
committed
Remove candidate method from Builder and BeanScope
1 parent 39497d9 commit cdcdc91

File tree

5 files changed

+3
-90
lines changed

5 files changed

+3
-90
lines changed

inject/src/main/java/io/avaje/inject/BeanScope.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ default <T> T getBean(Class<T> type, String name) {
128128
return get(type, name);
129129
}
130130

131-
/**
132-
* Return the wiring candidate bean with name and priority.
133-
*/
134-
<T> BeanEntry<T> candidate(Class<T> type, String name);
135-
136131
/**
137132
* Return the list of beans that have an annotation.
138133
*

inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@ public <T> T get(Class<T> beanClass, String name) {
192192
return context.get(beanClass, name);
193193
}
194194

195-
@Override
196-
public <T> BeanEntry<T> candidate(Class<T> type, String name) {
197-
return context.candidate(type, name);
198-
}
199-
200195
@Override
201196
public List<Object> getBeansWithAnnotation(Class<?> annotation) {
202197
return context.getBeansWithAnnotation(annotation);

inject/src/main/java/io/avaje/inject/spi/Builder.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ static Builder newBuilder(List<SuppliedBean> suppliedBeans, List<EnrichBean> enr
145145
*/
146146
<T> Set<T> getSet(Class<T> interfaceType);
147147

148-
/**
149-
* Get a candidate dependency allowing it to be null.
150-
*/
151-
<T> BeanEntry<T> candidate(Class<T> cls, String name);
152-
153148
/**
154149
* Return a potentially enriched bean for registration into the context.
155150
* Typically for use with mockito spy.

inject/src/main/java/io/avaje/inject/spi/DBeanScope.java

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,9 @@ public <T> T get(Class<T> beanClass) {
4646
return get(beanClass, null);
4747
}
4848

49-
@Override
50-
public <T> BeanEntry<T> candidate(Class<T> type, String name) {
51-
// sort candidates by priority - Primary, Normal, Secondary
52-
EntrySort<T> entrySort = new EntrySort<>();
53-
entrySort.add(beans.candidate(type, name));
54-
return entrySort.get();
55-
}
56-
5749
@Override
5850
public <T> T get(Class<T> beanClass, String name) {
59-
BeanEntry<T> candidate = candidate(beanClass, name);
51+
BeanEntry<T> candidate = beans.candidate(beanClass, name);
6052
return (candidate == null) ? null : candidate.getBean();
6153
}
6254

@@ -74,7 +66,7 @@ public <T> List<T> listByPriority(Class<T> interfaceType) {
7466

7567
@Override
7668
public <T> List<T> listByPriority(Class<T> interfaceType, Class<? extends Annotation> priorityAnnotation) {
77-
List<T> list = getBeans(interfaceType);
69+
List<T> list = list(interfaceType);
7870
return list.size() > 1 ? sortByPriority(list, priorityAnnotation) : list;
7971
}
8072

@@ -144,63 +136,6 @@ public void close() {
144136
}
145137
}
146138

147-
static class EntrySort<T> {
148-
149-
private BeanEntry<T> supplied;
150-
private BeanEntry<T> primary;
151-
private int primaryCount;
152-
private BeanEntry<T> secondary;
153-
private int secondaryCount;
154-
private BeanEntry<T> normal;
155-
private int normalCount;
156-
157-
private final List<BeanEntry<T>> all = new ArrayList<>();
158-
159-
void add(BeanEntry<T> candidate) {
160-
if (candidate == null) {
161-
return;
162-
}
163-
if (candidate.isSupplied()) {
164-
// a supplied bean trumps all
165-
supplied = candidate;
166-
return;
167-
}
168-
all.add(candidate);
169-
if (candidate.isPrimary()) {
170-
primary = candidate;
171-
primaryCount++;
172-
} else if (candidate.isSecondary()) {
173-
secondary = candidate;
174-
secondaryCount++;
175-
} else {
176-
normal = candidate;
177-
normalCount++;
178-
}
179-
}
180-
181-
BeanEntry<T> get() {
182-
if (supplied != null) {
183-
return supplied;
184-
}
185-
if (primaryCount > 1) {
186-
throw new IllegalStateException("Multiple @Primary beans when only expecting one? Beans: " + all);
187-
}
188-
if (primaryCount == 1) {
189-
return primary;
190-
}
191-
if (normalCount > 1) {
192-
throw new IllegalStateException("Multiple beans when only expecting one? Maybe use @Primary or @Secondary? Beans: " + all);
193-
}
194-
if (normalCount == 1) {
195-
return normal;
196-
}
197-
if (secondaryCount > 1) {
198-
throw new IllegalStateException("Multiple @Secondary beans when only expecting one? Beans: " + all);
199-
}
200-
return secondary;
201-
}
202-
}
203-
204139
private static class SortBean<T> implements Comparable<SortBean<T>> {
205140

206141
private final T bean;

inject/src/main/java/io/avaje/inject/spi/DBuilder.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,8 @@ public <T> List<T> getList(Class<T> interfaceType) {
8787
return (List<T>) list;
8888
}
8989

90-
@Override
91-
public <T> BeanEntry<T> candidate(Class<T> cls, String name) {
92-
DBeanScope.EntrySort<T> entrySort = new DBeanScope.EntrySort<>();
93-
entrySort.add(beanMap.candidate(cls, name));
94-
return entrySort.get();
95-
}
96-
9790
private <T> T getMaybe(Class<T> beanClass, String name) {
98-
BeanEntry<T> entry = candidate(beanClass, name);
91+
BeanEntry<T> entry = beanMap.candidate(beanClass, name);
9992
return (entry == null) ? null : entry.getBean();
10093
}
10194

0 commit comments

Comments
 (0)