2121import org .microbean .attributes .Attributes ;
2222
2323/**
24- * A utility class for working with commonly-used <dfn>qualifiers</dfn>.
24+ * A utility class for working with <dfn>qualifiers</dfn>.
25+ *
26+ * <p>This class is currently not used by other classes in this package. It may be useful in a variety of dependency
27+ * injection systems.</p>
2528 *
2629 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
2730 *
2831 * @see Attributes
2932 */
30- public final class Qualifiers {
31-
32- private static final Attributes QUALIFIER = Attributes .of ("Qualifier" );
33-
34- private static final List <Attributes > QUALIFIERS = List .of (QUALIFIER );
33+ public class Qualifiers {
3534
36- private static final Attributes ANY_QUALIFIER = Attributes .of ("Any" , QUALIFIERS );
3735
38- private static final List <Attributes > ANY_QUALIFIERS = List .of (ANY_QUALIFIER );
39-
40- private static final Attributes DEFAULT_QUALIFIER = Attributes .of ("Default" , QUALIFIERS );
41-
42- private static final List <Attributes > DEFAULT_QUALIFIERS = List .of (DEFAULT_QUALIFIER );
43-
44- private static final List <Attributes > ANY_AND_DEFAULT_QUALIFIERS = List .of (ANY_QUALIFIER , DEFAULT_QUALIFIER );
36+ /*
37+ * Static fields.
38+ */
4539
46- private static final Attributes PRIMORDIAL_QUALIFIER = Attributes .of ("Primordial" , QUALIFIERS );
4740
48- private static final List < Attributes > PRIMORDIAL_QUALIFIERS = List .of (PRIMORDIAL_QUALIFIER );
41+ private static final Attributes QUALIFIER = Attributes .of ("Qualifier" );
4942
50- private Qualifiers () {
51- super ();
52- }
43+ private static final List <Attributes > QUALIFIERS = List .of (QUALIFIER );
5344
54- /**
55- * Returns an unmodifiable {@link List} consisting solely of the unattributed <dfn>any qualifier</dfn> and the
56- * <dfn>default qualifier</dfn>.
57- *
58- * @return an unmodifiable {@link List} consisting solely of the unattributed any qualifier and the default qualifier;
59- * never {@code null}
60- *
61- * @see #anyQualifier()
62- *
63- * @see #defaultQualifier()
64- */
65- public static final List <Attributes > anyAndDefaultQualifiers () {
66- return ANY_AND_DEFAULT_QUALIFIERS ;
67- }
6845
69- /**
70- * Returns the unattributed <dfn>any qualifier</dfn>.
71- *
72- * @return the <dfn>any qualifier</dfn>; never {@code null}
73- *
74- * @see #anyQualifiers()
46+ /*
47+ * Constructors.
7548 */
76- public static final Attributes anyQualifier () {
77- return ANY_QUALIFIER ;
78- }
7949
80- /**
81- * Returns {@code true} if and only if the supplied {@link Attributes} {@linkplain Attributes#equals(Object) is equal
82- * to} the unattributed {@linkplain #anyQualifier() any qualifier}.
83- *
84- * @param a an {@link Attributes}; must not be {@code null}
85- *
86- * @return {@code true} if and only if the supplied {@link Attributes} {@linkplain Attributes#equals(Object) is equal
87- * to} the unattributed {@linkplain #anyQualifier() any qualifier}
88- *
89- * @exception NullPointerException if {@code a} is {@code null}
90- */
91- public static final boolean anyQualifier (final Attributes a ) {
92- return ANY_QUALIFIER == a || anyQualifier ().equals (a ) && qualifier (a );
93- }
9450
9551 /**
96- * Returns an immutable {@link List} consisting solely of the unattributed <dfn>any qualifier</dfn>.
97- *
98- * @return an immutable {@link List}; never {@code null}
99- *
100- * @see #anyQualifier()
52+ * Creates a new {@link Qualifiers}.
10153 */
102- public static final List < Attributes > anyQualifiers () {
103- return ANY_QUALIFIERS ;
54+ public Qualifiers () {
55+ super () ;
10456 }
10557
106- /**
107- * Returns the <dfn>default qualifier</dfn>.
108- *
109- * @return the <dfn>default qualifier</dfn>; never {@code null}
110- *
111- * @see #defaultQualifiers()
112- */
113- public static final Attributes defaultQualifier () {
114- return DEFAULT_QUALIFIER ;
115- }
11658
117- /**
118- * Returns {@code true} if and only if the supplied {@link Attributes} {@linkplain
119- * Attributes#equals(Object) is equal to} the {@linkplain #defaultQualifier() default qualifier}.
120- *
121- * @param a an {@link Attributes}; must not be {@code null}
122- *
123- * @return {@code true} if and only if the supplied {@link Attributes} {@linkplain
124- * Attributes#equals(Object) is equal to} the {@linkplain #defaultQualifier() default qualifier}
125- *
126- * @exception NullPointerException if {@code a} is {@code null}
59+ /*
60+ * Instance methods.
12761 */
128- public static final boolean defaultQualifier (final Attributes a ) {
129- return DEFAULT_QUALIFIER == a || defaultQualifier ().equals (a ) && qualifier (a );
130- }
13162
132- /**
133- * Returns an immutable {@link List} consisting solely of the <dfn>default qualifier</dfn>.
134- *
135- * @return an immutable {@link List}; never {@code null}
136- *
137- * @see #defaultQualifier()
138- */
139- public static final List <Attributes > defaultQualifiers () {
140- return DEFAULT_QUALIFIERS ;
141- }
14263
14364 /**
14465 * Returns an {@link Attributes} that is {@linkplain Attributes#equals(Object) equal to} the supplied {@link
@@ -153,11 +74,10 @@ public static final List<Attributes> defaultQualifiers() {
15374 *
15475 * @exception NullPointerException if {@code a} is {@code null}
15576 */
156- public static final Attributes normalize (final Attributes a ) {
77+ public Attributes normalize (final Attributes a ) {
15778 return switch (a ) {
15879 case null -> throw new NullPointerException ("a" );
159- case Attributes q when defaultQualifier (q ) -> defaultQualifier ();
160- case Attributes q when QUALIFIER .equals (q ) -> qualifier ();
80+ case Attributes q when this .qualifier ().equals (q ) -> this .qualifier ();
16181 default -> a ;
16282 };
16383 }
@@ -175,63 +95,26 @@ public static final Attributes normalize(final Attributes a) {
17595 *
17696 * @exception NullPointerException if {@code list} is {@code null}
17797 */
178- public static final List <Attributes > normalize (final List <Attributes > list ) {
98+ public List <Attributes > normalize (final List <Attributes > list ) {
17999 return switch (list .size ()) {
180100 case 0 -> List .of ();
181- case 1 -> list .equals (defaultQualifiers ()) ? defaultQualifiers () : List .copyOf (list );
101+ case 1 -> list .equals (this . qualifiers ()) ? this . qualifiers () : List .copyOf (list );
182102 default -> {
183103 final List <Attributes > l = new ArrayList <>(list .size ());
184104 for (final Attributes a : list ) {
185- l .add (normalize (a ));
105+ l .add (this . normalize (a ));
186106 }
187107 yield Collections .unmodifiableList (l );
188108 }
189109 };
190110 }
191111
192- /**
193- * Returns the <dfn>primordial qualifier</dfn>.
194- *
195- * @return the <dfn>primordial qualifier</dfn>; never {@code null}
196- *
197- * @see #primordialQualifiers()
198- */
199- public static final Attributes primordialQualifier () {
200- return PRIMORDIAL_QUALIFIER ;
201- }
202-
203- /**
204- * Returns {@code true} if and only if the supplied {@link Attributes} {@linkplain
205- * Attributes#equals(Object) is equal to} the {@linkplain #primordialQualifier() primordial qualifier}.
206- *
207- * @param a an {@link Attributes}; must not be {@code null}
208- *
209- * @return {@code true} if and only if the supplied {@link Attributes} {@linkplain
210- * Attributes#equals(Object) is equal to} the {@linkplain #primordialQualifier() primordial qualifier}
211- *
212- * @exception NullPointerException if {@code a} is {@code null}
213- */
214- public static final boolean primordialQualifier (final Attributes a ) {
215- return PRIMORDIAL_QUALIFIER == a || primordialQualifier ().equals (a ) && qualifier (a );
216- }
217-
218- /**
219- * Returns an immutable {@link List} consisting solely of the <dfn>primordial qualifier</dfn>.
220- *
221- * @return an immutable {@link List}; never {@code null}
222- *
223- * @see #primordialQualifier()
224- */
225- public static final List <Attributes > primordialQualifiers () {
226- return PRIMORDIAL_QUALIFIERS ;
227- }
228-
229112 /**
230113 * Returns the <dfn>qualifier</dfn> (meta-) qualifier.
231114 *
232115 * @return the <dfn>qualifier</dfn> (meta-) qualifier; never {@code null}
233116 */
234- public static final Attributes qualifier () {
117+ public Attributes qualifier () {
235118 return QUALIFIER ;
236119 }
237120
@@ -246,8 +129,8 @@ public static final Attributes qualifier() {
246129 *
247130 * @exception NullPointerException if {@code q} is {@code null}
248131 */
249- public static final boolean qualifier (final Attributes q ) {
250- return q .attributes ().contains (qualifier ());
132+ public boolean qualifier (final Attributes q ) {
133+ return q .attributes ().contains (this . qualifier ());
251134 }
252135
253136 /**
@@ -257,7 +140,7 @@ public static final boolean qualifier(final Attributes q) {
257140 *
258141 * @see #qualifier()
259142 */
260- public static final List <Attributes > qualifiers () {
143+ public List <Attributes > qualifiers () {
261144 return QUALIFIERS ;
262145 }
263146
@@ -272,16 +155,14 @@ public static final List<Attributes> qualifiers() {
272155 *
273156 * @exception NullPointerException if {@code c} is {@code null}
274157 */
275- public static final List <Attributes > qualifiers (final Collection <? extends Attributes > c ) {
158+ public List <Attributes > qualifiers (final Collection <? extends Attributes > c ) {
276159 return switch (c ) {
277160 case Collection <?> c0 when c0 .isEmpty () -> List .of ();
278- case Collection <?> c0 when c0 .equals (defaultQualifiers ()) -> defaultQualifiers ();
279- case Collection <?> c0 when c0 .equals (anyAndDefaultQualifiers ()) -> anyAndDefaultQualifiers ();
280- default ->{
161+ default -> {
281162 final ArrayList <Attributes > list = new ArrayList <>(c .size ());
282163 for (final Attributes a : c ) {
283- if (qualifier (a )) {
284- list .add (normalize (a ));
164+ if (this . qualifier (a )) {
165+ list .add (this . normalize (a ));
285166 }
286167 }
287168 list .trimToSize ();
0 commit comments