// Path: lib/src/main/java/hrv/lib/common/MathUtils.java
// public class MathUtils {
// 	
// 	/**
// 	 * Makes this class a utility class.
// 	 */
// 	private MathUtils() {}
// 	
// 	/**
// 	 * Rounds the given number (value) to places places. With rounding mode half down (5.5 => 5)
// 	 * @param value Value to round
// 	 * @param places Number of places the given number should be rounded to
// 	 * @return rounded number.
// 	 */
// 	public static double round(double value, int places) {
// 	    if (places < 0) 
// 	    	throw new IllegalArgumentException();
// 
// 	    var bd = BigDecimal.valueOf(value);
// 	    bd = bd.setScale(places, RoundingMode.HALF_DOWN);
// 	    return bd.doubleValue();
// 	}
// 	
// 	public static double round(double value, int places, RoundingMode mode) {
// 	    if (places < 0) 
// 	    { throw new IllegalArgumentException(); }
// 
// 	    var bd = BigDecimal.valueOf(value);
// 	    bd = bd.setScale(places, mode);
// 	    return bd.doubleValue();
// 	}
// 	
// 	/**
// 	 * Returns the largest number that is a power of two 
// 	 * and smaller than the given number (n) 
// 	 * @param n given number 
// 	 * @return the largest number that is a power of two 
// 	 * and smaller than the given number (n)
// 	 */
// 	public static int largestNumThatIsPowerOf2(int n) {
// 		return Integer.highestOneBit(n);
// 	}
// 	
// 	public static boolean almostEqual(double a, double b, double eps){
// 	    return Math.abs(a-b)<eps;
// 	}
// 	
// 	public static double[] calculateAverageArray(double[] values, int range) {
// 		var averages = new double[values.length];
// 		for(var i = 0; i < values.length; i++){
// 			
// 			int leftStart = i < range ? -i : -range;
// 			var count = 0;
// 			for(int j = leftStart; j < 0; j++) {
// 				averages[i] += values[i + j];
// 				count++;
// 			}
// 			
// 			int rightEnd = i + (range + 1) > values.length ? (values.length - i) : range + 1;
// 			for(var j = 1; j < rightEnd; j++) {
// 				averages[i] += values[i + j];
// 				count++;
// 			}
// 			
// 			if(count != 0) {
// 				averages[i] = averages[i] / count;
// 			} 			 
// 		}			
// 		
// 		return averages;
// 	}
// }
// 
// Path: lib/src/main/java/hrv/lib/hrv/RRData.java
// public class RRData {
// 
// 	private final TimeUnit rrValueAxisUnit;
// 	private final /*@ spec_public */ TimeUnit rrTimeAxisUnit;
// 
// 	private final double[] rrValuesAxis;
// 	private final double[] rrTimeAxis;
// 
// 	public RRData(double[] timeAxis, TimeUnit timeAxisUnit, double[] valueAxis, TimeUnit valueAxisUnit) {
// 		this.rrValuesAxis = valueAxis;
// 		this.rrValueAxisUnit = valueAxisUnit;
// 
// 		this.rrTimeAxis = timeAxis;
// 		this.rrTimeAxisUnit = timeAxisUnit;
// 	}
// 
// 	/**
// 	 * Creates a new RRData object from an RR-Interval
// 	 * 
// 	 * @param rrInterval
// 	 *            RR-Interval
// 	 * @param unit
// 	 *            of the given RR-Data.
// 	 * @return new RRData object with given RR-Interval data.
// 	 */
// 	public static RRData createFromRRInterval(double[] rrInterval, TimeUnit unit) {
// 		var rrTimeAxis = new double[rrInterval.length];
// 		for (var i = 1; i < rrInterval.length; i++) {
// 			rrTimeAxis[i] = rrTimeAxis[i - 1] + rrInterval[i - 1];
// 		}
// 
// 		return new RRData(rrTimeAxis, unit, rrInterval, unit);
// 	}
// 
// 	public double[] getValueAxis() {
// 		return rrValuesAxis;
// 	}
// 
// 	public double[] getTimeAxis() {
// 		return rrTimeAxis;
// 	}
// 	
// 	public TimeUnit getValueAxisUnit() {
// 		return rrValueAxisUnit;
// 	}
// 
// 	public TimeUnit getTimeAxisUnit() {
// 		return rrTimeAxisUnit;
// 	}
// }


import hrv.lib.common.MathUtils;
import hrv.lib.hrv.RRData;
package hrv.lib.hrv.calc.manipulator;


/**
 * Cuts the given data down, so that the resulting length of the data is a power of two.
 * 
 * @author Julian
 *
 */
public class HRVCutToPowerTwoDataManipulator implements HRVDataManipulator {

