Skip to content

Commit

Permalink
Merge pull request #3167 from ebean-orm/feature/InTuples-Literal-skip…
Browse files Browse the repository at this point in the history
…Cache

Change Lists.partition() argument order to match Guava's
  • Loading branch information
rob-bygrave authored Aug 17, 2023
2 parents 9331050 + bab9be0 commit d6e46b1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
14 changes: 10 additions & 4 deletions ebean-api/src/main/java/io/ebean/Lists.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
/**
* 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);
Expand Down
16 changes: 8 additions & 8 deletions ebean-api/src/test/java/io/ebean/ListsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,7 +41,7 @@ void partition_gt() {

@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);
Expand All @@ -51,7 +51,7 @@ void partition_gt1_letters() {

@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);
Expand All @@ -61,7 +61,7 @@ void partition_gt1a_letters() {

@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);
Expand All @@ -71,7 +71,7 @@ void partition_eq2_letters() {

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ private int delete(BeanDescriptor<?> descriptor, Object id, List<Object> idList,
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;
Expand Down

0 comments on commit d6e46b1

Please sign in to comment.