Merge pull request #3167 from ebean-orm/feature/InTuples-Literal-skipCache

Change Lists.partition() argument order to match Guava's
This commit is contained in:
Rob Bygrave
2023-08-17 15:36:35 +12:00
committed by GitHub
3 changed files with 19 additions and 13 deletions
+10 -4
View File
@@ -6,17 +6,23 @@ import java.util.List;
/**
* Helper methods for Lists.
*/
public interface Lists {
public final class Lists {
private Lists() {
}
/**
* Partition the source List into sub-lists with a maximum size.
* <p>
* The sub-lists will all be the max size except for the last sub-list
* which can potentially be smaller.
*
* @param max The max size of each partition
* @param source The source list
* @param max The max size of each partition
* @param <T> The list element type
* @return List of partitions
* @return List of sub-list partitions
*/
static <T> List<List<T>> partition(int max, List<T> source) {
public static <T> List<List<T>> partition(List<T> source, int max) {
final int totalCount = source.size();
if (totalCount <= max) {
return List.of(source);
@@ -10,28 +10,28 @@ class ListsTest {
@Test
void partition_empty() {
List<List<Integer>> partitions = Lists.partition(5, List.of());
List<List<Integer>> partitions = Lists.partition(List.of(), 5);
assertThat(partitions).hasSize(1);
assertThat(partitions.get(0)).hasSize(0);
}
@Test
void partition_lt() {
List<List<Integer>> partitions = Lists.partition(5, List.of(1, 2, 3, 4));
List<List<Integer>> partitions = Lists.partition(List.of(1, 2, 3, 4), 5);
assertThat(partitions).hasSize(1);
assertThat(partitions.get(0)).hasSize(4);
}
@Test
void partition_eq() {
List<List<Integer>> partitions = Lists.partition(5, List.of(1, 2, 3, 4, 5));
List<List<Integer>> partitions = Lists.partition(List.of(1, 2, 3, 4, 5), 5);
assertThat(partitions).hasSize(1);
assertThat(partitions.get(0)).hasSize(5);
}
@Test
void partition_gt() {
List<List<Integer>> partitions = Lists.partition(5, List.of(1, 2, 3, 4, 5, 6));
List<List<Integer>> partitions = Lists.partition(List.of(1, 2, 3, 4, 5, 6), 5);
assertThat(partitions).hasSize(2);
assertThat(partitions.get(0)).hasSize(5);
assertThat(partitions.get(1)).hasSize(1);
@@ -41,7 +41,7 @@ class ListsTest {
@Test
void partition_gt1_letters() {
var partitions = Lists.partition(3, List.of("a", "b", "c", "d"));
var partitions = Lists.partition(List.of("a", "b", "c", "d"), 3);
assertThat(partitions).hasSize(2);
assertThat(partitions.get(0)).hasSize(3);
assertThat(partitions.get(1)).hasSize(1);
@@ -51,7 +51,7 @@ class ListsTest {
@Test
void partition_gt1a_letters() {
var partitions = Lists.partition(3, List.of("a", "b", "c", "d", "e"));
var partitions = Lists.partition(List.of("a", "b", "c", "d", "e"), 3);
assertThat(partitions).hasSize(2);
assertThat(partitions.get(0)).hasSize(3);
assertThat(partitions.get(1)).hasSize(2);
@@ -61,7 +61,7 @@ class ListsTest {
@Test
void partition_eq2_letters() {
var partitions = Lists.partition(3, List.of("a", "b", "c", "d", "e", "f"));
var partitions = Lists.partition(List.of("a", "b", "c", "d", "e", "f"), 3);
assertThat(partitions).hasSize(2);
assertThat(partitions.get(0)).hasSize(3);
assertThat(partitions.get(1)).hasSize(3);
@@ -71,7 +71,7 @@ class ListsTest {
@Test
void partition_gt2_letters() {
var partitions = Lists.partition(3, List.of("a", "b", "c", "d", "e", "f", "g"));
var partitions = Lists.partition(List.of("a", "b", "c", "d", "e", "f", "g"), 3);
assertThat(partitions).hasSize(3);
assertThat(partitions.get(0)).hasSize(3);
assertThat(partitions.get(1)).hasSize(3);
@@ -659,7 +659,7 @@ public final class DefaultPersister implements Persister {
return deleteBatch(descriptor, id, idList, transaction, deleteMode);
}
int rows = 0;
for (List<Object> batchOfIds : Lists.partition(maxDeleteBatch, idList)) {
for (List<Object> batchOfIds : Lists.partition(idList, maxDeleteBatch)) {
rows += deleteBatch(descriptor, id, batchOfIds, transaction, deleteMode);
}
return rows;