Skip to content

Commit

Permalink
Generalize
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and rickie committed Aug 22, 2024
1 parent 92021c0 commit 1ca77b4
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
static final class MinOfArray<S, T extends S> {
@BeforeTemplate
T before(T[] array, Comparator<T> cmp) {
T before(T[] array, Comparator<S> cmp) {
return Arrays.stream(array).min(cmp).orElseThrow();
}

@AfterTemplate
T after(T[] array, Comparator<T> cmp) {
T after(T[] array, Comparator<S> cmp) {
return Collections.min(Arrays.asList(array), cmp);
}
}
Expand All @@ -264,14 +264,14 @@ T after(T[] array, Comparator<T> cmp) {
* Avoid unnecessary creation of a {@link Stream} to determine the minimum of a known collection
* of values.
*/
static final class MinOfCollection<T> {
static final class MinOfCollection<S, T extends S> {
@BeforeTemplate
T before(Collection<T> collection, Comparator<T> cmp) {
T before(Collection<T> collection, Comparator<S> cmp) {
return collection.stream().min(cmp).orElseThrow();
}

@AfterTemplate
T after(Collection<T> collection, Comparator<T> cmp) {
T after(Collection<T> collection, Comparator<S> cmp) {
return Collections.min(collection, cmp);
}
}
Expand All @@ -280,14 +280,14 @@ T after(Collection<T> collection, Comparator<T> cmp) {
* Avoid unnecessary creation of a {@link Stream} to determine the minimum of a known collection
* of values.
*/
static final class MinOfVarargs<T> {
static final class MinOfVarargs<S, T extends S> {
@BeforeTemplate
T before(@Repeated T value, Comparator<T> cmp) {
T before(@Repeated T value, Comparator<S> cmp) {
return Stream.of(Refaster.asVarargs(value)).min(cmp).orElseThrow();
}

@AfterTemplate
T after(@Repeated T value, Comparator<T> cmp) {
T after(@Repeated T value, Comparator<S> cmp) {
return Collections.min(Arrays.asList(value), cmp);
}
}
Expand Down Expand Up @@ -347,14 +347,14 @@ T after(T value1, T value2, Comparator<? super T> cmp) {
* Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection
* of values.
*/
static final class MaxOfArray<T> {
static final class MaxOfArray<S, T extends S> {
@BeforeTemplate
T before(T[] array, Comparator<T> cmp) {
T before(T[] array, Comparator<S> cmp) {
return Arrays.stream(array).max(cmp).orElseThrow();
}

@AfterTemplate
T after(T[] array, Comparator<T> cmp) {
T after(T[] array, Comparator<S> cmp) {
return Collections.max(Arrays.asList(array), cmp);
}
}
Expand All @@ -363,14 +363,14 @@ T after(T[] array, Comparator<T> cmp) {
* Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection
* of values.
*/
static final class MaxOfCollection<T> {
static final class MaxOfCollection<S, T extends S> {
@BeforeTemplate
T before(Collection<T> collection, Comparator<T> cmp) {
T before(Collection<T> collection, Comparator<S> cmp) {
return collection.stream().max(cmp).orElseThrow();
}

@AfterTemplate
T after(Collection<T> collection, Comparator<T> cmp) {
T after(Collection<T> collection, Comparator<S> cmp) {
return Collections.max(collection, cmp);
}
}
Expand All @@ -379,14 +379,14 @@ T after(Collection<T> collection, Comparator<T> cmp) {
* Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection
* of values.
*/
static final class MaxOfVarargs<T> {
static final class MaxOfVarargs<S, T extends S> {
@BeforeTemplate
T before(@Repeated T value, Comparator<T> cmp) {
T before(@Repeated T value, Comparator<S> cmp) {
return Stream.of(Refaster.asVarargs(value)).max(cmp).orElseThrow();
}

@AfterTemplate
T after(@Repeated T value, Comparator<T> cmp) {
T after(@Repeated T value, Comparator<S> cmp) {
return Collections.max(Arrays.asList(value), cmp);
}
}
Expand Down

0 comments on commit 1ca77b4

Please sign in to comment.