Class RepeatableContainers

java.lang.Object
org.springframework.core.annotation.RepeatableContainers

public abstract class RepeatableContainers extends Object
Strategy used to find repeatable annotations within container annotations.

RepeatableContainers.standardRepeatables() provides a default strategy that respects Java's @Repeatable support and is suitable for most situations.

If you need to register repeatable annotation types that do not make use of @Repeatable, you should typically use standardRepeatables() combined with plus(Class, Class). Note that multiple invocations of plus() can be chained together to register multiple repeatable/container type pairs. For example:

RepeatableContainers repeatableContainers =
    RepeatableContainers.standardRepeatables()
        .plus(MyRepeatable1.class, MyContainer1.class)
        .plus(MyRepeatable2.class, MyContainer2.class);

For special use cases where you are certain that you do not need Java's @Repeatable support, you can use RepeatableContainers.explicitRepeatable() to create an instance of RepeatableContainers that only supports explicit repeatable/container type pairs. As with standardRepeatables(), plus() can be used to register additional repeatable/container type pairs. For example:

RepeatableContainers repeatableContainers =
    RepeatableContainers.explicitRepeatable(MyRepeatable1.class, MyContainer1.class)
        .plus(MyRepeatable2.class, MyContainer2.class);

To completely disable repeatable annotation support use RepeatableContainers.none().

Since:
5.2
Author:
Phillip Webb, Sam Brannen
  • Method Details

    • plus

      public final RepeatableContainers plus(Class<? extends Annotation> repeatable, Class<? extends Annotation> container)
      Register a pair of repeatable and container annotation types.

      See the class-level javadoc for examples.

      Parameters:
      repeatable - the repeatable annotation type
      container - the container annotation type
      Returns:
      a new RepeatableContainers instance that is chained to the current instance
      Since:
      7.0
    • and

      @Deprecated(since="7.0") public RepeatableContainers and(Class<? extends Annotation> container, Class<? extends Annotation> repeatable)
      Deprecated.
      as of Spring Framework 7.0, in favor of plus(Class, Class)
      Register a pair of container and repeatable annotation types.

      WARNING: The arguments supplied to this method are in the reverse order of those supplied to plus(Class, Class), explicitRepeatable(Class, Class), and of(Class, Class).

      Parameters:
      container - the container annotation type
      repeatable - the repeatable annotation type
      Returns:
      a new RepeatableContainers instance that is chained to the current instance
    • equals

      @Contract("null -> false") public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • standardRepeatables

      public static RepeatableContainers standardRepeatables()
      Create a RepeatableContainers instance that searches for repeated annotations according to the semantics of Java's @Repeatable annotation.

      See the class-level javadoc for examples.

      Returns:
      a RepeatableContainers instance that supports @Repeatable
      See Also:
    • explicitRepeatable

      public static RepeatableContainers explicitRepeatable(Class<? extends Annotation> repeatable, @Nullable Class<? extends Annotation> container)
      Create a RepeatableContainers instance that searches for repeated annotations by taking into account the supplied repeatable and container annotation types.

      WARNING: The RepeatableContainers instance returned by this factory method does not respect Java's @Repeatable support. Use standardRepeatables() for standard @Repeatable support, optionally combined with plus(Class, Class).

      If the supplied container annotation type is not null, it must declare a value attribute returning an array of repeatable annotations. If the supplied container annotation type is null, the container will be deduced by inspecting the @Repeatable annotation on the repeatable annotation type.

      See the class-level javadoc for examples.

      Parameters:
      repeatable - the repeatable annotation type
      container - the container annotation type or null
      Returns:
      a RepeatableContainers instance that does not support @Repeatable
      Throws:
      IllegalArgumentException - if the supplied container type is null and the annotation type is not a repeatable annotation
      AnnotationConfigurationException - if the supplied container type is not a properly configured container for a repeatable annotation
      Since:
      7.0
      See Also:
    • of

      @Deprecated(since="7.0") public static RepeatableContainers of(Class<? extends Annotation> repeatable, @Nullable Class<? extends Annotation> container)
      Deprecated.
      as of Spring Framework 7.0, in favor of explicitRepeatable(Class, Class)
      Create a RepeatableContainers instance that searches for repeated annotations by taking into account the supplied repeatable and container annotation types.

      WARNING: The RepeatableContainers instance returned by this factory method does not respect Java's @Repeatable support. Use standardRepeatables() for standard @Repeatable support, optionally combined with plus(Class, Class).

      WARNING: The arguments supplied to this method are in the reverse order of those supplied to and(Class, Class).

      If the supplied container annotation type is not null, it must declare a value attribute returning an array of repeatable annotations. If the supplied container annotation type is null, the container will be deduced by inspecting the @Repeatable annotation on the repeatable annotation type.

      Parameters:
      repeatable - the repeatable annotation type
      container - the container annotation type or null
      Returns:
      a RepeatableContainers instance that does not support @Repeatable
      Throws:
      IllegalArgumentException - if the supplied container type is null and the annotation type is not a repeatable annotation
      AnnotationConfigurationException - if the supplied container type is not a properly configured container for a repeatable annotation
    • none

      public static RepeatableContainers none()
      Create a RepeatableContainers instance that does not support any repeatable annotations.

      Note, however, that plus(Class, Class) may still be invoked on the RepeatableContainers instance returned from this method.

      See the class-level javadoc for examples and further details.

      Returns:
      a RepeatableContainers instance that does not support repeatable annotations