From 05176b42e55a475b2008c1463daf9be7221f2e43 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 4 Aug 2020 23:54:25 +0800 Subject: Limit the size --- .../java/me/shedaniel/rei/gui/RecipeViewingScreen.java | 2 +- .../java/me/shedaniel/rei/utils/CollectionUtils.java | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index ad9a63011..91802beb4 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -227,7 +227,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { this.largestWidth = width - 100; this.largestHeight = Math.max(height - 34 - 30, 100); int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), selectedCategory::getDisplayWidth, Comparator.naturalOrder()).orElse(150); - this.guiWidth = Math.max(maxWidthDisplay + 40, 0); + this.guiWidth = Math.max(maxWidthDisplay + 40, 190); this.guiHeight = MathHelper.floor(MathHelper.clamp((double) (selectedCategory.getDisplayHeight() + 4) * (getRecipesPerPage() + 1) + 36, 100, largestHeight)); if (!ConfigObject.getInstance().shouldResizeDynamically()) this.guiHeight = largestHeight; this.tabsPerPage = Math.max(5, MathHelper.floor((guiWidth - 20d) / tabSize)); diff --git a/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java b/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java index 33f8ef457..7e46a05f6 100644 --- a/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java +++ b/src/main/java/me/shedaniel/rei/utils/CollectionUtils.java @@ -34,6 +34,7 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; public class CollectionUtils { public static List getOrPutEmptyList(Map> map, A key) { @@ -178,33 +179,25 @@ public class CollectionUtils { public static Optional mapAndMax(List list, Function function, Comparator comparator) { if (list.isEmpty()) return Optional.empty(); - List copyOf = CollectionUtils.map(list, function); - copyOf.sort(comparator); - return Optional.ofNullable(copyOf.get(copyOf.size() - 1)); + return list.stream().max(Comparator.comparing(function, comparator)).map(function); } public static Optional mapAndMax(T[] list, Function function, Comparator comparator) { if (list.length <= 0) return Optional.empty(); - List copyOf = CollectionUtils.map(list, function); - copyOf.sort(comparator); - return Optional.ofNullable(copyOf.get(copyOf.size() - 1)); + return Stream.of(list).max(Comparator.comparing(function, comparator)).map(function); } public static Optional max(List list, Comparator comparator) { if (list.isEmpty()) return Optional.empty(); - ArrayList ts = new ArrayList<>(list); - ts.sort(comparator); - return Optional.ofNullable(ts.get(ts.size() - 1)); + return list.stream().max(comparator); } public static Optional max(T[] list, Comparator comparator) { if (list.length <= 0) return Optional.empty(); - T[] copyOf = list.clone(); - Arrays.sort(copyOf, comparator); - return Optional.ofNullable(copyOf[copyOf.length - 1]); + return Stream.of(list).max(comparator); } public static String joinToString(List list, String separator) { -- cgit