Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
03c278e1
Commit
03c278e1
authored
Aug 11, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
默认日期格式的支持
parent
68830845
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
16 deletions
+38
-16
DataDaoVo.java
...base/src/main/java/com/yanzuoguang/util/vo/DataDaoVo.java
+38
-16
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/DataDaoVo.java
View file @
03c278e1
...
...
@@ -22,10 +22,9 @@ public class DataDaoVo<T> {
*
* @param hisitories 历史数据
* @param keyFunc 获取主键函数
* @param <T>
* @return
*/
private
static
<
T
>
Map
<
String
,
T
>
getMapHistory
(
List
<
T
>
hisitories
,
DataDaoKey
<
T
>
keyFunc
)
{
private
Map
<
String
,
T
>
getMapHistory
(
List
<
T
>
hisitories
,
DataDaoKey
<
T
>
keyFunc
)
{
// 定义缓存集合
Map
<
String
,
T
>
mapHistory
=
new
HashMap
<>(
10
);
// 历史数据处理
...
...
@@ -44,33 +43,31 @@ public class DataDaoVo<T> {
* @param mapHistory 历史数据映射
* @param nows 当前数据
* @param keyFunc 获取主键函数
* @param <T>
* @return
*/
private
static
<
T
>
DataDaoVo
<
T
>
getResult
(
Map
<
String
,
T
>
mapHistory
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
DataDaoVo
<
T
>
res
=
new
DataDaoVo
<
T
>();
private
void
addResult
(
Map
<
String
,
T
>
mapHistory
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
// 返回集
if
(
nows
!=
null
)
{
for
(
T
now
:
nows
)
{
String
key
=
keyFunc
.
getKey
(
now
);
T
his
=
mapHistory
.
get
(
key
);
if
(
his
==
null
)
{
re
s
.
creates
.
add
(
now
);
re
s
.
mapNow
.
put
(
key
,
now
);
thi
s
.
creates
.
add
(
now
);
thi
s
.
mapNow
.
put
(
key
,
now
);
}
else
{
mapHistory
.
remove
(
key
);
boolean
isChange
=
keyFunc
.
set
(
his
,
now
);
if
(
isChange
)
{
re
s
.
updates
.
add
(
his
);
thi
s
.
updates
.
add
(
his
);
}
re
s
.
mapNow
.
put
(
key
,
his
);
thi
s
.
mapNow
.
put
(
key
,
his
);
}
}
}
res
.
removes
.
addAll
(
mapHistory
.
values
());
return
res
;
this
.
removes
.
addAll
(
mapHistory
.
values
());
}
/**
* 初始话对象
*
...
...
@@ -78,10 +75,9 @@ public class DataDaoVo<T> {
* @param nows
* @param keyFunc
*/
public
static
<
T
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
public
void
add
(
List
<
T
>
hisitories
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
Map
<
String
,
T
>
mapHistory
=
getMapHistory
(
hisitories
,
keyFunc
);
DataDaoVo
<
T
>
res
=
getResult
(
mapHistory
,
nows
,
keyFunc
);
return
res
;
addResult
(
mapHistory
,
nows
,
keyFunc
);
}
...
...
@@ -92,7 +88,7 @@ public class DataDaoVo<T> {
* @param nows
* @param keyFunc
*/
public
static
<
T
,
M
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
M
>
nows
,
DataDaoKeyConvert
<
T
,
M
>
keyFunc
)
{
public
<
M
>
void
add
(
List
<
T
>
hisitories
,
List
<
M
>
nows
,
DataDaoKeyConvert
<
T
,
M
>
keyFunc
)
{
Map
<
String
,
T
>
mapHistory
=
getMapHistory
(
hisitories
,
keyFunc
);
List
<
T
>
toNows
=
new
ArrayList
<>(
10
);
if
(
nows
!=
null
)
{
...
...
@@ -101,7 +97,33 @@ public class DataDaoVo<T> {
toNows
.
add
(
t
);
}
}
DataDaoVo
<
T
>
res
=
getResult
(
mapHistory
,
toNows
,
keyFunc
);
addResult
(
mapHistory
,
toNows
,
keyFunc
);
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public
static
<
T
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
T
>
nows
,
DataDaoKey
<
T
>
keyFunc
)
{
DataDaoVo
<
T
>
res
=
new
DataDaoVo
<
T
>();
res
.
add
(
hisitories
,
nows
,
keyFunc
);
return
res
;
}
/**
* 初始话对象
*
* @param hisitories
* @param nows
* @param keyFunc
*/
public
static
<
T
,
M
>
DataDaoVo
<
T
>
init
(
List
<
T
>
hisitories
,
List
<
M
>
nows
,
DataDaoKeyConvert
<
T
,
M
>
keyFunc
)
{
DataDaoVo
<
T
>
res
=
new
DataDaoVo
<
T
>();
res
.
add
(
hisitories
,
nows
,
keyFunc
);
return
res
;
}
...
...
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