	@Override
	public RRData manipulate(RRData data) {
// Path: lib/src/main/java/hrv/lib/common/MathUtils.java
// public class MathUtils {
// 	
// 	/**
// 	 * Makes this class a utility class.
// 	 */
// 	private MathUtils() {}
// 	
// 	/**
// 	 * Rounds the given number (value) to places places. With rounding mode half down (5.5 => 5)
// 	 * @param value Value to round
// 	 * @param places Number of places the given number should be rounded to
// 	 * @return rounded number.
// 	 */
// 	public static double round(double value, int places) {
// 	    if (places < 0) 
// 	    	throw new IllegalArgumentException();
// 
// 	    var bd = BigDecimal.valueOf(value);
// 	    bd = bd.setScale(places, RoundingMode.HALF_DOWN);
// 	    return bd.doubleValue();
// 	}
// 	
// 	public static double round(double value, int places, RoundingMode mode) {
// 	    if (places < 0) 
// 	    { throw new IllegalArgumentException(); }
// 
// 	    var bd = BigDecimal.valueOf(value);
// 	    bd = bd.setScale(places, mode);
// 	    return bd.doubleValue();
// 	}
// 	
// 	/**
// 	 * Returns the largest number that is a power of two 
// 	 * and smaller than the given number (n) 
// 	 * @param n given number 
// 	 * @return the largest number that is a power of two 
// 	 * and smaller than the given number (n)
// 	 */
// 	public static int largestNumThatIsPowerOf2(int n) {
// 		return Integer.highestOneBit(n);
// 	}
// 	
// 	public static boolean almostEqual(double a, double b, double eps){
// 	    return Math.abs(a-b)<eps;
// 	}
// 	
// 	public static double[] calculateAverageArray(double[] values, int range) {
// 		var averages = new double[values.length];
// 		for(var i = 0; i < values.length; i++){
// 			
// 			int leftStart = i < range ? -i : -range;
// 			var count = 0;
// 			for(int j = leftStart; j < 0; j++) {
// 				averages[i] += values[i + j];
// 				count++;
// 			}
// 			
// 			int rightEnd = i + (range + 1) > values.length ? (values.length - i) : range + 1;
// 			for(var j = 1; j < rightEnd; j++) {
// 				averages[i] += values[i + j];
// 				count++;
// 			}
// 			
// 			if(count != 0) {
// 				averages[i] = averages[i] / count;
// 			} 			 
// 		}			
// 		
// 		return averages;
// 	}
// }
// 
// Path: lib/src/main/java/hrv/lib/hrv/RRData.java
// public class RRData {
// 
// 	private final TimeUnit rrValueAxisUnit;
// 	private final /*@ spec_public */ TimeUnit rrTimeAxisUnit;
// 
// 	private final double[] rrValuesAxis;
// 	private final double[] rrTimeAxis;
// 
// 	public RRData(double[] timeAxis, TimeUnit timeAxisUnit, double[] valueAxis, TimeUnit valueAxisUnit) {
// 		this.rrValuesAxis = valueAxis;
// 		this.rrValueAxisUnit = valueAxisUnit;
// 
// 		this.rrTimeAxis = timeAxis;
// 		this.rrTimeAxisUnit = timeAxisUnit;
// 	}
// 
// 	/**
// 	 * Creates a new RRData object from an RR-Interval
// 	 * 
// 	 * @param rrInterval
// 	 *            RR-Interval
// 	 * @param unit
// 	 *            of the given RR-Data.
// 	 * @return new RRData object with given RR-Interval data.
// 	 */
// 	public static RRData createFromRRInterval(double[] rrInterval, TimeUnit unit) {
// 		var rrTimeAxis = new double[rrInterval.length];
// 		for (var i = 1; i < rrInterval.length; i++) {
// 			rrTimeAxis[i] = rrTimeAxis[i - 1] + rrInterval[i - 1];
// 		}
// 
// 		return new RRData(rrTimeAxis, unit, rrInterval, unit);
// 	}
// 
// 	public double[] getValueAxis() {
// 		return rrValuesAxis;
// 	}
// 
// 	public double[] getTimeAxis() {
// 		return rrTimeAxis;
// 	}
// 	
// 	public TimeUnit getValueAxisUnit() {
// 		return rrValueAxisUnit;
// 	}
// 
// 	public TimeUnit getTimeAxisUnit() {
// 		return rrTimeAxisUnit;
// 	}
// }


// Path: lib/src/main/java/hrv/lib/hrv/calc/manipulator/HRVCutToPowerTwoDataManipulator.java
import hrv.lib.common.MathUtils;
import hrv.lib.hrv.RRData;

package hrv.lib.hrv.calc.manipulator;


/**
 * Cuts the given data down, so that the resulting length of the data is a power of two.
 * 
 * @author Julian
 *
 */
public class HRVCutToPowerTwoDataManipulator implements HRVDataManipulator {

	@Override
	public RRData manipulate(RRData data) {
		int cutAt = MathUtils.largestNumThatIsPowerOf2(data.getTimeAxis().length);