I'm starting to learn java annotation and I want to use this as some sort of Generator label. I want to generate random texts only, numbers only or text and numbers.
Here is my custom annotation:
public @interface RandomGenerator {
public int length() default 5;
public GeneratorTypeEnum type();
public GeneratorCaseTypeEnum caseType() default GeneratorCaseTypeEnum.TO_LOWER_AND_UPPER;
}
So far so good. I'm using enum to provide some extra definition if used by client. Here is the init: I have a Class to use the annotation
public class Employee {
@RandomGenerator(type = GeneratorTypeEnum.NUMBERS_ONLY, caseType = GeneratorCaseTypeEnum.TO_LOWER_AND_UPPER)
private String id;
private String name;
// getters and setters
}
But as you can see, I can use the GeneratorTypeEnum.NUMBERS_ONLY
WITH caseType GeneratorCaseTypeEnum.TO_LOWER_AND_UPPER
which is obviously not good because there are no upper or lower case numbers.
Enums:
GeneratorTypeEnum
public enum GeneratorTypeEnum {
TEXT_AND_NUMBERS,
NUMBERS_ONLY,
TEXT_ONLY
}
GeneratorCaseTypeEnum
public enum GeneratorCaseTypeEnum {
TO_LOWER,
TO_UPPER,
TO_LOWER_AND_UPPER
}
Questions:
- Is there a way to restrict parameters in annotation?
- If false for question #1, can you give your theory or opinion and if those are not beginner friendly, can you please provide some links for references.
Answers will be very much appreciated.
PS: I feel bad because I can't give any of my trial and error solutions as I am a beginner.