comparison flys-artifacts/src/main/java/de/intevation/flys/utils/DateAverager.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents d520a0869972
children
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.utils;
2
3 import gnu.trove.TLongArrayList;
4
5 import java.util.Date;
6
7 public class DateAverager
8 {
9 protected TLongArrayList dates;
10
11 public DateAverager() {
12 dates = new TLongArrayList();
13 }
14
15 public void add(Date date) {
16 dates.add(date.getTime());
17 }
18
19 public Date getAverage() {
20 int N = dates.size();
21 if (N == 0) {
22 return null;
23 }
24 long min = dates.min();
25 long sum = 0L;
26 for (int i = 0; i < N; ++i) {
27 sum += dates.getQuick(i) - min;
28 }
29 return new Date(min + (long)Math.round(sum/(double)N));
30 }
31
32 public void clear() {
33 dates.resetQuick();
34 }
35 }
36 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org