org.jfree.data.DefaultKeyedValues Java Examples

The following examples show how to use org.jfree.data.DefaultKeyedValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() methods.
 */
public void testGetIndex() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    assertEquals(-1, v1.getIndex("K1"));

    DefaultKeyedValues v2 = new DefaultKeyedValues();
    v2.addValue("K1", new Integer(1));
    v2.addValue("K2", new Integer(2));
    v2.addValue("K3", new Integer(3));
    assertEquals(2, v2.getIndex("K3"));
    
    // try null
    boolean pass = false;
    try {
        v2.getIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #2
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some tests for the removeValue() method.
 */
public void testRemoveValue() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("A", new Double(1.0));
    data.addValue("B", null);
    data.addValue("C", new Double(3.0));
    data.addValue("D", new Double(2.0));
    assertEquals(1, data.getIndex("B"));
    data.removeValue("B");
    assertEquals(-1, data.getIndex("B"));
    
    boolean pass = false;
    try {
        data.removeValue("XXX");
    }
    catch (UnknownKeyException e) {
        pass = true;   
    }
    assertTrue(pass);
}
 
Example #3
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getKeys() method.
 */
public void testGetKeys() {
    DefaultKeyedValues d = new DefaultKeyedValues();
    List keys = d.getKeys();
    assertTrue(keys.isEmpty());
    d.addValue("A", 1.0);
    keys = d.getKeys();
    assertEquals(1, keys.size());
    assertTrue(keys.contains("A"));
    d.addValue("B", 2.0);
    keys = d.getKeys();
    assertEquals(2, keys.size());
    assertTrue(keys.contains("A"));
    assertTrue(keys.contains("B"));
    d.clear();
    keys = d.getKeys();
    assertEquals(0, keys.size());
}
 
Example #4
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() methods.
 */
public void testGetIndex() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    assertEquals(-1, v1.getIndex("K1"));

    DefaultKeyedValues v2 = new DefaultKeyedValues();
    v2.addValue("K1", new Integer(1));
    v2.addValue("K2", new Integer(2));
    v2.addValue("K3", new Integer(3));
    assertEquals(2, v2.getIndex("K3"));

    // try null
    boolean pass = false;
    try {
        v2.getIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #5
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the addValue() method.
 */
public void testAddValue() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("A", 1.0);
    assertEquals(new Double(1.0), v1.getValue("A"));
    v1.addValue("B", 2.0);
    assertEquals(new Double(2.0), v1.getValue("B"));
    v1.addValue("B", 3.0);
    assertEquals(new Double(3.0), v1.getValue("B"));
    assertEquals(2, v1.getItemCount());
    v1.addValue("A", null);
    assertNull(v1.getValue("A"));
    assertEquals(2, v1.getItemCount());

    boolean pass = false;
    try {
        v1.addValue(null, 99.9);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #6
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the insertValue() method.
 */
public void testInsertValue() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.insertValue(0, "A", 1.0);
    assertEquals(new Double(1.0), v1.getValue(0));
    v1.insertValue(0, "B", 2.0);
    assertEquals(new Double(2.0), v1.getValue(0));
    assertEquals(new Double(1.0), v1.getValue(1));

    // it's OK to use an index equal to the size of the list
    v1.insertValue(2, "C", 3.0);
    assertEquals(new Double(2.0), v1.getValue(0));
    assertEquals(new Double(1.0), v1.getValue(1));
    assertEquals(new Double(3.0), v1.getValue(2));

    // try replacing an existing value
    v1.insertValue(2, "B", 4.0);
    assertEquals(new Double(1.0), v1.getValue(0));
    assertEquals(new Double(3.0), v1.getValue(1));
    assertEquals(new Double(4.0), v1.getValue(2));
}
 
Example #7
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that inserting and retrieving values works as expected.
 */
public void testInsertAndRetrieve() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("A", new Double(1.0));
    data.addValue("B", new Double(2.0));
    data.addValue("C", new Double(3.0));
    data.addValue("D", null);

    // check key order
    assertEquals(data.getKey(0), "A");
    assertEquals(data.getKey(1), "B");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "D");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(1.0));
    assertEquals(data.getValue("B"), new Double(2.0));
    assertEquals(data.getValue("C"), new Double(3.0));
    assertEquals(data.getValue("D"), null);

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(1.0));
    assertEquals(data.getValue(1), new Double(2.0));
    assertEquals(data.getValue(2), new Double(3.0));
    assertEquals(data.getValue(3), null);
}
 
Example #8
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some tests for the removeValue() method.
 */
public void testRemoveValue() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("A", new Double(1.0));
    data.addValue("B", null);
    data.addValue("C", new Double(3.0));
    data.addValue("D", new Double(2.0));
    assertEquals(1, data.getIndex("B"));
    data.removeValue("B");
    assertEquals(-1, data.getIndex("B"));

    boolean pass = false;
    try {
        data.removeValue("XXX");
    }
    catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #9
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the insertValue() method.
 */
