Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
c58a4b13
Commit
c58a4b13
authored
Nov 14, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ValidateUtils
parent
f0741e83
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
27 deletions
+32
-27
commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java
...src/main/java/com/schbrain/common/util/ValidateUtils.java
+32
-27
No files found.
commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java
View file @
c58a4b13
...
@@ -37,24 +37,25 @@ public class ValidateUtils {
...
@@ -37,24 +37,25 @@ public class ValidateUtils {
isFalse
(
expression
,
()
->
new
ParamInvalidException
(
message
));
isFalse
(
expression
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
isFalse
(
boolean
expression
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
E
extends
BaseException
>
void
isFalse
(
boolean
expression
,
Supplier
<
E
>
errorSupplier
)
{
if
(
expression
)
{
if
(
expression
)
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
}
}
public
static
void
notNull
(
Object
object
)
{
public
static
<
T
>
T
notNull
(
T
object
)
{
notNull
(
object
,
"The validated object is null"
);
return
notNull
(
object
,
"The validated object is null"
);
}
}
public
static
void
notNull
(
Object
object
,
String
message
)
{
public
static
<
T
>
T
notNull
(
T
object
,
String
message
)
{
notNull
(
object
,
()
->
new
ParamInvalidException
(
message
));
return
notNull
(
object
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
notNull
(
Object
object
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
T
,
E
extends
BaseException
>
T
notNull
(
T
object
,
Supplier
<
E
>
errorSupplier
)
{
if
(
object
==
null
)
{
if
(
object
==
null
)
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
return
object
;
}
}
public
static
void
isNull
(
Object
object
)
{
public
static
void
isNull
(
Object
object
)
{
...
@@ -71,18 +72,19 @@ public class ValidateUtils {
...
@@ -71,18 +72,19 @@ public class ValidateUtils {
}
}
}
}
public
static
void
notEmpty
(
String
value
)
{
public
static
String
notEmpty
(
String
value
)
{
notEmpty
(
value
,
"The validated string is empty"
);
return
notEmpty
(
value
,
"The validated string is empty"
);
}
}
public
static
void
notEmpty
(
String
value
,
String
message
)
{
public
static
String
notEmpty
(
String
value
,
String
message
)
{
notEmpty
(
value
,
()
->
new
ParamInvalidException
(
message
));
return
notEmpty
(
value
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
notEmpty
(
String
value
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
E
extends
BaseException
>
String
notEmpty
(
String
value
,
Supplier
<
E
>
errorSupplier
)
{
if
(
value
==
null
||
value
.
isBlank
())
{
if
(
value
==
null
||
value
.
isBlank
())
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
return
value
;
}
}
public
static
void
isEmpty
(
String
value
)
{
public
static
void
isEmpty
(
String
value
)
{
...
@@ -99,18 +101,19 @@ public class ValidateUtils {
...
@@ -99,18 +101,19 @@ public class ValidateUtils {
}
}
}
}
public
static
void
notEmpty
(
Object
[]
array
)
{
public
static
<
T
>
T
[]
notEmpty
(
T
[]
array
)
{
notEmpty
(
array
,
"The validated array is empty"
);
return
notEmpty
(
array
,
"The validated array is empty"
);
}
}
public
static
void
notEmpty
(
Object
[]
array
,
String
message
)
{
public
static
<
T
>
T
[]
notEmpty
(
T
[]
array
,
String
message
)
{
notEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
));
return
notEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
notEmpty
(
Object
[]
array
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
T
,
E
extends
BaseException
>
T
[]
notEmpty
(
T
[]
array
,
Supplier
<
E
>
errorSupplier
)
{
if
(
array
==
null
||
array
.
length
==
0
)
{
if
(
array
==
null
||
array
.
length
==
0
)
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
return
array
;
}
}
public
static
void
isEmpty
(
Object
[]
array
)
{
public
static
void
isEmpty
(
Object
[]
array
)
{
...
@@ -121,24 +124,25 @@ public class ValidateUtils {
...
@@ -121,24 +124,25 @@ public class ValidateUtils {
isEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
));
isEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
isEmpty
(
Object
[]
array
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
E
extends
BaseException
>
void
isEmpty
(
Object
[]
array
,
Supplier
<
E
>
errorSupplier
)
{
if
(
array
!=
null
&&
array
.
length
!=
0
)
{
if
(
array
!=
null
&&
array
.
length
!=
0
)
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
}
}
public
static
void
notEmpty
(
Collection
<?>
collection
)
{
public
static
<
T
,
C
extends
Collection
<
T
>>
C
notEmpty
(
C
collection
)
{
notEmpty
(
collection
,
"The validated collection is empty"
);
return
notEmpty
(
collection
,
"The validated collection is empty"
);
}
}
public
static
void
notEmpty
(
Collection
<?>
collection
,
String
message
)
{
public
static
<
T
,
C
extends
Collection
<
T
>>
C
notEmpty
(
C
collection
,
String
message
)
{
notEmpty
(
collection
,
()
->
new
ParamInvalidException
(
message
));
return
notEmpty
(
collection
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
notEmpty
(
Collection
<?>
collection
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
T
,
C
extends
Collection
<
T
>,
E
extends
BaseException
>
C
notEmpty
(
C
collection
,
Supplier
<
E
>
errorSupplier
)
{
if
(
collection
==
null
||
collection
.
isEmpty
())
{
if
(
collection
==
null
||
collection
.
isEmpty
())
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
return
collection
;
}
}
public
static
void
isEmpty
(
Collection
<?>
collection
)
{
public
static
void
isEmpty
(
Collection
<?>
collection
)
{
...
@@ -155,18 +159,19 @@ public class ValidateUtils {
...
@@ -155,18 +159,19 @@ public class ValidateUtils {
}
}
}
}
public
static
void
notEmpty
(
Map
<?,
?
>
map
)
{
public
static
<
K
,
V
>
Map
<
K
,
V
>
notEmpty
(
Map
<
K
,
V
>
map
)
{
notEmpty
(
map
,
"The validated map is empty"
);
return
notEmpty
(
map
,
"The validated map is empty"
);
}
}
public
static
void
notEmpty
(
Map
<?,
?
>
map
,
String
message
)
{
public
static
<
K
,
V
>
Map
<
K
,
V
>
notEmpty
(
Map
<
K
,
V
>
map
,
String
message
)
{
notEmpty
(
map
,
()
->
new
ParamInvalidException
(
message
));
return
notEmpty
(
map
,
()
->
new
ParamInvalidException
(
message
));
}
}
public
static
<
T
extends
BaseException
>
void
notEmpty
(
Map
<?,
?>
map
,
Supplier
<
T
>
errorSupplier
)
{
public
static
<
K
,
V
,
E
extends
BaseException
>
Map
<
K
,
V
>
notEmpty
(
Map
<
K
,
V
>
map
,
Supplier
<
E
>
errorSupplier
)
{
if
(
map
==
null
||
map
.
isEmpty
())
{
if
(
map
==
null
||
map
.
isEmpty
())
{
throw
errorSupplier
.
get
();
throw
errorSupplier
.
get
();
}
}
return
map
;
}
}
public
static
void
isEmpty
(
Map
<?,
?>
map
)
{
public
static
void
isEmpty
(
Map
<?,
?>
map
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment