defaultQualifiers() {
return DEFAULT_QUALIFIERS;
}
/**
- * Returns the qualifier (meta-) qualifier.
+ * Returns an {@link Attributes} that is {@linkplain Attributes#equals(Object) equal to} the supplied {@link
+ * Attributes}.
*
- * @return the qualifier (meta-) qualifier; never {@code null}
+ * The returned {@link Attributes} may be the supplied {@link Attributes} or a different instance.
+ *
+ * @param a an {@link Attributes}; must not be {@code null}
+ *
+ * @return an {@link Attributes} that is {@linkplain Attributes#equals(Object) equal to} the supplied {@link
+ * Attributes}; never {@code null}
+ *
+ * @exception NullPointerException if {@code a} is {@code null}
*/
- public static final NamedAttributeMap> qualifier() {
- return QUALIFIER;
+ public static final Attributes normalize(final Attributes a) {
+ return switch (a) {
+ case null -> throw new NullPointerException("a");
+ case Attributes q when defaultQualifier(q) -> defaultQualifier();
+ case Attributes q when QUALIFIER.equals(q) -> qualifier();
+ default -> a;
+ };
}
/**
- * Returns {@code true} if and only if the supplied {@link NamedAttributeMap} is itself a {@link NamedAttributeMap}
- * that can be used to designate other {@link NamedAttributeMap}s as qualifiers, or a {@link NamedAttributeMap} so
- * designated.
+ * Returns an immutable {@link List} of {@link Attributes}s that is {@linkplain List#equals(Object) equal to} the
+ * supplied {@link List}.
*
- * A {@link NamedAttributeMap} whose {@linkplain NamedAttributeMap#name() name} is {@code Qualifier} and whose
- * {@linkplain NamedAttributeMap#metadata() metadata} is empty is an example of the former.
+ * The returned {@link List} may be the supplied {@link List} or a different instance.
*
- * A {@link NamedAttributeMap} whose {@linkplain NamedAttributeMap#metadata() metadata} contains a {@link
- * NamedAttributeMap} whose {@linkplain NamedAttributeMap#name() name} is {@code Qualifier} is an example of the
- * latter.
+ * @param list a {@link List} of {@link Attributes}s; must not be {@code null}
*
- * @param q a {@link NamedAttributeMap}; must not be {@code null}
+ * @return an immutable {@link List} of {@link Attributes}s that is {@linkplain List#equals(Object) equal to} the
+ * supplied {@link List}; never {@code null}
*
- * @return {@code true} if and only if the supplied {@link NamedAttributeMap} is itself a {@link NamedAttributeMap}
- * that can be used to designate other {@link NamedAttributeMap}s as qualifiers, or a {@link NamedAttributeMap} so
- * designated
+ * @exception NullPointerException if {@code list} is {@code null}
+ */
+ public static final List normalize(final List list) {
+ return switch (list.size()) {
+ case 0 -> List.of();
+ case 1 -> list.equals(defaultQualifiers()) ? defaultQualifiers() : List.copyOf(list);
+ default -> {
+ final List l = new ArrayList<>(list.size());
+ for (final Attributes a : list) {
+ l.add(normalize(a));
+ }
+ yield Collections.unmodifiableList(l);
+ }
+ };
+ }
+
+ /**
+ * Returns the primordial qualifier.
*
- * @exception NullPointerException if {@code nam} is {@code null}
+ * @return the primordial qualifier; never {@code null}
*
- * @see NamedAttributeMap#metadata()
+ * @see #primordialQualifiers()
*/
- public static final boolean qualifier(final NamedAttributeMap> q) {
- return q != null && qualifier(q.metadata());
+ public static final Attributes primordialQualifier() {
+ return PRIMORDIAL_QUALIFIER;
}
- private static final boolean qualifier(final Iterable extends NamedAttributeMap>> mds) {
- for (final NamedAttributeMap> md : mds) {
- if (QUALIFIER.equals(md) && md.metadata().isEmpty() || qualifier(md)) {
- return true;
- }
- }
- return false;
+ /**
+ * Returns {@code true} if and only if the supplied {@link Attributes} {@linkplain
+ * Attributes#equals(Object) is equal to} the {@linkplain #primordialQualifier() primordial qualifier}.
+ *
+ * @param a an {@link Attributes}; must not be {@code null}
+ *
+ * @return {@code true} if and only if the supplied {@link Attributes} {@linkplain
+ * Attributes#equals(Object) is equal to} the {@linkplain #primordialQualifier() primordial qualifier}
+ *
+ * @exception NullPointerException if {@code a} is {@code null}
+ */
+ public static final boolean primordialQualifier(final Attributes a) {
+ return PRIMORDIAL_QUALIFIER == a || primordialQualifier().equals(a) && qualifier(a);
}
/**
- * Returns an unmodifiable {@link List} consisting only of those {@link NamedAttributeMap}s in the supplied {@link
- * Collection} that {@linkplain #qualifier(NamedAttributeMap) are qualifiers}.
- *
- * @param c a {@link Collection} of {@link NamedAttributeMap}s; must not be {@code null}
+ * Returns an immutable {@link List} consisting solely of the primordial qualifier.
*
- * @return an unmodifiable {@link List} consisting only of those {@link NamedAttributeMap}s in the supplied {@link
- * Collection} that {@linkplain #qualifier(NamedAttributeMap) are qualifiers}; never {@code null}
+ * @return an immutable {@link List}; never {@code null}
*
- * @exception NullPointerException if {@code c} is {@code null}
+ * @see #primordialQualifier()
*/
- public static final List> qualifiers(final Collection extends NamedAttributeMap>> c) {
- if (c == null || c.isEmpty()) {
- return List.of();
- }
- final ArrayList> list = new ArrayList<>(c.size());
- for (final NamedAttributeMap> a : c) {
- if (qualifier(a)) {
- list.add(normalize(a));
- }
- }
- list.trimToSize();
- return Collections.unmodifiableList(list);
+ public static final List primordialQualifiers() {
+ return PRIMORDIAL_QUALIFIERS;
}
/**
- * Returns a {@link NamedAttributeMap} that is {@linkplain NamedAttributeMap#equals(Object) equal to} the supplied
- * {@link NamedAttributeMap}.
+ * Returns the qualifier (meta-) qualifier.
*
- * The returned {@link NamedAttributeMap} may be the supplied {@link NamedAttributeMap} or a different
- * instance.
+ * @return the qualifier (meta-) qualifier; never {@code null}
+ */
+ public static final Attributes qualifier() {
+ return QUALIFIER;
+ }
+
+ /**
+ * Returns {@code true} if and only if the supplied {@link Attributes} is an {@link Attributes} that can be used to
+ * designate other {@link Attributes} as qualifiers.
*
- * @param nam a {@link NamedAttributeMap}; must not be {@code null}
+ * @param q an {@link Attributes}; must not be {@code null}
*
- * @return a {@link NamedAttributeMap} that is {@linkplain NamedAttributeMap#equals(Object) equal to} the supplied
- * {@link NamedAttributeMap}; never {@code null}
+ * @return {@code true} if and only if the supplied {@link Attributes} is an {@link Attributes} that can be used to
+ * designate other {@link Attributes} as qualifiers
*
- * @exception NullPointerException if {@code nam} is {@code null}
+ * @exception NullPointerException if {@code q} is {@code null}
*/
- public static final NamedAttributeMap> normalize(final NamedAttributeMap> nam) {
- return switch (nam) {
- case null -> throw new NullPointerException("nam");
- case NamedAttributeMap> q when anyQualifier(q) -> anyQualifier();
- case NamedAttributeMap> q when defaultQualifier(q) -> defaultQualifier();
- case NamedAttributeMap> q when QUALIFIER.equals(q) && q.metadata().isEmpty() -> qualifier();
- default -> nam;
- };
+ public static final boolean qualifier(final Attributes q) {
+ return q.attributes().contains(qualifier());
}
/**
- * Returns an immutable {@link List} of {@link NamedAttributeMap}s that is {@linkplain List#equals(Object) equal to} the supplied
- * {@link List}.
+ * Returns an immutable {@link List} consisting solely of the qualifier (meta-) qualifier.
*
- * The returned {@link List} may be the supplied {@link List} or a different instance.
+ * @return an immutable {@link List}; never {@code null}
*
- * @param list a {@link List} of {@link NamedAttributeMap}s; must not be {@code null}
+ * @see #qualifier()
+ */
+ public static final List qualifiers() {
+ return QUALIFIERS;
+ }
+
+ /**
+ * Returns an unmodifiable {@link List} consisting only of those {@link Attributes} in the supplied {@link
+ * Collection} that {@linkplain #qualifier(Attributes) are qualifiers}.
*
- * @return an immutable {@link List} of {@link NamedAttributeMap}s that is {@linkplain List#equals(Object) equal to} the supplied
- * {@link List}; never {@code null}
+ * @param c a {@link Collection} of {@link Attributes}s; must not be {@code null}
*
- * @exception NullPointerException if {@code list} is {@code null}
+ * @return an unmodifiable {@link List} consisting only of those {@link Attributes}s in the supplied {@link
+ * Collection} that {@linkplain #qualifier(Attributes) are qualifiers}; never {@code null}
+ *
+ * @exception NullPointerException if {@code c} is {@code null}
*/
- public static final List> normalize(final List> list) {
- return switch (list) {
- case null -> throw new NullPointerException("list");
- case List> l when l.size() == 1 && anyQualifier(l.get(0)) -> anyQualifiers();
- case List> l when l.size() == 1 && defaultQualifier(l.get(0)) -> defaultQualifiers();
- case List> l when l.size() == 2 && anyQualifier(l.get(0)) && defaultQualifier(l.get(1)) -> anyAndDefaultQualifiers();
- default -> List.copyOf(list);
+ public static final List qualifiers(final Collection extends Attributes> c) {
+ return switch (c) {
+ case Collection> c0 when c0.isEmpty() -> List.of();
+ case Collection> c0 when c0.equals(defaultQualifiers()) -> defaultQualifiers();
+ case Collection> c0 when c0.equals(anyAndDefaultQualifiers()) -> anyAndDefaultQualifiers();
+ default ->{
+ final ArrayList list = new ArrayList<>(c.size());
+ for (final Attributes a : c) {
+ if (qualifier(a)) {
+ list.add(normalize(a));
+ }
+ }
+ list.trimToSize();
+ yield Collections.unmodifiableList(list);
+ }
};
}