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
4bdeb70e
Commit
4bdeb70e
authored
May 05, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve ValidateUtils
parent
45db497f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
122 deletions
+58
-122
commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java
...src/main/java/com/schbrain/common/util/ValidateUtils.java
+53
-108
integration/integration-jenkins-plugin/pom.xml
integration/integration-jenkins-plugin/pom.xml
+5
-14
No files found.
commons/common/src/main/java/com/schbrain/common/util/ValidateUtils.java
View file @
4bdeb70e
package
com.schbrain.common.util
;
import
com.schbrain.common.exception.BaseException
;
import
com.schbrain.common.exception.ParamInvalidException
;
import
java.util.*
;
import
java.util.Collection
;
import
java.util.Map
;
import
java.util.function.Supplier
;
public
class
ValidateUtils
{
...
...
@@ -12,181 +15,123 @@ public class ValidateUtils {
private
ValidateUtils
()
{
}
public
static
void
isTrue
(
boolean
expression
)
{
isTrue
(
expression
,
"操作有误"
);
public
static
void
isTrue
(
boolean
expression
,
String
message
)
{
isTrue
(
expression
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
isTrue
(
boolean
expression
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
isTrue
(
boolean
expression
,
Supplier
<
T
>
errorSupplier
)
{
if
(!
expression
)
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
isFalse
(
boolean
expression
)
{
isFalse
(
expression
,
"操作有误"
);
public
static
void
isFalse
(
boolean
expression
,
String
message
)
{
isFalse
(
expression
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
isFalse
(
boolean
expression
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
isFalse
(
boolean
expression
,
Supplier
<
T
>
errorSupplier
)
{
if
(
expression
)
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
notNull
(
Object
object
)
{
notNull
(
object
,
"The validated object is null"
);
public
static
void
notNull
(
Object
object
,
String
message
)
{
notNull
(
object
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
notNull
(
Object
object
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
notNull
(
Object
object
,
Supplier
<
T
>
errorSupplier
)
{
if
(
object
==
null
)
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
isNull
(
Object
object
)
{
isNull
(
object
,
"The validated object is not null"
);
public
static
void
isNull
(
Object
object
,
String
message
)
{
isNull
(
object
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
isNull
(
Object
object
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
isNull
(
Object
object
,
Supplier
<
T
>
errorSupplier
)
{
if
(
object
!=
null
)
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
notEmpty
(
String
value
)
{
notEmpty
(
value
,
"The validated string is empty"
);
public
static
void
notEmpty
(
String
value
,
String
message
)
{
notEmpty
(
value
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
notEmpty
(
String
value
,
String
message
)
{
if
(
null
==
value
||
value
.
isBlank
())
{
throw
new
ParamInvalidException
(
message
);
public
static
<
T
extends
BaseException
>
void
notEmpty
(
String
value
,
Supplier
<
T
>
errorSupplier
)
{
if
(
value
==
null
||
value
.
isBlank
())
{
throw
errorSupplier
.
get
(
);
}
}
public
static
void
isEmpty
(
String
value
)
{
isEmpty
(
value
,
"The validated string is not empty"
);
public
static
void
isEmpty
(
String
value
,
String
message
)
{
isEmpty
(
value
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
isEmpty
(
String
value
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
isEmpty
(
String
value
,
Supplier
<
T
>
errorSupplier
)
{
if
(
value
!=
null
&&
!
value
.
isEmpty
())
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
notEmpty
(
Object
[]
array
)
{
notEmpty
(
array
,
"The validated array is empty"
);
public
static
void
notEmpty
(
Object
[]
array
,
String
message
)
{
notEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
notEmpty
(
Object
[]
array
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
notEmpty
(
Object
[]
array
,
Supplier
<
T
>
errorSupplier
)
{
if
(
array
==
null
||
array
.
length
==
0
)
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
isEmpty
(
Object
[]
array
)
{
isEmpty
(
array
,
"The validated array is not empty"
);
public
static
void
isEmpty
(
Object
[]
array
,
String
message
)
{
isEmpty
(
array
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
isEmpty
(
Object
[]
array
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
isEmpty
(
Object
[]
array
,
Supplier
<
T
>
errorSupplier
)
{
if
(
array
!=
null
&&
array
.
length
!=
0
)
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
notEmpty
(
Collection
<?>
collection
)
{
notEmpty
(
collection
,
"The validated collection is empty"
);
public
static
void
notEmpty
(
Collection
<?>
collection
,
String
message
)
{
notEmpty
(
collection
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
notEmpty
(
Collection
<?>
collection
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
notEmpty
(
Collection
<?>
collection
,
Supplier
<
T
>
errorSupplier
)
{
if
(
collection
==
null
||
collection
.
isEmpty
())
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
isEmpty
(
Collection
<?>
collection
)
{
isEmpty
(
collection
,
"The validated collection is not empty"
);
public
static
void
isEmpty
(
Collection
<?>
collection
,
String
message
)
{
isEmpty
(
collection
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
isEmpty
(
Collection
<?>
collection
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
isEmpty
(
Collection
<?>
collection
,
Supplier
<
T
>
errorSupplier
)
{
if
(
collection
!=
null
&&
!
collection
.
isEmpty
())
{
throw
new
ParamInvalidException
(
message
);
throw
errorSupplier
.
get
(
);
}
}
public
static
void
notEmpty
(
Map
<?,
?>
map
)
{
notEmpty
(
map
,
"The validated map is empty"
);
public
static
void
notEmpty
(
Map
<?,
?>
map
,
String
message
)
{
notEmpty
(
map
,
()
->
new
ParamInvalidException
(
message
)
);
}
public
static
void
notEmpty
(
Map
<?,
?>
map
,
String
message
)
{
public
static
<
T
extends
BaseException
>
void
notEmpty
(
Map
<?,
?>
map
,
Supplier
<
T
>
errorSupplier
)
{
if
(
map
==
null
||
map
.
isEmpty
())
{
throw
new
ParamInvalidException
(
message
);
}
throw
errorSupplier
.
get
();
}
public
static
void
isEmpty
(
Map
<?,
?>
map
)
{
isEmpty
(
map
,
"The validated map is not empty"
);
}
public
static
void
isEmpty
(
Map
<?,
?>
map
,
String
message
)
{
if
(
map
!=
null
&&
!
map
.
isEmpty
())
{
throw
new
ParamInvalidException
(
message
);
}
}
public
static
void
noNullElements
(
Object
[]
array
)
{
notNull
(
array
);
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
null
)
{
throw
new
ParamInvalidException
(
"The validated array contains null element at index: "
+
i
);
}
}
}
public
static
void
noNullElements
(
Object
[]
array
,
String
message
)
{
notNull
(
array
);
for
(
Object
item
:
array
)
{
if
(
item
==
null
)
{
throw
new
ParamInvalidException
(
message
);
}
}
}
public
static
void
noNullElements
(
Collection
<?>
collection
,
String
message
)
{
notNull
(
collection
);
for
(
Object
item
:
collection
)
{
if
(
item
==
null
)
{
throw
new
ParamInvalidException
(
message
);
}
}
}
public
static
void
noNullElements
(
Collection
<?>
collection
)
{
notNull
(
collection
);
int
i
=
0
;
for
(
Iterator
<?>
it
=
collection
.
iterator
();
it
.
hasNext
();
i
++)
{
if
(
it
.
next
()
==
null
)
{
throw
new
ParamInvalidException
(
"The validated collection contains null element at index: "
+
i
);
}
}
isEmpty
(
map
,
()
->
new
ParamInvalidException
(
message
));
}
public
static
void
allElementsOfType
(
Collection
<?>
collection
,
Class
<?>
clazz
,
String
message
)
{
notNull
(
collection
);
notNull
(
clazz
);
for
(
Object
item
:
collection
)
{
if
(!
clazz
.
isInstance
(
item
))
{
throw
new
ParamInvalidException
(
message
);
}
}
}
public
static
void
allElementsOfType
(
Collection
<?>
collection
,
Class
<?>
clazz
)
{
notNull
(
collection
);
notNull
(
clazz
);
int
i
=
0
;
for
(
Iterator
<?>
it
=
collection
.
iterator
();
it
.
hasNext
();
i
++)
{
if
(!
clazz
.
isInstance
(
it
.
next
()))
{
throw
new
ParamInvalidException
(
"The validated collection contains an element not of type "
+
clazz
.
getName
()
+
" at index: "
+
i
);
}
public
static
<
T
extends
BaseException
>
void
isEmpty
(
Map
<?,
?>
map
,
Supplier
<
T
>
errorSupplier
)
{
if
(
map
!=
null
&&
!
map
.
isEmpty
())
{
throw
errorSupplier
.
get
();
}
}
...
...
integration/integration-jenkins-plugin/pom.xml
View file @
4bdeb70e
...
...
@@ -35,6 +35,11 @@
<artifactId>
velocity-engine-core
</artifactId>
<version>
2.3
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
1.7.36
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
...
...
@@ -57,20 +62,6 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>
maven-enforcer-plugin
</artifactId>
<executions>
<execution>
<id>
display-info
</id>
<phase>
none
</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>
repo.jenkins-ci.org
</id>
...
...
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