11/*
2- * Copyright 2008-2012 the original author or authors.
2+ * Copyright 2008-2019 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616package org .springframework .plugin .core ;
1717
1818import java .util .ArrayList ;
19+ import java .util .Arrays ;
1920import java .util .Collections ;
2021import java .util .Comparator ;
2122import java .util .List ;
@@ -37,12 +38,12 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends SimplePlug
3738 * Comparator regarding {@link org.springframework.core.Ordered} interface or
3839 * {@link org.springframework.core.annotation.Order} annotation.
3940 */
40- private static final Comparator <Object > DEFAULT_COMPARATOR = new AnnotationAwareOrderComparator ();
41+ static final Comparator <Object > DEFAULT_COMPARATOR = new AnnotationAwareOrderComparator ();
4142
4243/**
4344 * Comparator reverting the {@value #DEFAULT_COMPARATOR}.
4445 */
45- private static final Comparator <Object > DEFAULT_REVERSE_COMPARATOR = DEFAULT_COMPARATOR .reversed ();
46+ static final Comparator <Object > DEFAULT_REVERSE_COMPARATOR = DEFAULT_COMPARATOR .reversed ();
4647
4748private final Comparator <? super T > comparator ;
4849
@@ -67,8 +68,9 @@ protected OrderAwarePluginRegistry(List<? extends T> plugins, Comparator<? super
6768 * Creates a new {@link OrderAwarePluginRegistry} using the {@code #DEFAULT_COMPARATOR}.
6869 *
6970 * @return
71+ * @since 2.0
7072 */
71- public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create () {
73+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > empty () {
7274return create (Collections .emptyList ());
7375}
7476
@@ -78,8 +80,9 @@ public static <S, T extends Plugin<S>> OrderAwarePluginRegistry<T, S> create() {
7880 *
7981 * @param comparator must not be {@literal null}.
8082 * @return
83+ * @since 2.0
8184 */
82- public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create (Comparator <? super T > comparator ) {
85+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > of (Comparator <? super T > comparator ) {
8386
8487Assert .notNull (comparator , "Comparator must not be null!" );
8588
@@ -88,11 +91,23 @@ public static <S, T extends Plugin<S>> OrderAwarePluginRegistry<T, S> create(Com
8891
8992/**
9093 * Creates a new {@link OrderAwarePluginRegistry} with the given plugins.
91- *
9294 * @param plugins must not be {@literal null}.
9395 * @return
96+ * @since 2.0
9497 */
95- public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create (List <? extends T > plugins ) {
98+ @ SafeVarargs
99+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > of (T ... plugins ) {
100+ return create (Arrays .asList (plugins ), DEFAULT_COMPARATOR );
101+ }
102+
103+ /**
104+ * Creates a new {@link OrderAwarePluginRegistry} with the given plugins.
105+ *
106+ * @param plugins must not be {@literal null}.
107+ * @return
108+ * @since 2.0
109+ */
110+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > of (List <? extends T > plugins ) {
96111return create (plugins , DEFAULT_COMPARATOR );
97112}
98113
@@ -102,8 +117,9 @@ public static <S, T extends Plugin<S>> OrderAwarePluginRegistry<T, S> create(Lis
102117 *
103118 * @param plugins must not be {@literal null}.
104119 * @return
120+ * @since 2.0
105121 */
106- public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > createReverse (List <? extends T > plugins ) {
122+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > ofReverse (List <? extends T > plugins ) {
107123return create (plugins , DEFAULT_REVERSE_COMPARATOR );
108124}
109125
@@ -112,8 +128,9 @@ public static <S, T extends Plugin<S>> OrderAwarePluginRegistry<T, S> createReve
112128 *
113129 * @param plugins
114130 * @return
131+ * @since 2.0
115132 */
116- public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create (List <? extends T > plugins ,
133+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > of (List <? extends T > plugins ,
117134Comparator <? super T > comparator ) {
118135
119136Assert .notNull (plugins , "Plugins must not be null!" );
@@ -122,7 +139,73 @@ public static <S, T extends Plugin<S>> OrderAwarePluginRegistry<T, S> create(Lis
122139return new OrderAwarePluginRegistry <>(plugins , comparator );
123140}
124141
125- /*
142+ /**
143+ * Creates a new {@link OrderAwarePluginRegistry} using the {@code #DEFAULT_COMPARATOR}.
144+ *
145+ * @return
146+ * @deprecated since 2.0, for removal in 2.1. Prefer {@link PluginRegistry#empty()}.
147+ */
148+ @ Deprecated
149+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create () {
150+ return empty ();
151+ }
152+
153+ /**
154+ * Creates a new {@link OrderAwarePluginRegistry} using the given {@link Comparator} for ordering contained
155+ * {@link Plugin}s.
156+ *
157+ * @param comparator must not be {@literal null}.
158+ * @return
159+ * @deprecated since 2.0, for removal in 2.1. Prefer {@link PluginRegistry#of(Comparator)}.
160+ */
161+ @ Deprecated
162+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create (Comparator <? super T > comparator ) {
163+
164+ Assert .notNull (comparator , "Comparator must not be null!" );
165+
166+ return of (Collections .emptyList (), comparator );
167+ }
168+
169+ /**
170+ * Creates a new {@link OrderAwarePluginRegistry} with the given plugins.
171+ *
172+ * @param plugins must not be {@literal null}.
173+ * @return
174+ * @deprecated since 2.0, for removal in 2.1. Prefer {@link PluginRegistry#of(List)}.
175+ */
176+ @ Deprecated
177+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create (List <? extends T > plugins ) {
178+ return of (plugins , DEFAULT_COMPARATOR );
179+ }
180+
181+ /**
182+ * Creates a new {@link OrderAwarePluginRegistry} with the given {@link Plugin}s and the order of the {@link Plugin}s
183+ * reverted.
184+ *
185+ * @param plugins must not be {@literal null}.
186+ * @return
187+ * @deprecated since 2.0, for removal in 2.1. Prefer {@link OrderAwarePluginRegistry#ofReverse(List)}
188+ */
189+ @ Deprecated
190+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > createReverse (List <? extends T > plugins ) {
191+ return of (plugins , DEFAULT_REVERSE_COMPARATOR );
192+ }
193+
194+ /**
195+ * Creates a new {@link OrderAwarePluginRegistry} with the given plugins.
196+ *
197+ * @param plugins must not be {@literal null}.
198+ * @return
199+ * @deprecated since 2.0, for removal in 2.1. Prefer {@link PluginRegistry#of(List, Comparator)}.
200+ */
201+ @ Deprecated
202+ public static <S , T extends Plugin <S >> OrderAwarePluginRegistry <T , S > create (List <? extends T > plugins ,
203+ Comparator <? super T > comparator ) {
204+
205+ return of (plugins , comparator );
206+ }
207+
208+ /*
126209 * (non-Javadoc)
127210 * @see org.springframework.plugin.core.PluginRegistrySupport#initialize(java.util.List)
128211 */
0 commit comments