Example usage for org.jfree.data KeyedValues getValue

List of usage examples for org.jfree.data KeyedValues getValue

Introduction

In this page you can find the example usage for org.jfree.data KeyedValues getValue.

Prototype

public Number getValue(Comparable key);

Source Link

Document

Returns the value for a given key.

Usage

From source file:org.jfree.data.DataUtils.java

/**
 * Returns a {@link KeyedValues} instance that contains the cumulative
 * percentage values for the data in another {@link KeyedValues} instance.
 * <p>/*  w  w  w  .j a v a2s . c o m*/
 * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%).
 *
 * @param data  the data ({@code null} not permitted).
 *
 * @return The cumulative percentages.
 */
public static KeyedValues getCumulativePercentages(KeyedValues data) {
    Args.nullNotPermitted(data, "data");
    DefaultKeyedValues result = new DefaultKeyedValues();
    double total = 0.0;
    for (int i = 0; i < data.getItemCount(); i++) {
        Number v = data.getValue(i);
        if (v != null) {
            total = total + v.doubleValue();
        }
    }
    double runningTotal = 0.0;
    for (int i = 0; i < data.getItemCount(); i++) {
        Number v = data.getValue(i);
        if (v != null) {
            runningTotal = runningTotal + v.doubleValue();
        }
        result.addValue(data.getKey(i), new Double(runningTotal / total));
    }
    return result;
}

From source file:org.jfree.data.DataUtilities.java

/**
 * Returns a {@link KeyedValues} instance that contains the cumulative
 * percentage values for the data in another {@link KeyedValues} instance.
 * <p>//  w ww.j  av  a  2  s. co  m
 * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%).
 *
 * @param data  the data (<code>null</code> not permitted).
 *
 * @return The cumulative percentages.
 */
public static KeyedValues getCumulativePercentages(KeyedValues data) {
    ParamChecks.nullNotPermitted(data, "data");
    DefaultKeyedValues result = new DefaultKeyedValues();
    double total = 0.0;
    for (int i = 0; i < data.getItemCount(); i++) {
        Number v = data.getValue(i);
        if (v != null) {
            total = total + v.doubleValue();
        }
    }
    double runningTotal = 0.0;
    for (int i = 0; i < data.getItemCount(); i++) {
        Number v = data.getValue(i);
        if (v != null) {
            runningTotal = runningTotal + v.doubleValue();
        }
        result.addValue(data.getKey(i), new Double(runningTotal / total));
    }
    return result;
}

From source file:org.jfree.data.general.DefaultPieDataset.java

/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance./*from   w  w  w .jav a  2  s. co m*/
 *
 * @param data  the data (<code>null</code> not permitted).
 */
public DefaultPieDataset(KeyedValues data) {
    ParamChecks.nullNotPermitted(data, "data");
    this.data = new DefaultKeyedValues();
    for (int i = 0; i < data.getItemCount(); i++) {
        this.data.addValue(data.getKey(i), data.getValue(i));
    }
}

From source file:org.jfree.data.pie.DefaultPieDataset.java

/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance./*from  w ww  . j  a  v  a2 s  .  com*/
 *
 * @param data  the data (<code>null</code> not permitted).
 */
public DefaultPieDataset(KeyedValues data) {
    if (data == null) {
        throw new IllegalArgumentException("Null 'data' argument.");
    }
    this.data = new KeyedObjects();
    for (int i = 0; i < data.getItemCount(); i++) {
        SelectableValue dataItem = new SelectableValue(data.getValue(i));
        this.data.addObject(data.getKey(i), dataItem);
    }
}

From source file:org.jfree.data.DefaultKeyedValues.java

/**
 * Tests if this object is equal to another.
 *
 * @param obj  the object (<code>null</code> permitted).
 *
 * @return A boolean.//from   w  w  w. ja  v a 2 s . c  o m
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }

    if (!(obj instanceof KeyedValues)) {
        return false;
    }

    KeyedValues that = (KeyedValues) obj;
    int count = getItemCount();
    if (count != that.getItemCount()) {
        return false;
    }

    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }
        Number v1 = getValue(i);
        Number v2 = that.getValue(i);
        if (v1 == null) {
            if (v2 != null) {
                return false;
            }
        } else {
            if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;
}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Creates a {@link CategoryDataset} by copying the data from the supplied
 * {@link KeyedValues} instance./*  w  ww.  j  a  v a  2 s. co  m*/
 *
 * @param rowKey  the row key ({@code null} not permitted).
 * @param rowData  the row data ({@code null} not permitted).
 *
 * @return A dataset.
 */
public static CategoryDataset createCategoryDataset(Comparable rowKey, KeyedValues rowData) {

    Args.nullNotPermitted(rowKey, "rowKey");
    Args.nullNotPermitted(rowData, "rowData");
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    for (int i = 0; i < rowData.getItemCount(); i++) {
        result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i));
    }
    return result;

}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates a {@link CategoryDataset} by copying the data from the supplied
 * {@link KeyedValues} instance.//w  w  w.  j ava2 s .co m
 *
 * @param rowKey  the row key (<code>null</code> not permitted).
 * @param rowData  the row data (<code>null</code> not permitted).
 *
 * @return A dataset.
 */
public static CategoryDataset createCategoryDataset(Comparable rowKey, KeyedValues rowData) {

    ParamChecks.nullNotPermitted(rowKey, "rowKey");
    ParamChecks.nullNotPermitted(rowData, "rowData");
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    for (int i = 0; i < rowData.getItemCount(); i++) {
        result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i));
    }
    return result;

}