T8068399.java revision 3170:dc017a37aac5
140516Swpaul/* 240516Swpaul * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 340516Swpaul * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 440516Swpaul * 540516Swpaul * This code is free software; you can redistribute it and/or modify it 640516Swpaul * under the terms of the GNU General Public License version 2 only, as 740516Swpaul * published by the Free Software Foundation. 840516Swpaul * 940516Swpaul * This code is distributed in the hope that it will be useful, but WITHOUT 1040516Swpaul * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1140516Swpaul * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1240516Swpaul * version 2 for more details (a copy is included in the LICENSE file that 1340516Swpaul * accompanied this code). 1440516Swpaul * 1540516Swpaul * You should have received a copy of the GNU General Public License version 1640516Swpaul * 2 along with this work; if not, write to the Free Software Foundation, 1740516Swpaul * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1840516Swpaul * 1940516Swpaul * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2040516Swpaul * or visit www.oracle.com if you need additional information or have any 2140516Swpaul * questions. 2240516Swpaul */ 2340516Swpaul 2440516Swpaul/* 2540516Swpaul * @test 2640516Swpaul * @bug 8068399 8069545 2740516Swpaul * @summary structural most specific and stuckness 2840516Swpaul */ 2940516Swpaul 3040516Swpaulimport java.util.function.Function; 3140516Swpaulimport java.util.stream.IntStream; 3250477Speterimport java.util.stream.Stream; 3340516Swpaul 3440516Swpaulpublic class T8068399 { 3540516Swpaul 3640516Swpaul public static class Spectrum { 3740516Swpaul public double[] getEnergy() { 3840516Swpaul return new double[0]; 3940516Swpaul } 4040516Swpaul } 4140516Swpaul 4240516Swpaul protected Spectrum spectrum; 4340516Swpaul 4440516Swpaul public static class Ref<T> { 4540516Swpaul 4640516Swpaul T value; 4740516Swpaul 4840516Swpaul public Ref() { 4940516Swpaul } 5040516Swpaul 5140516Swpaul public Ref(T value) { 5240516Swpaul this.value = value; 5340516Swpaul } 5440516Swpaul 5540516Swpaul public boolean isNull() { 5641569Swpaul return value == null; 5740516Swpaul } 5840516Swpaul 5940516Swpaul public T get() { 6040516Swpaul return value; 6140516Swpaul } 6240516Swpaul 6340516Swpaul public void set(T value) { 6440516Swpaul this.value = value; 6540516Swpaul } 6640516Swpaul } 6740516Swpaul 6840516Swpaul public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) { 6940516Swpaul Ref<Double> max = new Ref<>(); 7040516Swpaul Ref<T> index = new Ref<>(); 7140516Swpaul stream.forEach(v -> { 7240516Swpaul Double value = function.apply(v); 7340516Swpaul 7440516Swpaul if (max.isNull() || value > max.get()) { 7540516Swpaul max.set(value); 7640516Swpaul index.set(v); 7740516Swpaul } 7840516Swpaul }); 7940516Swpaul 8040516Swpaul return index.get(); 8140516Swpaul } 8240516Swpaul 8340516Swpaul public static int interpolate(int x, int x0, int x1, int y0, int y1) { 8440516Swpaul return y0 + (x - x0) * (y1 - y0) / (x1 - x0); 8540516Swpaul } 8648645Sdes 8740516Swpaul public static double interpolate(double x, double x0, double x1, double y0, double y1) { 8840516Swpaul return y0 + (x - x0) * (y1 - y0) / (x1 - x0); 8940516Swpaul } 9050135Smsmith 9140516Swpaul protected int getXByFrequency(double frequency) { 9240516Swpaul return (int) Math.round(interpolate(frequency, 9340516Swpaul getMinSpectrumCoord(), 9440516Swpaul getMaxSpectrumCoord(), 9540516Swpaul 0, getWidth())); 9640516Swpaul } 9740516Swpaul 9840516Swpaul private int getWidth() { 9940516Swpaul return 0; 10040516Swpaul } 10140516Swpaul 10240516Swpaul private double getMaxSpectrumCoord() { 10348645Sdes return 0; 10440516Swpaul } 10540516Swpaul 10640516Swpaul private double getMinSpectrumCoord() { 10740516Swpaul return 0; 10840516Swpaul } 10940516Swpaul 11041569Swpaul void foo() { 11141569Swpaul int maxBpmIndex = 0; 11241569Swpaul int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(), 11340516Swpaul i -> Math.abs(spectrum.getEnergy()[i]))); 11440516Swpaul } 11540516Swpaul 11640516Swpaul public static void main(String [] args) { 11740516Swpaul } 11840516Swpaul} 11940516Swpaul