2 // Getdown - application installer, patcher and launcher
3 // Copyright (C) 2004-2018 Getdown authors
4 // https://github.com/threerings/getdown/blob/master/LICENSE
6 package com.threerings.getdown.util;
9 * Accumulates the progress from a number of (potentially parallel) elements into a single smoothly
10 * progressing progress.
12 public class ProgressAggregator
14 public ProgressAggregator (ProgressObserver target, long[] sizes) {
17 _progress = new int[sizes.length];
20 public ProgressObserver startElement (final int index) {
21 return new ProgressObserver() {
22 public void progress (int percent) {
23 _progress[index] = percent;
29 protected void updateAggProgress () {
30 long totalSize = 0L, currentSize = 0L;
32 for (int ii = 0, ll = _sizes.length; ii < ll; ii++) {
33 long size = _sizes[ii];
35 currentSize += (int)((size * _progress[ii])/100.0);
38 _target.progress((int)(100.0*currentSize / totalSize));
41 protected static long sum (long[] sizes) {
43 for (long size : sizes) totalSize += size;
47 protected ProgressObserver _target;
48 protected long[] _sizes;
49 protected int[] _progress;