Example usage for org.jfree.data KeyedObjects2D getColumnCount

List of usage examples for org.jfree.data KeyedObjects2D getColumnCount

Introduction

In this page you can find the example usage for org.jfree.data KeyedObjects2D getColumnCount.

Prototype

public int getColumnCount() 

Source Link

Document

Returns the column count.

Usage

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

/**
 * Some checks for the removeColumn(int) method.
 *///from w  w  w .j  a  va2 s  .  com
@Test
public void testRemoveColumnByIndex() {
    KeyedObjects2D data = new KeyedObjects2D();
    data.setObject("Obj1", "R1", "C1");
    data.setObject("Obj2", "R2", "C2");
    data.removeColumn(0);
    assertEquals(1, data.getColumnCount());
    assertEquals("Obj2", data.getObject(1, 0));

    // try negative column index
    boolean pass = false;
    try {
        data.removeColumn(-1);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);

    // try column index too high
    pass = false;
    try {
        data.removeColumn(data.getColumnCount());
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the removeColumn(Comparable) method.
 *///from w w  w  . ja  v  a  2  s .co m
@Test
public void testRemoveColumnByKey() {
    KeyedObjects2D data = new KeyedObjects2D();
    data.setObject("Obj1", "R1", "C1");
    data.setObject("Obj2", "R2", "C2");
    data.removeColumn("C2");
    assertEquals(1, data.getColumnCount());
    assertEquals("Obj1", data.getObject(0, 0));

    // try unknown column key
    boolean pass = false;
    try {
        data.removeColumn("XXX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    // try null column key
    pass = false;
    try {
        data.removeColumn(null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * A simple check for the removeValue() method.
 *//*w  w w .  ja  v a  2 s . c o m*/
@Test
public void testRemoveValue() {
    KeyedObjects2D data = new KeyedObjects2D();
    data.setObject("Obj1", "R1", "C1");
    data.setObject("Obj2", "R2", "C2");
    data.removeObject("R2", "C2");
    assertEquals(1, data.getRowCount());
    assertEquals(1, data.getColumnCount());
    assertEquals("Obj1", data.getObject(0, 0));
}

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

/**
 * Tests this object for equality with an arbitrary object.
 *
 * @param obj  the object to test (<code>null</code> permitted).
 *
 * @return A boolean.//w ww. j  a  v  a 2  s  .  c  o m
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof KeyedObjects2D)) {
        return false;
    }

    KeyedObjects2D that = (KeyedObjects2D) obj;
    if (!getRowKeys().equals(that.getRowKeys())) {
        return false;
    }
    if (!getColumnKeys().equals(that.getColumnKeys())) {
        return false;
    }
    int rowCount = getRowCount();
    if (rowCount != that.getRowCount()) {
        return false;
    }
    int colCount = getColumnCount();
    if (colCount != that.getColumnCount()) {
        return false;
    }
    for (int r = 0; r < rowCount; r++) {
        for (int c = 0; c < colCount; c++) {
            Object v1 = getObject(r, c);
            Object v2 = that.getObject(r, c);
            if (v1 == null) {
                if (v2 != null) {
                    return false;
                }
            } else {
                if (!v1.equals(v2)) {
                    return false;
                }
            }
        }
    }
    return true;
}