Merge "Replace .toList() with .collect()" into main

This commit is contained in:
Treehugger Robot
2025-02-10 12:58:19 -08:00
committed by Gerrit Code Review
10 changed files with 35 additions and 20 deletions
+4 -2
View File
@@ -282,6 +282,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -2240,8 +2241,9 @@ public class Launcher extends StatefulActivity<LauncherState>
*/
@Override
public void bindItems(final List<ItemInfo> items, final boolean forceAnimateIcons) {
bindInflatedItems(items.stream().map(i -> Pair.create(
i, getItemInflater().inflateItem(i, getModelWriter()))).toList(),
bindInflatedItems(items.stream()
.map(i -> Pair.create(i, getItemInflater().inflateItem(i, getModelWriter())))
.collect(Collectors.toList()),
forceAnimateIcons ? new AnimatorSet() : null);
}
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
/**
* Contains the logic of a reorder.
@@ -143,12 +144,14 @@ public class ReorderAlgorithm {
// and not by the views hash which is "random".
// The views are sorted twice, once for the X position and a second time for the Y position
// to ensure same order everytime.
Comparator comparator = Comparator.comparing(
view -> ((CellLayoutLayoutParams) ((View) view).getLayoutParams()).getCellX()
Comparator<View> comparator = Comparator.comparing(
(View view) -> ((CellLayoutLayoutParams) view.getLayoutParams()).getCellX()
).thenComparing(
view -> ((CellLayoutLayoutParams) ((View) view).getLayoutParams()).getCellY()
(View view) -> ((CellLayoutLayoutParams) view.getLayoutParams()).getCellY()
);
List<View> views = solution.map.keySet().stream().sorted(comparator).toList();
List<View> views = solution.map.keySet().stream()
.sorted(comparator)
.collect(Collectors.toList());
for (View child : views) {
if (child == ignoreView) continue;
CellAndSpan c = solution.map.get(child);
@@ -412,8 +412,9 @@ public class BaseLauncherBinder {
ModelWriter writer = mApp.getModel()
.getWriter(false /* verifyChanges */, CellPosMapper.DEFAULT, null);
List<Pair<ItemInfo, View>> bindItems = items.stream().map(i ->
Pair.create(i, inflater.inflateItem(i, writer, null))).toList();
List<Pair<ItemInfo, View>> bindItems = items.stream()
.map(i -> Pair.create(i, inflater.inflateItem(i, writer, null)))
.collect(Collectors.toList());
executeCallbacksTask(c -> c.bindInflatedItems(bindItems), executor);
}
@@ -217,9 +217,12 @@ public class GridSizeMigrationUtil {
Collections.sort(hotseatToBeAdded);
Collections.sort(workspaceToBeAdded);
List<Integer> idsInUse = dstWorkspaceItems.stream().map(entry -> entry.id).collect(
Collectors.toList());
idsInUse.addAll(dstHotseatItems.stream().map(entry -> entry.id).toList());
List<Integer> idsInUse = dstWorkspaceItems.stream()
.map(entry -> entry.id)
.collect(Collectors.toList());
idsInUse.addAll(dstHotseatItems.stream()
.map(entry -> entry.id)
.collect(Collectors.toList()));
// Migrate hotseat
solveHotseatPlacement(helper, destHotseatSize,
@@ -249,7 +252,8 @@ public class GridSizeMigrationUtil {
int screenId = destReader.mLastScreenId + 1;
while (!workspaceToBeAdded.isEmpty()) {
solveGridPlacement(helper, srcReader, destReader, screenId, trgX, trgY,
workspaceToBeAdded, srcWorkspaceItems.stream().map(entry -> entry.id).toList());
workspaceToBeAdded,
srcWorkspaceItems.stream().map(entry -> entry.id).collect(Collectors.toList()));
screenId++;
}
@@ -22,6 +22,7 @@ import com.android.launcher3.R
import com.android.launcher3.icons.IconCache
import com.android.launcher3.logger.LauncherAtom
import com.android.launcher3.views.ActivityContext
import java.util.stream.Collectors
/** A type of app collection that launches multiple apps into split screen. */
class AppPairInfo() : CollectionInfo() {
@@ -54,7 +55,7 @@ class AppPairInfo() : CollectionInfo() {
/** Returns the app pair's member apps as an ArrayList of [ItemInfo]. */
override fun getContents(): ArrayList<ItemInfo> =
ArrayList(contents.stream().map { it as ItemInfo }.toList())
ArrayList(contents.stream().map { it as ItemInfo }.collect(Collectors.toList()))
/** Returns the app pair's member apps as an ArrayList of [WorkspaceItemInfo]. */
override fun getAppContents(): ArrayList<WorkspaceItemInfo> = contents
@@ -74,7 +75,7 @@ class AppPairInfo() : CollectionInfo() {
(ActivityContext.lookupContext(context) as ActivityContext).getDeviceProfile().isTablet
return Pair(
isTablet || !getFirstApp().isNonResizeable(),
isTablet || !getSecondApp().isNonResizeable()
isTablet || !getSecondApp().isNonResizeable(),
)
}
@@ -170,7 +170,7 @@ public class RestoreDbTask {
// At this point idp.dbFile contains the name of the dbFile from the previous phone
return LauncherFiles.GRID_DB_FILES.stream()
.filter(dbName -> new File(dbName).exists())
.toList();
.collect(Collectors.toList());
}
/**
@@ -222,7 +222,8 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
if (shouldShowFullPageView(recommendations)) {
// Show all widgets in single page with unlimited available height.
return setRecommendations(
recommendations.values().stream().flatMap(Collection::stream).toList(),
recommendations.values().stream().flatMap(Collection::stream)
.collect(Collectors.toList()),
deviceProfile, /*availableHeight=*/ Float.MAX_VALUE, availableWidth,
cellPadding);
@@ -357,7 +358,7 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
// Show only those widgets that were displayed when user first opened the picker.
if (!mDisplayedWidgets.isEmpty()) {
filteredRecommendedWidgets = recommendedWidgets.stream().filter(
w -> mDisplayedWidgets.contains(w.componentName)).toList();
w -> mDisplayedWidgets.contains(w.componentName)).collect(Collectors.toList());
}
Context context = getContext();
LayoutInflater inflater = LayoutInflater.from(context);
@@ -80,6 +80,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
@@ -595,7 +596,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
mRecommendedWidgets = mActivityContext.getWidgetPickerDataProvider().get()
.getRecommendations()
.values().stream()
.flatMap(Collection::stream).toList();
.flatMap(Collection::stream).collect(Collectors.toList());
mRecommendedWidgetsCount = mWidgetRecommendationsView.setRecommendations(
mRecommendedWidgets,
mDeviceProfile,
@@ -41,6 +41,7 @@ import com.android.launcher3.widget.picker.util.WidgetPreviewContainerSize;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/** A {@link TableLayout} for showing recommended widgets. */
public final class WidgetsRecommendationTableLayout extends TableLayout {
@@ -163,6 +164,7 @@ public final class WidgetsRecommendationTableLayout extends TableLayout {
}
// Perform re-ordering once we have filtered out recommendations that fit.
return filteredRows.stream().sorted(WIDGETS_TABLE_ROW_COUNT_COMPARATOR).toList();
return filteredRows.stream().sorted(WIDGETS_TABLE_ROW_COUNT_COMPARATOR)
.collect(Collectors.toList());
}
}
@@ -95,7 +95,7 @@ public final class WidgetsTableUtils {
List<ArrayList<WidgetItem>> rows = groupWidgetItemsUsingRowPxWithoutReordering(
sortedWidgetItems, context, dp, rowPx,
cellPadding);
return rows.stream().sorted(WIDGETS_TABLE_ROW_SIZE_COMPARATOR).toList();
return rows.stream().sorted(WIDGETS_TABLE_ROW_SIZE_COMPARATOR).collect(Collectors.toList());
}
/**