Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jh-boot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jan Hrabal
jh-boot
Commits
b2a3d6e0
Commit
b2a3d6e0
authored
Oct 13, 2019
by
Jan Hrabal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
cfc11eb8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
56 deletions
+56
-56
Converter.java
src/main/java/com/jh/boot/web/Converter.java
+56
-56
No files found.
src/main/java/com/jh/boot/web/Converter.java
View file @
b2a3d6e0
package
com
.
jh
.
boot
.
web
;
import
com.jh.boot.jpa.AbstractIdEntity
;
import
com.jh.boot.web.list.Page
;
import
com.jh.boot.web.list.SortTrend
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
public
class
Converter
{
private
Converter
()
{}
public
static
<
S
,
D
>
D
convert
(
S
source
,
Function
<
S
,
D
>
mappingFunction
)
{
if
(
source
==
null
||
mappingFunction
==
null
)
{
return
null
;
}
return
mappingFunction
.
apply
(
source
);
}
public
static
<
S
,
D
>
List
<
D
>
convertList
(
List
<
S
>
list
,
Function
<
S
,
D
>
mappingFunction
)
{
if
(
list
==
null
)
{
return
null
;
}
return
list
.
stream
().
map
(
mappingFunction
).
collect
(
Collectors
.
toList
());
}
public
static
<
S
,
D
>
Page
<
D
>
convertPage
(
Page
<
S
>
page
,
Function
<
S
,
D
>
mappingFunction
)
{
if
(
page
==
null
||
mappingFunction
==
null
)
{
return
null
;
}
List
<
D
>
content
=
new
ArrayList
<>();
if
(
page
.
getContent
()
!=
null
)
{
for
(
S
s
:
page
.
getContent
())
{
content
.
add
(
mappingFunction
.
apply
(
s
));
}
}
return
new
Page
<
D
>(
page
.
getPage
(),
page
.
getPagesCount
(),
page
.
get
TotalElements
(),
content
,
page
.
getSortBy
(),
SortTrend
.
parse
(
page
.
getTrend
()));
}
/**
* Helper function to safely get id
*
* @param entity
* @return
*/
public
static
Long
getId
(
AbstractIdEntity
entity
)
{
return
entity
==
null
?
null
:
entity
.
getId
();
}
}
package
com
.
jh
.
boot
.
web
;
import
com.jh.boot.jpa.AbstractIdEntity
;
import
com.jh.boot.web.list.Page
;
import
com.jh.boot.web.list.SortTrend
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
public
class
Converter
{
private
Converter
()
{}
public
static
<
S
,
D
>
D
convert
(
S
source
,
Function
<
S
,
D
>
mappingFunction
)
{
if
(
source
==
null
||
mappingFunction
==
null
)
{
return
null
;
}
return
mappingFunction
.
apply
(
source
);
}
public
static
<
S
,
D
>
List
<
D
>
convertList
(
List
<
S
>
list
,
Function
<
S
,
D
>
mappingFunction
)
{
if
(
list
==
null
)
{
return
null
;
}
return
list
.
stream
().
map
(
mappingFunction
).
collect
(
Collectors
.
toList
());
}
public
static
<
S
,
D
>
Page
<
D
>
convertPage
(
Page
<
S
>
page
,
Function
<
S
,
D
>
mappingFunction
)
{
if
(
page
==
null
||
mappingFunction
==
null
)
{
return
null
;
}
List
<
D
>
content
=
new
ArrayList
<>();
if
(
page
.
getContent
()
!=
null
)
{
for
(
S
s
:
page
.
getContent
())
{
content
.
add
(
mappingFunction
.
apply
(
s
));
}
}
return
new
Page
<
D
>(
page
.
getPage
(),
page
.
getPagesCount
(),
page
.
get
PageSize
(),
page
.
getTotalElements
(),
content
,
page
.
getSortBy
(),
SortTrend
.
parse
(
page
.
getTrend
()));
}
/**
* Helper function to safely get id
*
* @param entity
* @return
*/
public
static
Long
getId
(
AbstractIdEntity
entity
)
{
return
entity
==
null
?
null
:
entity
.
getId
();
}
}
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