I have a custom annotation as shown below.
@Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD }) @Documented @Conditional(OnApiVersionConditional.class) public @interface ConditionalOnApiVersion { int[] value() default 5; String property(); }
OnApiVersionConditional,
public class OnApiVersionConditional implements Condition { @Override public boolean matches(final ConditionContext context, final AnnotatedTypeMetadata metadata) { final MultiValueMap<String, Object> attributes = metadata.getAllAnnotationAttributes(ConditionalOnApiVersion.class.getName()); attributes.get("value"); final String inputVersion = context.getEnvironment().getProperty("userInputVersion"); }
In my Bean annotation
@Bean @ConditionalOnApiVersion(value = {6, 7}, property = "userInputVersion")
There are beans with the same version match, for example
@Bean @ConditionalOnApiVersion(value = 8, property = "userInputVersion")
I would like to check the version of userInput from the properties file for available versions of beans. Not sure how I can get the value, repeat and compare with userInoutVersion. The value can be 8 or {6,7} as an int array. Not sure how I can repeat the value to check if any value matches the input version.
final List apiVersions = attributes.get ("value"). stream (). collect (Collectors.toList ());
Question:
How to iterate attribute.get ("value") and compare with userInputVersion?
attributes.get ("value") returns a list of objects.
I tried the code below,
final List<Object> apiVersions = attributes.get("value").stream().collect(Collectors.toList()); boolean result = apiVersions.stream().anyMatch(version -> (int)version == Integer.parseInt(userInputVersion));
But getting below error int eh 2nd line anyMatch,
java.lang.ClassCastException: [I cannot be added to java.lang.Integer
thanks