Example usage for org.jfree.data KeyedObjects clone

List of usage examples for org.jfree.data KeyedObjects clone

Introduction

In this page you can find the example usage for org.jfree.data KeyedObjects clone.

Prototype

@Override
public Object clone() throws CloneNotSupportedException 

Source Link

Document

Returns a clone of this object.

Usage

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

/**
 * Confirm special features of cloning.//from  w  ww.j  a v a  2 s  .c om
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    // case 1 - object is mutable but not PublicCloneable
    Object obj1 = new ArrayList();
    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("K1", obj1);
    KeyedObjects ko2 = (KeyedObjects) ko1.clone();
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));

    // the clone contains a reference to the original object
    assertTrue(ko2.getObject("K1") == obj1);

    // CASE 2 - object is mutable AND PublicCloneable
    obj1 = new DefaultPieDataset();
    ko1 = new KeyedObjects();
    ko1.addObject("K1", obj1);
    ko2 = (KeyedObjects) ko1.clone();
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));

    // the clone contains a reference to a CLONE of the original object
    assertTrue(ko2.getObject("K1") != obj1);
}

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

/**
 * Confirm that cloning works.//from w  w w . j  a va 2 s. co m
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("V1", new Integer(1));
    ko1.addObject("V2", null);
    ko1.addObject("V3", new Integer(3));
    KeyedObjects ko2 = (KeyedObjects) ko1.clone();
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));
}

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

/**
 * Returns a clone.//from  w  w  w .  j ava2  s.c  o m
 *
 * @return A clone.
 *
 * @throws CloneNotSupportedException  this class will not throw this
 *         exception, but subclasses (if any) might.
 */
@Override
public Object clone() throws CloneNotSupportedException {
    KeyedObjects2D clone = (KeyedObjects2D) super.clone();
    clone.columnKeys = new java.util.ArrayList(this.columnKeys);
    clone.rowKeys = new java.util.ArrayList(this.rowKeys);
    clone.rows = new java.util.ArrayList(this.rows.size());
    Iterator iterator = this.rows.iterator();
    while (iterator.hasNext()) {
        KeyedObjects row = (KeyedObjects) iterator.next();
        clone.rows.add(row.clone());
    }
    return clone;
}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Confirm special features of cloning.//from  w w w  .ja v a  2  s.  c  o m
 */
public void testCloning2() {
    // case 1 - object is mutable but not PublicCloneable
    Object obj1 = new ArrayList();
    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("K1", obj1);
    KeyedObjects ko2 = null;
    try {
        ko2 = (KeyedObjects) ko1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));

    // the clone contains a reference to the original object
    assertTrue(ko2.getObject("K1") == obj1);

    // CASE 2 - object is mutable AND PublicCloneable
    obj1 = new DefaultPieDataset();
    ko1 = new KeyedObjects();
    ko1.addObject("K1", obj1);
    ko2 = null;
    try {
        ko2 = (KeyedObjects) ko1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));

    // the clone contains a reference to a CLONE of the original object
    assertTrue(ko2.getObject("K1") != obj1);
}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Confirm that cloning works.//ww w. jav a  2 s. c om
 */
public void testCloning() {
    KeyedObjects ko1 = new KeyedObjects();
    ko1.addObject("V1", new Integer(1));
    ko1.addObject("V2", null);
    ko1.addObject("V3", new Integer(3));
    KeyedObjects ko2 = null;
    try {
        ko2 = (KeyedObjects) ko1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));
}