author | vasya |
Mon, 14 Dec 2015 20:18:19 +0100 | |
changeset 34752 | 9c262a013456 |
parent 32337 | c9d3ab9f601c |
permissions | -rw-r--r-- |
28891
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
1 |
/* |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
4 |
* |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
32337 | 7 |
* published by the Free Software Foundation. |
28891
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
8 |
* |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
13 |
* accompanied this code). |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
14 |
* |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
18 |
* |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
21 |
* questions. |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
22 |
*/ |
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
32337
diff
changeset
|
23 |
|
28891
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
24 |
/* |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
25 |
* @test |
29052
d1bc1685d7ce
8073201: Incorrect @bug annotation in checkin for JDK-8069545
sadayapalam
parents:
28891
diff
changeset
|
26 |
* @bug 8068399 8069545 |
28891
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
27 |
* @summary structural most specific and stuckness |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
28 |
*/ |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
29 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
30 |
import java.util.function.Function; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
31 |
import java.util.stream.IntStream; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
32 |
import java.util.stream.Stream; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
33 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
34 |
public class T8068399 { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
35 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
36 |
public static class Spectrum { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
37 |
public double[] getEnergy() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
38 |
return new double[0]; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
39 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
40 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
41 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
42 |
protected Spectrum spectrum; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
43 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
44 |
public static class Ref<T> { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
45 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
46 |
T value; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
47 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
48 |
public Ref() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
49 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
50 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
51 |
public Ref(T value) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
52 |
this.value = value; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
53 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
54 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
55 |
public boolean isNull() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
56 |
return value == null; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
57 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
58 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
59 |
public T get() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
60 |
return value; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
61 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
62 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
63 |
public void set(T value) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
64 |
this.value = value; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
65 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
66 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
67 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
68 |
public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
69 |
Ref<Double> max = new Ref<>(); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
70 |
Ref<T> index = new Ref<>(); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
71 |
stream.forEach(v -> { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
72 |
Double value = function.apply(v); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
73 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
74 |
if (max.isNull() || value > max.get()) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
75 |
max.set(value); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
76 |
index.set(v); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
77 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
78 |
}); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
79 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
80 |
return index.get(); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
81 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
82 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
83 |
public static int interpolate(int x, int x0, int x1, int y0, int y1) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
84 |
return y0 + (x - x0) * (y1 - y0) / (x1 - x0); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
85 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
86 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
87 |
public static double interpolate(double x, double x0, double x1, double y0, double y1) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
88 |
return y0 + (x - x0) * (y1 - y0) / (x1 - x0); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
89 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
90 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
91 |
protected int getXByFrequency(double frequency) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
92 |
return (int) Math.round(interpolate(frequency, |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
93 |
getMinSpectrumCoord(), |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
94 |
getMaxSpectrumCoord(), |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
95 |
0, getWidth())); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
96 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
97 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
98 |
private int getWidth() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
99 |
return 0; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
100 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
101 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
102 |
private double getMaxSpectrumCoord() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
103 |
return 0; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
104 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
105 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
106 |
private double getMinSpectrumCoord() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
107 |
return 0; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
108 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
109 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
110 |
void foo() { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
111 |
int maxBpmIndex = 0; |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
112 |
int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(), |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
113 |
i -> Math.abs(spectrum.getEnergy()[i]))); |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
114 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
115 |
|
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
116 |
public static void main(String [] args) { |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
117 |
} |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff
changeset
|
118 |
} |