Set Source/Release Version to 24 always and remove Wildcards from Collectors.toList and toSet

This commit is contained in:
Andreas Stadelmeier 2024-12-16 20:41:58 +01:00
parent 2d7b87edd7
commit 849209b8cb
3 changed files with 37 additions and 19 deletions

View File

@ -222,7 +222,7 @@ public final class Collectors {
* {@code Collection}, in encounter order * {@code Collection}, in encounter order
*/ */
public static <T, C extends Collection<T>> public static <T, C extends Collection<T>>
Collector<T, ?, C> toCollection(Supplier<C> collectionFactory) { Collector<T, C, C> toCollection(Supplier<C> collectionFactory) {
return new CollectorImpl<>(collectionFactory, Collection::add, return new CollectorImpl<>(collectionFactory, Collection::add,
(r1, r2) -> { r1.addAll(r2); return r1; }, (r1, r2) -> { r1.addAll(r2); return r1; },
CH_ID); CH_ID);
@ -239,7 +239,25 @@ public final class Collectors {
* {@code List}, in encounter order * {@code List}, in encounter order
*/ */
public static <T> public static <T>
Collector<T, ?, List<T>> toList() { Collector<T, ArrayList<Object>, List<T>> toList() {
return new CollectorImpl<>(ArrayList::new, List::add,
(left, right) -> { left.addAll(right); return left; },
CH_ID);
}
/**
* Returns a {@code Collector} that accumulates the input elements into a
* new {@code List}. There are no guarantees on the type, mutability,
* serializability, or thread-safety of the {@code List} returned; if more
* control over the returned {@code List} is required, use {@link #toCollection(Supplier)}.
*
* @param <T> the type of the input elements
* @return a {@code Collector} which collects all the input elements into a
* {@code List}, in encounter order
*/
public static <T>
Collector<T, ArrayList<Object>, List<T>> toList2() {
return new CollectorImpl<>(ArrayList::new, List::add, return new CollectorImpl<>(ArrayList::new, List::add,
(left, right) -> { left.addAll(right); return left; }, (left, right) -> { left.addAll(right); return left; },
CH_ID); CH_ID);
@ -257,7 +275,7 @@ public final class Collectors {
* @since 10 * @since 10
*/ */
public static <T> public static <T>
Collector<T, ?, List<T>> toUnmodifiableList() { Collector<T, ArrayList<Object>, List<T>> toUnmodifiableList() {
return new CollectorImpl<>(ArrayList::new, List::add, return new CollectorImpl<>(ArrayList::new, List::add,
(left, right) -> { left.addAll(right); return left; }, (left, right) -> { left.addAll(right); return left; },
list -> { list -> {
@ -286,7 +304,7 @@ public final class Collectors {
* {@code Set} * {@code Set}
*/ */
public static <T> public static <T>
Collector<T, ?, Set<T>> toSet() { Collector<T, HashSet<Object>, Set<T>> toSet() {
return new CollectorImpl<>(HashSet::new, Set::add, return new CollectorImpl<>(HashSet::new, Set::add,
(left, right) -> { (left, right) -> {
if (left.size() < right.size()) { if (left.size() < right.size()) {
@ -315,7 +333,7 @@ public final class Collectors {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> public static <T>
Collector<T, ?, Set<T>> toUnmodifiableSet() { Collector<T, HashSet<Object>, Set<T>> toUnmodifiableSet() {
return new CollectorImpl<>(HashSet::new, Set::add, return new CollectorImpl<>(HashSet::new, Set::add,
(left, right) -> { (left, right) -> {
if (left.size() < right.size()) { if (left.size() < right.size()) {
@ -335,7 +353,7 @@ public final class Collectors {
* @return a {@code Collector} that concatenates the input elements into a * @return a {@code Collector} that concatenates the input elements into a
* {@code String}, in encounter order * {@code String}, in encounter order
*/ */
public static Collector<CharSequence, ?, String> joining() { public static Collector<CharSequence, StringBuilder, String> joining() {
return new CollectorImpl<>( return new CollectorImpl<>(
StringBuilder::new, StringBuilder::append, StringBuilder::new, StringBuilder::append,
(r1, r2) -> { (r1, r2) -> {
@ -353,7 +371,7 @@ public final class Collectors {
* @return A {@code Collector} which concatenates CharSequence elements, * @return A {@code Collector} which concatenates CharSequence elements,
* separated by the specified delimiter, in encounter order * separated by the specified delimiter, in encounter order
*/ */
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter) { public static Collector<CharSequence, StringJoiner, String> joining(CharSequence delimiter) {
return joining(delimiter, "", ""); return joining(delimiter, "", "");
} }
@ -370,7 +388,7 @@ public final class Collectors {
* @return A {@code Collector} which concatenates CharSequence elements, * @return A {@code Collector} which concatenates CharSequence elements,
* separated by the specified delimiter, in encounter order * separated by the specified delimiter, in encounter order
*/ */
public static Collector<CharSequence, ?, String> joining(CharSequence delimiter, public static Collector<CharSequence, StringJoiner, String> joining(CharSequence delimiter,
CharSequence prefix, CharSequence prefix,
CharSequence suffix) { CharSequence suffix) {
return new CollectorImpl<>( return new CollectorImpl<>(
@ -428,7 +446,7 @@ public final class Collectors {
* elements and provides the mapped results to the downstream collector * elements and provides the mapped results to the downstream collector
*/ */
public static <T, U, A, R> public static <T, U, A, R>
Collector<T, ?, R> mapping(Function<? super T, ? extends U> mapper, Collector<T, A, R> mapping(Function<? super T, ? extends U> mapper,
Collector<? super U, A, R> downstream) { Collector<? super U, A, R> downstream) {
BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator(); BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator();
return new CollectorImpl<>(downstream.supplier(), return new CollectorImpl<>(downstream.supplier(),
@ -473,7 +491,7 @@ public final class Collectors {
* @since 9 * @since 9
*/ */
public static <T, U, A, R> public static <T, U, A, R>
Collector<T, ?, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper, Collector<T, A, R> flatMapping(Function<? super T, ? extends Stream<? extends U>> mapper,
Collector<? super U, A, R> downstream) { Collector<? super U, A, R> downstream) {
BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator(); BiConsumer<A, ? super U> downstreamAccumulator = downstream.accumulator();
return new CollectorImpl<>(downstream.supplier(), return new CollectorImpl<>(downstream.supplier(),
@ -1102,7 +1120,7 @@ public final class Collectors {
* @see #groupingByConcurrent(Function, Supplier, Collector) * @see #groupingByConcurrent(Function, Supplier, Collector)
*/ */
public static <T, K, D, A, M extends Map<K, D>> public static <T, K, D, A, M extends Map<K, D>>
Collector<T, ?, M> groupingBy(Function<? super T, ? extends K> classifier, Collector<T, Map<K,A>, M> groupingBy(Function<? super T, ? extends K> classifier,
Supplier<M> mapFactory, Supplier<M> mapFactory,
Collector<? super T, A, D> downstream) { Collector<? super T, A, D> downstream) {
Supplier<A> downstreamSupplier = downstream.supplier(); Supplier<A> downstreamSupplier = downstream.supplier();
@ -1260,7 +1278,7 @@ public final class Collectors {
* @see #groupingBy(Function, Supplier, Collector) * @see #groupingBy(Function, Supplier, Collector)
*/ */
public static <T, K, A, D, M extends ConcurrentMap<K, D>> public static <T, K, A, D, M extends ConcurrentMap<K, D>>
Collector<T, ?, M> groupingByConcurrent(Function<? super T, ? extends K> classifier, Collector<T, ConcurrentMap<K,A>, M> groupingByConcurrent(Function<? super T, ? extends K> classifier,
Supplier<M> mapFactory, Supplier<M> mapFactory,
Collector<? super T, A, D> downstream) { Collector<? super T, A, D> downstream) {
Supplier<A> downstreamSupplier = downstream.supplier(); Supplier<A> downstreamSupplier = downstream.supplier();
@ -1438,7 +1456,7 @@ public final class Collectors {
* @see #toConcurrentMap(Function, Function) * @see #toConcurrentMap(Function, Function)
*/ */
public static <T, K, U> public static <T, K, U>
Collector<T, ?, Map<K,U>> toMap(Function<? super T, ? extends K> keyMapper, Collector<T, Map<K,U>, Map<K,U>> toMap(Function<? super T, ? extends K> keyMapper,
Function<? super T, ? extends U> valueMapper) { Function<? super T, ? extends U> valueMapper) {
return new CollectorImpl<>(HashMap::new, return new CollectorImpl<>(HashMap::new,
uniqKeysMapAccumulator(keyMapper, valueMapper), uniqKeysMapAccumulator(keyMapper, valueMapper),

View File

@ -295,7 +295,7 @@ public class Arguments {
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
public boolean handleReleaseOptions(Predicate<Iterable<String>> additionalOptions) { public boolean handleReleaseOptions(Predicate<Iterable<String>> additionalOptions) {
String platformString = options.get(Option.RELEASE); String platformString = options.get("24");
checkOptionAllowed(platformString == null, checkOptionAllowed(platformString == null,
option -> reportDiag(Errors.ReleaseBootclasspathConflict(option)), option -> reportDiag(Errors.ReleaseBootclasspathConflict(option)),

View File

@ -341,15 +341,15 @@ public class ToolOptions {
new ToolOption("--release", STANDARD, true) { new ToolOption("--release", STANDARD, true) {
@Override @Override
public void process(String arg) throws InvalidValueException { public void process(String arg) throws InvalidValueException {
processCompilerOption(Option.RELEASE, primaryName, arg); processCompilerOption(Option.RELEASE, primaryName, "24");
} }
}, },
new ToolOption("--source -source", STANDARD, true) { new ToolOption("--source -source", STANDARD, true) {
@Override @Override
public void process(String arg) throws InvalidValueException { public void process(String arg) throws InvalidValueException {
processCompilerOption(Option.SOURCE, primaryName, arg); //processCompilerOption(Option.SOURCE, primaryName, arg);
processCompilerOption(Option.TARGET, Option.TARGET.primaryName, arg); //processCompilerOption(Option.TARGET, Option.TARGET.primaryName, arg);
} }
}, },