1 package com.github.mygreen.supercsv.util;
2
3 import java.util.Collection;
4 import java.util.Map;
5
6
7
8
9
10
11
12
13 public class ArgUtils {
14
15
16
17
18
19
20
21 public static void notNull(final Object arg, final String name) {
22 if(arg == null) {
23 throw new NullPointerException(String.format("%s should not be null.", name));
24 }
25 }
26
27
28
29
30
31
32
33
34 public static void notEmpty(final String arg, final String name) {
35 if(arg == null) {
36 throw new NullPointerException(String.format("%s should not be null.", name));
37 }
38
39 if(arg.isEmpty()) {
40 throw new IllegalArgumentException(String.format("%s should not be empty.", name));
41 }
42 }
43
44
45
46
47
48
49
50
51 public static void notEmpty(final Object[] arg, final String name) {
52 if(arg == null) {
53 throw new NullPointerException(String.format("%s should not be null.", name));
54 }
55
56 if(arg.length == 0) {
57 throw new IllegalArgumentException(String.format("%s should has length ararys.", name));
58 }
59 }
60
61
62
63
64
65
66
67
68 public static void notEmpty(final Collection<?> arg, final String name) {
69 if(arg == null) {
70 throw new NullPointerException(String.format("%s should not be null.", name));
71 }
72
73 if(arg.isEmpty()) {
74 throw new IllegalArgumentException(String.format("%s should not be empty.", name));
75 }
76 }
77
78
79
80
81
82
83
84
85 public static void notEmpty(final Map<?, ?> arg, final String name) {
86 if(arg == null) {
87 throw new NullPointerException(String.format("%s should not be null.", name));
88 }
89
90 if(arg.isEmpty()) {
91 throw new IllegalArgumentException(String.format("%s should not be empty.", name));
92 }
93 }
94
95
96
97
98
99
100
101
102
103 @SuppressWarnings({"unchecked", "rawtypes"})
104 public static <T extends Comparable> void notMin(final T arg, final T min, final String name) {
105
106 if(arg == null) {
107 throw new NullPointerException(String.format("%s should not be null.", name));
108 }
109
110 if(arg.compareTo(min) < 0) {
111 throw new IllegalArgumentException(String.format("%s cannot be smaller than %s", name, min.toString()));
112 }
113
114 }
115
116
117
118
119
120
121
122
123
124 @SuppressWarnings({"rawtypes", "unchecked"})
125 public static <T extends Comparable> void notMax(final T arg, final T max, final String name) {
126
127 if(arg == null) {
128 throw new NullPointerException(String.format("%s should not be null.", name));
129 }
130
131 if(arg.compareTo(max) > 0) {
132 throw new IllegalArgumentException(String.format("%s cannot be greater than %s", name, max.toString()));
133 }
134
135 }
136
137 }