1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http.multipart;
17
18 import java.io.Serializable;
19 import java.util.Comparator;
20
21 final class CaseIgnoringComparator implements Comparator<CharSequence>, Serializable {
22
23 private static final long serialVersionUID = 4582133183775373862L;
24
25 static final CaseIgnoringComparator INSTANCE = new CaseIgnoringComparator();
26
27 private CaseIgnoringComparator() {
28 }
29
30 @Override
31 public int compare(CharSequence o1, CharSequence o2) {
32 int o1Length = o1.length();
33 int o2Length = o2.length();
34 int min = Math.min(o1Length, o2Length);
35 for (int i = 0; i < min; i++) {
36 char c1 = o1.charAt(i);
37 char c2 = o2.charAt(i);
38 if (c1 != c2) {
39 c1 = Character.toUpperCase(c1);
40 c2 = Character.toUpperCase(c2);
41 if (c1 != c2) {
42 c1 = Character.toLowerCase(c1);
43 c2 = Character.toLowerCase(c2);
44 if (c1 != c2) {
45 return c1 - c2;
46 }
47 }
48 }
49 }
50 return o1Length - o2Length;
51 }
52
53 private Object readResolve() {
54 return INSTANCE;
55 }
56 }