Skip to content

Commit 53fa6a8

Browse files
committed
Remove the sortByPriority methods from the public API
1 parent baea3f7 commit 53fa6a8

File tree

6 files changed

+14
-64
lines changed

6 files changed

+14
-64
lines changed

inject-test/src/test/java/org/example/coffee/priority/base/PriorityTest.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.example.coffee.priority.base;
22

3-
import io.avaje.inject.BeanScope;
4-
import io.avaje.inject.SystemContext;
3+
import io.avaje.inject.ApplicationScope;
54
import org.junit.jupiter.api.Test;
65

76
import java.util.List;
@@ -11,20 +10,8 @@
1110
public class PriorityTest {
1211

1312
@Test
14-
void getBeansByPriority() {
15-
final BeanScope context = SystemContext.context();
16-
17-
final List<BaseIface> beans = context.getBeansByPriority(BaseIface.class);
18-
assertExpectedOrder(beans);
19-
}
20-
21-
@Test
22-
void sortByPriority() {
23-
final BeanScope context = SystemContext.context();
24-
25-
final List<BaseIface> beans = context.getBeans(BaseIface.class);
26-
final List<BaseIface> sorted = context.sortByPriority(beans);
27-
13+
void listByPriority() {
14+
final List<BaseIface> sorted = ApplicationScope.listByPriority(BaseIface.class);
2815
assertExpectedOrder(sorted);
2916
}
3017

inject-test/src/test/java/org/example/coffee/priority/custom/CustomPriorityTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.example.coffee.priority.custom;
22

3+
import io.avaje.inject.ApplicationScope;
34
import io.avaje.inject.BeanScope;
4-
import io.avaje.inject.SystemContext;
55
import org.junit.jupiter.api.Test;
66

77
import java.util.List;
@@ -12,10 +12,9 @@ public class CustomPriorityTest {
1212

1313
@Test
1414
void test() {
15-
final BeanScope context = SystemContext.context();
15+
final BeanScope context = ApplicationScope.scope();
1616

17-
final List<OtherIface> beans = context.getBeans(OtherIface.class);
18-
final List<OtherIface> sorted = context.sortByPriority(beans, CustomPriority.class);
17+
final List<OtherIface> sorted = context.listByPriority(OtherIface.class, CustomPriority.class);
1918

2019
assertThat(sorted.get(0)).isInstanceOf(COtheri.class);
2120
assertThat(sorted.get(1)).isInstanceOf(BOtheri.class);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public static BeanScope scope() {
6060
* @param type an interface or bean type
6161
*/
6262
public static <T> T get(Class<T> type) {
63-
return rootContext.getBean(type);
63+
return rootContext.get(type);
6464
}
6565

6666
/**
6767
* Return a single bean given the type and name.
6868
*
6969
* <pre>{@code
7070
*
71-
* Heater heater = ApplicationScope.getBean(Heater.class, "electric");
71+
* Heater heater = ApplicationScope.get(Heater.class, "electric");
7272
* heater.heat();
7373
*
7474
* }</pre>
@@ -77,7 +77,7 @@ public static <T> T get(Class<T> type) {
7777
* @param name the name qualifier of a specific bean
7878
*/
7979
public static <T> T get(Class<T> type, String name) {
80-
return rootContext.getBean(type, name);
80+
return rootContext.get(type, name);
8181
}
8282

8383

@@ -95,7 +95,7 @@ public static <T> T get(Class<T> type, String name) {
9595
* @param interfaceType An interface class.
9696
*/
9797
public static <T> List<T> list(Class<T> interfaceType) {
98-
return rootContext.getBeans(interfaceType);
98+
return rootContext.list(interfaceType);
9999
}
100100

101101
/**
@@ -112,7 +112,7 @@ public static <T> List<T> list(Class<T> interfaceType) {
112112
* @param interfaceType An interface class.
113113
*/
114114
public static <T> List<T> listByPriority(Class<T> interfaceType) {
115-
return rootContext.getBeansByPriority(interfaceType);
115+
return rootContext.listByPriority(interfaceType);
116116
}
117117

118118
/**

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

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static BeanScopeBuilder newBuilder() {
8888
*
8989
* <pre>{@code
9090
*
91-
* CoffeeMaker coffeeMaker = beanContext.getBean(CoffeeMaker.class);
91+
* CoffeeMaker coffeeMaker = beanScope.get(CoffeeMaker.class);
9292
* coffeeMaker.brew();
9393
*
9494
* }</pre>
@@ -110,7 +110,7 @@ default <T> T getBean(Class<T> type) {
110110
*
111111
* <pre>{@code
112112
*
113-
* Heater heater = beanContext.getBean(Heater.class, "electric");
113+
* Heater heater = beanScope.get(Heater.class, "electric");
114114
* heater.heat();
115115
*
116116
* }</pre>
@@ -203,26 +203,6 @@ default <T> List<T> getBeansByPriority(Class<T> interfaceType, Class<? extends A
203203
return listByPriority(interfaceType, priority);
204204
}
205205

206-
/**
207-
* Sort the beans by javax.annotation.Priority annotation.
208-
*
209-
* @param list The beans to sort by priority
210-
* @return A new list of beans sorted by priority
211-
*/
212-
<T> List<T> sortByPriority(List<T> list);
213-
214-
/**
215-
* Sort the beans using the given Priority annotation.
216-
* <p>
217-
* The priority annotation will typically be either <code>javax.annotation.Priority</code>
218-
* or <code>jakarta.annotation.Priority</code>.
219-
*
220-
* @param list The beans to sort by priority
221-
* @param priority The priority annotation used to sort the beans
222-
* @return A new list of beans sorted by priority
223-
*/
224-
<T> List<T> sortByPriority(List<T> list, final Class<? extends Annotation> priority);
225-
226206
/**
227207
* Return a request scoped provided for the specific type and name.
228208
*

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,6 @@ public <T> List<T> listByPriority(Class<T> interfaceType, Class<? extends Annota
212212
return context.listByPriority(interfaceType, priority);
213213
}
214214

215-
@Override
216-
public <T> List<T> sortByPriority(List<T> list) {
217-
return context.sortByPriority(list);
218-
}
219-
220-
@Override
221-
public <T> List<T> sortByPriority(List<T> list, Class<? extends Annotation> priority) {
222-
return context.sortByPriority(list, priority);
223-
}
224-
225215
@Override
226216
public void start() {
227217
context.start();

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ public <T> List<T> listByPriority(Class<T> interfaceType, Class<? extends Annota
6868
return list.size() > 1 ? sortByPriority(list, priorityAnnotation) : list;
6969
}
7070

71-
@Override
72-
public <T> List<T> sortByPriority(List<T> list) {
73-
return sortByPriority(list, Priority.class);
74-
}
75-
76-
@Override
77-
public <T> List<T> sortByPriority(List<T> list, final Class<? extends Annotation> priorityAnnotation) {
71+
private <T> List<T> sortByPriority(List<T> list, final Class<? extends Annotation> priorityAnnotation) {
7872
boolean priorityUsed = false;
7973
List<SortBean<T>> tempList = new ArrayList<>(list.size());
8074
for (T bean : list) {

0 commit comments

Comments
 (0)