public void testInsertValue() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.insertValue(0, "A", 1.0);
    assertEquals(new Double(1.0), v1.getValue(0));
    v1.insertValue(0, "B", 2.0);
    assertEquals(new Double(2.0), v1.getValue(0));
    assertEquals(new Double(1.0), v1.getValue(1));
    
    // it's OK to use an index equal to the size of the list
    v1.insertValue(2, "C", 3.0);
    assertEquals(new Double(2.0), v1.getValue(0));
    assertEquals(new Double(1.0), v1.getValue(1));
    assertEquals(new Double(3.0), v1.getValue(2));
    
    // try replacing an existing value
    v1.insertValue(2, "B", 4.0);
    assertEquals(new Double(1.0), v1.getValue(0));
    assertEquals(new Double(3.0), v1.getValue(1));
    assertEquals(new Double(4.0), v1.getValue(2));
}
 
Example #10
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the addValue() method.
 */
public void testAddValue() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("A", 1.0);
    assertEquals(new Double(1.0), v1.getValue("A"));
    v1.addValue("B", 2.0);
    assertEquals(new Double(2.0), v1.getValue("B"));
    v1.addValue("B", 3.0);
    assertEquals(new Double(3.0), v1.getValue("B"));
    assertEquals(2, v1.getItemCount());
    v1.addValue("A", null);
    assertNull(v1.getValue("A"));
    assertEquals(2, v1.getItemCount());
    
    boolean pass = false;
    try {
        v1.addValue(null, 99.9);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #11
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getKeys() method.
 */
public void testGetKeys() {
    DefaultKeyedValues d = new DefaultKeyedValues();
    List keys = d.getKeys();
    assertTrue(keys.isEmpty());
    d.addValue("A", 1.0);
    keys = d.getKeys();
    assertEquals(1, keys.size());
    assertTrue(keys.contains("A"));
    d.addValue("B", 2.0);
    keys = d.getKeys();
    assertEquals(2, keys.size());
    assertTrue(keys.contains("A"));
    assertTrue(keys.contains("B"));
    d.clear();
    keys = d.getKeys();
    assertEquals(0, keys.size());        
}
 
Example #12
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A simple test for the clear() method.
 */
public void testClear() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("A", 1.0);
    v1.addValue("B", 2.0);
    assertEquals(2, v1.getItemCount());
    v1.clear();
    assertEquals(0, v1.getItemCount());
}
 
Example #13
Source File: GraphPieDataset.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Remplit le Dataset avec les valeurs de la collection de MarkerStat.
 *
 * @param stats
 *          the Checkstyle violation stats
 */
public void setStats(Stats stats) {

  Collection<MarkerStat> markerStatCollection = stats != null ? stats.getMarkerStats()
          : Collections.emptyList();
  mData = new DefaultKeyedValues();

  // markers que l'on comptera dans une catégorie "Autres" car ils
  // représentent trop peu de %
  int leftCount = 0;
  float mCount = stats.getMarkerCount();
  // et on remplit
  for (Iterator<MarkerStat> iter = markerStatCollection.iterator(); iter.hasNext();) {
    MarkerStat markerStat = iter.next();

    // on calcule le %
    float percentage = CENT * markerStat.getCount() / mCount;
    if (mShowAllCategories) {
      setValue(markerStat.getIdentifiant(), percentage);
    } else {
      // on ne veut pas montrer toutes les catégories : on fait le tri
      if (percentage > POURCENTAGE_MIN) {
        setValue(markerStat.getIdentifiant(), percentage);
      } else {
        leftCount += markerStat.getCount();
      }
    }
  }
  if (!mShowAllCategories && leftCount != 0) {
    // on ne veut pas montrer toutes les catégories, et certaines
    // n'ont pas été prises en compte : on les mets dans "Autres"
    setValue(Messages.GraphPieDataset_otherCategories, CENT * leftCount / mCount);
  }
  fireDatasetChanged();
}
 
Example #14
Source File: DefaultPieDataset.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance.
 *
 * @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));
    }
}
 
Example #15
Source File: DefaultPieDataset.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance.
 *
 * @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));
    }
}
 
Example #16
Source File: DefaultPieDataset.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance.
 *
 * @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));
    }
}
 
Example #17
Source File: DefaultPieDataset.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues} 
 * instance.
 *
 * @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 DefaultKeyedValues();
    for (int i = 0; i < data.getItemCount(); i++) {
        this.data.addValue(data.getKey(i), data.getValue(i));
    }
}
 
Example #18
Source File: DefaultPieDataset.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance.
 *
 * @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));
    }
}
 
