1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21
22
23
24 final class ApplicationProtocolUtil {
25 private static final int DEFAULT_LIST_SIZE = 2;
26
27 private ApplicationProtocolUtil() {
28 }
29
30 static List<String> toList(Iterable<String> protocols) {
31 return toList(DEFAULT_LIST_SIZE, protocols);
32 }
33
34 static List<String> toList(int initialListSize, Iterable<String> protocols) {
35 if (protocols == null) {
36 return null;
37 }
38
39 List<String> result = new ArrayList<String>(initialListSize);
40 for (String p : protocols) {
41 if (p == null || p.isEmpty()) {
42 throw new IllegalArgumentException("protocol cannot be null or empty");
43 }
44 result.add(p);
45 }
46
47 if (result.isEmpty()) {
48 throw new IllegalArgumentException("protocols cannot empty");
49 }
50
51 return result;
52 }
53
54 static List<String> toList(String... protocols) {
55 return toList(DEFAULT_LIST_SIZE, protocols);
56 }
57
58 static List<String> toList(int initialListSize, String... protocols) {
59 if (protocols == null) {
60 return null;
61 }
62
63 List<String> result = new ArrayList<String>(initialListSize);
64 for (String p : protocols) {
65 if (p == null || p.isEmpty()) {
66 throw new IllegalArgumentException("protocol cannot be null or empty");
67 }
68 result.add(p);
69 }
70
71 if (result.isEmpty()) {
72 throw new IllegalArgumentException("protocols cannot empty");
73 }
74
75 return result;
76 }
77 }