aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-08-04 23:54:25 +0800
committershedaniel <daniel@shedaniel.me>2020-08-04 23:54:25 +0800
commit05176b42e55a475b2008c1463daf9be7221f2e43 (patch)
tree932ba0ac41b8f5545dcc1d5b2595b5321b30ddba /src/main/java
parent77378ad674bdefcecd45494996262af59d684d1d (diff)
downloadRoughlyEnoughItems-05176b42e55a475b2008c1463daf9be7221f2e43.tar.gz
RoughlyEnoughItems-05176b42e55a475b2008c1463daf9be7221f2e43.tar.bz2
RoughlyEnoughItems-05176b42e55a475b2008c1463daf9be7221f2e43.zip
Limit the size
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java2
-rw-r--r--src/main/java/me/shedaniel/rei/utils/CollectionUtils.java17
2 files changed, 6 insertions, 13 deletions
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 <A, B> List<B> getOrPutEmptyList(Map<A, List<B>> map, A key) {
@@ -178,33 +179,25 @@ public class CollectionUtils {
public static <T, R> Optional<R> mapAndMax(List<T> list, Function<T, R> function, Comparator<R> comparator) {
if (list.isEmpty())
return Optional.empty();
- List<R> 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 <T, R> Optional<R> mapAndMax(T[] list, Function<T, R> function, Comparator<R> comparator) {
if (list.length <= 0)
return Optional.empty();
- List<R> 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 <T> Optional<T> max(List<T> list, Comparator<T> comparator) {
if (list.isEmpty())
return Optional.empty();
- ArrayList<T> ts = new ArrayList<>(list);
- ts.sort(comparator);
- return Optional.ofNullable(ts.get(ts.size() - 1));
+ return list.stream().max(comparator);
}
public static <T> Optional<T> max(T[] list, Comparator<T> 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<String> list, String separator) {