Example #19
Source File: DefaultPieDataset.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues} 
 * instance.
 *
 * @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 DefaultKeyedValues();
    for (int i = 0; i < data.getItemCount(); i++) {
        this.data.addValue(data.getKey(i), data.getValue(i));
    }
}
 
Example #20
Source File: DefaultPieDataset.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new dataset by copying data from a {@link KeyedValues}
 * instance.
 *
 * @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));
    }
}
 
Example #21
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Another check for the getIndex(Comparable) method.
 */
public void testGetIndex2() {
	DefaultKeyedValues v = new DefaultKeyedValues();
	assertEquals(-1, v.getIndex("K1"));
	v.addValue("K1", 1.0);
	assertEquals(0, v.getIndex("K1"));
	v.removeValue("K1");
	assertEquals(-1, v.getIndex("K1"));
}
 
Example #22
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getItemCount() method.
 */
public void testGetItemCount() {
    DefaultKeyedValues d = new DefaultKeyedValues();
    assertEquals(0, d.getItemCount());
    d.addValue("A", 1.0);
    assertEquals(1, d.getItemCount());
    d.addValue("B", 2.0);
    assertEquals(2, d.getItemCount());
    d.clear();
    assertEquals(0, d.getItemCount());
}
 
Example #23
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests sorting of data by key (descending).
 */
public void testSortByValueDescending() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByValues(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "A");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "B");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(3.0));
    assertEquals(data.getValue(1), new Double(2.0));
    assertEquals(data.getValue(2), new Double(1.0));
    assertEquals(data.getValue(3), null);
}
 
Example #24
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A simple test for the clear() method.
 */
public void testClear() {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("A", 1.0);
    v1.addValue("B", 2.0);
    assertEquals(2, v1.getItemCount());
    v1.clear();
    assertEquals(0, v1.getItemCount());
}
 
Example #25
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Another check for the getIndex(Comparable) method.
 */
public void testGetIndex2() {
    DefaultKeyedValues v = new DefaultKeyedValues();
    assertEquals(-1, v.getIndex("K1"));
    v.addValue("K1", 1.0);
    assertEquals(0, v.getIndex("K1"));
    v.removeValue("K1");
    assertEquals(-1, v.getIndex("K1"));
}
 
Example #26
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getItemCount() method.
 */
public void testGetItemCount() {
    DefaultKeyedValues d = new DefaultKeyedValues();
    assertEquals(0, d.getItemCount());
    d.addValue("A", 1.0);
    assertEquals(1, d.getItemCount());
    d.addValue("B", 2.0);
    assertEquals(2, d.getItemCount());
    d.clear();
    assertEquals(0, d.getItemCount());        
}
 
Example #27
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that inserting and retrieving values works as expected.
 */
public void testInsertAndRetrieve() {

    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("A", new Double(1.0));
    data.addValue("B", new Double(2.0));
    data.addValue("C", new Double(3.0));
    data.addValue("D", null);

    // check key order
    assertEquals(data.getKey(0), "A");
    assertEquals(data.getKey(1), "B");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "D");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(1.0));
    assertEquals(data.getValue("B"), new Double(2.0));
    assertEquals(data.getValue("C"), new Double(3.0));
    assertEquals(data.getValue("D"), null);

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(1.0));
    assertEquals(data.getValue(1), new Double(2.0));
    assertEquals(data.getValue(2), new Double(3.0));
    assertEquals(data.getValue(3), null);

}
 
Example #28
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests sorting of data by key (ascending).
 */
public void testSortByKeyAscending() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByKeys(SortOrder.ASCENDING);

    // check key order
    assertEquals(data.getKey(0), "A");
    assertEquals(data.getKey(1), "B");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "D");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(2.0));
    assertEquals(data.getValue(1), null);
    assertEquals(data.getValue(2), new Double(1.0));
    assertEquals(data.getValue(3), new Double(3.0));
}
 
Example #29
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests sorting of data by key (descending).
 */
public void testSortByKeyDescending() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByKeys(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "C");
    assertEquals(data.getKey(2), "B");
    assertEquals(data.getKey(3), "A");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(3.0));
    assertEquals(data.getValue(1), new Double(1.0));
    assertEquals(data.getValue(2), null);
    assertEquals(data.getValue(3), new Double(2.0));
}
 
Example #30
Source File: DefaultKeyedValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests sorting of data by value (ascending).
 */
public void testSortByValueAscending() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByValues(SortOrder.ASCENDING);

    // check key order
    assertEquals(data.getKey(0), "C");
    assertEquals(data.getKey(1), "A");
    assertEquals(data.getKey(2), "D");
    assertEquals(data.getKey(3), "B");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(1.0));
    assertEquals(data.getValue(1), new Double(2.0));
    assertEquals(data.getValue(2), new Double(3.0));
    assertEquals(data.getValue(3), null);
}