1 package com.github.mygreen.supercsv.builder;
2
3 import java.lang.annotation.Annotation;
4 import java.util.Comparator;
5
6 import com.github.mygreen.supercsv.util.Utils;
7
8
9
10
11
12
13
14
15
16
17
18 public class AnnotationComparator implements Comparator<Annotation> {
19
20
21
22
23 private static final int DEFAULT_ORDER = Integer.MAX_VALUE;
24
25 @Override
26 public int compare(final Annotation anno1, final Annotation anno2) {
27
28 final String name1 = anno1.annotationType().getName();
29 final String name2 = anno2.annotationType().getName();
30
31 final int order1 = Utils.getAnnotationAttribute(anno1, "order", int.class).orElse(DEFAULT_ORDER);
32 final int order2 = Utils.getAnnotationAttribute(anno2, "order", int.class).orElse(DEFAULT_ORDER);
33
34 if(order1 == order2) {
35 return name1.compareTo(name2);
36 } else {
37 return Integer.compare(order1, order2);
38 }
39 }
40
41 }