From 1ca77b4d4eed74bd09b21c3e97613899fdb32e77 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 10 Aug 2024 17:20:29 +0200 Subject: [PATCH] Generalize --- .../refasterrules/ComparatorRules.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java index b6de7bdecb..d01820135b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java @@ -248,14 +248,14 @@ int after(T value1, T value2) { * Avoid unnecessary creation of a {@link Stream} to determine the minimum of a known collection * of values. */ - static final class MinOfArray { + static final class MinOfArray { @BeforeTemplate - T before(T[] array, Comparator cmp) { + T before(T[] array, Comparator cmp) { return Arrays.stream(array).min(cmp).orElseThrow(); } @AfterTemplate - T after(T[] array, Comparator cmp) { + T after(T[] array, Comparator cmp) { return Collections.min(Arrays.asList(array), cmp); } } @@ -264,14 +264,14 @@ T after(T[] array, Comparator cmp) { * Avoid unnecessary creation of a {@link Stream} to determine the minimum of a known collection * of values. */ - static final class MinOfCollection { + static final class MinOfCollection { @BeforeTemplate - T before(Collection collection, Comparator cmp) { + T before(Collection collection, Comparator cmp) { return collection.stream().min(cmp).orElseThrow(); } @AfterTemplate - T after(Collection collection, Comparator cmp) { + T after(Collection collection, Comparator cmp) { return Collections.min(collection, cmp); } } @@ -280,14 +280,14 @@ T after(Collection collection, Comparator cmp) { * Avoid unnecessary creation of a {@link Stream} to determine the minimum of a known collection * of values. */ - static final class MinOfVarargs { + static final class MinOfVarargs { @BeforeTemplate - T before(@Repeated T value, Comparator cmp) { + T before(@Repeated T value, Comparator cmp) { return Stream.of(Refaster.asVarargs(value)).min(cmp).orElseThrow(); } @AfterTemplate - T after(@Repeated T value, Comparator cmp) { + T after(@Repeated T value, Comparator cmp) { return Collections.min(Arrays.asList(value), cmp); } } @@ -347,14 +347,14 @@ T after(T value1, T value2, Comparator cmp) { * Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection * of values. */ - static final class MaxOfArray { + static final class MaxOfArray { @BeforeTemplate - T before(T[] array, Comparator cmp) { + T before(T[] array, Comparator cmp) { return Arrays.stream(array).max(cmp).orElseThrow(); } @AfterTemplate - T after(T[] array, Comparator cmp) { + T after(T[] array, Comparator cmp) { return Collections.max(Arrays.asList(array), cmp); } } @@ -363,14 +363,14 @@ T after(T[] array, Comparator cmp) { * Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection * of values. */ - static final class MaxOfCollection { + static final class MaxOfCollection { @BeforeTemplate - T before(Collection collection, Comparator cmp) { + T before(Collection collection, Comparator cmp) { return collection.stream().max(cmp).orElseThrow(); } @AfterTemplate - T after(Collection collection, Comparator cmp) { + T after(Collection collection, Comparator cmp) { return Collections.max(collection, cmp); } } @@ -379,14 +379,14 @@ T after(Collection collection, Comparator cmp) { * Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection * of values. */ - static final class MaxOfVarargs { + static final class MaxOfVarargs { @BeforeTemplate - T before(@Repeated T value, Comparator cmp) { + T before(@Repeated T value, Comparator cmp) { return Stream.of(Refaster.asVarargs(value)).max(cmp).orElseThrow(); } @AfterTemplate - T after(@Repeated T value, Comparator cmp) { + T after(@Repeated T value, Comparator cmp) { return Collections.max(Arrays.asList(value), cmp); } }