1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/lambda/8068399/T8068399.java Thu Feb 12 10:16:19 2015 +0530 1.3 @@ -0,0 +1,119 @@ 1.4 +/* 1.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 +/* 1.29 + * @test 1.30 + * @bug 8068399 1.31 + * @summary structural most specific and stuckness 1.32 + */ 1.33 + 1.34 +import java.util.function.Function; 1.35 +import java.util.stream.IntStream; 1.36 +import java.util.stream.Stream; 1.37 + 1.38 +public class T8068399 { 1.39 + 1.40 + public static class Spectrum { 1.41 + public double[] getEnergy() { 1.42 + return new double[0]; 1.43 + } 1.44 + } 1.45 + 1.46 + protected Spectrum spectrum; 1.47 + 1.48 + public static class Ref<T> { 1.49 + 1.50 + T value; 1.51 + 1.52 + public Ref() { 1.53 + } 1.54 + 1.55 + public Ref(T value) { 1.56 + this.value = value; 1.57 + } 1.58 + 1.59 + public boolean isNull() { 1.60 + return value == null; 1.61 + } 1.62 + 1.63 + public T get() { 1.64 + return value; 1.65 + } 1.66 + 1.67 + public void set(T value) { 1.68 + this.value = value; 1.69 + } 1.70 + } 1.71 + 1.72 + public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) { 1.73 + Ref<Double> max = new Ref<>(); 1.74 + Ref<T> index = new Ref<>(); 1.75 + stream.forEach(v -> { 1.76 + Double value = function.apply(v); 1.77 + 1.78 + if (max.isNull() || value > max.get()) { 1.79 + max.set(value); 1.80 + index.set(v); 1.81 + } 1.82 + }); 1.83 + 1.84 + return index.get(); 1.85 + } 1.86 + 1.87 + public static int interpolate(int x, int x0, int x1, int y0, int y1) { 1.88 + return y0 + (x - x0) * (y1 - y0) / (x1 - x0); 1.89 + } 1.90 + 1.91 + public static double interpolate(double x, double x0, double x1, double y0, double y1) { 1.92 + return y0 + (x - x0) * (y1 - y0) / (x1 - x0); 1.93 + } 1.94 + 1.95 + protected int getXByFrequency(double frequency) { 1.96 + return (int) Math.round(interpolate(frequency, 1.97 + getMinSpectrumCoord(), 1.98 + getMaxSpectrumCoord(), 1.99 + 0, getWidth())); 1.100 + } 1.101 + 1.102 + private int getWidth() { 1.103 + return 0; 1.104 + } 1.105 + 1.106 + private double getMaxSpectrumCoord() { 1.107 + return 0; 1.108 + } 1.109 + 1.110 + private double getMinSpectrumCoord() { 1.111 + return 0; 1.112 + } 1.113 + 1.114 + void foo() { 1.115 + int maxBpmIndex = 0; 1.116 + int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(), 1.117 + i -> Math.abs(spectrum.getEnergy()[i]))); 1.118 + } 1.119 + 1.120 + public static void main(String [] args) { 1.121 + } 1.122 +}