All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kg.apc.charting.rows.GraphRowOverallAverages Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package kg.apc.charting.rows;

import kg.apc.charting.AbstractGraphRow;
import kg.apc.charting.elements.GraphPanelChartAverageElement;
import kg.apc.charting.AbstractGraphPanelChartElement;
import java.util.Iterator;
import java.util.Map.Entry;

public class GraphRowOverallAverages
        extends AbstractGraphRow
        implements Iterator>,
        Entry {

    private boolean hasNext;
    private GraphPanelChartAverageElement element;
    private double avgX = 0;

    /**
     *
     */
    public GraphRowOverallAverages() {
        super();
        element = new GraphPanelChartAverageElement();
        hasNext = true;
    }

    /**
     *
     * @param xVal
     * @param yVal
     */
    @Override
    public void add(long xVal, double yVal) {
        avgX = (avgX * element.getCount() + xVal) / (element.getCount() + 1);
        element.add(yVal);

        super.add((long) avgX, element.getValue());
    }

    /**
     *
     * @return
     */
    public Iterator> iterator() {
        hasNext = true;
        return this;
    }

    public boolean hasNext() {
        return hasNext;
    }

    public Entry next() {
        hasNext = false;
        return this;
    }

    public void remove() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Long getKey() {
        return Math.round(avgX);
    }

    public GraphPanelChartAverageElement getValue() {
        return element;
    }

    public AbstractGraphPanelChartElement setValue(AbstractGraphPanelChartElement value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int size() {
        return 1;
    }

    @Override
    public AbstractGraphPanelChartElement getElement(long value) {
        if (getKey() == value) {
            return element;
        } else {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy