Repository navigation
Expand file tree
/
Copy pathArgumentVerifierUtil.java
More file actions
71 lines (63 loc) · 2.04 KB
/
Copy pathArgumentVerifierUtil.java
File metadata and controls
71 lines (63 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright 2012: Thomson Reuters Global Resources. All Rights Reserved.
*
* Proprietary and Confidential information of TRGR. Disclosure, Use or
* Reproduction without the written authorization of TRGR is prohibited
*/
package com.research.course.debate.util ;
/**
*
*
*/
public class ArgumentVerifierUtil
{
private ArgumentVerifierUtil() {}
/**
* Checks if the given Object value is null. If the object is null an IllegalArgumentException
* is thrown.
*
* @param value the value to check
* @param paramName the name of the parameter being checked which is included in the exception message
*
* @throws IllegalArgumentException if value is null
*/
public static void checkForNull(Object value, String paramName) throws IllegalArgumentException
{
if (value == null)
{
throw new IllegalArgumentException("Param [" + paramName + "] can not be null");
}
}
/**
* Checks if the given String is null, empty or contains all whitespace. If the value is null, empty
* or all whitespace an IllegalArgumentException is thrown.
*
* @param value the value to check
* @param paramName the name of the parameter being checked which is included in the exception message
*
* @throws IllegalArgumentException if value is null, empty or all whitespace
*/
public static void checkForNullOrEmpty(String value, String paramName) throws IllegalArgumentException
{
if (isBlank(value))
{
throw new IllegalArgumentException("Param [" + paramName + "] can not be null or empty. It is [" + value + ']');
}
}
private static boolean isBlank(String value)
{
if (value == null || value.isEmpty())
{
return true;
}
int length = value.length();
for (int i = 0; i < length; i++)
{
if (!Character.isWhitespace(value.charAt(i)))
{
return false;
}
}
return true;
}
}