Thu, 31 Aug 2017 15:17:03 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 8016081 8016178 |
aoqi@0 | 27 | * @summary structural most specific and stuckness |
aoqi@0 | 28 | * @compile T8016177f.java |
aoqi@0 | 29 | */ |
aoqi@0 | 30 | import java.util.*; |
aoqi@0 | 31 | |
aoqi@0 | 32 | class T8016177f { |
aoqi@0 | 33 | |
aoqi@0 | 34 | interface Function<S, T> { |
aoqi@0 | 35 | T apply(S s); |
aoqi@0 | 36 | } |
aoqi@0 | 37 | |
aoqi@0 | 38 | interface IntFunction<T> { |
aoqi@0 | 39 | T apply(int s); |
aoqi@0 | 40 | } |
aoqi@0 | 41 | |
aoqi@0 | 42 | |
aoqi@0 | 43 | interface BiConsumer<X,Y> { |
aoqi@0 | 44 | void m(X x, Y y); |
aoqi@0 | 45 | } |
aoqi@0 | 46 | |
aoqi@0 | 47 | interface Consumer<X> { |
aoqi@0 | 48 | void m(X x); |
aoqi@0 | 49 | } |
aoqi@0 | 50 | |
aoqi@0 | 51 | interface Supplier<X> { |
aoqi@0 | 52 | X make(); |
aoqi@0 | 53 | } |
aoqi@0 | 54 | |
aoqi@0 | 55 | interface TestData<T, S extends BaseStream<T, S>> { |
aoqi@0 | 56 | interface OfRef<T> extends TestData<T, Stream<T>> { } |
aoqi@0 | 57 | interface OfDouble extends TestData<Double, DoubleStream> { } |
aoqi@0 | 58 | } |
aoqi@0 | 59 | |
aoqi@0 | 60 | interface BaseStream<T, S extends BaseStream<T, S>> { } |
aoqi@0 | 61 | |
aoqi@0 | 62 | interface Stream<T> extends BaseStream<T, Stream<T>> { |
aoqi@0 | 63 | <M> Stream<M> map(Function<T, M> s); |
aoqi@0 | 64 | <R> R collect(Supplier<R> resultFactory, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner); |
aoqi@0 | 65 | <Z> Z[] toArray(IntFunction<Z[]> s); |
aoqi@0 | 66 | } |
aoqi@0 | 67 | |
aoqi@0 | 68 | interface DoubleStream extends BaseStream<Double, DoubleStream> { |
aoqi@0 | 69 | DoubleStream filter(DoublePredicate dp); |
aoqi@0 | 70 | double[] toArray(); |
aoqi@0 | 71 | } |
aoqi@0 | 72 | |
aoqi@0 | 73 | interface DoublePredicate { |
aoqi@0 | 74 | boolean p(double d); |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | <T, U, R, S_IN extends BaseStream<T, S_IN>, S_OUT extends BaseStream<U, S_OUT>> |
aoqi@0 | 78 | R exerciseTerminalOps(TestData<T, S_IN> data, |
aoqi@0 | 79 | Function<S_IN, S_OUT> streamF, |
aoqi@0 | 80 | Function<S_OUT, R> terminalF) { return null; } |
aoqi@0 | 81 | |
aoqi@0 | 82 | <O> TestData.OfRef<O> ofCollection(Collection<O> collection) { return null; } |
aoqi@0 | 83 | |
aoqi@0 | 84 | void test1(TestData.OfDouble data, DoublePredicate dp) { |
aoqi@0 | 85 | exerciseTerminalOps(data, s -> s.filter(dp), s -> s.toArray()); |
aoqi@0 | 86 | } |
aoqi@0 | 87 | |
aoqi@0 | 88 | void test2(Function<Double, Integer> fdi, TestData.OfRef<Double> td, Stream<Integer> si) { |
aoqi@0 | 89 | exerciseTerminalOps( |
aoqi@0 | 90 | ofCollection((List<Double>)null), |
aoqi@0 | 91 | s -> s.map(fdi), |
aoqi@0 | 92 | s -> s.toArray(Integer[]::new)); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | } |