List of usage examples for org.jfree.data ComparableObjectItem ComparableObjectItem
public ComparableObjectItem(Comparable x, Object y)
From source file:org.jfree.data.ComparableObjectItemTest.java
/** * Some checks for the constructor./*from w ww. j a va 2 s. c o m*/ */ @Test public void testConstructor() { // check null argument 1 try { /* ComparableObjectItem item1 = */ new ComparableObjectItem(null, "XYZ"); fail("There should be an exception."); } catch (IllegalArgumentException e) { // expected } }
From source file:org.jfree.data.ComparableObjectItemTest.java
/** * Confirm that the equals method can distinguish all the required fields. */// w w w. j a va 2 s .com @Test public void testEquals() { ComparableObjectItem item1 = new ComparableObjectItem(new Integer(1), "XYZ"); ComparableObjectItem item2 = new ComparableObjectItem(new Integer(1), "XYZ"); assertEquals(item1, item2); item1 = new ComparableObjectItem(new Integer(2), "XYZ"); assertNotEquals(item1, item2); item2 = new ComparableObjectItem(new Integer(2), "XYZ"); assertEquals(item1, item2); item1 = new ComparableObjectItem(new Integer(2), null); assertNotEquals(item1, item2); item2 = new ComparableObjectItem(new Integer(2), null); assertEquals(item1, item2); }
From source file:org.jfree.data.ComparableObjectItemTest.java
/** * Some checks for the clone() method.// ww w . j a v a2s . c o m */ @Test public void testCloning() throws CloneNotSupportedException { ComparableObjectItem item1 = new ComparableObjectItem(new Integer(1), "XYZ"); ComparableObjectItem item2 = (ComparableObjectItem) item1.clone(); assertNotSame(item1, item2); assertSame(item1.getClass(), item2.getClass()); assertEquals(item1, item2); }
From source file:org.jfree.data.ComparableObjectItemTest.java
/** * Serialize an instance, restore it, and check for equality. *//* w ww.java2s .c om*/ @Test public void testSerialization() { ComparableObjectItem item1 = new ComparableObjectItem(new Integer(1), "XYZ"); ComparableObjectItem item2 = (ComparableObjectItem) TestUtilities.serialised(item1); assertEquals(item1, item2); }
From source file:org.jfree.data.ComparableObjectItemTest.java
/** * Some checks for the compareTo() method. *//*from ww w. j a v a2 s . c om*/ @Test public void testCompareTo() { ComparableObjectItem item1 = new ComparableObjectItem(new Integer(1), "XYZ"); ComparableObjectItem item2 = new ComparableObjectItem(new Integer(2), "XYZ"); ComparableObjectItem item3 = new ComparableObjectItem(new Integer(3), "XYZ"); ComparableObjectItem item4 = new ComparableObjectItem(new Integer(1), "XYZ"); assertTrue(item2.compareTo(item1) > 0); assertTrue(item3.compareTo(item1) > 0); assertTrue(item4.compareTo(item1) == 0); assertTrue(item1.compareTo(item2) < 0); }
From source file:org.jfree.data.ComparableObjectSeries.java
/** * Adds new data to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * <P>/* ww w .j av a 2 s. c o m*/ * Throws an exception if the x-value is a duplicate AND the * allowDuplicateXValues flag is false. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). * @param notify a flag the controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ protected void add(Comparable x, Object y, boolean notify) { // delegate argument checking to XYDataItem... ComparableObjectItem item = new ComparableObjectItem(x, y); add(item, notify); }
From source file:org.jfree.data.ComparableObjectSeries.java
/** * Returns the index of the item with the specified x-value, or a negative * index if the series does not contain an item with that x-value. Be * aware that for an unsorted series, the index is found by iterating * through all items in the series./*from w w w. j a v a 2s.c o m*/ * * @param x the x-value (<code>null</code> not permitted). * * @return The index. */ public int indexOf(Comparable x) { if (this.autoSort) { return Collections.binarySearch(this.data, new ComparableObjectItem(x, null)); } else { for (int i = 0; i < this.data.size(); i++) { ComparableObjectItem item = (ComparableObjectItem) this.data.get(i); if (item.getComparable().equals(x)) { return i; } } return -1; } }