OnJava8-Examples/annotations/UseCaseTracker.java

38 lines
1.1 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// annotations/UseCaseTracker.java
2016-12-30 17:23:13 -08:00
// (c)2017 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());
2015-06-15 17:47:35 -07:00
useCases.remove(new Integer(uc.id()));
}
}
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:
2017-01-22 16:48:11 -08:00
Found Use Case 49
New passwords can't equal previously used ones
Found Use Case 47
Passwords must contain at least one numeric
Found Use Case 48
no description
Missing use case 50
2015-09-07 11:44:36 -06:00
*/