List of usage examples for org.jfree.data KeyedObject KeyedObject
public KeyedObject(Comparable key, Object object)
From source file:org.jfree.data.KeyedObjectTest.java
/** * Confirm that the equals method can distinguish all the required fields. */// w ww . j ava 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.// w ww.j av a 2 s . c o m */ @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 w w w .j av a2 s . co m */ @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); }
From source file:org.jfree.data.KeyedObjectTest.java
/** * Serialize an instance, restore it, and check for equality. *//*from w w w . j av a 2 s. co m*/ @Test public void testSerialization() { KeyedObject ko1 = new KeyedObject("Test", "Object"); KeyedObject ko2 = (KeyedObject) TestUtilities.serialised(ko1); assertEquals(ko1, ko2); }
From source file:org.jfree.data.KeyedObjects.java
/** * Replaces an existing object, or adds a new object to the collection. * This is the same as the {@link #addObject(Comparable, Object)} * method.//from w ww .j ava 2s. co m * * @param key the key (<code>null</code> not permitted). * @param object the object. * * @see #getObject(Comparable) */ public void setObject(Comparable key, Object object) { int keyIndex = getIndex(key); if (keyIndex >= 0) { KeyedObject ko = (KeyedObject) this.data.get(keyIndex); ko.setObject(object); } else { KeyedObject ko = new KeyedObject(key, object); this.data.add(ko); } }
From source file:org.jfree.data.KeyedObjects.java
/** * Inserts a new value at the specified position in the dataset or, if * there is an existing item with the specified key, updates the value * for that item and moves it to the specified position. * * @param position the position (in the range <code>0</code> to * <code>getItemCount()</code>). * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * * @since 1.0.7//from w ww . j av a 2 s . c om */ public void insertValue(int position, Comparable key, Object value) { if (position < 0 || position > this.data.size()) { throw new IllegalArgumentException("'position' out of bounds."); } ParamChecks.nullNotPermitted(key, "key"); int pos = getIndex(key); if (pos >= 0) { this.data.remove(pos); } KeyedObject item = new KeyedObject(key, value); if (position <= this.data.size()) { this.data.add(position, item); } else { this.data.add(item); } }