Here you can find the source of getAverageInterval(List
Parameter | Description |
---|---|
tapTimestamps | the list of timestamps |
n | the number of timestamp intervals we'd like to use for the calculation. |
public static long getAverageInterval(List<Long> tapTimestamps, int n)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**/*w ww . j av a 2 s .c om*/ * Calculates the average difference between the last n timestamp intervals of the input array. The assumption is that the list of timestamps is increasing. * * @param tapTimestamps * the list of timestamps * @param n * the number of timestamp intervals we'd like to use for the calculation. * @return the average interval between the considered values */ public static long getAverageInterval(List<Long> tapTimestamps, int n) { long result = 0; int start = tapTimestamps.size() - (n + 1); if (start < 0) { start = 0; n = tapTimestamps.size() - 1; } if (n == 0) { return 0; } for (int i = start; i < tapTimestamps.size() - 1; i++) { result += Math.abs(tapTimestamps.get(i + 1) - tapTimestamps.get(i)); } return (result / n); } }