Example usage for org.jfree.data KeyedObject equals

List of usage examples for org.jfree.data KeyedObject equals

Introduction

In this page you can find the example usage for org.jfree.data KeyedObject equals.

Prototype

@Override
public boolean equals(Object obj) 

Source Link

Document

Tests if this object is equal to another.

Usage

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *///from  w  w w.ja v a  2  s . co m
@Test
public void testEquals() {

    KeyedObject ko1 = new KeyedObject("Test", "Object");
    KeyedObject ko2 = new KeyedObject("Test", "Object");
    assertTrue(ko1.equals(ko2));
    assertTrue(ko2.equals(ko1));

    ko1 = new KeyedObject("Test 1", "Object");
    ko2 = new KeyedObject("Test 2", "Object");
    assertFalse(ko1.equals(ko2));

    ko1 = new KeyedObject("Test", "Object 1");
    ko2 = new KeyedObject("Test", "Object 2");
    assertFalse(ko1.equals(ko2));

}

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

/**
 * Confirm that cloning works./* ww w  .j  a  va 2s.  c om*/
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    KeyedObject ko1 = new KeyedObject("Test", "Object");
    KeyedObject ko2 = (KeyedObject) ko1.clone();
    assertTrue(ko1 != ko2);
    assertTrue(ko1.getClass() == ko2.getClass());
    assertTrue(ko1.equals(ko2));
}

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

/**
 * Confirm special features of cloning.//from   ww w .ja v  a  2s  .  c om
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    // case 1 - object is mutable but not PublicCloneable
    Object obj1 = new ArrayList();
    KeyedObject ko1 = new KeyedObject("Test", obj1);
    KeyedObject ko2 = (KeyedObject) 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() == obj1);

    // CASE 2 - object is mutable AND PublicCloneable
    obj1 = new DefaultPieDataset();
    ko1 = new KeyedObject("Test", obj1);
    ko2 = (KeyedObject) 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() != obj1);
}