Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
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
徐少华
midjourney-proxy
Commits
ff8da1b7
Commit
ff8da1b7
authored
Dec 02, 2020
by
tc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feature:[none]增加list分组方法
parent
3cd6b662
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletions
+54
-1
a.txt
a.txt
+2
-0
ListUtils.java
...mmon/src/main/java/com/pcloud/common/utils/ListUtils.java
+52
-1
No files found.
a.txt
0 → 100644
View file @
ff8da1b7
afafa
\ No newline at end of file
pcloud-common/src/main/java/com/pcloud/common/utils/ListUtils.java
View file @
ff8da1b7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
*/
*/
package
com
.
pcloud
.
common
.
utils
;
package
com
.
pcloud
.
common
.
utils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -16,5 +17,55 @@ public class ListUtils {
...
@@ -16,5 +17,55 @@ public class ListUtils {
public
static
boolean
isEmpty
(
List
<?>
list
)
{
public
static
boolean
isEmpty
(
List
<?>
list
)
{
return
(
list
==
null
||
list
.
isEmpty
());
return
(
list
==
null
||
list
.
isEmpty
());
}
}
private
static
final
Integer
OFFSET
=
500
;
/**
* 切割list,默认500长度一个
* @param list
* @param <T>
* @return
*/
public
static
<
T
>
List
<
List
<
T
>>
groupList
(
List
<
T
>
list
)
{
return
groupList
(
list
,
OFFSET
);
}
/**
* 切割list,自定义长度
* @param list
* @param length
* @param <T>
* @return
*/
public
static
<
T
>
List
<
List
<
T
>>
groupList
(
List
<
T
>
list
,
int
length
)
{
List
<
List
<
T
>>
listGroup
=
new
ArrayList
<>();
int
listSize
=
list
.
size
();
//子集合的长度
int
toIndex
=
length
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
+=
length
)
{
if
(
i
+
length
>
listSize
)
{
toIndex
=
listSize
-
i
;
}
List
<
T
>
newList
=
list
.
subList
(
i
,
i
+
toIndex
);
listGroup
.
add
(
newList
);
}
return
listGroup
;
}
/**
* 切割list,自定义子集合个数
* @param list
* @param <T>
* @return
*/
public
static
<
T
>
List
<
List
<
T
>>
groupListBySize
(
List
<
T
>
list
,
int
size
)
{
int
length
=
list
.
size
()/
size
;
if
(
list
.
size
()<
10
){
length
=
1
;
}
return
groupList
(
list
,
length
);
}
}
}
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