diff options
Diffstat (limited to 'systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/aggregates/SumAggregate.java')
-rw-r--r-- | systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/aggregates/SumAggregate.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/aggregates/SumAggregate.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/aggregates/SumAggregate.java new file mode 100644 index 0000000000..09a3bb23ec --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/aggregates/SumAggregate.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse + *******************************************************************************/ + +package org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates; + +import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.NumberType; + +public class SumAggregate implements IDataAggregate { + + /** + * Ensure column isn't empty, then get the sum total of all the column's values. + * + * @param column The column to total. + * + * @return The sum total of all the column's values. + */ + public Number aggregate(Number[] column) { + if(column == null || column.length == 0) + return null; + + double num = 0; + + for(int i=0; i<column.length; i++) + num += column[i].doubleValue(); + + return NumberType.getNumber(column[0], num); + } + + public String getID() { + return ID; + } + + public static final String ID = "org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.aggregates.SumAggregate"; +} |