langtools/test/tools/javac/lambda/8068399/T8068399.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 29052 d1bc1685d7ce
child 34752 9c262a013456
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 29052
diff changeset
     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
 */
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    23
/*
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    24
 * @test
29052
d1bc1685d7ce 8073201: Incorrect @bug annotation in checkin for JDK-8069545
sadayapalam
parents: 28891
diff changeset
    25
 * @bug 8068399 8069545
28891
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    26
 * @summary structural most specific and stuckness
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    27
 */
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
import java.util.function.Function;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    30
import java.util.stream.IntStream;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    31
import java.util.stream.Stream;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    32
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    33
public class T8068399 {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    34
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    35
    public static class Spectrum {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    36
        public double[] getEnergy() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    37
            return new double[0];
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    38
        }
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
    protected Spectrum spectrum;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    42
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    43
    public static class Ref<T> {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    44
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    45
        T value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    46
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    47
        public Ref() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    48
        }
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
        public Ref(T value) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    51
            this.value = value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    52
        }
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
        public boolean isNull() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    55
            return value == null;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    56
        }
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
        public T get() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    59
            return value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    60
        }
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
        public void set(T value) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    63
            this.value = value;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    64
        }
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
    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
    68
        Ref<Double> max = new Ref<>();
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    69
        Ref<T> index = new Ref<>();
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    70
        stream.forEach(v -> {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    71
            Double value = function.apply(v);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    72
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    73
            if (max.isNull() || value > max.get()) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    74
                max.set(value);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    75
                index.set(v);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    76
            }
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
        return index.get();
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    80
    }
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
    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
    83
        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    84
    }
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
    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
    87
        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    88
    }
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
    protected int getXByFrequency(double frequency) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    91
        return (int) Math.round(interpolate(frequency,
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    92
                                            getMinSpectrumCoord(),
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    93
                                            getMaxSpectrumCoord(),
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    94
                                            0, getWidth()));
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    95
    }
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
    private int getWidth() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    98
        return 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
    99
    }
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
    private double getMaxSpectrumCoord() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   102
        return 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   103
    }
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
    private double getMinSpectrumCoord() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   106
        return 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   107
    }
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
    void foo() {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   110
        int maxBpmIndex = 0;
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   111
        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
   112
                                          i -> Math.abs(spectrum.getEnergy()[i])));
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   113
    }
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
    public static void main(String [] args) {
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   116
    }
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
diff changeset
   117
}