OnJava8-Examples/annotations/UseCaseTracker.java

38 lines
1.1 KiB
Java
Raw Permalink Normal View History

2015-09-07 11:44:36 -06:00
// annotations/UseCaseTracker.java
// (c)2021 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2015-06-15 17:47:35 -07:00
import java.util.*;
2017-01-22 16:48:11 -08:00
import java.util.stream.*;
import java.lang.reflect.*;
2015-06-15 17:47:35 -07:00
public class UseCaseTracker {
public static void
trackUseCases(List<Integer> useCases, Class<?> cl) {
for(Method m : cl.getDeclaredMethods()) {
UseCase uc = m.getAnnotation(UseCase.class);
if(uc != null) {
2017-01-22 16:48:11 -08:00
System.out.println("Found Use Case " +
uc.id() + "\n " + uc.description());
2017-05-01 17:43:21 -06:00
useCases.remove(Integer.valueOf(uc.id()));
2015-06-15 17:47:35 -07:00
}
}
2017-01-22 16:48:11 -08:00
useCases.forEach(i ->
System.out.println("Missing use case " + i));
2015-06-15 17:47:35 -07:00
}
public static void main(String[] args) {
2017-01-22 16:48:11 -08:00
List<Integer> useCases = IntStream.range(47, 51)
.boxed().collect(Collectors.toList());
2015-06-15 17:47:35 -07:00
trackUseCases(useCases, PasswordUtils.class);
}
2015-09-07 11:44:36 -06:00
}
/* Output:
Found Use Case 49
New passwords can't equal previously used ones
2017-01-22 16:48:11 -08:00
Found Use Case 48
no description
Found Use Case 47
Passwords must contain at least one numeric
2017-01-22 16:48:11 -08:00
Missing use case 50
2015-09-07 11:44:36 -06:00
*/