Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Sep 11, 2024
1 parent f1e86c2 commit 4d0a612
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.MapInfo;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import java.util.List;
import java.util.Map;

@Dao
public interface SplitDao {
Expand All @@ -29,10 +27,6 @@ public interface SplitDao {
@Query("DELETE FROM splits")
void deleteAll();

@MapInfo(keyColumn = "name", valueColumn = "body")
@Query("SELECT name, body FROM splits")
Map<String, String> getAllAsMap();

@Query("SELECT body FROM splits")
List<String> getAllBodies();
}
28 changes: 1 addition & 27 deletions src/main/java/io/split/android/client/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,14 @@ public static <T> List<List<T>> partition(List<T> list, int size) {
partitions.add(new ArrayList<>(list.subList(i, Math.min(i + size, list.size()))));
}

if (!partitions.isEmpty() && partitions.size() % size != 0) {
if (partitions.size() > 1 && partitions.size() % size != 0) {
partitions.get(0).addAll(partitions.get(partitions.size() - 1));
partitions.remove(partitions.size() - 1);
}

return partitions;
}

public static <T> List<Map<String, T>> partition(Map<String, T> map, int size) {
if (map == null) {
return new ArrayList<>();
}

if (size <= 0) {
return Collections.singletonList(map);
}

List<Map<String, T>> partitions = new ArrayList<>();
for (int i = 0; i < map.size(); i += size) {
// partition the map
Map<String, T> partition = new HashMap<>();
int j = 0;
for (Map.Entry<String, T> entry : map.entrySet()) {
if (j >= i && j < Math.min(i + size, map.size())) {
partition.put(entry.getKey(), entry.getValue());
}
j++;
}
partitions.add(partition);
}

return partitions;
}

public static <T> Set<T> intersection(Set<T> set1, Set<T> set2) {
Set<T> result = new HashSet<>(set1);
result.retainAll(set2);
Expand Down

0 comments on commit 4d0a612

Please sign in to comment.