file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
CrosshairTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/CrosshairTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * CrosshairTests.java * ------------------- * (C) Copyright 2009-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 09-Apr-2009 : Version 1 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.labels.StandardCrosshairLabelGenerator; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.util.PublicCloneable; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.text.NumberFormat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link Crosshair} class. */ public class CrosshairTest { /** * Some checks for the equals() method. */ @Test public void testEquals() { Crosshair c1 = new Crosshair(1.0, Color.BLUE, new BasicStroke(1.0f)); Crosshair c2 = new Crosshair(1.0, Color.BLUE, new BasicStroke(1.0f)); assertEquals(c1, c1); assertEquals(c2, c1); c1.setVisible(false); assertFalse(c1.equals(c2)); c2.setVisible(false); assertEquals(c1, c2); c1.setValue(2.0); assertFalse(c1.equals(c2)); c2.setValue(2.0); assertEquals(c1, c2); c1.setPaint(Color.RED); assertFalse(c1.equals(c2)); c2.setPaint(Color.RED); assertEquals(c1, c2); c1.setStroke(new BasicStroke(1.1f)); assertFalse(c1.equals(c2)); c2.setStroke(new BasicStroke(1.1f)); assertEquals(c1, c2); c1.setLabelVisible(true); assertFalse(c1.equals(c2)); c2.setLabelVisible(true); assertEquals(c1, c2); c1.setLabelAnchor(RectangleAnchor.TOP_LEFT); assertFalse(c1.equals(c2)); c2.setLabelAnchor(RectangleAnchor.TOP_LEFT); assertEquals(c1, c2); c1.setLabelGenerator(new StandardCrosshairLabelGenerator("Value = {0}", NumberFormat.getNumberInstance())); assertFalse(c1.equals(c2)); c2.setLabelGenerator(new StandardCrosshairLabelGenerator("Value = {0}", NumberFormat.getNumberInstance())); assertEquals(c1, c2); c1.setLabelXOffset(11); assertFalse(c1.equals(c2)); c2.setLabelXOffset(11); assertEquals(c1, c2); c1.setLabelYOffset(22); assertFalse(c1.equals(c2)); c2.setLabelYOffset(22); assertEquals(c1, c2); c1.setLabelFont(new Font("Dialog", Font.PLAIN, 8)); assertFalse(c1.equals(c2)); c2.setLabelFont(new Font("Dialog", Font.PLAIN, 8)); assertEquals(c1, c2); c1.setLabelPaint(Color.RED); assertFalse(c1.equals(c2)); c2.setLabelPaint(Color.RED); assertEquals(c1, c2); c1.setLabelBackgroundPaint(Color.yellow); assertFalse(c1.equals(c2)); c2.setLabelBackgroundPaint(Color.yellow); assertEquals(c1, c2); c1.setLabelOutlineVisible(false); assertFalse(c1.equals(c2)); c2.setLabelOutlineVisible(false); assertEquals(c1, c2); c1.setLabelOutlineStroke(new BasicStroke(2.0f)); assertFalse(c1.equals(c2)); c2.setLabelOutlineStroke(new BasicStroke(2.0f)); assertEquals(c1, c2); c1.setLabelOutlinePaint(Color.darkGray); assertFalse(c1.equals(c2)); c2.setLabelOutlinePaint(Color.darkGray); assertEquals(c1, c2); } /** * Simple check that hashCode is implemented. */ @Test public void testHashCode() { Crosshair c1 = new Crosshair(1.0); Crosshair c2 = new Crosshair(1.0); assertEquals(c1, c2); assertEquals(c1.hashCode(), c2.hashCode()); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { Crosshair c1 = new Crosshair(1.0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE), new BasicStroke(1.0f)); Crosshair c2 = (Crosshair) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); } /** * Check to ensure that this class implements PublicCloneable. */ @Test public void testPublicCloneable() { Crosshair c1 = new Crosshair(1.0); assertTrue(c1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Crosshair c1 = new Crosshair(1.0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE), new BasicStroke(1.0f)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); Crosshair c2 = (Crosshair) in.readObject(); in.close(); assertEquals(c1, c2); } }
6,891
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryPlotTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/CategoryPlotTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * CategoryPlotTests.java * ---------------------- * (C) Copyright 2003-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 26-Mar-2003 : Version 1 (DG); * 15-Sep-2003 : Added a unit test to reproduce a bug in serialization (now * fixed) (DG); * 05-Feb-2007 : Added testAddDomainMarker() and testAddRangeMarker() (DG); * 07-Feb-2007 : Added test1654215() (DG); * 07-Apr-2008 : Added testRemoveDomainMarker() and * testRemoveRangeMarker() (DG); * 23-Apr-2008 : Extended testEquals() and testCloning(), and added * testCloning2() and testCloning3() (DG); * 26-Jun-2008 : Updated testEquals() (DG); * 21-Jan-2009 : Updated testEquals() for new fields (DG); * 10-Jul-2009 : Updated testEquals() for new field (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; import org.jfree.chart.annotations.CategoryLineAnnotation; import org.jfree.chart.annotations.CategoryTextAnnotation; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.CategoryAnchor; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.event.MarkerChangeListener; import org.jfree.chart.renderer.category.AreaRenderer; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.DefaultCategoryItemRenderer; import org.jfree.chart.renderer.category.LineAndShapeRenderer; import org.jfree.chart.ui.Layer; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.DefaultShadowGenerator; import org.jfree.chart.util.SortOrder; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Stroke; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link CategoryPlot} class. */ public class CategoryPlotTest { /** * Some checks for the constructor. */ @Test public void testConstructor() { CategoryPlot plot = new CategoryPlot(); assertEquals(RectangleInsets.ZERO_INSETS, plot.getAxisOffset()); } /** * A test for a bug reported in the forum. */ @Test public void testAxisRange() { DefaultCategoryDataset datasetA = new DefaultCategoryDataset(); DefaultCategoryDataset datasetB = new DefaultCategoryDataset(); datasetB.addValue(50.0, "R1", "C1"); datasetB.addValue(80.0, "R1", "C1"); CategoryPlot plot = new CategoryPlot(datasetA, new CategoryAxis(null), new NumberAxis(null), new LineAndShapeRenderer()); plot.setDataset(1, datasetB); plot.setRenderer(1, new LineAndShapeRenderer()); Range r = plot.getRangeAxis().getRange(); assertEquals(84.0, r.getUpperBound(), 0.00001); } /** * Test that the equals() method differentiates all the required fields. */ @Test public void testEquals() { CategoryPlot plot1 = new CategoryPlot(); CategoryPlot plot2 = new CategoryPlot(); assertEquals(plot1, plot2); assertEquals(plot2, plot1); // orientation... plot1.setOrientation(PlotOrientation.HORIZONTAL); assertFalse(plot1.equals(plot2)); plot2.setOrientation(PlotOrientation.HORIZONTAL); assertEquals(plot1, plot2); // axisOffset... plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05)); assertFalse(plot1.equals(plot2)); plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05)); assertEquals(plot1, plot2); // domainAxis - no longer a separate field but test anyway... plot1.setDomainAxis(new CategoryAxis("Category Axis")); assertFalse(plot1.equals(plot2)); plot2.setDomainAxis(new CategoryAxis("Category Axis")); assertEquals(plot1, plot2); // domainAxes... plot1.setDomainAxis(11, new CategoryAxis("Secondary Axis")); assertFalse(plot1.equals(plot2)); plot2.setDomainAxis(11, new CategoryAxis("Secondary Axis")); assertEquals(plot1, plot2); // domainAxisLocation - no longer a separate field but test anyway... plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // domainAxisLocations... plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // draw shared domain axis... plot1.setDrawSharedDomainAxis(!plot1.getDrawSharedDomainAxis()); assertFalse(plot1.equals(plot2)); plot2.setDrawSharedDomainAxis(!plot2.getDrawSharedDomainAxis()); assertEquals(plot1, plot2); // rangeAxis - no longer a separate field but test anyway... plot1.setRangeAxis(new NumberAxis("Range Axis")); assertFalse(plot1.equals(plot2)); plot2.setRangeAxis(new NumberAxis("Range Axis")); assertEquals(plot1, plot2); // rangeAxes... plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis")); assertFalse(plot1.equals(plot2)); plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis")); assertEquals(plot1, plot2); // rangeAxisLocation - no longer a separate field but test anyway... plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // rangeAxisLocations... plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // datasetToDomainAxisMap... plot1.mapDatasetToDomainAxis(11, 11); assertFalse(plot1.equals(plot2)); plot2.mapDatasetToDomainAxis(11, 11); assertEquals(plot1, plot2); // datasetToRangeAxisMap... plot1.mapDatasetToRangeAxis(11, 11); assertFalse(plot1.equals(plot2)); plot2.mapDatasetToRangeAxis(11, 11); assertEquals(plot1, plot2); // renderer - no longer a separate field but test anyway... plot1.setRenderer(new AreaRenderer()); assertFalse(plot1.equals(plot2)); plot2.setRenderer(new AreaRenderer()); assertEquals(plot1, plot2); // renderers... plot1.setRenderer(11, new AreaRenderer()); assertFalse(plot1.equals(plot2)); plot2.setRenderer(11, new AreaRenderer()); assertEquals(plot1, plot2); // rendering order... plot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); assertFalse(plot1.equals(plot2)); plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); assertEquals(plot1, plot2); // columnRenderingOrder... plot1.setColumnRenderingOrder(SortOrder.DESCENDING); assertFalse(plot1.equals(plot2)); plot2.setColumnRenderingOrder(SortOrder.DESCENDING); assertEquals(plot1, plot2); // rowRenderingOrder... plot1.setRowRenderingOrder(SortOrder.DESCENDING); assertFalse(plot1.equals(plot2)); plot2.setRowRenderingOrder(SortOrder.DESCENDING); assertEquals(plot1, plot2); // domainGridlinesVisible plot1.setDomainGridlinesVisible(true); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinesVisible(true); assertEquals(plot1, plot2); // domainGridlinePosition plot1.setDomainGridlinePosition(CategoryAnchor.END); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinePosition(CategoryAnchor.END); assertEquals(plot1, plot2); // domainGridlineStroke Stroke stroke = new BasicStroke(2.0f); plot1.setDomainGridlineStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlineStroke(stroke); assertEquals(plot1, plot2); // domainGridlinePaint plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.yellow)); assertEquals(plot1, plot2); // rangeGridlinesVisible plot1.setRangeGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinesVisible(false); assertEquals(plot1, plot2); // rangeGridlineStroke plot1.setRangeGridlineStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlineStroke(stroke); assertEquals(plot1, plot2); // rangeGridlinePaint plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertEquals(plot1, plot2); // anchorValue plot1.setAnchorValue(100.0); assertFalse(plot1.equals(plot2)); plot2.setAnchorValue(100.0); assertEquals(plot1, plot2); // rangeCrosshairVisible plot1.setRangeCrosshairVisible(true); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairVisible(true); assertEquals(plot1, plot2); // rangeCrosshairValue plot1.setRangeCrosshairValue(100.0); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairValue(100.0); assertEquals(plot1, plot2); // rangeCrosshairStroke plot1.setRangeCrosshairStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairStroke(stroke); assertEquals(plot1, plot2); // rangeCrosshairPaint plot1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.yellow)); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.yellow)); assertEquals(plot1, plot2); // rangeCrosshairLockedOnData plot1.setRangeCrosshairLockedOnData(false); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairLockedOnData(false); assertEquals(plot1, plot2); // foreground domain markers plot1.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND); assertFalse(plot1.equals(plot2)); plot2.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND); assertEquals(plot1, plot2); // background domain markers plot1.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND); assertFalse(plot1.equals(plot2)); plot2.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND); assertEquals(plot1, plot2); // range markers - no longer separate fields but test anyway... plot1.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND); assertEquals(plot1, plot2); plot1.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(new ValueMarker(5.0), Layer.BACKGROUND); assertEquals(plot1, plot2); // foreground range markers... plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND); assertEquals(plot1, plot2); // background range markers... plot1.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(1, new ValueMarker(5.0), Layer.BACKGROUND); assertEquals(plot1, plot2); // annotations plot1.addAnnotation(new CategoryTextAnnotation("Text", "Category", 43.0)); assertFalse(plot1.equals(plot2)); plot2.addAnnotation(new CategoryTextAnnotation("Text", "Category", 43.0)); assertEquals(plot1, plot2); // weight plot1.setWeight(3); assertFalse(plot1.equals(plot2)); plot2.setWeight(3); assertEquals(plot1, plot2); // fixed domain axis space... plot1.setFixedDomainAxisSpace(new AxisSpace()); assertFalse(plot1.equals(plot2)); plot2.setFixedDomainAxisSpace(new AxisSpace()); assertEquals(plot1, plot2); // fixed range axis space... plot1.setFixedRangeAxisSpace(new AxisSpace()); assertFalse(plot1.equals(plot2)); plot2.setFixedRangeAxisSpace(new AxisSpace()); assertEquals(plot1, plot2); // fixed legend items plot1.setFixedLegendItems(new ArrayList<LegendItem>()); assertFalse(plot1.equals(plot2)); plot2.setFixedLegendItems(new ArrayList<LegendItem>()); assertEquals(plot1, plot2); // crosshairDatasetIndex plot1.setCrosshairDatasetIndex(99); assertFalse(plot1.equals(plot2)); plot2.setCrosshairDatasetIndex(99); assertEquals(plot1, plot2); // domainCrosshairColumnKey plot1.setDomainCrosshairColumnKey("A"); assertFalse(plot1.equals(plot2)); plot2.setDomainCrosshairColumnKey("A"); assertEquals(plot1, plot2); // domainCrosshairRowKey plot1.setDomainCrosshairRowKey("B"); assertFalse(plot1.equals(plot2)); plot2.setDomainCrosshairRowKey("B"); assertEquals(plot1, plot2); // domainCrosshairVisible plot1.setDomainCrosshairVisible(true); assertFalse(plot1.equals(plot2)); plot2.setDomainCrosshairVisible(true); assertEquals(plot1, plot2); // domainCrosshairPaint plot1.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setDomainCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(plot1, plot2); // domainCrosshairStroke plot1.setDomainCrosshairStroke(new BasicStroke(1.23f)); assertFalse(plot1.equals(plot2)); plot2.setDomainCrosshairStroke(new BasicStroke(1.23f)); assertEquals(plot1, plot2); plot1.setRangeMinorGridlinesVisible(true); assertFalse(plot1.equals(plot2)); plot2.setRangeMinorGridlinesVisible(true); assertEquals(plot1, plot2); plot1.setRangeMinorGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setRangeMinorGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(plot1, plot2); plot1.setRangeMinorGridlineStroke(new BasicStroke(1.23f)); assertFalse(plot1.equals(plot2)); plot2.setRangeMinorGridlineStroke(new BasicStroke(1.23f)); assertEquals(plot1, plot2); plot1.setRangeZeroBaselineVisible(!plot1.isRangeZeroBaselineVisible()); assertFalse(plot1.equals(plot2)); plot2.setRangeZeroBaselineVisible(!plot2.isRangeZeroBaselineVisible()); assertEquals(plot1, plot2); plot1.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(plot1, plot2); plot1.setRangeZeroBaselineStroke(new BasicStroke(1.23f)); assertFalse(plot1.equals(plot2)); plot2.setRangeZeroBaselineStroke(new BasicStroke(1.23f)); assertEquals(plot1, plot2); // shadowGenerator plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4)); assertFalse(plot1.equals(plot2)); plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4)); assertEquals(plot1, plot2); plot1.setShadowGenerator(null); assertFalse(plot1.equals(plot2)); plot2.setShadowGenerator(null); assertEquals(plot1, plot2); } /** * Confirm that cloning works. * @throws CloneNotSupportedException */ @Test public void testCloning() throws CloneNotSupportedException { CategoryPlot p1 = new CategoryPlot(); p1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.yellow)); p1.setRangeMinorGridlinePaint(new GradientPaint(2.0f, 3.0f, Color.WHITE, 4.0f, 5.0f, Color.RED)); p1.setRangeZeroBaselinePaint(new GradientPaint(3.0f, 4.0f, Color.RED, 5.0f, 6.0f, Color.WHITE)); CategoryPlot p2 = (CategoryPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check independence p1.addAnnotation(new CategoryLineAnnotation("C1", 1.0, "C2", 2.0, Color.RED, new BasicStroke(1.0f))); assertFalse(p1.equals(p2)); p2.addAnnotation(new CategoryLineAnnotation("C1", 1.0, "C2", 2.0, Color.RED, new BasicStroke(1.0f))); assertEquals(p1, p2); p1.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND); assertFalse(p1.equals(p2)); p2.addDomainMarker(new CategoryMarker("C1"), Layer.FOREGROUND); assertEquals(p1, p2); p1.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND); assertFalse(p1.equals(p2)); p2.addDomainMarker(new CategoryMarker("C2"), Layer.BACKGROUND); assertEquals(p1, p2); p1.addRangeMarker(new ValueMarker(1.0), Layer.FOREGROUND); assertFalse(p1.equals(p2)); p2.addRangeMarker(new ValueMarker(1.0), Layer.FOREGROUND); assertEquals(p1, p2); p1.addRangeMarker(new ValueMarker(2.0), Layer.BACKGROUND); assertFalse(p1.equals(p2)); p2.addRangeMarker(new ValueMarker(2.0), Layer.BACKGROUND); assertEquals(p1, p2); } /** * Some more cloning checks. * @throws CloneNotSupportedException */ @Test public void testCloning2() throws CloneNotSupportedException { AxisSpace da1 = new AxisSpace(); AxisSpace ra1 = new AxisSpace(); CategoryPlot p1 = new CategoryPlot(); p1.setFixedDomainAxisSpace(da1); p1.setFixedRangeAxisSpace(ra1); CategoryPlot p2 = (CategoryPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); da1.setBottom(99.0); assertFalse(p1.equals(p2)); p2.getFixedDomainAxisSpace().setBottom(99.0); assertEquals(p1, p2); ra1.setBottom(11.0); assertFalse(p1.equals(p2)); p2.getFixedRangeAxisSpace().setBottom(11.0); assertEquals(p1, p2); } /** * Some more cloning checks. * @throws CloneNotSupportedException */ @Test public void testCloning3() throws CloneNotSupportedException { List<LegendItem> c1 = new ArrayList<LegendItem>(); CategoryPlot p1 = new CategoryPlot(); p1.setFixedLegendItems(c1); CategoryPlot p2 = (CategoryPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); c1.add(new LegendItem("X", "XX", "tt", "url", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.yellow, new BasicStroke(1.0f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f), Color.green)); assertFalse(p1.equals(p2)); p2.getFixedLegendItems().add(new LegendItem("X", "XX", "tt", "url", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.yellow, new BasicStroke(1.0f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(1.0f), Color.green)); assertEquals(p1, p2); } /** * Renderers that belong to the plot are being cloned but they are * retaining a reference to the original plot. * @throws CloneNotSupportedException */ @Test public void testBug2817504() throws CloneNotSupportedException { CategoryPlot p1 = new CategoryPlot(); LineAndShapeRenderer r1 = new LineAndShapeRenderer(); p1.setRenderer(r1); CategoryPlot p2 = (CategoryPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check for independence LineAndShapeRenderer r2 = (LineAndShapeRenderer) p2.getRenderer(); assertSame(r2.getPlot(), p2); } /** * Serialize an instance, restore it, and check for equality. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis domainAxis = new CategoryAxis("Domain"); NumberAxis rangeAxis = new NumberAxis("Range"); BarRenderer renderer = new BarRenderer(); CategoryPlot p1 = new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); p1.setOrientation(PlotOrientation.HORIZONTAL); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); CategoryPlot p2 = (CategoryPlot) in.readObject(); in.close(); assertEquals(p1, p2); } /** * Serialize an instance, restore it, and check for equality. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { DefaultCategoryDataset data = new DefaultCategoryDataset(); CategoryAxis domainAxis = new CategoryAxis("Domain"); NumberAxis rangeAxis = new NumberAxis("Range"); BarRenderer renderer = new BarRenderer(); CategoryPlot p1 = new CategoryPlot(data, domainAxis, rangeAxis, renderer); p1.setOrientation(PlotOrientation.VERTICAL); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); CategoryPlot p2 = (CategoryPlot) in.readObject(); in.close(); assertEquals(p1, p2); } /** * Serialize an instance, restore it, and check for equality. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization3() throws IOException, ClassNotFoundException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createBarChart("Test Chart", "Category Axis", "Value Axis", dataset); // serialize and deserialize the chart.... ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chart); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); JFreeChart chart2 = (JFreeChart) in.readObject(); in.close(); // now check that the chart is usable... chart2.createBufferedImage(300, 200); //FIXME we should really assert a value here } /** * This test ensures that a plot with markers is serialized correctly. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization4() throws IOException, ClassNotFoundException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createBarChart("Test Chart", "Category Axis", "Value Axis", dataset); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.addRangeMarker(new ValueMarker(1.1), Layer.FOREGROUND); plot.addRangeMarker(new IntervalMarker(2.2, 3.3), Layer.BACKGROUND); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chart); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); JFreeChart chart2 = (JFreeChart) in.readObject(); in.close(); assertEquals(chart, chart2); // now check that the chart is usable... chart2.createBufferedImage(300, 200); } /** * Tests a bug where the plot is no longer registered as a listener * with the dataset(s) and axes after deserialization. See patch 1209475 * at SourceForge. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization5() throws IOException, ClassNotFoundException { DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); CategoryAxis domainAxis1 = new CategoryAxis("Domain 1"); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); BarRenderer renderer1 = new BarRenderer(); CategoryPlot p1 = new CategoryPlot(dataset1, domainAxis1, rangeAxis1, renderer1); CategoryAxis domainAxis2 = new CategoryAxis("Domain 2"); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); BarRenderer renderer2 = new BarRenderer(); DefaultCategoryDataset dataset2 = new DefaultCategoryDataset(); p1.setDataset(1, dataset2); p1.setDomainAxis(1, domainAxis2); p1.setRangeAxis(1, rangeAxis2); p1.setRenderer(1, renderer2); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); CategoryPlot p2 = (CategoryPlot) in.readObject(); in.close(); assertEquals(p1, p2); // now check that all datasets, renderers and axes are being listened // too... CategoryAxis domainAxisA = p2.getDomainAxis(0); NumberAxis rangeAxisA = (NumberAxis) p2.getRangeAxis(0); DefaultCategoryDataset datasetA = (DefaultCategoryDataset) p2.getDataset(0); BarRenderer rendererA = (BarRenderer) p2.getRenderer(0); CategoryAxis domainAxisB = p2.getDomainAxis(1); NumberAxis rangeAxisB = (NumberAxis) p2.getRangeAxis(1); DefaultCategoryDataset datasetB = (DefaultCategoryDataset) p2.getDataset(1); BarRenderer rendererB = (BarRenderer) p2.getRenderer(1); assertTrue(datasetA.hasListener(p2)); assertTrue(domainAxisA.hasListener(p2)); assertTrue(rangeAxisA.hasListener(p2)); assertTrue(rendererA.hasListener(p2)); assertTrue(datasetB.hasListener(p2)); assertTrue(domainAxisB.hasListener(p2)); assertTrue(rangeAxisB.hasListener(p2)); assertTrue(rendererB.hasListener(p2)); } /** * A test for a bug where setting the renderer doesn't register the plot * as a RendererChangeListener. */ @Test public void testSetRenderer() { CategoryPlot plot = new CategoryPlot(); CategoryItemRenderer renderer = new LineAndShapeRenderer(); plot.setRenderer(renderer); // now make a change to the renderer and see if it triggers a plot // change event... MyPlotChangeListener listener = new MyPlotChangeListener(); plot.addChangeListener(listener); renderer.setSeriesPaint(0, Color.BLACK); assertNotSame(listener.getEvent(), null); } /** * A test for bug report 1169972. */ @Test public void test1169972() { CategoryPlot plot = new CategoryPlot(null, null, null, null); plot.setDomainAxis(new CategoryAxis("C")); plot.setRangeAxis(new NumberAxis("Y")); plot.setRenderer(new BarRenderer()); plot.setDataset(new DefaultCategoryDataset()); assertTrue(true); // we didn't get an exception so all is good } /** * Some tests for the addDomainMarker() method(s). */ @Test public void testAddDomainMarker() { CategoryPlot plot = new CategoryPlot(); CategoryMarker m = new CategoryMarker("C1"); plot.addDomainMarker(m); List listeners = Arrays.asList(m.getListeners( MarkerChangeListener.class)); assertTrue(listeners.contains(plot)); plot.clearDomainMarkers(); listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class)); assertFalse(listeners.contains(plot)); } /** * Some tests for the addRangeMarker() method(s). */ @Test public void testAddRangeMarker() { CategoryPlot plot = new CategoryPlot(); Marker m = new ValueMarker(1.0); plot.addRangeMarker(m); List listeners = Arrays.asList(m.getListeners( MarkerChangeListener.class)); assertTrue(listeners.contains(plot)); plot.clearRangeMarkers(); listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class)); assertFalse(listeners.contains(plot)); } /** * A test for bug 1654215 (where a renderer is added to the plot without * a corresponding dataset and it throws an exception at drawing time). */ @Test public void test1654215() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y", dataset); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setRenderer(1, new LineAndShapeRenderer()); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); } /** * Some checks for the getDomainAxisIndex() method. */ @Test public void testGetDomainAxisIndex() { CategoryAxis domainAxis1 = new CategoryAxis("X1"); CategoryAxis domainAxis2 = new CategoryAxis("X2"); NumberAxis rangeAxis1 = new NumberAxis("Y1"); CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1, null); assertEquals(0, plot.getDomainAxisIndex(domainAxis1)); assertEquals(-1, plot.getDomainAxisIndex(domainAxis2)); plot.setDomainAxis(1, domainAxis2); assertEquals(1, plot.getDomainAxisIndex(domainAxis2)); assertEquals(-1, plot.getDomainAxisIndex(new CategoryAxis("X2"))); try { plot.getDomainAxisIndex(null); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'axis' argument.", e.getMessage()); } } /** * Some checks for the getRangeAxisIndex() method. */ @Test public void testGetRangeAxisIndex() { CategoryAxis domainAxis1 = new CategoryAxis("X1"); NumberAxis rangeAxis1 = new NumberAxis("Y1"); NumberAxis rangeAxis2 = new NumberAxis("Y2"); CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1, null); assertEquals(0, plot.getRangeAxisIndex(rangeAxis1)); assertEquals(-1, plot.getRangeAxisIndex(rangeAxis2)); plot.setRangeAxis(1, rangeAxis2); assertEquals(1, plot.getRangeAxisIndex(rangeAxis2)); assertEquals(-1, plot.getRangeAxisIndex(new NumberAxis("Y2"))); try { plot.getRangeAxisIndex(null); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'axis' argument.", e.getMessage()); } } /** * Check that removing a marker that isn't assigned to the plot returns * false. */ @Test public void testRemoveDomainMarker() { CategoryPlot plot = new CategoryPlot(); assertFalse(plot.removeDomainMarker(new CategoryMarker("Category 1"))); } /** * Check that removing a marker that isn't assigned to the plot returns * false. */ @Test public void testRemoveRangeMarker() { CategoryPlot plot = new CategoryPlot(); assertFalse(plot.removeRangeMarker(new ValueMarker(0.5))); } /** * Some tests for the getDomainAxisForDataset() method. */ @Test public void testGetDomainAxisForDataset() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new BarRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); assertEquals(xAxis, plot.getDomainAxisForDataset(0)); // should get IllegalArgumentException for negative index try { plot.getDomainAxisForDataset(-1); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Negative 'index'.", e.getMessage()); } // if multiple axes are mapped, the first in the list should be // returned... CategoryAxis xAxis2 = new CategoryAxis("X2"); plot.setDomainAxis(1, xAxis2); assertEquals(xAxis, plot.getDomainAxisForDataset(0)); plot.mapDatasetToDomainAxis(0, 1); assertEquals(xAxis2, plot.getDomainAxisForDataset(0)); List axisIndices = Arrays.asList(0, 1); plot.mapDatasetToDomainAxes(0, axisIndices); assertEquals(xAxis, plot.getDomainAxisForDataset(0)); axisIndices = Arrays.asList(1, 2); plot.mapDatasetToDomainAxes(0, axisIndices); assertEquals(xAxis2, plot.getDomainAxisForDataset(0)); } /** * Some tests for the getRangeAxisForDataset() method. */ @Test public void testGetRangeAxisForDataset() { CategoryDataset dataset = new DefaultCategoryDataset(); CategoryAxis xAxis = new CategoryAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); CategoryItemRenderer renderer = new DefaultCategoryItemRenderer(); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); assertEquals(yAxis, plot.getRangeAxisForDataset(0)); // should get IllegalArgumentException for negative index try { plot.getRangeAxisForDataset(-1); fail("IllegalArgumentException should have been thrown on negative parameter"); } catch (IllegalArgumentException e) { assertEquals("Negative 'index'.", e.getMessage()); } // if multiple axes are mapped, the first in the list should be // returned... NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setRangeAxis(1, yAxis2); assertEquals(yAxis, plot.getRangeAxisForDataset(0)); plot.mapDatasetToRangeAxis(0, 1); assertEquals(yAxis2, plot.getRangeAxisForDataset(0)); List axisIndices = Arrays.asList(0, 1); plot.mapDatasetToRangeAxes(0, axisIndices); assertEquals(yAxis, plot.getRangeAxisForDataset(0)); axisIndices = Arrays.asList(1, 2); plot.mapDatasetToRangeAxes(0, axisIndices); assertEquals(yAxis2, plot.getRangeAxisForDataset(0)); } }
39,297
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYPlotTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/XYPlotTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * XYPlotTests.java * ---------------- * (C) Copyright 2003-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 26-Mar-2003 : Version 1 (DG); * 22-Mar-2004 : Added new cloning test (DG); * 05-Oct-2004 : Strengthened test for clone independence (DG); * 22-Nov-2006 : Added quadrant fields to equals() and clone() tests (DG); * 09-Jan-2007 : Mark and comment out testGetDatasetCount() (DG); * 05-Feb-2007 : Added testAddDomainMarker() and testAddRangeMarker() (DG); * 07-Feb-2007 : Added test1654215() (DG); * 24-May-2007 : Added testDrawSeriesWithZeroItems() (DG); * 07-Apr-2008 : Added testRemoveDomainMarker() and * testRemoveRangeMarker() (DG); * 10-May-2009 : Extended testEquals(), added testCloning3() (DG); * 06-Jul-2009 : Added testBug2817504() (DG); * 17-Jul-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.date.MonthConstants; import org.jfree.chart.event.MarkerChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.renderer.xy.DefaultXYItemRenderer; import org.jfree.chart.renderer.xy.StandardXYItemRenderer; import org.jfree.chart.renderer.xy.XYBarRenderer; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.chart.ui.Layer; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.DefaultShadowGenerator; import org.jfree.data.time.Day; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.xy.DefaultXYDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Stroke; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.jfree.chart.TestUtilities; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link XYPlot} class. */ public class XYPlotTest { // FIXME: the getDatasetCount() method is returning a count of the slots // available for datasets, rather than the number of datasets actually // specified...see if there is some way to clean this up. // /** // * Added this test in response to a bug report. // */ // public void testGetDatasetCount() { // XYPlot plot = new XYPlot(); // assertEquals(0, plot.getDatasetCount()); // } /** * Some checks for the equals() method. */ @Test public void testEquals() { XYPlot plot1 = new XYPlot(); XYPlot plot2 = new XYPlot(); assertEquals(plot1, plot2); // orientation... plot1.setOrientation(PlotOrientation.HORIZONTAL); assertFalse(plot1.equals(plot2)); plot2.setOrientation(PlotOrientation.HORIZONTAL); assertEquals(plot1, plot2); // axisOffset... plot1.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05)); assertFalse(plot1.equals(plot2)); plot2.setAxisOffset(new RectangleInsets(0.05, 0.05, 0.05, 0.05)); assertEquals(plot1, plot2); // domainAxis... plot1.setDomainAxis(new NumberAxis("Domain Axis")); assertFalse(plot1.equals(plot2)); plot2.setDomainAxis(new NumberAxis("Domain Axis")); assertEquals(plot1, plot2); // domainAxisLocation... plot1.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // secondary DomainAxes... plot1.setDomainAxis(11, new NumberAxis("Secondary Domain Axis")); assertFalse(plot1.equals(plot2)); plot2.setDomainAxis(11, new NumberAxis("Secondary Domain Axis")); assertEquals(plot1, plot2); // secondary DomainAxisLocations... plot1.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setDomainAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // rangeAxis... plot1.setRangeAxis(new NumberAxis("Range Axis")); assertFalse(plot1.equals(plot2)); plot2.setRangeAxis(new NumberAxis("Range Axis")); assertEquals(plot1, plot2); // rangeAxisLocation... plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // secondary RangeAxes... plot1.setRangeAxis(11, new NumberAxis("Secondary Range Axis")); assertFalse(plot1.equals(plot2)); plot2.setRangeAxis(11, new NumberAxis("Secondary Range Axis")); assertEquals(plot1, plot2); // secondary RangeAxisLocations... plot1.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertFalse(plot1.equals(plot2)); plot2.setRangeAxisLocation(11, AxisLocation.TOP_OR_RIGHT); assertEquals(plot1, plot2); // secondary DatasetDomainAxisMap... plot1.mapDatasetToDomainAxis(11, 11); assertFalse(plot1.equals(plot2)); plot2.mapDatasetToDomainAxis(11, 11); assertEquals(plot1, plot2); // secondaryDatasetRangeAxisMap... plot1.mapDatasetToRangeAxis(11, 11); assertFalse(plot1.equals(plot2)); plot2.mapDatasetToRangeAxis(11, 11); assertEquals(plot1, plot2); // renderer plot1.setRenderer(new DefaultXYItemRenderer()); assertFalse(plot1.equals(plot2)); plot2.setRenderer(new DefaultXYItemRenderer()); assertEquals(plot1, plot2); // secondary renderers plot1.setRenderer(11, new DefaultXYItemRenderer()); assertFalse(plot1.equals(plot2)); plot2.setRenderer(11, new DefaultXYItemRenderer()); assertEquals(plot1, plot2); // domainGridlinesVisible plot1.setDomainGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinesVisible(false); assertEquals(plot1, plot2); // domainGridlineStroke Stroke stroke = new BasicStroke(2.0f); plot1.setDomainGridlineStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlineStroke(stroke); assertEquals(plot1, plot2); // domainGridlinePaint plot1.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.RED)); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.RED)); assertEquals(plot1, plot2); // rangeGridlinesVisible plot1.setRangeGridlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinesVisible(false); assertEquals(plot1, plot2); // rangeGridlineStroke plot1.setRangeGridlineStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlineStroke(stroke); assertEquals(plot1, plot2); // rangeGridlinePaint plot1.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.RED)); assertFalse(plot1.equals(plot2)); plot2.setRangeGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.RED)); assertEquals(plot1, plot2); // rangeZeroBaselineVisible plot1.setRangeZeroBaselineVisible(true); assertFalse(plot1.equals(plot2)); plot2.setRangeZeroBaselineVisible(true); assertEquals(plot1, plot2); // rangeZeroBaselineStroke plot1.setRangeZeroBaselineStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setRangeZeroBaselineStroke(stroke); assertEquals(plot1, plot2); // rangeZeroBaselinePaint plot1.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.RED)); assertFalse(plot1.equals(plot2)); plot2.setRangeZeroBaselinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.RED)); assertEquals(plot1, plot2); // rangeCrosshairVisible plot1.setRangeCrosshairVisible(true); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairVisible(true); assertEquals(plot1, plot2); // rangeCrosshairValue plot1.setRangeCrosshairValue(100.0); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairValue(100.0); assertEquals(plot1, plot2); // rangeCrosshairStroke plot1.setRangeCrosshairStroke(stroke); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairStroke(stroke); assertEquals(plot1, plot2); // rangeCrosshairPaint plot1.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.pink, 3.0f, 4.0f, Color.RED)); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairPaint(new GradientPaint(1.0f, 2.0f, Color.pink, 3.0f, 4.0f, Color.RED)); assertEquals(plot1, plot2); // rangeCrosshairLockedOnData plot1.setRangeCrosshairLockedOnData(false); assertFalse(plot1.equals(plot2)); plot2.setRangeCrosshairLockedOnData(false); assertEquals(plot1, plot2); // range markers plot1.addRangeMarker(new ValueMarker(4.0)); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(new ValueMarker(4.0)); assertEquals(plot1, plot2); // secondary range markers plot1.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(1, new ValueMarker(4.0), Layer.FOREGROUND); assertEquals(plot1, plot2); plot1.addRangeMarker(1, new ValueMarker(99.0), Layer.BACKGROUND); assertFalse(plot1.equals(plot2)); plot2.addRangeMarker(1, new ValueMarker(99.0), Layer.BACKGROUND); assertEquals(plot1, plot2); // fixed legend items plot1.setFixedLegendItems(new ArrayList<LegendItem>()); assertFalse(plot1.equals(plot2)); plot2.setFixedLegendItems(new ArrayList<LegendItem>()); assertEquals(plot1, plot2); // weight plot1.setWeight(3); assertFalse(plot1.equals(plot2)); plot2.setWeight(3); assertEquals(plot1, plot2); // quadrant origin plot1.setQuadrantOrigin(new Point2D.Double(12.3, 45.6)); assertFalse(plot1.equals(plot2)); plot2.setQuadrantOrigin(new Point2D.Double(12.3, 45.6)); assertEquals(plot1, plot2); // quadrant paint plot1.setQuadrantPaint(0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setQuadrantPaint(0, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(plot1, plot2); plot1.setQuadrantPaint(1, new GradientPaint(2.0f, 3.0f, Color.RED, 4.0f, 5.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setQuadrantPaint(1, new GradientPaint(2.0f, 3.0f, Color.RED, 4.0f, 5.0f, Color.BLUE)); assertEquals(plot1, plot2); plot1.setQuadrantPaint(2, new GradientPaint(3.0f, 4.0f, Color.RED, 5.0f, 6.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setQuadrantPaint(2, new GradientPaint(3.0f, 4.0f, Color.RED, 5.0f, 6.0f, Color.BLUE)); assertEquals(plot1, plot2); plot1.setQuadrantPaint(3, new GradientPaint(4.0f, 5.0f, Color.RED, 6.0f, 7.0f, Color.BLUE)); assertFalse(plot1.equals(plot2)); plot2.setQuadrantPaint(3, new GradientPaint(4.0f, 5.0f, Color.RED, 6.0f, 7.0f, Color.BLUE)); assertEquals(plot1, plot2); plot1.setDomainTickBandPaint(Color.RED); assertFalse(plot1.equals(plot2)); plot2.setDomainTickBandPaint(Color.RED); assertEquals(plot1, plot2); plot1.setRangeTickBandPaint(Color.BLUE); assertFalse(plot1.equals(plot2)); plot2.setRangeTickBandPaint(Color.BLUE); assertEquals(plot1, plot2); plot1.setDomainMinorGridlinesVisible(true); assertFalse(plot1.equals(plot2)); plot2.setDomainMinorGridlinesVisible(true); assertEquals(plot1, plot2); plot1.setDomainMinorGridlinePaint(Color.RED); assertFalse(plot1.equals(plot2)); plot2.setDomainMinorGridlinePaint(Color.RED); assertEquals(plot1, plot2); plot1.setDomainGridlineStroke(new BasicStroke(1.1f)); assertFalse(plot1.equals(plot2)); plot2.setDomainGridlineStroke(new BasicStroke(1.1f)); assertEquals(plot1, plot2); plot1.setRangeMinorGridlinesVisible(true); assertFalse(plot1.equals(plot2)); plot2.setRangeMinorGridlinesVisible(true); assertEquals(plot1, plot2); plot1.setRangeMinorGridlinePaint(Color.BLUE); assertFalse(plot1.equals(plot2)); plot2.setRangeMinorGridlinePaint(Color.BLUE); assertEquals(plot1, plot2); plot1.setRangeMinorGridlineStroke(new BasicStroke(1.23f)); assertFalse(plot1.equals(plot2)); plot2.setRangeMinorGridlineStroke(new BasicStroke(1.23f)); assertEquals(plot1, plot2); List<Integer> axisIndices = Arrays.asList(0, 1); plot1.mapDatasetToDomainAxes(0, axisIndices); assertFalse(plot1.equals(plot2)); plot2.mapDatasetToDomainAxes(0, axisIndices); assertEquals(plot1, plot2); plot1.mapDatasetToRangeAxes(0, axisIndices); assertFalse(plot1.equals(plot2)); plot2.mapDatasetToRangeAxes(0, axisIndices); assertEquals(plot1, plot2); // shadowGenerator plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4)); assertFalse(plot1.equals(plot2)); plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4)); assertEquals(plot1, plot2); plot1.setShadowGenerator(null); assertFalse(plot1.equals(plot2)); plot2.setShadowGenerator(null); assertEquals(plot1, plot2); List<LegendItem> lic1 = new ArrayList<LegendItem>(); lic1.add(new LegendItem("XYZ", Color.RED)); plot1.setFixedLegendItems(lic1); assertFalse(plot1.equals(plot2)); List<LegendItem> lic2 = new ArrayList<LegendItem>(); lic2.add(new LegendItem("XYZ", Color.RED)); plot2.setFixedLegendItems(lic2); assertEquals(plot1, plot2); } /** * Confirm that basic cloning works. * @throws CloneNotSupportedException */ @Test public void testCloning() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); } /** * Tests cloning for a more complex plot. * @throws CloneNotSupportedException */ @Test public void testCloning2() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); p1.setRangeAxis(1, new NumberAxis("Range Axis 2")); List<Integer> axisIndices = Arrays.asList(0, 1); p1.mapDatasetToDomainAxes(0, axisIndices); p1.mapDatasetToRangeAxes(0, axisIndices); p1.setRenderer(1, new XYBarRenderer()); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); } /** * Tests cloning for a plot where the fixed legend items have been * specified. */ @Test public void testCloning3() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); List<LegendItem> c1 = new ArrayList<LegendItem>(); p1.setFixedLegendItems(c1); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // verify independence of fixed legend item collection c1.add(new LegendItem("X")); assertFalse(p1.equals(p2)); } /** * Tests cloning to ensure that the cloned plot is registered as a listener * on the cloned renderer. * @throws CloneNotSupportedException */ @Test public void testCloning4() throws CloneNotSupportedException { XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer(); XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), r1); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // verify that the plot is listening to the cloned renderer XYLineAndShapeRenderer r2 = (XYLineAndShapeRenderer) p2.getRenderer(); assertTrue(r2.hasListener(p2)); } /** * Confirm that cloning captures the quadrantOrigin field. * @throws CloneNotSupportedException */ @Test public void testCloning_QuadrantOrigin() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(); Point2D p = new Point2D.Double(1.2, 3.4); p1.setQuadrantOrigin(p); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); assertNotSame(p2.getQuadrantOrigin(), p); } /** * Confirm that cloning captures the quadrantOrigin field. * @throws CloneNotSupportedException */ @Test public void testCloning_QuadrantPaint() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(); p1.setQuadrantPaint(3, new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check for independence p1.setQuadrantPaint(1, Color.RED); assertFalse(p1.equals(p2)); p2.setQuadrantPaint(1, Color.RED); assertEquals(p1, p2); } /** * Renderers that belong to the plot are being cloned but they are * retaining a reference to the original plot. * @throws CloneNotSupportedException */ @Test public void testBug2817504() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(); XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer(); p1.setRenderer(r1); XYPlot p2 = (XYPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check for independence XYLineAndShapeRenderer r2 = (XYLineAndShapeRenderer) p2.getRenderer(); assertSame(r2.getPlot(), p2); } /** * Tests the independence of the clones. * @throws CloneNotSupportedException */ @Test public void testCloneIndependence() throws CloneNotSupportedException { XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"), new NumberAxis("Range Axis"), new StandardXYItemRenderer()); p1.setDomainAxis(1, new NumberAxis("Domain Axis 2")); p1.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT); p1.setRangeAxis(1, new NumberAxis("Range Axis 2")); p1.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); p1.setRenderer(1, new XYBarRenderer()); XYPlot p2 = (XYPlot) p1.clone(); assertEquals(p1, p2); p1.getDomainAxis().setLabel("Label"); assertFalse(p1.equals(p2)); p2.getDomainAxis().setLabel("Label"); assertEquals(p1, p2); p1.getDomainAxis(1).setLabel("S1"); assertFalse(p1.equals(p2)); p2.getDomainAxis(1).setLabel("S1"); assertEquals(p1, p2); p1.setDomainAxisLocation(1, AxisLocation.TOP_OR_RIGHT); assertFalse(p1.equals(p2)); p2.setDomainAxisLocation(1, AxisLocation.TOP_OR_RIGHT); assertEquals(p1, p2); p1.mapDatasetToDomainAxis(2, 1); assertFalse(p1.equals(p2)); p2.mapDatasetToDomainAxis(2, 1); assertEquals(p1, p2); p1.getRangeAxis().setLabel("Label"); assertFalse(p1.equals(p2)); p2.getRangeAxis().setLabel("Label"); assertEquals(p1, p2); p1.getRangeAxis(1).setLabel("S1"); assertFalse(p1.equals(p2)); p2.getRangeAxis(1).setLabel("S1"); assertEquals(p1, p2); p1.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT); assertFalse(p1.equals(p2)); p2.setRangeAxisLocation(1, AxisLocation.TOP_OR_LEFT); assertEquals(p1, p2); p1.mapDatasetToRangeAxis(2, 1); assertFalse(p1.equals(p2)); p2.mapDatasetToRangeAxis(2, 1); assertEquals(p1, p2); } /** * Setting a null renderer should be allowed, but is generating a null * pointer exception in 0.9.7. */ @Test public void testSetNullRenderer() { XYPlot plot = new XYPlot(null, new NumberAxis("X"), new NumberAxis("Y"), null); plot.setRenderer(null); } /** * Serialize an instance, restore it, and check for equality. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization1() throws IOException, ClassNotFoundException { XYDataset data = new XYSeriesCollection(); NumberAxis domainAxis = new NumberAxis("Domain"); NumberAxis rangeAxis = new NumberAxis("Range"); StandardXYItemRenderer renderer = new StandardXYItemRenderer(); XYPlot p1 = new XYPlot(data, domainAxis, rangeAxis, renderer); XYPlot p2 = (XYPlot) TestUtilities.serialised(p1); assertEquals(p1, p2); } /** * Serialize an instance, restore it, and check for equality. This test * uses a {@link DateAxis} and a {@link StandardXYToolTipGenerator}. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYBarRenderer(0.20); renderer1.setDefaultToolTipGenerator( StandardXYToolTipGenerator.getTimeSeriesInstance()); XYPlot p1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); XYPlot p2 = (XYPlot) in.readObject(); in.close(); assertEquals(p1, p2); } /** * Problem to reproduce a bug in serialization. The bug (first reported * against the {@link org.jfree.chart.plot.CategoryPlot} class) is a null * pointer exception that occurs when drawing a plot after deserialization. * It is caused by four temporary storage structures (axesAtTop, * axesAtBottom, axesAtLeft and axesAtRight - all initialized as empty * lists in the constructor) not being initialized by the readObject() * method following deserialization. This test has been written to * reproduce the bug (now fixed). */ @Test public void testSerialization3() throws IOException, ClassNotFoundException { XYSeriesCollection dataset = new XYSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "Domain Axis", "Range Axis", dataset); // serialize and deserialize the chart.... ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chart); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); JFreeChart chart2 = (JFreeChart) in.readObject(); in.close(); assertEquals(chart, chart2); chart2.createBufferedImage(300, 200); //FIXME we should really be asserting a value here } /** * A test to reproduce a bug in serialization: the domain and/or range * markers for a plot are not being serialized. */ @Test public void testSerialization4() throws IOException, ClassNotFoundException { XYSeriesCollection dataset = new XYSeriesCollection(); JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "Domain Axis", "Range Axis", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.addDomainMarker(new ValueMarker(1.0), Layer.FOREGROUND); plot.addDomainMarker(new IntervalMarker(2.0, 3.0), Layer.BACKGROUND); plot.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND); plot.addRangeMarker(new IntervalMarker(5.0, 6.0), Layer.BACKGROUND); // serialize and deserialize the chart.... ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(chart); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); JFreeChart chart2 = (JFreeChart) in.readObject(); in.close(); assertEquals(chart, chart2); chart2.createBufferedImage(300, 200); //FIXME we should be asserting a value here } /** * Tests a bug where the plot is no longer registered as a listener * with the dataset(s) and axes after deserialization. See patch 1209475 * at SourceForge. */ @Test public void testSerialization5() throws IOException, ClassNotFoundException { XYSeriesCollection dataset1 = new XYSeriesCollection(); NumberAxis domainAxis1 = new NumberAxis("Domain 1"); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); XYPlot p1 = new XYPlot(dataset1, domainAxis1, rangeAxis1, renderer1); NumberAxis domainAxis2 = new NumberAxis("Domain 2"); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); XYSeriesCollection dataset2 = new XYSeriesCollection(); p1.setDataset(1, dataset2); p1.setDomainAxis(1, domainAxis2); p1.setRangeAxis(1, rangeAxis2); p1.setRenderer(1, renderer2); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); XYPlot p2 = (XYPlot) in.readObject(); in.close(); assertEquals(p1, p2); // now check that all datasets, renderers and axes are being listened // too... NumberAxis domainAxisA = (NumberAxis) p2.getDomainAxis(0); NumberAxis rangeAxisA = (NumberAxis) p2.getRangeAxis(0); XYSeriesCollection datasetA = (XYSeriesCollection) p2.getDataset(0); StandardXYItemRenderer rendererA = (StandardXYItemRenderer) p2.getRenderer(0); NumberAxis domainAxisB = (NumberAxis) p2.getDomainAxis(1); NumberAxis rangeAxisB = (NumberAxis) p2.getRangeAxis(1); XYSeriesCollection datasetB = (XYSeriesCollection) p2.getDataset(1); StandardXYItemRenderer rendererB = (StandardXYItemRenderer) p2.getRenderer(1); assertTrue(datasetA.hasListener(p2)); assertTrue(domainAxisA.hasListener(p2)); assertTrue(rangeAxisA.hasListener(p2)); assertTrue(rendererA.hasListener(p2)); assertTrue(datasetB.hasListener(p2)); assertTrue(domainAxisB.hasListener(p2)); assertTrue(rangeAxisB.hasListener(p2)); assertTrue(rendererB.hasListener(p2)); } /** * Some checks for the getRendererForDataset() method. */ @Test public void testGetRendererForDataset() { XYDataset d0 = new XYSeriesCollection(); XYDataset d1 = new XYSeriesCollection(); XYDataset d2 = new XYSeriesCollection(); XYDataset d3 = new XYSeriesCollection(); // not used by plot XYItemRenderer r0 = new XYLineAndShapeRenderer(); XYItemRenderer r2 = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(); plot.setDataset(0, d0); plot.setDataset(1, d1); plot.setDataset(2, d2); plot.setRenderer(0, r0); // no renderer 1 plot.setRenderer(2, r2); assertEquals(r0, plot.getRendererForDataset(d0)); assertEquals(r0, plot.getRendererForDataset(d1)); assertEquals(r2, plot.getRendererForDataset(d2)); assertEquals(null, plot.getRendererForDataset(d3)); assertEquals(null, plot.getRendererForDataset(null)); } /** * Some checks for the getLegendItems() method. */ @Test public void testGetLegendItems() { // check the case where there is a secondary dataset that doesn't // have a renderer (i.e. falls back to renderer 0) XYDataset d0 = createDataset1(); XYDataset d1 = createDataset2(); XYItemRenderer r0 = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(); plot.setDataset(0, d0); plot.setDataset(1, d1); plot.setRenderer(0, r0); List<LegendItem> items = plot.getLegendItems(); assertEquals(2, items.size()); } /** * Creates a sample dataset. * * @return Series 1. */ private IntervalXYDataset createDataset1() { // create dataset 1... TimeSeries series1 = new TimeSeries("Series 1"); series1.add(new Day(1, MonthConstants.MARCH, 2002), 12353.3); series1.add(new Day(2, MonthConstants.MARCH, 2002), 13734.4); series1.add(new Day(3, MonthConstants.MARCH, 2002), 14525.3); series1.add(new Day(4, MonthConstants.MARCH, 2002), 13984.3); series1.add(new Day(5, MonthConstants.MARCH, 2002), 12999.4); series1.add(new Day(6, MonthConstants.MARCH, 2002), 14274.3); series1.add(new Day(7, MonthConstants.MARCH, 2002), 15943.5); series1.add(new Day(8, MonthConstants.MARCH, 2002), 14845.3); series1.add(new Day(9, MonthConstants.MARCH, 2002), 14645.4); series1.add(new Day(10, MonthConstants.MARCH, 2002), 16234.6); series1.add(new Day(11, MonthConstants.MARCH, 2002), 17232.3); series1.add(new Day(12, MonthConstants.MARCH, 2002), 14232.2); series1.add(new Day(13, MonthConstants.MARCH, 2002), 13102.2); series1.add(new Day(14, MonthConstants.MARCH, 2002), 14230.2); series1.add(new Day(15, MonthConstants.MARCH, 2002), 11235.2); TimeSeriesCollection collection = new TimeSeriesCollection(series1); return collection; } /** * Creates a sample dataset. * * @return A sample dataset. */ private XYDataset createDataset2() { // create dataset 1... XYSeries series = new XYSeries("Series 2"); XYSeriesCollection collection = new XYSeriesCollection(series); return collection; } /** * A test for a bug where setting the renderer doesn't register the plot * as a RendererChangeListener. */ @Test public void testSetRenderer() { XYPlot plot = new XYPlot(); XYItemRenderer renderer = new XYLineAndShapeRenderer(); plot.setRenderer(renderer); // now make a change to the renderer and see if it triggers a plot // change event... MyPlotChangeListener listener = new MyPlotChangeListener(); plot.addChangeListener(listener); renderer.setSeriesPaint(0, Color.BLACK); assertNotSame(listener.getEvent(), null); } /** * Some checks for the removeAnnotation() method. */ @Test public void testRemoveAnnotation() { XYPlot plot = new XYPlot(); XYTextAnnotation a1 = new XYTextAnnotation("X", 1.0, 2.0); XYTextAnnotation a2 = new XYTextAnnotation("X", 3.0, 4.0); XYTextAnnotation a3 = new XYTextAnnotation("X", 1.0, 2.0); plot.addAnnotation(a1); plot.addAnnotation(a2); plot.addAnnotation(a3); plot.removeAnnotation(a2); XYTextAnnotation x = (XYTextAnnotation) plot.getAnnotations().get(0); assertEquals(x, a1); // now remove a3, but since a3.equals(a1), this will in fact remove // a1... assertEquals(a1, a3); plot.removeAnnotation(a3); // actually removes a1 x = (XYTextAnnotation) plot.getAnnotations().get(0); assertEquals(x, a3); } /** * Some tests for the addDomainMarker() method(s). */ @Test public void testAddDomainMarker() { XYPlot plot = new XYPlot(); Marker m = new ValueMarker(1.0); plot.addDomainMarker(m); List listeners = Arrays.asList(m.getListeners( MarkerChangeListener.class)); assertTrue(listeners.contains(plot)); plot.clearDomainMarkers(); listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class)); assertFalse(listeners.contains(plot)); } /** * Some tests for the addRangeMarker() method(s). */ @Test public void testAddRangeMarker() { XYPlot plot = new XYPlot(); Marker m = new ValueMarker(1.0); plot.addRangeMarker(m); List listeners = Arrays.asList(m.getListeners( MarkerChangeListener.class)); assertTrue(listeners.contains(plot)); plot.clearRangeMarkers(); listeners = Arrays.asList(m.getListeners(MarkerChangeListener.class)); assertFalse(listeners.contains(plot)); } /** * A test for bug 1654215 (where a renderer is added to the plot without * a corresponding dataset and it throws an exception at drawing time). */ @Test public void test1654215() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(1, new XYLineAndShapeRenderer()); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should be asserting a value here } /** * A test for drawing range grid lines when there is no primary renderer. * In 1.0.4, this is throwing a NullPointerException. */ @Test public void testDrawRangeGridlines() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(null); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should be asserting a value here } /** * A test for drawing a plot where a series has zero items. With * JFreeChart 1.0.5+cvs this was throwing an exception at one point. */ @Test public void testDrawSeriesWithZeroItems() { DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries("Series 1", new double[][] {{1.0, 2.0}, {3.0, 4.0}}); dataset.addSeries("Series 2", new double[][] {{}, {}}); JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", dataset); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); } /** * Check that removing a marker that isn't assigned to the plot returns * false. */ @Test public void testRemoveDomainMarker() { XYPlot plot = new XYPlot(); assertFalse(plot.removeDomainMarker(new ValueMarker(0.5))); } /** * Check that removing a marker that isn't assigned to the plot returns * false. */ @Test public void testRemoveRangeMarker() { XYPlot plot = new XYPlot(); assertFalse(plot.removeRangeMarker(new ValueMarker(0.5))); } /** * Some tests for the getDomainAxisForDataset() method. */ @Test public void testGetDomainAxisForDataset() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); assertEquals(xAxis, plot.getDomainAxisForDataset(0)); // should get IllegalArgumentException for negative index try { plot.getDomainAxisForDataset(-1); fail("Should have thrown an IllegalArgumentException on negative index"); } catch (IllegalArgumentException e) { assertEquals("Index -1 out of bounds.", e.getMessage()); } // should get IllegalArgumentException for index too high try { plot.getDomainAxisForDataset(1); fail("Should have thrown an IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("Index 1 out of bounds.", e.getMessage()); } // if multiple axes are mapped, the first in the list should be // returned... NumberAxis xAxis2 = new NumberAxis("X2"); plot.setDomainAxis(1, xAxis2); assertEquals(xAxis, plot.getDomainAxisForDataset(0)); plot.mapDatasetToDomainAxis(0, 1); assertEquals(xAxis2, plot.getDomainAxisForDataset(0)); List<Integer> axisIndices = Arrays.asList(0, 1); plot.mapDatasetToDomainAxes(0, axisIndices); assertEquals(xAxis, plot.getDomainAxisForDataset(0)); axisIndices = Arrays.asList(1, 2); plot.mapDatasetToDomainAxes(0, axisIndices); assertEquals(xAxis2, plot.getDomainAxisForDataset(0)); } /** * Some tests for the getRangeAxisForDataset() method. */ @Test public void testGetRangeAxisForDataset() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); assertEquals(yAxis, plot.getRangeAxisForDataset(0)); // should get IllegalArgumentException for negative index try { plot.getRangeAxisForDataset(-1); fail("Should have thrown an IllegalArgumentException on negative value"); } catch (IllegalArgumentException e) { assertEquals("Index -1 out of bounds.", e.getMessage()); } // should get IllegalArgumentException for index too high try { plot.getRangeAxisForDataset(1); fail("Should have thrown an IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("Index 1 out of bounds.", e.getMessage()); } // if multiple axes are mapped, the first in the list should be // returned... NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setRangeAxis(1, yAxis2); assertEquals(yAxis, plot.getRangeAxisForDataset(0)); plot.mapDatasetToRangeAxis(0, 1); assertEquals(yAxis2, plot.getRangeAxisForDataset(0)); List<Integer> axisIndices = Arrays.asList(0, 1); plot.mapDatasetToRangeAxes(0, axisIndices); assertEquals(yAxis, plot.getRangeAxisForDataset(0)); axisIndices = Arrays.asList(1, 2); plot.mapDatasetToRangeAxes(0, axisIndices); assertEquals(yAxis2, plot.getRangeAxisForDataset(0)); } }
43,746
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MultiplePiePlotTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/MultiplePiePlotTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * MultiplePiePlotTests.java * ------------------------- * (C) Copyright 2005-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Jun-2005 : Version 1 (DG); * 06-Apr-2006 : Added tests for new fields (DG); * 18-Apr-2008 : Added testConstructor() (DG); * 30-Dec-2008 : Updated for new legendItemShape field (DG); * 01-Jun-2009 : Added test for getLegendItems() bug, series key is not * set (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.ChartFactory; import org.jfree.chart.LegendItem; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.jfree.chart.util.TableOrder; import org.jfree.data.category.DefaultCategoryDataset; import org.junit.Test; import java.awt.Color; import java.awt.GradientPaint; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for the {@link MultiplePiePlot} class. */ public class MultiplePiePlotTest implements PlotChangeListener { /** The last event received. */ PlotChangeEvent lastEvent; /** * Receives a plot change event and records it. Some tests will use this * to check that events have been generated (or not) when required. * * @param event the event. */ @Override public void plotChanged(PlotChangeEvent event) { this.lastEvent = event; } /** * Some checks for the constructors. */ @Test public void testConstructor() { MultiplePiePlot plot = new MultiplePiePlot(); assertNull(plot.getDataset()); // the following checks that the plot registers itself as a listener // with the dataset passed to the constructor - see patch 1943021 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); plot = new MultiplePiePlot(dataset); assertTrue(dataset.hasListener(plot)); } /** * Check that the equals() method distinguishes the required fields. */ @Test public void testEquals() { MultiplePiePlot p1 = new MultiplePiePlot(); MultiplePiePlot p2 = new MultiplePiePlot(); assertEquals(p1, p2); assertEquals(p2, p1); p1.setDataExtractOrder(TableOrder.BY_ROW); assertFalse(p1.equals(p2)); p2.setDataExtractOrder(TableOrder.BY_ROW); assertEquals(p1, p2); p1.setLimit(1.23); assertFalse(p1.equals(p2)); p2.setLimit(1.23); assertEquals(p1, p2); p1.setAggregatedItemsKey("Aggregated Items"); assertFalse(p1.equals(p2)); p2.setAggregatedItemsKey("Aggregated Items"); assertEquals(p1, p2); p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertFalse(p1.equals(p2)); p2.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertEquals(p1, p2); p1.setPieChart(ChartFactory.createPieChart("Title", null)); assertFalse(p1.equals(p2)); p2.setPieChart(ChartFactory.createPieChart("Title", null)); assertEquals(p1, p2); p1.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertFalse(p1.equals(p2)); p2.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertEquals(p1, p2); } /** * Some basic checks for the clone() method. * @throws CloneNotSupportedException */ @Test public void testCloning() throws CloneNotSupportedException { MultiplePiePlot p1 = new MultiplePiePlot(); Rectangle2D rect = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0); p1.setLegendItemShape(rect); MultiplePiePlot p2 = (MultiplePiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check independence rect.setRect(2.0, 3.0, 4.0, 5.0); assertFalse(p1.equals(p2)); } /** * Serialize an instance, restore it, and check for equality. * @throws IOException * @throws ClassNotFoundException */ @Test public void testSerialization() throws IOException, ClassNotFoundException { MultiplePiePlot p1 = new MultiplePiePlot(null); p1.setAggregatedItemsPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.RED)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); MultiplePiePlot p2 = (MultiplePiePlot) in.readObject(); in.close(); assertEquals(p1, p2); } /** * Fetches the legend items and checks the values. */ @Test public void testGetLegendItems() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(35.0, "S1", "C1"); dataset.addValue(45.0, "S1", "C2"); dataset.addValue(55.0, "S2", "C1"); dataset.addValue(15.0, "S2", "C2"); MultiplePiePlot plot = new MultiplePiePlot(dataset); List<LegendItem> legendItems = plot.getLegendItems(); assertEquals(2, legendItems.size()); LegendItem item1 = legendItems.get(0); assertEquals("S1", item1.getLabel()); assertEquals("S1", item1.getSeriesKey()); assertEquals(0, item1.getSeriesIndex()); assertEquals(dataset, item1.getDataset()); assertEquals(0, item1.getDatasetIndex()); LegendItem item2 = legendItems.get(1); assertEquals("S2", item2.getLabel()); assertEquals("S2", item2.getSeriesKey()); assertEquals(1, item2.getSeriesIndex()); assertEquals(dataset, item2.getDataset()); assertEquals(0, item2.getDatasetIndex()); } }
7,870
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ArcDialFrameTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/ArcDialFrameTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * ArcDialFrameTests.java * ---------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 24-Oct-2007 : Renamed (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link ArcDialFrame} class. */ public class ArcDialFrameTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { ArcDialFrame f1 = new ArcDialFrame(); ArcDialFrame f2 = new ArcDialFrame(); assertEquals(f1, f2); // background paint f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertFalse(f1.equals(f2)); f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertEquals(f1, f2); // foreground paint f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertFalse(f1.equals(f2)); f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertEquals(f1, f2); // stroke f1.setStroke(new BasicStroke(1.1f)); assertFalse(f1.equals(f2)); f2.setStroke(new BasicStroke(1.1f)); assertEquals(f1, f2); // inner radius f1.setInnerRadius(0.11); assertFalse(f1.equals(f2)); f2.setInnerRadius(0.11); assertEquals(f1, f2); // outer radius f1.setOuterRadius(0.88); assertFalse(f1.equals(f2)); f2.setOuterRadius(0.88); assertEquals(f1, f2); // startAngle f1.setStartAngle(99); assertFalse(f1.equals(f2)); f2.setStartAngle(99); assertEquals(f1, f2); // extent f1.setExtent(33); assertFalse(f1.equals(f2)); f2.setExtent(33); assertEquals(f1, f2); // check an inherited attribute f1.setVisible(false); assertFalse(f1.equals(f2)); f2.setVisible(false); assertEquals(f1, f2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { ArcDialFrame f1 = new ArcDialFrame(); ArcDialFrame f2 = new ArcDialFrame(); assertEquals(f1, f2); int h1 = f1.hashCode(); int h2 = f2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { ArcDialFrame f1 = new ArcDialFrame(); ArcDialFrame f2 = (ArcDialFrame) f1.clone(); assertNotSame(f1, f2); assertSame(f1.getClass(), f2.getClass()); assertEquals(f1, f2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); f1.addChangeListener(l1); assertTrue(f1.hasListener(l1)); assertFalse(f2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { ArcDialFrame f1 = new ArcDialFrame(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); ArcDialFrame f2 = (ArcDialFrame) in.readObject(); in.close(); assertEquals(f1, f2); } }
5,714
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialValueIndicatorTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/DialValueIndicatorTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * DialValueIndicatorTests.java * ---------------------------- * (C) Copyright 2006-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 24-Oct-2007 : Updated for API changes (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot.dial; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.TextAnchor; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DialValueIndicator} class. */ public class DialValueIndicatorTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialValueIndicator i1 = new DialValueIndicator(0); DialValueIndicator i2 = new DialValueIndicator(0); assertEquals(i1, i2); // dataset index i1.setDatasetIndex(99); assertFalse(i1.equals(i2)); i2.setDatasetIndex(99); assertEquals(i1, i2); // angle i1.setAngle(43); assertFalse(i1.equals(i2)); i2.setAngle(43); assertEquals(i1, i2); // radius i1.setRadius(0.77); assertFalse(i1.equals(i2)); i2.setRadius(0.77); assertEquals(i1, i2); // frameAnchor i1.setFrameAnchor(RectangleAnchor.TOP_LEFT); assertFalse(i1.equals(i2)); i2.setFrameAnchor(RectangleAnchor.TOP_LEFT); assertEquals(i1, i2); // templateValue i1.setTemplateValue(1.23); assertFalse(i1.equals(i2)); i2.setTemplateValue(1.23); assertEquals(i1, i2); // font i1.setFont(new Font("Dialog", Font.PLAIN, 7)); assertFalse(i1.equals(i2)); i2.setFont(new Font("Dialog", Font.PLAIN, 7)); assertEquals(i1, i2); // paint i1.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); assertFalse(i1.equals(i2)); i2.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); assertEquals(i1, i2); // backgroundPaint i1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); assertFalse(i1.equals(i2)); i2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); assertEquals(i1, i2); // outlineStroke i1.setOutlineStroke(new BasicStroke(1.1f)); assertFalse(i1.equals(i2)); i2.setOutlineStroke(new BasicStroke(1.1f)); assertEquals(i1, i2); // outlinePaint i1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); assertFalse(i1.equals(i2)); i2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); assertEquals(i1, i2); // insets i1.setInsets(new RectangleInsets(1, 2, 3, 4)); assertFalse(i1.equals(i2)); i2.setInsets(new RectangleInsets(1, 2, 3, 4)); assertEquals(i1, i2); // valueAnchor i1.setValueAnchor(RectangleAnchor.BOTTOM_LEFT); assertFalse(i1.equals(i2)); i2.setValueAnchor(RectangleAnchor.BOTTOM_LEFT); assertEquals(i1, i2); // textAnchor i1.setTextAnchor(TextAnchor.TOP_LEFT); assertFalse(i1.equals(i2)); i2.setTextAnchor(TextAnchor.TOP_LEFT); assertEquals(i1, i2); // check an inherited attribute i1.setVisible(false); assertFalse(i1.equals(i2)); i2.setVisible(false); assertEquals(i1, i2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { DialValueIndicator i1 = new DialValueIndicator(0); DialValueIndicator i2 = new DialValueIndicator(0); assertEquals(i1, i2); int h1 = i1.hashCode(); int h2 = i2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { // test a default instance DialValueIndicator i1 = new DialValueIndicator(0); DialValueIndicator i2 = (DialValueIndicator) i1.clone(); assertNotSame(i1, i2); assertSame(i1.getClass(), i2.getClass()); assertEquals(i1, i2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); i1.addChangeListener(l1); assertTrue(i1.hasListener(l1)); assertFalse(i2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // test a default instance DialValueIndicator i1 = new DialValueIndicator(0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialValueIndicator i2 = (DialValueIndicator) in.readObject(); in.close(); assertEquals(i1, i2); // test a custom instance } }
7,398
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialBackgroundTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/DialBackgroundTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * DialBackgroundTests.java * ------------------------ * (C) Copyright 2006-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot.dial; import org.jfree.chart.ui.GradientPaintTransformType; import org.jfree.chart.ui.StandardGradientPaintTransformer; import org.junit.Test; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DialBackground} class. */ public class DialBackgroundTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialBackground b1 = new DialBackground(); DialBackground b2 = new DialBackground(); assertEquals(b1, b2); // paint b1.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertFalse(b1.equals(b2)); b2.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertEquals(b1, b2); // gradient paint transformer b1.setGradientPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); assertFalse(b1.equals(b2)); b2.setGradientPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); assertEquals(b1, b2); // check an inherited attribute b1.setVisible(false); assertFalse(b1.equals(b2)); b2.setVisible(false); assertEquals(b1, b2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { DialBackground b1 = new DialBackground(Color.RED); DialBackground b2 = new DialBackground(Color.RED); assertEquals(b1, b2); int h1 = b1.hashCode(); int h2 = b2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { // test default instance DialBackground b1 = new DialBackground(); DialBackground b2 = (DialBackground) b1.clone(); assertNotSame(b1, b2); assertSame(b1.getClass(), b2.getClass()); assertEquals(b1, b2); // test a customised instance b1 = new DialBackground(); b1.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); b1.setGradientPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); b2 = (DialBackground) b1.clone(); assertNotSame(b1, b2); assertSame(b1.getClass(), b2.getClass()); assertEquals(b1, b2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); b1.addChangeListener(l1); assertTrue(b1.hasListener(l1)); assertFalse(b2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // test a default instance DialBackground b1 = new DialBackground(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(b1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialBackground b2 = (DialBackground) in.readObject(); in.close(); assertEquals(b1, b2); // test a customised instance b1 = new DialBackground(); b1.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.green)); b1.setGradientPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); buffer = new ByteArrayOutputStream(); out = new ObjectOutputStream(buffer); out.writeObject(b1); out.close(); in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); b2 = (DialBackground) in.readObject(); in.close(); assertEquals(b1, b2); } }
6,363
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialTextAnnotationTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/DialTextAnnotationTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * DialTextAnnotationTests.java * ---------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DialTextAnnotation} class. */ public class DialTextAnnotationTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialTextAnnotation a1 = new DialTextAnnotation("A1"); DialTextAnnotation a2 = new DialTextAnnotation("A1"); assertEquals(a1, a2); // angle a1.setAngle(1.1); assertFalse(a1.equals(a2)); a2.setAngle(1.1); assertEquals(a1, a2); // radius a1.setRadius(9.9); assertFalse(a1.equals(a2)); a2.setRadius(9.9); assertEquals(a1, a2); // font Font f = new Font("SansSerif", Font.PLAIN, 14); a1.setFont(f); assertFalse(a1.equals(a2)); a2.setFont(f); assertEquals(a1, a2); // paint a1.setPaint(Color.RED); assertFalse(a1.equals(a2)); a2.setPaint(Color.RED); assertEquals(a1, a2); // label a1.setLabel("ABC"); assertFalse(a1.equals(a2)); a2.setLabel("ABC"); assertEquals(a1, a2); // check an inherited attribute a1.setVisible(false); assertFalse(a1.equals(a2)); a2.setVisible(false); assertEquals(a1, a2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { DialTextAnnotation a1 = new DialTextAnnotation("A1"); DialTextAnnotation a2 = new DialTextAnnotation("A1"); assertEquals(a1, a2); int h1 = a1.hashCode(); int h2 = a2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { // test a default instance DialTextAnnotation a1 = new DialTextAnnotation("A1"); DialTextAnnotation a2 = (DialTextAnnotation) a1.clone(); assertNotSame(a1, a2); assertSame(a1.getClass(), a2.getClass()); assertEquals(a1, a2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); a1.addChangeListener(l1); assertTrue(a1.hasListener(l1)); assertFalse(a2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // test a default instance DialTextAnnotation a1 = new DialTextAnnotation("A1"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(a1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialTextAnnotation a2 = (DialTextAnnotation) in.readObject(); in.close(); assertEquals(a1, a2); // test a custom instance a1 = new DialTextAnnotation("A1"); a1.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); buffer = new ByteArrayOutputStream(); out = new ObjectOutputStream(buffer); out.writeObject(a1); out.close(); in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); a2 = (DialTextAnnotation) in.readObject(); in.close(); assertEquals(a1, a2); } }
5,771
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractDialLayerTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/AbstractDialLayerTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * AbstractDialLayerTests.java * --------------------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Oct-2007 : Version 1 (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link AbstractDialLayer} class. */ public class AbstractDialLayerTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialCap c1 = new DialCap(); DialCap c2 = new DialCap(); assertEquals(c1, c2); // visible c1.setVisible(false); assertFalse(c1.equals(c2)); c2.setVisible(false); assertEquals(c1, c2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { // test a default instance DialCap c1 = new DialCap(); DialCap c2 = (DialCap) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); c1.addChangeListener(l1); assertTrue(c1.hasListener(l1)); assertFalse(c2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // test a default instance DialCap c1 = new DialCap(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialCap c2 = (DialCap) in.readObject(); in.close(); assertEquals(c1, c2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); c1.addChangeListener(l1); assertTrue(c1.hasListener(l1)); assertFalse(c2.hasListener(l1)); } }
4,077
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialCapTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/DialCapTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * DialCapTests.java * ----------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DialCap} class. */ public class DialCapTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialCap c1 = new DialCap(); DialCap c2 = new DialCap(); assertEquals(c1, c2); // radius c1.setRadius(0.5); assertFalse(c1.equals(c2)); c2.setRadius(0.5); assertEquals(c1, c2); // fill paint c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.green)); assertFalse(c1.equals(c2)); c2.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.green)); // outline paint c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.gray)); assertFalse(c1.equals(c2)); c2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.gray)); assertEquals(c1, c2); // outline stroke c1.setOutlineStroke(new BasicStroke(1.1f)); assertFalse(c1.equals(c2)); c2.setOutlineStroke(new BasicStroke(1.1f)); assertEquals(c1, c2); // check an inherited attribute c1.setVisible(false); assertFalse(c1.equals(c2)); c2.setVisible(false); assertEquals(c1, c2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { DialCap c1 = new DialCap(); DialCap c2 = new DialCap(); assertEquals(c1, c2); int h1 = c1.hashCode(); int h2 = c2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { // test a default instance DialCap c1 = new DialCap(); DialCap c2 = (DialCap) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // test a customised instance c1 = new DialCap(); c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.green)); c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.gray)); c1.setOutlineStroke(new BasicStroke(2.0f)); c2 = (DialCap) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); c1.addChangeListener(l1); assertTrue(c1.hasListener(l1)); assertFalse(c2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // test a default instance DialCap c1 = new DialCap(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialCap c2 = (DialCap) in.readObject(); in.close(); assertEquals(c1, c2); // test a custom instance c1 = new DialCap(); c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.green)); c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.gray)); c1.setOutlineStroke(new BasicStroke(2.0f)); buffer = new ByteArrayOutputStream(); out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); c2 = (DialCap) in.readObject(); in.close(); assertEquals(c1, c2); } }
6,333
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialPointerTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/DialPointerTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * DialPointerTests.java * --------------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Apr-2007 : Version 1 (DG); * 23-Nov-2007 : Added testEqualsPointer() and testSerialization2() (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DialPointer} class. */ public class DialPointerTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialPointer i1 = new DialPointer.Pin(1); DialPointer i2 = new DialPointer.Pin(1); assertEquals(i1, i2); // dataset index i1 = new DialPointer.Pin(2); assertFalse(i1.equals(i2)); i2 = new DialPointer.Pin(2); assertEquals(i1, i2); // check an inherited attribute i1.setVisible(false); assertFalse(i1.equals(i2)); i2.setVisible(false); assertEquals(i1, i2); } /** * Check the equals() method for the DialPointer.Pin class. */ @Test public void testEqualsPin() { DialPointer.Pin p1 = new DialPointer.Pin(); DialPointer.Pin p2 = new DialPointer.Pin(); assertEquals(p1, p2); p1.setPaint(Color.green); assertFalse(p1.equals(p2)); p2.setPaint(Color.green); assertEquals(p1, p2); BasicStroke s = new BasicStroke(4.4f); p1.setStroke(s); assertFalse(p1.equals(p2)); p2.setStroke(s); assertEquals(p1, p2); } /** * Check the equals() method for the DialPointer.Pointer class. */ @Test public void testEqualsPointer() { DialPointer.Pointer p1 = new DialPointer.Pointer(); DialPointer.Pointer p2 = new DialPointer.Pointer(); assertEquals(p1, p2); p1.setFillPaint(Color.green); assertFalse(p1.equals(p2)); p2.setFillPaint(Color.green); assertEquals(p1, p2); p1.setOutlinePaint(Color.green); assertFalse(p1.equals(p2)); p2.setOutlinePaint(Color.green); assertEquals(p1, p2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { DialPointer i1 = new DialPointer.Pin(1); DialPointer i2 = new DialPointer.Pin(1); assertEquals(i1, i2); int h1 = i1.hashCode(); int h2 = i2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DialPointer i1 = new DialPointer.Pin(1); DialPointer i2 = (DialPointer) i1.clone(); assertNotSame(i1, i2); assertSame(i1.getClass(), i2.getClass()); assertEquals(i1, i2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); i1.addChangeListener(l1); assertTrue(i1.hasListener(l1)); assertFalse(i2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // test a default instance DialPointer i1 = new DialPointer.Pin(1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialPointer i2 = (DialPointer) in.readObject(); in.close(); assertEquals(i1, i2); // test a custom instance } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { // test a default instance DialPointer i1 = new DialPointer.Pointer(1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialPointer i2 = (DialPointer) in.readObject(); in.close(); assertEquals(i1, i2); // test a custom instance } }
6,422
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MyDialLayerChangeListener.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/MyDialLayerChangeListener.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * MyDialLayerChangeListener.java * ------------------------------ * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Oct-2007 : Version 1 (DG); * */ package org.jfree.chart.plot.dial; /** * A dial layer change listener. */ public class MyDialLayerChangeListener implements DialLayerChangeListener { /** * Creates a new instance. */ public MyDialLayerChangeListener() { } /** * Receives a change event. * * @param event the event. */ @Override public void dialLayerChanged(DialLayerChangeEvent event) { } }
1,980
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StandardDialFrameTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/StandardDialFrameTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * StandardDialFrameTests.java * --------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 29-Oct-2007 : Renamed StandardDialFrameTests (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link StandardDialFrame} class. */ public class StandardDialFrameTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = new StandardDialFrame(); assertEquals(f1, f2); // radius f1.setRadius(0.2); assertFalse(f1.equals(f2)); f2.setRadius(0.2); assertEquals(f1, f2); // backgroundPaint f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.yellow)); assertFalse(f1.equals(f2)); f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.yellow)); assertEquals(f1, f2); // foregroundPaint f1.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.green)); assertFalse(f1.equals(f2)); f2.setForegroundPaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.green)); assertEquals(f1, f2); // stroke f1.setStroke(new BasicStroke(2.4f)); assertFalse(f1.equals(f2)); f2.setStroke(new BasicStroke(2.4f)); assertEquals(f1, f2); // check an inherited attribute f1.setVisible(false); assertFalse(f1.equals(f2)); f2.setVisible(false); assertEquals(f1, f2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = new StandardDialFrame(); assertEquals(f1, f2); int h1 = f1.hashCode(); int h2 = f2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { StandardDialFrame f1 = new StandardDialFrame(); StandardDialFrame f2 = (StandardDialFrame) f1.clone(); assertNotSame(f1, f2); assertSame(f1.getClass(), f2.getClass()); assertEquals(f1, f2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); f1.addChangeListener(l1); assertTrue(f1.hasListener(l1)); assertFalse(f2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { StandardDialFrame f1 = new StandardDialFrame(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); StandardDialFrame f2 = (StandardDialFrame) in.readObject(); in.close(); assertEquals(f1, f2); } }
5,383
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StandardDialScaleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/StandardDialScaleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * SimpleDialScaleTests.java * ------------------------- * (C) Copyright 2006-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 24-Oct-2007 : Updated for API changes (DG); * 08-Jan-2012 : Added tests for valueToAngle() and angleToValue(); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link StandardDialScale} class. */ public class StandardDialScaleTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { StandardDialScale s1 = new StandardDialScale(); StandardDialScale s2 = new StandardDialScale(); assertEquals(s1, s2); // lowerBound s1 = new StandardDialScale(10.0, 100.0, 0.0, 270.0, 10.0, 4); assertFalse(s1.equals(s2)); s2 = new StandardDialScale(10.0, 100.0, 0.0, 270.0, 10.0, 4); assertEquals(s1, s2); // upperBound s1 = new StandardDialScale(10.0, 200.0, 0.0, 270.0, 10.0, 4); assertFalse(s1.equals(s2)); s2 = new StandardDialScale(10.0, 200.0, 0.0, 270.0, 10.0, 4); assertEquals(s1, s2); // startAngle s1 = new StandardDialScale(10.0, 200.0, 20.0, 270.0, 10.0, 4); assertFalse(s1.equals(s2)); s2 = new StandardDialScale(10.0, 200.0, 20.0, 270.0, 10.0, 4); assertEquals(s1, s2); // extent s1 = new StandardDialScale(10.0, 200.0, 20.0, 99.0, 10.0, 4); assertFalse(s1.equals(s2)); s2 = new StandardDialScale(10.0, 200.0, 20.0, 99.0, 10.0, 4); assertEquals(s1, s2); // tickRadius s1.setTickRadius(0.99); assertFalse(s1.equals(s2)); s2.setTickRadius(0.99); assertEquals(s1, s2); // majorTickIncrement s1.setMajorTickIncrement(11.1); assertFalse(s1.equals(s2)); s2.setMajorTickIncrement(11.1); assertEquals(s1, s2); // majorTickLength s1.setMajorTickLength(0.09); assertFalse(s1.equals(s2)); s2.setMajorTickLength(0.09); assertEquals(s1, s2); // majorTickPaint s1.setMajorTickPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertFalse(s1.equals(s2)); s2.setMajorTickPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); assertEquals(s1, s2); // majorTickStroke s1.setMajorTickStroke(new BasicStroke(1.1f)); assertFalse(s1.equals(s2)); s2.setMajorTickStroke(new BasicStroke(1.1f)); assertEquals(s1, s2); // minorTickCount s1.setMinorTickCount(7); assertFalse(s1.equals(s2)); s2.setMinorTickCount(7); assertEquals(s1, s2); // minorTickLength s1.setMinorTickLength(0.09); assertFalse(s1.equals(s2)); s2.setMinorTickLength(0.09); assertEquals(s1, s2); // tickLabelOffset s1.setTickLabelOffset(0.11); assertFalse(s1.equals(s2)); s2.setTickLabelOffset(0.11); assertEquals(s1, s2); // tickLabelFont s1.setTickLabelFont(new Font("Dialog", Font.PLAIN, 15)); assertFalse(s1.equals(s2)); s2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 15)); assertEquals(s1, s2); // tickLabelPaint s1.setTickLabelPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.green)); assertFalse(s1.equals(s2)); s2.setTickLabelPaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.green)); assertEquals(s1, s2); s1.setTickLabelsVisible(false); assertFalse(s1.equals(s2)); s2.setTickLabelsVisible(false); assertEquals(s1, s2); // check an inherited attribute s1.setVisible(false); assertFalse(s1.equals(s2)); s2.setVisible(false); assertEquals(s1, s2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { StandardDialScale s1 = new StandardDialScale(); StandardDialScale s2 = new StandardDialScale(); assertEquals(s1, s2); int h1 = s1.hashCode(); int h2 = s2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { // try a default instance StandardDialScale s1 = new StandardDialScale(); StandardDialScale s2 = (StandardDialScale) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); // try a customised instance s1 = new StandardDialScale(); s1.setExtent(123.4); s1.setMajorTickPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.WHITE)); s1.setMajorTickStroke(new BasicStroke(2.0f)); s2 = (StandardDialScale) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); s1.addChangeListener(l1); assertTrue(s1.hasListener(l1)); assertFalse(s2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { // try a default instance StandardDialScale s1 = new StandardDialScale(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); StandardDialScale s2 = (StandardDialScale) in.readObject(); in.close(); assertEquals(s1, s2); // try a customised instance s1 = new StandardDialScale(); s1.setExtent(123.4); s1.setMajorTickPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.WHITE)); s1.setMajorTickStroke(new BasicStroke(2.0f)); buffer = new ByteArrayOutputStream(); out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); s2 = (StandardDialScale) in.readObject(); in.close(); assertEquals(s1, s2); } private static final double EPSILON = 0.0000000001; /** * Some checks for the valueToAngle() method. */ @Test public void testValueToAngle() { StandardDialScale s = new StandardDialScale(); assertEquals(175.0, s.valueToAngle(0.0), EPSILON); assertEquals(90.0, s.valueToAngle(50.0), EPSILON); assertEquals(5.0, s.valueToAngle(100.0), EPSILON); assertEquals(192.0, s.valueToAngle(-10.0), EPSILON); assertEquals(-12.0, s.valueToAngle(110.0), EPSILON); s = new StandardDialScale(0, 20, 180, -180.0, 10, 3); assertEquals(180.0, s.valueToAngle(0.0), EPSILON); assertEquals(90.0, s.valueToAngle(10.0), EPSILON); assertEquals(0.0, s.valueToAngle(20.0), EPSILON); } /** * Some checks for the angleToValue() method. */ @Test public void testAngleToValue() { StandardDialScale s = new StandardDialScale(); assertEquals(0.0, s.angleToValue(175.0), EPSILON); assertEquals(50.0, s.angleToValue(90.0), EPSILON); assertEquals(100.0, s.angleToValue(5.0), EPSILON); assertEquals(-10.0, s.angleToValue(192.0), EPSILON); assertEquals(110.0, s.angleToValue(-12.0), EPSILON); s = new StandardDialScale(0, 20, 180, -180.0, 10, 3); assertEquals(0.0, s.angleToValue(180.0), EPSILON); assertEquals(10.0, s.angleToValue(90.0), EPSILON); assertEquals(20.0, s.angleToValue(0.0), EPSILON); } }
10,235
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialPlotTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/DialPlotTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * DialPlotTests.java * ------------------ * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * */ package org.jfree.chart.plot.dial; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.junit.Test; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; /** * Tests for the {@link DialPlot} class. */ public class DialPlotTest implements PlotChangeListener { /** The last plot change event received. */ private PlotChangeEvent lastEvent; /** * Records the last plot change event received. * * @param event the event. */ @Override public void plotChanged(PlotChangeEvent event) { this.lastEvent = event; } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DialPlot p1 = new DialPlot(); DialPlot p2 = new DialPlot(); assertEquals(p1, p2); // background p1.setBackground(new DialBackground(Color.green)); assertFalse(p1.equals(p2)); p2.setBackground(new DialBackground(Color.green)); assertEquals(p1, p2); p1.setBackground(null); assertFalse(p1.equals(p2)); p2.setBackground(null); assertEquals(p1, p2); // dial cap DialCap cap1 = new DialCap(); cap1.setFillPaint(Color.RED); p1.setCap(cap1); assertFalse(p1.equals(p2)); DialCap cap2 = new DialCap(); cap2.setFillPaint(Color.RED); p2.setCap(cap2); assertEquals(p1, p2); p1.setCap(null); assertFalse(p1.equals(p2)); p2.setCap(null); assertEquals(p1, p2); // frame StandardDialFrame f1 = new StandardDialFrame(); f1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.WHITE)); p1.setDialFrame(f1); assertFalse(p1.equals(p2)); StandardDialFrame f2 = new StandardDialFrame(); f2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.WHITE)); p2.setDialFrame(f2); assertEquals(p1, p2); // view p1.setView(0.2, 0.0, 0.8, 1.0); assertFalse(p1.equals(p2)); p2.setView(0.2, 0.0, 0.8, 1.0); assertEquals(p1, p2); // layer p1.addLayer(new StandardDialScale()); assertFalse(p1.equals(p2)); p2.addLayer(new StandardDialScale()); assertEquals(p1, p2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { DialPlot p1 = new DialPlot(); DialPlot p2 = new DialPlot(); assertEquals(p1, p2); int h1 = p1.hashCode(); int h2 = p2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DialPlot p1 = new DialPlot(); DialPlot p2 = (DialPlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DialPlot p1 = new DialPlot(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DialPlot p2 = (DialPlot) in.readObject(); in.close(); assertEquals(p1, p2); } /** * Check the notification event mechanism for the dial background. */ @Test public void testBackgroundListener() { DialPlot p = new DialPlot(); DialBackground b1 = new DialBackground(Color.RED); p.setBackground(b1); p.addChangeListener(this); this.lastEvent = null; b1.setPaint(Color.BLUE); assertNotNull(this.lastEvent); DialBackground b2 = new DialBackground(Color.green); p.setBackground(b2); this.lastEvent = null; b1.setPaint(Color.RED); assertNull(this.lastEvent); b2.setPaint(Color.RED); assertNotNull(this.lastEvent); } /** * Check the notification event mechanism for the dial cap. */ @Test public void testCapListener() { DialPlot p = new DialPlot(); DialCap c1 = new DialCap(); p.setCap(c1); p.addChangeListener(this); this.lastEvent = null; c1.setFillPaint(Color.RED); assertNotNull(this.lastEvent); DialCap c2 = new DialCap(); p.setCap(c2); this.lastEvent = null; c1.setFillPaint(Color.BLUE); assertNull(this.lastEvent); c2.setFillPaint(Color.green); assertNotNull(this.lastEvent); } /** * Check the notification event mechanism for the dial frame. */ @Test public void testFrameListener() { DialPlot p = new DialPlot(); ArcDialFrame f1 = new ArcDialFrame(); p.setDialFrame(f1); p.addChangeListener(this); this.lastEvent = null; f1.setBackgroundPaint(Color.gray); assertNotNull(this.lastEvent); ArcDialFrame f2 = new ArcDialFrame(); p.setDialFrame(f2); this.lastEvent = null; f1.setBackgroundPaint(Color.BLUE); assertNull(this.lastEvent); f2.setBackgroundPaint(Color.green); assertNotNull(this.lastEvent); } /** * Check the notification event mechanism for the dial scales. */ @Test public void testScaleListener() { DialPlot p = new DialPlot(); StandardDialScale s1 = new StandardDialScale(); p.addScale(0, s1); p.addChangeListener(this); this.lastEvent = null; s1.setStartAngle(22.0); assertNotNull(this.lastEvent); StandardDialScale s2 = new StandardDialScale(); p.addScale(0, s2); this.lastEvent = null; s1.setStartAngle(33.0); assertNull(this.lastEvent); s2.setStartAngle(33.0); assertNotNull(this.lastEvent); } /** * Check the notification event mechanism for a layer. */ @Test public void testLayerListener() { DialPlot p = new DialPlot(); DialBackground b1 = new DialBackground(Color.RED); p.addLayer(b1); p.addChangeListener(this); this.lastEvent = null; b1.setPaint(Color.BLUE); assertNotNull(this.lastEvent); DialBackground b2 = new DialBackground(Color.green); p.addLayer(b2); this.lastEvent = null; b1.setPaint(Color.RED); assertNotNull(this.lastEvent); b2.setPaint(Color.green); assertNotNull(this.lastEvent); p.removeLayer(b2); this.lastEvent = null; b2.setPaint(Color.RED); assertNull(this.lastEvent); } }
9,138
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StandardDialRangeTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/plot/dial/StandardDialRangeTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * SimpleDialRangeTests.java * ------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * */ package org.jfree.chart.plot.dial; import org.junit.Test; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link StandardDialRange} class. */ public class StandardDialRangeTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { StandardDialRange r1 = new StandardDialRange(); StandardDialRange r2 = new StandardDialRange(); assertEquals(r1, r2); // lowerBound r1.setLowerBound(1.1); assertFalse(r1.equals(r2)); r2.setLowerBound(1.1); assertEquals(r1, r2); // upperBound r1.setUpperBound(11.1); assertFalse(r1.equals(r2)); r2.setUpperBound(11.1); assertEquals(r1, r2); // paint r1.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(r1.equals(r2)); r2.setPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(r1, r2); // check an inherited attribute r1.setVisible(false); assertFalse(r1.equals(r2)); r2.setVisible(false); assertEquals(r1, r2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashCode() { StandardDialRange r1 = new StandardDialRange(); StandardDialRange r2 = new StandardDialRange(); assertEquals(r1, r2); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { StandardDialRange r1 = new StandardDialRange(); StandardDialRange r2 = (StandardDialRange) r1.clone(); assertNotSame(r1, r2); assertSame(r1.getClass(), r2.getClass()); assertEquals(r1, r2); // check that the listener lists are independent MyDialLayerChangeListener l1 = new MyDialLayerChangeListener(); r1.addChangeListener(l1); assertTrue(r1.hasListener(l1)); assertFalse(r2.hasListener(l1)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { StandardDialRange r1 = new StandardDialRange(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(r1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); StandardDialRange r2 = (StandardDialRange) in.readObject(); in.close(); assertEquals(r1, r2); } }
4,922
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MeterNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/MeterNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * MeterNeedleTests.java * --------------------- * (C) Copyright 2005, 2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Stroke; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link MeterNeedle} class. */ public class MeterNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { MeterNeedle n1 = new LineNeedle(); MeterNeedle n2 = new LineNeedle(); assertEquals(n1, n2); n1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(n1.equals(n2)); n2.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(n1, n2); n1.setOutlinePaint(new GradientPaint(5.0f, 6.0f, Color.RED, 7.0f, 8.0f, Color.BLUE)); assertFalse(n1.equals(n2)); n2.setOutlinePaint(new GradientPaint(5.0f, 6.0f, Color.RED, 7.0f, 8.0f, Color.BLUE)); assertEquals(n1, n2); n1.setHighlightPaint(new GradientPaint(9.0f, 0.0f, Color.RED, 1.0f, 2.0f, Color.BLUE)); assertFalse(n1.equals(n2)); n2.setHighlightPaint(new GradientPaint(9.0f, 0.0f, Color.RED, 1.0f, 2.0f, Color.BLUE)); assertEquals(n1, n2); Stroke s = new BasicStroke(1.23f); n1.setOutlineStroke(s); assertFalse(n1.equals(n2)); n2.setOutlineStroke(s); assertEquals(n1, n2); n1.setRotateX(1.23); assertFalse(n1.equals(n2)); n2.setRotateX(1.23); assertEquals(n1, n2); n1.setRotateY(4.56); assertFalse(n1.equals(n2)); n2.setRotateY(4.56); assertEquals(n1, n2); n1.setSize(11); assertFalse(n1.equals(n2)); n2.setSize(11); assertEquals(n1, n2); } }
3,427
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PointerNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/PointerNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * PointerNeedleTests.java * ----------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link PointerNeedle} class. */ public class PointerNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { PointerNeedle n1 = new PointerNeedle(); PointerNeedle n2 = new PointerNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { PointerNeedle n1 = new PointerNeedle(); PointerNeedle n2 = (PointerNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { PointerNeedle n1 = new PointerNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); PointerNeedle n2 = (PointerNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,350
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WindNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/WindNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * WindNeedleTests.java * -------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link WindNeedle} class. */ public class WindNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { WindNeedle n1 = new WindNeedle(); WindNeedle n2 = new WindNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { WindNeedle n1 = new WindNeedle(); WindNeedle n2 = (WindNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { WindNeedle n1 = new WindNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); WindNeedle n2 = (WindNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,300
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ShipNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/ShipNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * ShipNeedleTests.java * -------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link ShipNeedle} class. */ public class ShipNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { ShipNeedle n1 = new ShipNeedle(); ShipNeedle n2 = new ShipNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { ShipNeedle n1 = new ShipNeedle(); ShipNeedle n2 = (ShipNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { ShipNeedle n1 = new ShipNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); ShipNeedle n2 = (ShipNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,300
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MiddlePinNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/MiddlePinNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * MiddlePinNeedleTests.java * ------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link MiddlePinNeedle} class. */ public class MiddlePinNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { MiddlePinNeedle n1 = new MiddlePinNeedle(); MiddlePinNeedle n2 = new MiddlePinNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { MiddlePinNeedle n1 = new MiddlePinNeedle(); MiddlePinNeedle n2 = (MiddlePinNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { MiddlePinNeedle n1 = new MiddlePinNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); MiddlePinNeedle n2 = (MiddlePinNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,385
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LongNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/LongNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * LongNeedleTests.java * -------------------- * (C) Copyright 2005, 2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link LongNeedle} class. */ public class LongNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { LongNeedle n1 = new LongNeedle(); LongNeedle n2 = new LongNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { LongNeedle n1 = new LongNeedle(); LongNeedle n2 = (LongNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { LongNeedle n1 = new LongNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); LongNeedle n2 = (LongNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,300
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PinNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/PinNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * PinNeedleTests.java * ------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link PinNeedle} class. */ public class PinNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { PinNeedle n1 = new PinNeedle(); PinNeedle n2 = new PinNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { PinNeedle n1 = new PinNeedle(); PinNeedle n2 = (PinNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { PinNeedle n1 = new PinNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); PinNeedle n2 = (PinNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,282
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ArrowNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/ArrowNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * ArrowNeedleTests.java * --------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link ArrowNeedle} class. */ public class ArrowNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { ArrowNeedle n1 = new ArrowNeedle(false); ArrowNeedle n2 = new ArrowNeedle(false); assertEquals(n1, n2); assertEquals(n2, n1); n1 = new ArrowNeedle(true); assertFalse(n1.equals(n2)); n2 = new ArrowNeedle(true); assertEquals(n1, n2); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { ArrowNeedle n1 = new ArrowNeedle(false); ArrowNeedle n2 = (ArrowNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { ArrowNeedle n1 = new ArrowNeedle(false); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); ArrowNeedle n2 = (ArrowNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,483
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PlumNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/PlumNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * PlumNeedleTests.java * -------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link PlumNeedle} class. */ public class PlumNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { PlumNeedle n1 = new PlumNeedle(); PlumNeedle n2 = new PlumNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { PlumNeedle n1 = new PlumNeedle(); PlumNeedle n2 = (PlumNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { PlumNeedle n1 = new PlumNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); PlumNeedle n2 = (PlumNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,300
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LineNeedleTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/needle/LineNeedleTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * LineNeedleTests.java * -------------------- * (C) Copyright 2005, 2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Jun-2005 : Version 1 (DG); * */ package org.jfree.chart.needle; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link LineNeedle} class. */ public class LineNeedleTest { /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { LineNeedle n1 = new LineNeedle(); LineNeedle n2 = new LineNeedle(); assertEquals(n1, n2); assertEquals(n2, n1); } /** * Check that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { LineNeedle n1 = new LineNeedle(); LineNeedle n2 = (LineNeedle) n1.clone(); assertNotSame(n1, n2); assertSame(n1.getClass(), n2.getClass()); assertEquals(n1, n2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { LineNeedle n1 = new LineNeedle(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(n1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); LineNeedle n2 = (LineNeedle) in.readObject(); in.close(); assertEquals(n1, n2); } }
3,304
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedObjects2D.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedObjects2D.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * KeyedObject2D.java * ------------------ * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 05-Feb-2003 : Version 1 (DG); * 01-Mar-2004 : Added equals() and clone() methods and implemented * Serializable (DG); * 03-Oct-2007 : Updated getObject() to handle modified behaviour in * KeyedObjects class, added clear() method (DG); * */ package org.jfree.data; import java.io.Serializable; import java.util.Collections; import java.util.List; /** * A data structure that stores zero, one or many objects, where each object is * associated with two keys (a 'row' key and a 'column' key). */ public class KeyedObjects2D implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -1015873563138522374L; /** The row keys. */ private List<Comparable> rowKeys; /** The column keys. */ private List<Comparable> columnKeys; /** The row data. */ private List<KeyedObjects> rows; /** * Creates a new instance (initially empty). */ public KeyedObjects2D() { this.rowKeys = new java.util.ArrayList<Comparable>(); this.columnKeys = new java.util.ArrayList<Comparable>(); this.rows = new java.util.ArrayList<KeyedObjects>(); } /** * Returns the row count. * * @return The row count. * * @see #getColumnCount() */ public int getRowCount() { return this.rowKeys.size(); } /** * Returns the column count. * * @return The column count. * * @see #getRowCount() */ public int getColumnCount() { return this.columnKeys.size(); } /** * Returns the object for a given row and column. * * @param row the row index (in the range 0 to getRowCount() - 1). * @param column the column index (in the range 0 to getColumnCount() - 1). * * @return The object (possibly <code>null</code>). * * @see #getObject(Comparable, Comparable) */ public Object getObject(int row, int column) { Object result = null; KeyedObjects rowData = this.rows.get(row); if (rowData != null) { Comparable columnKey = this.columnKeys.get(column); if (columnKey != null) { int index = rowData.getIndex(columnKey); if (index >= 0) { result = rowData.getObject(columnKey); } } } return result; } /** * Returns the key for a given row. * * @param row the row index (zero based). * * @return The row index. * * @see #getRowIndex(Comparable) */ public Comparable getRowKey(int row) { return this.rowKeys.get(row); } /** * Returns the row index for a given key, or <code>-1</code> if the key * is not recognised. * * @param key the key (<code>null</code> not permitted). * * @return The row index. * * @see #getRowKey(int) */ public int getRowIndex(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return this.rowKeys.indexOf(key); } /** * Returns the row keys. * * @return The row keys (never <code>null</code>). * * @see #getRowKeys() */ public List<Comparable> getRowKeys() { return Collections.unmodifiableList(this.rowKeys); } /** * Returns the key for a given column. * * @param column the column. * * @return The key. * * @see #getColumnIndex(Comparable) */ public Comparable getColumnKey(int column) { return this.columnKeys.get(column); } /** * Returns the column index for a given key, or <code>-1</code> if the key * is not recognised. * * @param key the key (<code>null</code> not permitted). * * @return The column index. * * @see #getColumnKey(int) */ public int getColumnIndex(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return this.columnKeys.indexOf(key); } /** * Returns the column keys. * * @return The column keys (never <code>null</code>). * * @see #getRowKeys() */ public List<Comparable> getColumnKeys() { return Collections.unmodifiableList(this.columnKeys); } /** * Returns the object for the given row and column keys. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The object (possibly <code>null</code>). * * @throws IllegalArgumentException if <code>rowKey</code> or * <code>columnKey</code> is <code>null</code>. * @throws UnknownKeyException if <code>rowKey</code> or * <code>columnKey</code> is not recognised. */ public Object getObject(Comparable rowKey, Comparable columnKey) { if (rowKey == null) { throw new IllegalArgumentException("Null 'rowKey' argument."); } if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } int row = this.rowKeys.indexOf(rowKey); if (row < 0) { throw new UnknownKeyException("Row key (" + rowKey + ") not recognised."); } int column = this.columnKeys.indexOf(columnKey); if (column < 0) { throw new UnknownKeyException("Column key (" + columnKey + ") not recognised."); } KeyedObjects rowData = this.rows.get(row); int index = rowData.getIndex(columnKey); if (index >= 0) { return rowData.getObject(index); } else { return null; } } /** * Adds an object to the table. Performs the same function as setObject(). * * @param object the object. * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). */ public void addObject(Object object, Comparable rowKey, Comparable columnKey) { setObject(object, rowKey, columnKey); } /** * Adds or updates an object. * * @param object the object. * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). */ public void setObject(Object object, Comparable rowKey, Comparable columnKey) { if (rowKey == null) { throw new IllegalArgumentException("Null 'rowKey' argument."); } if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } KeyedObjects row; int rowIndex = this.rowKeys.indexOf(rowKey); if (rowIndex >= 0) { row = this.rows.get(rowIndex); } else { this.rowKeys.add(rowKey); row = new KeyedObjects(); this.rows.add(row); } row.setObject(columnKey, object); int columnIndex = this.columnKeys.indexOf(columnKey); if (columnIndex < 0) { this.columnKeys.add(columnKey); } } /** * Removes an object from the table by setting it to <code>null</code>. If * all the objects in the specified row and/or column are now * <code>null</code>, the row and/or column is removed from the table. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #addObject(Object, Comparable, Comparable) */ public void removeObject(Comparable rowKey, Comparable columnKey) { int rowIndex = getRowIndex(rowKey); if (rowIndex < 0) { throw new UnknownKeyException("Row key (" + rowKey + ") not recognised."); } int columnIndex = getColumnIndex(columnKey); if (columnIndex < 0) { throw new UnknownKeyException("Column key (" + columnKey + ") not recognised."); } setObject(null, rowKey, columnKey); // 1. check whether the row is now empty. boolean allNull = true; KeyedObjects row = this.rows.get(rowIndex); for (int item = 0, itemCount = row.getItemCount(); item < itemCount; item++) { if (row.getObject(item) != null) { allNull = false; break; } } if (allNull) { this.rowKeys.remove(rowIndex); this.rows.remove(rowIndex); } // 2. check whether the column is now empty. allNull = true; for (KeyedObjects innerRow : this.rows) { int colIndex = innerRow.getIndex(columnKey); if (colIndex >= 0 && innerRow.getObject(colIndex) != null) { allNull = false; break; } } if (allNull) { for (KeyedObjects innerRow : this.rows) { int colIndex = innerRow.getIndex(columnKey); if (colIndex >= 0) { innerRow.removeValue(colIndex); } } this.columnKeys.remove(columnKey); } } /** * Removes an entire row from the table. * * @param rowIndex the row index. * * @see #removeColumn(int) */ public void removeRow(int rowIndex) { this.rowKeys.remove(rowIndex); this.rows.remove(rowIndex); } /** * Removes an entire row from the table. * * @param rowKey the row key (<code>null</code> not permitted). * * @throws UnknownKeyException if <code>rowKey</code> is not recognised. * * @see #removeColumn(Comparable) */ public void removeRow(Comparable rowKey) { int index = getRowIndex(rowKey); if (index < 0) { throw new UnknownKeyException("Row key (" + rowKey + ") not recognised."); } removeRow(index); } /** * Removes an entire column from the table. * * @param columnIndex the column index. * * @see #removeRow(int) */ public void removeColumn(int columnIndex) { Comparable columnKey = getColumnKey(columnIndex); removeColumn(columnKey); } /** * Removes an entire column from the table. * * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if <code>rowKey</code> is not recognised. * * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { int index = getColumnIndex(columnKey); if (index < 0) { throw new UnknownKeyException("Column key (" + columnKey + ") not recognised."); } for (KeyedObjects rowData : this.rows) { int i = rowData.getIndex(columnKey); if (i >= 0) { rowData.removeValue(i); } } this.columnKeys.remove(columnKey); } /** * Clears all the data and associated keys. * * @since 1.0.7 */ public void clear() { this.rowKeys.clear(); this.columnKeys.clear(); this.rows.clear(); } /** * Tests this object for equality with an arbitrary object. * * @param obj the object to test (<code>null</code> permitted). * * @return A boolean. */ @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; } /** * Returns a hashcode for this object. * * @return A hashcode. */ @Override public int hashCode() { int result; result = this.rowKeys.hashCode(); result = 29 * result + this.columnKeys.hashCode(); result = 29 * result + this.rows.hashCode(); return result; } /** * Returns a clone. * * @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<Comparable>(this.columnKeys); clone.rowKeys = new java.util.ArrayList<Comparable>(this.rowKeys); clone.rows = new java.util.ArrayList<KeyedObjects>(this.rows.size()); for (KeyedObjects row : this.rows) { clone.rows.add((KeyedObjects) row.clone()); } return clone; } }
15,506
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ComparableObjectSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/ComparableObjectSeries.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * ComparableObjectSeries.java * --------------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 19-Oct-2006 : New class (DG); * 31-Oct-2007 : Implemented faster hashCode() (DG); * 27-Nov-2007 : Changed clear() from protected to public (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import java.util.Collections; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.data.general.Series; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesException; /** * A (possibly ordered) list of (Comparable, Object) data items. * * @since 1.0.3 */ public class ComparableObjectSeries extends Series implements Cloneable, Serializable { /** Storage for the data items in the series. */ protected List<ComparableObjectItem> data; /** The maximum number of items for the series. */ private int maximumItemCount = Integer.MAX_VALUE; /** A flag that controls whether the items are automatically sorted. */ private boolean autoSort; /** A flag that controls whether or not duplicate x-values are allowed. */ private boolean allowDuplicateXValues; /** * Creates a new empty series. By default, items added to the series will * be sorted into ascending order by x-value, and duplicate x-values will * be allowed (these defaults can be modified with another constructor. * * @param key the series key (<code>null</code> not permitted). */ public ComparableObjectSeries(Comparable key) { this(key, true, true); } /** * Constructs a new series that contains no data. You can specify * whether or not duplicate x-values are allowed for the series. * * @param key the series key (<code>null</code> not permitted). * @param autoSort a flag that controls whether or not the items in the * series are sorted. * @param allowDuplicateXValues a flag that controls whether duplicate * x-values are allowed. */ public ComparableObjectSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) { super(key); this.data = new java.util.ArrayList<ComparableObjectItem>(); this.autoSort = autoSort; this.allowDuplicateXValues = allowDuplicateXValues; } /** * Returns the flag that controls whether the items in the series are * automatically sorted. There is no setter for this flag, it must be * defined in the series constructor. * * @return A boolean. */ public boolean getAutoSort() { return this.autoSort; } /** * Returns a flag that controls whether duplicate x-values are allowed. * This flag can only be set in the constructor. * * @return A boolean. */ public boolean getAllowDuplicateXValues() { return this.allowDuplicateXValues; } /** * Returns the number of items in the series. * * @return The item count. */ @Override public int getItemCount() { return this.data.size(); } /** * Returns the maximum number of items that will be retained in the series. * The default value is <code>Integer.MAX_VALUE</code>. * * @return The maximum item count. * @see #setMaximumItemCount(int) */ public int getMaximumItemCount() { return this.maximumItemCount; } /** * Sets the maximum number of items that will be retained in the series. * If you add a new item to the series such that the number of items will * exceed the maximum item count, then the first element in the series is * automatically removed, ensuring that the maximum item count is not * exceeded. * <p> * Typically this value is set before the series is populated with data, * but if it is applied later, it may cause some items to be removed from * the series (in which case a {@link SeriesChangeEvent} will be sent to * all registered listeners. * * @param maximum the maximum number of items for the series. */ public void setMaximumItemCount(int maximum) { this.maximumItemCount = maximum; boolean dataRemoved = false; while (this.data.size() > maximum) { this.data.remove(0); dataRemoved = true; } if (dataRemoved) { fireSeriesChanged(); } } /** * Adds new data to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. * <P> * 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). */ protected void add(Comparable x, Object y) { // argument checking delegated... add(x, y, true); } /** * Adds new data to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * <P> * 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); } /** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the (x, y) item (<code>null</code> not permitted). * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ protected void add(ComparableObjectItem item, boolean notify) { if (item == null) { throw new IllegalArgumentException("Null 'item' argument."); } if (this.autoSort) { int index = Collections.binarySearch(this.data, item); if (index < 0) { this.data.add(-index - 1, item); } else { if (this.allowDuplicateXValues) { // need to make sure we are adding *after* any duplicates int size = this.data.size(); while (index < size && item.compareTo(this.data.get(index)) == 0) { index++; } if (index < this.data.size()) { this.data.add(index, item); } else { this.data.add(item); } } else { throw new SeriesException("X-value already exists."); } } } else { if (!this.allowDuplicateXValues) { // can't allow duplicate values, so we need to check whether // there is an item with the given x-value already int index = indexOf(item.getComparable()); if (index >= 0) { throw new SeriesException("X-value already exists."); } } this.data.add(item); } if (getItemCount() > this.maximumItemCount) { this.data.remove(0); } if (notify) { fireSeriesChanged(); } } /** * 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. * * @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 = this.data.get(i); if (item.getComparable().equals(x)) { return i; } } return -1; } } /** * Updates an item in the series. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). * * @throws SeriesException if there is no existing item with the specified * x-value. */ protected void update(Comparable x, Object y) { int index = indexOf(x); if (index < 0) { throw new SeriesException("No observation for x = " + x); } else { ComparableObjectItem item = getDataItem(index); item.setObject(y); fireSeriesChanged(); } } /** * Updates the value of an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the item (zero based index). * @param y the new value (<code>null</code> permitted). */ protected void updateByIndex(int index, Object y) { ComparableObjectItem item = getDataItem(index); item.setObject(y); fireSeriesChanged(); } /** * Return the data item with the specified index. * * @param index the index. * * @return The data item with the specified index. */ protected ComparableObjectItem getDataItem(int index) { return this.data.get(index); } /** * Deletes a range of items from the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param start the start index (zero-based). * @param end the end index (zero-based). */ protected void delete(int start, int end) { for (int i = start; i <= end; i++) { this.data.remove(start); } fireSeriesChanged(); } /** * Removes all data items from the series and, unless the series is * already empty, sends a {@link SeriesChangeEvent} to all registered * listeners. */ public void clear() { if (this.data.size() > 0) { this.data.clear(); fireSeriesChanged(); } } /** * Removes the item at the specified index and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the index. * * @return The item removed. */ protected ComparableObjectItem remove(int index) { ComparableObjectItem result = this.data.remove( index); fireSeriesChanged(); return result; } /** * Removes the item with the specified x-value and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param x the x-value. * @return The item removed. */ public ComparableObjectItem remove(Comparable x) { return remove(indexOf(x)); } /** * Tests this series for equality with an arbitrary object. * * @param obj the object to test against for equality * (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ComparableObjectSeries)) { return false; } if (!super.equals(obj)) { return false; } ComparableObjectSeries that = (ComparableObjectSeries) obj; if (this.maximumItemCount != that.maximumItemCount) { return false; } if (this.autoSort != that.autoSort) { return false; } if (this.allowDuplicateXValues != that.allowDuplicateXValues) { return false; } if (!ObjectUtilities.equal(this.data, that.data)) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result = super.hashCode(); // it is too slow to look at every data item, so let's just look at // the first, middle and last items... int count = getItemCount(); if (count > 0) { ComparableObjectItem item = getDataItem(0); result = 29 * result + item.hashCode(); } if (count > 1) { ComparableObjectItem item = getDataItem(count - 1); result = 29 * result + item.hashCode(); } if (count > 2) { ComparableObjectItem item = getDataItem(count / 2); result = 29 * result + item.hashCode(); } result = 29 * result + this.maximumItemCount; result = 29 * result + (this.autoSort ? 1 : 0); result = 29 * result + (this.allowDuplicateXValues ? 1 : 0); return result; } }
14,976
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/package-info.java
/** * The base package for classes that represent various types of data. */ package org.jfree.data;
102
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
RangeInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/RangeInfo.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * RangeInfo.java * -------------- * (C) Copyright 2000-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes (from 18-Sep-2001) * -------------------------- * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG); * 15-Nov-2001 : Moved to package com.jrefinery.data.* (DG); * Updated Javadoc comments (DG); * 22-Apr-2002 : Added getValueRange() method (DG); * 17-Nov-2004 : Replaced getMinimumRangeValue() --> getRangeLowerBound(), * getMaximumRangeValue() --> getRangeUpperBound(), * getValueRange() --> getRangeBounds(). * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * */ package org.jfree.data; /** * An interface (optional) that can be implemented by a dataset to assist in * determining the minimum and maximum values. See also {@link DomainInfo}. */ public interface RangeInfo { /** * Returns the minimum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The minimum value. */ public double getRangeLowerBound(boolean includeInterval); /** * Returns the maximum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The maximum value. */ public double getRangeUpperBound(boolean includeInterval); /** * Returns the range of the values in this dataset's range. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (or <code>null</code> if the dataset contains no * values). */ public Range getRangeBounds(boolean includeInterval); }
3,270
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValues.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedValues.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * KeyedValues.java * ---------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 23-Oct-2002 : Version 1 (DG); * 12-Jan-2005 : Updated Javadocs to specify new behaviour when key * is not recognised (DG); * ------------- JFREECHART 1.0.0 --------------------------------------------- * 02-May-2006 : Updated API docs (DG); * 15-Jun-2012 : Added generic types (DG); * */ package org.jfree.data; import java.util.List; /** * An ordered list of (key, value) items where the keys are unique and * non-<code>null</code>. * * @see Values * @see DefaultKeyedValues */ public interface KeyedValues extends Values { /** * Returns the key associated with the item at a given position. Note * that some implementations allow re-ordering of the data items, so the * result may be transient. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The key (never <code>null</code>). * * @throws IndexOutOfBoundsException if <code>index</code> is not in the * specified range. */ public Comparable getKey(int index); /** * Returns the index for a given key. * * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public int getIndex(Comparable key); /** * Returns the keys for the values in the collection. Note that you can * access the values in this collection by key or by index. For this * reason, the key order is important - this method should return the keys * in order. The returned list may be unmodifiable. * * @return The keys (never <code>null</code>). */ public List<Comparable> getKeys(); /** * Returns the value for a given key. * * @param key the key. * * @return The value (possibly <code>null</code>). * * @throws UnknownKeyException if the key is not recognised. */ public Number getValue(Comparable key); }
3,574
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultKeyedValue.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/DefaultKeyedValue.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * DefaultKeyedValue.java * ---------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 31-Oct-2002 : Version 1 (DG); * 13-Mar-2003 : Added equals() method, and implemented Serializable (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.base (DG); * 15-Sep-2004 : Added PublicCloneable interface (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 11-Jun-2007 : Added toString() method to help with debugging (DG); * 15-Feb-2008 : Prevent null key (DG); * 07-Apr-2008 : Removed to-do item (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import org.jfree.chart.util.PublicCloneable; /** * A (key, value) pair. This class provides a default implementation * of the {@link KeyedValue} interface. */ public class DefaultKeyedValue implements KeyedValue, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -7388924517460437712L; /** The key. */ private Comparable key; /** The value. */ private Number value; /** * Creates a new (key, value) item. * * @param key the key (should be immutable, <code>null</code> not * permitted). * @param value the value (<code>null</code> permitted). */ public DefaultKeyedValue(Comparable key, Number value) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } this.key = key; this.value = value; } /** * Returns the key. * * @return The key (never <code>null</code>). */ @Override public Comparable getKey() { return this.key; } /** * Returns the value. * * @return The value (possibly <code>null</code>). */ @Override public Number getValue() { return this.value; } /** * Sets the value. * * @param value the value (<code>null</code> permitted). */ public synchronized void setValue(Number value) { this.value = value; } /** * Tests this key-value pair for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DefaultKeyedValue)) { return false; } DefaultKeyedValue that = (DefaultKeyedValue) obj; if (!this.key.equals(that.key)) { return false; } if (this.value != null ? !this.value.equals(that.value) : that.value != null) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; result = (this.key != null ? this.key.hashCode() : 0); result = 29 * result + (this.value != null ? this.value.hashCode() : 0); return result; } /** * Returns a clone. It is assumed that both the key and value are * immutable objects, so only the references are cloned, not the objects * themselves. * * @return A clone. * * @throws CloneNotSupportedException Not thrown by this class, but * subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { DefaultKeyedValue clone = (DefaultKeyedValue) super.clone(); return clone; } /** * Returns a string representing this instance, primarily useful for * debugging. * * @return A string. */ @Override public String toString() { return "(" + this.key.toString() + ", " + this.value.toString() + ")"; } }
5,377
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Values.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/Values.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------- * Values.java * ----------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 08-Nov-2001 : Version 1 (DG); * 23-Oct-2002 : Renamed getValueCount --> getItemCount (DG);# * ------------- JFREECHART 1.0.x --------------------------------------------- * 02-May-2006 : Updated API docs (DG); * */ package org.jfree.data; /** * An interface through which (single-dimension) data values can be accessed. */ public interface Values { /** * Returns the number of items (values) in the collection. * * @return The item count (possibly zero). */ public int getItemCount(); /** * Returns the value with the specified index. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The value (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if <code>index</code> is not in the * specified range. */ public Number getValue(int index); }
2,375
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
UnknownKeyException.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/UnknownKeyException.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * UnknownKeyException.java * ------------------------ * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 12-Jan-2005 : Version 1 (DG); * */ package org.jfree.data; /** * An exception that indicates an unknown key value. */ public class UnknownKeyException extends IllegalArgumentException { /** * Creates a new exception. * * @param message a message describing the exception. */ public UnknownKeyException(String message) { super(message); } }
1,874
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DomainInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/DomainInfo.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * DomainInfo.java * --------------- * (C) Copyright 2000-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes (from 18-Sep-2001) * -------------------------- * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG); * 15-Nov-2001 : Moved to package com.jrefinery.data.* (DG); * Updated Javadoc comments (DG); * 22-Apr-2002 : Added getValueRange() method (DG); * 12-Jul-2002 : Renamed getValueRange() --> getDomainRange() (DG); * 06-Oct-2004 : Renamed getDomainRange() --> getDomainBounds() (DG); * 17-Nov-2004 : Added 'includeInterval' argument to all methods (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * */ package org.jfree.data; /** * An interface (optional) that can be implemented by a dataset to assist in * determining the minimum and maximum values. */ public interface DomainInfo { /** * Returns the minimum x-value in the dataset. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The minimum value. */ public double getDomainLowerBound(boolean includeInterval); /** * Returns the maximum x-value in the dataset. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The maximum value. */ public double getDomainUpperBound(boolean includeInterval); /** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The range (or <code>null</code> if the dataset contains no * values). */ public Range getDomainBounds(boolean includeInterval); }
3,261
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Range.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/Range.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------- * Range.java * ---------- * (C) Copyright 2002-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Chuanhao Chiu; * Bill Kelemen; * Nicolas Brodu; * Sergei Ivanov; * * Changes (from 23-Jun-2001) * -------------------------- * 22-Apr-2002 : Version 1, loosely based by code by Bill Kelemen (DG); * 30-Apr-2002 : Added getLength() and getCentralValue() methods. Changed * argument check in constructor (DG); * 13-Jun-2002 : Added contains(double) method (DG); * 22-Aug-2002 : Added fix to combine method where both ranges are null, thanks * to Chuanhao Chiu for reporting and fixing this (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 14-Aug-2003 : Added equals() method (DG); * 27-Aug-2003 : Added toString() method (BK); * 11-Sep-2003 : Added Clone Support (NB); * 23-Sep-2003 : Fixed Checkstyle issues (DG); * 25-Sep-2003 : Oops, Range immutable, clone not necessary (NB); * 05-May-2004 : Added constrain() and intersects() methods (DG); * 18-May-2004 : Added expand() method (DG); * ------------- JFreeChart 1.0.x --------------------------------------------- * 11-Jan-2006 : Added new method expandToInclude(Range, double) (DG); * 18-Dec-2007 : New methods intersects(Range) and scale(...) thanks to Sergei * Ivanov (DG); * 08-Jan-2012 : New method combineIgnoringNaN() (DG); * 23-Feb-2014 : Added isNaNRange() method (DG); * */ package org.jfree.data; import java.io.Serializable; import org.jfree.chart.util.ParamChecks; /** * Represents an immutable range of values. */ public strictfp class Range implements Serializable { /** For serialization. */ private static final long serialVersionUID = -906333695431863380L; /** The lower bound of the range. */ private double lower; /** The upper bound of the range. */ private double upper; /** * Creates a new range. * * @param lower the lower bound (must be <= upper bound). * @param upper the upper bound (must be >= lower bound). */ public Range(double lower, double upper) { if (lower > upper) { String msg = "Range(double, double): require lower (" + lower + ") <= upper (" + upper + ")."; throw new IllegalArgumentException(msg); } this.lower = lower; this.upper = upper; } /** * Returns the lower bound for the range. * * @return The lower bound. */ public double getLowerBound() { return this.lower; } /** * Returns the upper bound for the range. * * @return The upper bound. */ public double getUpperBound() { return this.upper; } /** * Returns the length of the range. * * @return The length. */ public double getLength() { return this.upper - this.lower; } /** * Returns the central value for the range. * * @return The central value. */ public double getCentralValue() { return this.lower / 2.0 + this.upper / 2.0; } /** * Returns <code>true</code> if the range contains the specified value and * <code>false</code> otherwise. * * @param value the value to lookup. * * @return <code>true</code> if the range contains the specified value. */ public boolean contains(double value) { return (value >= this.lower && value <= this.upper); } /** * Returns <code>true</code> if the range intersects with the specified * range, and <code>false</code> otherwise. * * @param b0 the lower bound (should be <= b1). * @param b1 the upper bound (should be >= b0). * * @return A boolean. */ public boolean intersects(double b0, double b1) { if (b0 <= this.lower) { return (b1 > this.lower); } else { return (b0 < this.upper && b1 >= b0); } } /** * Returns <code>true</code> if the range intersects with the specified * range, and <code>false</code> otherwise. * * @param range another range (<code>null</code> not permitted). * * @return A boolean. * * @since 1.0.9 */ public boolean intersects(Range range) { return intersects(range.getLowerBound(), range.getUpperBound()); } /** * Returns the value within the range that is closest to the specified * value. * * @param value the value. * * @return The constrained value. */ public double constrain(double value) { double result = value; if (!contains(value)) { if (value > this.upper) { result = this.upper; } else if (value < this.lower) { result = this.lower; } } return result; } /** * Creates a new range by combining two existing ranges. * <P> * Note that: * <ul> * <li>either range can be <code>null</code>, in which case the other * range is returned;</li> * <li>if both ranges are <code>null</code> the return value is * <code>null</code>.</li> * </ul> * * @param range1 the first range (<code>null</code> permitted). * @param range2 the second range (<code>null</code> permitted). * * @return A new range (possibly <code>null</code>). */ public static Range combine(Range range1, Range range2) { if (range1 == null) { return range2; } if (range2 == null) { return range1; } double l = Math.min(range1.getLowerBound(), range2.getLowerBound()); double u = Math.max(range1.getUpperBound(), range2.getUpperBound()); return new Range(l, u); } /** * Returns a new range that spans both <code>range1</code> and * <code>range2</code>. This method has a special handling to ignore * Double.NaN values. * * @param range1 the first range (<code>null</code> permitted). * @param range2 the second range (<code>null</code> permitted). * * @return A new range (possibly <code>null</code>). * * @since 1.0.15 */ public static Range combineIgnoringNaN(Range range1, Range range2) { if (range1 == null) { return range2; } if (range2 == null) { return range1; } double l = min(range1.getLowerBound(), range2.getLowerBound()); double u = max(range1.getUpperBound(), range2.getUpperBound()); return new Range(l, u); } private static double min(double d1, double d2) { if (Double.isNaN(d1)) { return d2; } if (Double.isNaN(d2)) { return d1; } return Math.min(d1, d2); } private static double max(double d1, double d2) { if (Double.isNaN(d1)) { return d2; } if (Double.isNaN(d2)) { return d1; } return Math.max(d1, d2); } /** * Returns a range that includes all the values in the specified * <code>range</code> AND the specified <code>value</code>. * * @param range the range (<code>null</code> permitted). * @param value the value that must be included. * * @return A range. * * @since 1.0.1 */ public static Range expandToInclude(Range range, double value) { if (range == null) { return new Range(value, value); } if (value < range.getLowerBound()) { return new Range(value, range.getUpperBound()); } else if (value > range.getUpperBound()) { return new Range(range.getLowerBound(), value); } else { return range; } } /** * Creates a new range by adding margins to an existing range. * * @param range the range (<code>null</code> not permitted). * @param lowerMargin the lower margin (expressed as a percentage of the * range length). * @param upperMargin the upper margin (expressed as a percentage of the * range length). * * @return The expanded range. */ public static Range expand(Range range, double lowerMargin, double upperMargin) { if (range == null) { throw new IllegalArgumentException("Null 'range' argument."); } double length = range.getLength(); double lower = range.getLowerBound() - length * lowerMargin; double upper = range.getUpperBound() + length * upperMargin; if (lower > upper) { lower = lower / 2.0 + upper / 2.0; upper = lower; } return new Range(lower, upper); } /** * Shifts the range by the specified amount. * * @param base the base range (<code>null</code> not permitted). * @param delta the shift amount. * * @return A new range. */ public static Range shift(Range base, double delta) { return shift(base, delta, false); } /** * Shifts the range by the specified amount. * * @param base the base range (<code>null</code> not permitted). * @param delta the shift amount. * @param allowZeroCrossing a flag that determines whether or not the * bounds of the range are allowed to cross * zero after adjustment. * * @return A new range. */ public static Range shift(Range base, double delta, boolean allowZeroCrossing) { ParamChecks.nullNotPermitted(base, "base"); if (allowZeroCrossing) { return new Range(base.getLowerBound() + delta, base.getUpperBound() + delta); } else { return new Range(shiftWithNoZeroCrossing(base.getLowerBound(), delta), shiftWithNoZeroCrossing(base.getUpperBound(), delta)); } } /** * Returns the given <code>value</code> adjusted by <code>delta</code> but * with a check to prevent the result from crossing <code>0.0</code>. * * @param value the value. * @param delta the adjustment. * * @return The adjusted value. */ private static double shiftWithNoZeroCrossing(double value, double delta) { if (value > 0.0) { return Math.max(value + delta, 0.0); } else if (value < 0.0) { return Math.min(value + delta, 0.0); } else { return value + delta; } } /** * Scales the range by the specified factor. * * @param base the base range (<code>null</code> not permitted). * @param factor the scaling factor (must be non-negative). * * @return A new range. * * @since 1.0.9 */ public static Range scale(Range base, double factor) { ParamChecks.nullNotPermitted(base, "base"); if (factor < 0) { throw new IllegalArgumentException("Negative 'factor' argument."); } return new Range(base.getLowerBound() * factor, base.getUpperBound() * factor); } /** * Tests this object for equality with an arbitrary object. * * @param obj the object to test against (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (!(obj instanceof Range)) { return false; } Range range = (Range) obj; if (!(this.lower == range.lower)) { return false; } if (!(this.upper == range.upper)) { return false; } return true; } /** * Returns <code>true</code> if both the lower and upper bounds are * <code>Double.NaN</code>, and <code>false</code> otherwise. * * @return A boolean. * * @since 1.0.18 */ public boolean isNaNRange() { return Double.isNaN(this.lower) && Double.isNaN(this.upper); } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(this.lower); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.upper); result = 29 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a string representation of this Range. * * @return A String "Range[lower,upper]" where lower=lower range and * upper=upper range. */ @Override public String toString() { return ("Range[" + this.lower + "," + this.upper + "]"); } }
14,377
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValueComparatorType.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedValueComparatorType.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------------- * KeyedValueComparatorType.java * ----------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 05-Mar-2003 : Version 1 (DG); * */ package org.jfree.data; /** * Used to indicate the type of a {@link KeyedValueComparator} : 'by key' or * 'by value'. */ public enum KeyedValueComparatorType { /** An object representing 'by key' sorting. */ BY_KEY("KeyedValueComparatorType.BY_KEY"), /** An object representing 'by value' sorting. */ BY_VALUE("KeyedValueComparatorType.BY_VALUE"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private KeyedValueComparatorType(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,303
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValues2D.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedValues2D.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * KeyedValues2D.java * ------------------ * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-Oct-2002 : Version 1 (DG); * 12-Jan-2005 : Updated Javadocs (DG); * */ package org.jfree.data; import java.util.List; /** * An extension of the {@link Values2D} interface where a unique key is * associated with the row and column indices. */ public interface KeyedValues2D extends Values2D { /** * Returns the row key for a given index. * * @param row the row index (zero-based). * * @return The row key. * * @throws IndexOutOfBoundsException if <code>row</code> is out of bounds. */ public Comparable getRowKey(int row); /** * Returns the row index for a given key. * * @param key the row key. * * @return The row index, or <code>-1</code> if the key is unrecognised. */ public int getRowIndex(Comparable key); /** * Returns the row keys. * * @return The keys. */ public List<Comparable> getRowKeys(); /** * Returns the column key for a given index. * * @param column the column index (zero-based). * * @return The column key. * * @throws IndexOutOfBoundsException if <code>row</code> is out of bounds. */ public Comparable getColumnKey(int column); /** * Returns the column index for a given key. * * @param key the column key. * * @return The column index, or <code>-1</code> if the key is unrecognised. */ public int getColumnIndex(Comparable key); /** * Returns the column keys. * * @return The keys. */ public List<Comparable> getColumnKeys(); /** * Returns the value associated with the specified keys. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The value. * * @throws UnknownKeyException if either key is not recognised. */ public Number getValue(Comparable rowKey, Comparable columnKey); }
3,476
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
RangeType.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/RangeType.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * RangeType.java * -------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 24-Feb-2005 : Version 1 (DG); * */ package org.jfree.data; /** * Used to indicate the type of range to display on an axis (full, positive or * negative). */ public enum RangeType { /** Full range (positive and negative). */ FULL("RangeType.FULL"), /** Positive range. */ POSITIVE("RangeType.POSITIVE"), /** Negative range. */ NEGATIVE("RangeType.NEGATIVE"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private RangeType(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,226
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValueComparator.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedValueComparator.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * KeyedValueComparator.java * ------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 05-Mar-2003 : Version 1 (DG); * 27-Aug-2003 : Moved SortOrder from org.jfree.data --> org.jfree.util (DG); * 12-Jan-2005 : Added accessor methods (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import java.util.Comparator; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.SortOrder; /** * A utility class that can compare and order two {@link KeyedValue} instances * and sort them into ascending or descending order by key or by value. */ public class KeyedValueComparator implements Comparator<KeyedValue>, Serializable { /** The comparator type. */ private KeyedValueComparatorType type; /** The sort order. */ private SortOrder order; /** * Creates a new comparator. * * @param type the type (<code>BY_KEY</code> or <code>BY_VALUE</code>, * <code>null</code> not permitted). * @param order the order (<code>null</code> not permitted). */ public KeyedValueComparator(KeyedValueComparatorType type, SortOrder order) { ParamChecks.nullNotPermitted(type, "type"); ParamChecks.nullNotPermitted(order, "order"); this.type = type; this.order = order; } /** * Returns the type. * * @return The type (never <code>null</code>). */ public KeyedValueComparatorType getType() { return this.type; } /** * Returns the sort order. * * @return The sort order (never <code>null</code>). */ public SortOrder getOrder() { return this.order; } /** * Compares two {@link KeyedValue} instances and returns an * <code>int</code> that indicates the relative order of the two objects. * * @param kv1 object 1. * @param kv2 object 2. * * @return An int indicating the relative order of the objects. */ @Override public int compare(KeyedValue kv1, KeyedValue kv2) { if (kv2 == null) { if (kv1 ==null) { return 0; } return -1; } if (kv1 == null) { return 1; } int result; if (this.type == KeyedValueComparatorType.BY_KEY) { if (this.order.equals(SortOrder.ASCENDING)) { result = kv1.getKey().compareTo(kv2.getKey()); } else if (this.order.equals(SortOrder.DESCENDING)) { result = kv2.getKey().compareTo(kv1.getKey()); } else { throw new IllegalArgumentException("Unrecognised sort order."); } } else if (this.type == KeyedValueComparatorType.BY_VALUE) { Number n1 = kv1.getValue(); Number n2 = kv2.getValue(); if (n2 == null) { return -1; } if (n1 == null) { return 1; } double d1 = n1.doubleValue(); double d2 = n2.doubleValue(); if (this.order.equals(SortOrder.ASCENDING)) { if (d1 > d2) { result = 1; } else if (d1 < d2) { result = -1; } else { result = 0; } } else if (this.order.equals(SortOrder.DESCENDING)) { if (d1 > d2) { result = -1; } else if (d1 < d2) { result = 1; } else { result = 0; } } else { throw new IllegalArgumentException("Unrecognised sort order."); } } else { throw new IllegalArgumentException("Unrecognised type."); } return result; } }
5,432
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedObject.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedObject.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * KeyedObject.java * ---------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 05-Feb-2003 : Version 1 (DG); * 27-Jan-2003 : Implemented Cloneable and Serializable, and added an equals() * method (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; /** * A (key, object) pair. */ public class KeyedObject implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 2677930479256885863L; /** The key. */ private Comparable key; /** The object. */ private Object object; /** * Creates a new (key, object) pair. * * @param key the key. * @param object the object (<code>null</code> permitted). */ public KeyedObject(Comparable key, Object object) { this.key = key; this.object = object; } /** * Returns the key. * * @return The key. */ public Comparable getKey() { return this.key; } /** * Returns the object. * * @return The object (possibly <code>null</code>). */ public Object getObject() { return this.object; } /** * Sets the object. * * @param object the object (<code>null</code> permitted). */ public void setObject(Object object) { this.object = object; } /** * Returns a clone of this object. It is assumed that the key is an * immutable object, so it is not deep-cloned. The object is deep-cloned * if it implements {@link PublicCloneable}, otherwise a shallow clone is * made. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { KeyedObject clone = (KeyedObject) super.clone(); if (this.object instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.object; clone.object = pc.clone(); } return clone; } /** * Tests if this object is equal to another. * * @param obj the other object. * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof KeyedObject)) { return false; } KeyedObject that = (KeyedObject) obj; if (!ObjectUtilities.equal(this.key, that.key)) { return false; } if (!ObjectUtilities.equal(this.object, that.object)) { return false; } return true; } }
4,206
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/DataUtilities.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * DataUtilities.java * ------------------ * (C) Copyright 2003-2009, by Object Refinery Limited and contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2511330); * * Changes * ------- * 05-Mar-2003 : Version 1 (DG); * 03-Mar-2005 : Moved createNumberArray() and createNumberArray2D() methods * from the DatasetUtilities class (DG); * 17-May-2005 : Added calculateColumnTotal() and calculateRowTotal() * methods (DG); * 28-Jan-2009 : Added equal(double[][], double[][]) method (DG); * 28-Jan-2009 : Added clone(double[][]) method (DG); * 04-Feb-2009 : Added calculateColumnTotal/RowTotal variants (PK); * */ package org.jfree.data; import java.util.Arrays; import org.jfree.data.general.DatasetUtilities; /** * Utility methods for use with some of the data classes (but not the datasets, * see {@link DatasetUtilities}). */ public abstract class DataUtilities { /** * Tests two arrays for equality. To be considered equal, the arrays must * have exactly the same dimensions, and the values in each array must also * match (two values that qre both NaN or both INF are considered equal * in this test). * * @param a the first array (<code>null</code> permitted). * @param b the second array (<code>null</code> permitted). * * @return A boolean. * * @since 1.0.13 */ public static boolean equal(double[][] a, double[][] b) { if (a == null) { return (b == null); } if (b == null) { return false; // already know 'a' isn't null } if (a.length != b.length) { return false; } for (int i = 0; i < a.length; i++) { if (!Arrays.equals(a[i], b[i])) { return false; } } return true; } /** * Returns a clone of the specified array. * * @param source the source array (<code>null</code> not permitted). * * @return A clone of the array. * * @since 1.0.13 */ public static double[][] clone(double[][] source) { if (source == null) { throw new IllegalArgumentException("Null 'source' argument."); } double[][] clone = new double[source.length][]; for (int i = 0; i < source.length; i++) { if (source[i] != null) { double[] row = new double[source[i].length]; System.arraycopy(source[i], 0, row, 0, source[i].length); clone[i] = row; } } return clone; } /** * Returns the total of the values in one column of the supplied data * table. * * @param data the table of values (<code>null</code> not permitted). * @param column the column index (zero-based). * * @return The total of the values in the specified column. */ public static double calculateColumnTotal(Values2D data, int column) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } double total = 0.0; int rowCount = data.getRowCount(); for (int r = 0; r < rowCount; r++) { Number n = data.getValue(r, column); if (n != null) { total += n.doubleValue(); } } return total; } /** * Returns the total of the values in one column of the supplied data * table by taking only the row numbers in the array into account. * * @param data the table of values (<code>null</code> not permitted). * @param column the column index (zero-based). * @param validRows the array with valid rows (zero-based). * * @return The total of the valid values in the specified column. * * @since 1.0.13 */ public static double calculateColumnTotal(Values2D data, int column, int[] validRows) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } double total = 0.0; int rowCount = data.getRowCount(); for (int row : validRows) { if (row < rowCount) { Number n = data.getValue(row, column); if (n != null) { total += n.doubleValue(); } } } return total; } /** * Returns the total of the values in one row of the supplied data * table. * * @param data the table of values (<code>null</code> not permitted). * @param row the row index (zero-based). * * @return The total of the values in the specified row. */ public static double calculateRowTotal(Values2D data, int row) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } double total = 0.0; int columnCount = data.getColumnCount(); for (int c = 0; c < columnCount; c++) { Number n = data.getValue(row, c); if (n != null) { total += n.doubleValue(); } } return total; } /** * Returns the total of the values in one row of the supplied data * table by taking only the column numbers in the array into account. * * @param data the table of values (<code>null</code> not permitted). * @param row the row index (zero-based). * @param validCols the array with valid cols (zero-based). * * @return The total of the valid values in the specified row. * * @since 1.0.13 */ public static double calculateRowTotal(Values2D data, int row, int[] validCols) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } double total = 0.0; int colCount = data.getColumnCount(); for (int col : validCols) { if (col < colCount) { Number n = data.getValue(row, col); if (n != null) { total += n.doubleValue(); } } } return total; } /** * Constructs an array of <code>Number</code> objects from an array of * <code>double</code> primitives. * * @param data the data (<code>null</code> not permitted). * * @return An array of <code>Double</code>. */ public static Number[] createNumberArray(double[] data) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } Number[] result = new Number[data.length]; for (int i = 0; i < data.length; i++) { result[i] = data[i]; } return result; } /** * Constructs an array of arrays of <code>Number</code> objects from a * corresponding structure containing <code>double</code> primitives. * * @param data the data (<code>null</code> not permitted). * * @return An array of <code>Double</code>. */ public static Number[][] createNumberArray2D(double[][] data) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } int l1 = data.length; Number[][] result = new Number[l1][]; for (int i = 0; i < l1; i++) { result[i] = createNumberArray(data[i]); } return result; } /** * Returns a {@link KeyedValues} instance that contains the cumulative * percentage values for the data in another {@link KeyedValues} instance. * <p> * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%). * * @param data the data (<code>null</code> not permitted). * * @return The cumulative percentages. */ public static KeyedValues getCumulativePercentages(KeyedValues data) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } DefaultKeyedValues result = new DefaultKeyedValues(); double total = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { total = total + v.doubleValue(); } } double runningTotal = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { runningTotal = runningTotal + v.doubleValue(); } result.addValue(data.getKey(i), new Double(runningTotal / total)); } return result; } }
10,018
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultKeyedValues2D.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/DefaultKeyedValues2D.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * DefaultKeyedValues2D.java * ------------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andreas Schroeder; * * Changes * ------- * 28-Oct-2002 : Version 1 (DG); * 21-Jan-2003 : Updated Javadocs (DG); * 13-Mar-2003 : Implemented Serializable (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 31-Mar-2004 : Made the rows optionally sortable by a flag (AS); * 01-Apr-2004 : Implemented remove method (AS); * 05-Apr-2004 : Added clear() method (DG); * 15-Sep-2004 : Fixed clone() method (DG); * 12-Jan-2005 : Fixed bug in getValue() method (DG); * 23-Mar-2005 : Implemented PublicCloneable (DG); * 09-Jun-2005 : Modified getValue() method to throw exception for unknown * keys (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 18-Jan-2007 : Fixed bug in getValue() method (DG); * 30-Mar-2007 : Fixed bug 1690654, problem with removeValue() (DG); * 21-Nov-2007 : Fixed bug (1835955) in removeColumn(Comparable) method (DG); * 23-Nov-2007 : Added argument checks to removeRow(Comparable) to make it * consistent with the removeRow(Comparable) method (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; /** * A data structure that stores zero, one or many values, where each value * is associated with two keys (a 'row' key and a 'column' key). The keys * should be (a) instances of {@link Comparable} and (b) immutable. */ public class DefaultKeyedValues2D implements KeyedValues2D, PublicCloneable, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -5514169970951994748L; /** The row keys. */ private List<Comparable> rowKeys; /** The column keys. */ private List<Comparable> columnKeys; /** The row data. */ private List<DefaultKeyedValues> rows; /** If the row keys should be sorted by their comparable order. */ private boolean sortRowKeys; /** * Creates a new instance (initially empty). */ public DefaultKeyedValues2D() { this(false); } /** * Creates a new instance (initially empty). * * @param sortRowKeys if the row keys should be sorted. */ public DefaultKeyedValues2D(boolean sortRowKeys) { this.rowKeys = new java.util.ArrayList<Comparable>(); this.columnKeys = new java.util.ArrayList<Comparable>(); this.rows = new java.util.ArrayList<DefaultKeyedValues>(); this.sortRowKeys = sortRowKeys; } /** * Returns the row count. * * @return The row count. * * @see #getColumnCount() */ @Override public int getRowCount() { return this.rowKeys.size(); } /** * Returns the column count. * * @return The column count. * * @see #getRowCount() */ @Override public int getColumnCount() { return this.columnKeys.size(); } /** * Returns the value for a given row and column. * * @param row the row index. * @param column the column index. * * @return The value. * * @see #getValue(Comparable, Comparable) */ @Override public Number getValue(int row, int column) { Number result = null; DefaultKeyedValues rowData = this.rows.get(row); if (rowData != null) { Comparable columnKey = this.columnKeys.get(column); // the row may not have an entry for this key, in which case the // return value is null int index = rowData.getIndex(columnKey); if (index >= 0) { result = rowData.getValue(index); } } return result; } /** * Returns the key for a given row. * * @param row the row index (in the range 0 to {@link #getRowCount()} - 1). * * @return The row key. * * @see #getRowIndex(Comparable) * @see #getColumnKey(int) */ @Override public Comparable getRowKey(int row) { return this.rowKeys.get(row); } /** * Returns the row index for a given key. * * @param key the key (<code>null</code> not permitted). * * @return The row index. * * @see #getRowKey(int) * @see #getColumnIndex(Comparable) */ @Override public int getRowIndex(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } if (this.sortRowKeys) { return Collections.binarySearch(this.rowKeys, key, new Comparator<Comparable>() { @Override public int compare(Comparable o1, Comparable o2) { return o1.compareTo(o2); } }); //FIXME MMC remove this comparator } else { return this.rowKeys.indexOf(key); } } /** * Returns the row keys in an unmodifiable list. * * @return The row keys. * * @see #getColumnKeys() */ @Override public List<Comparable> getRowKeys() { return Collections.unmodifiableList(this.rowKeys); } /** * Returns the key for a given column. * * @param column the column (in the range 0 to {@link #getColumnCount()} * - 1). * * @return The key. * * @see #getColumnIndex(Comparable) * @see #getRowKey(int) */ @Override public Comparable getColumnKey(int column) { return this.columnKeys.get(column); } /** * Returns the column index for a given key. * * @param key the key (<code>null</code> not permitted). * * @return The column index. * * @see #getColumnKey(int) * @see #getRowIndex(Comparable) */ @Override public int getColumnIndex(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return this.columnKeys.indexOf(key); } /** * Returns the column keys in an unmodifiable list. * * @return The column keys. * * @see #getRowKeys() */ @Override public List<Comparable> getColumnKeys() { return Collections.unmodifiableList(this.columnKeys); } /** * Returns the value for the given row and column keys. This method will * throw an {@link UnknownKeyException} if either key is not defined in the * data structure. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @see #addValue(Number, Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ @Override public Number getValue(Comparable rowKey, Comparable columnKey) { if (rowKey == null) { throw new IllegalArgumentException("Null 'rowKey' argument."); } if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } // check that the column key is defined in the 2D structure if (!(this.columnKeys.contains(columnKey))) { throw new UnknownKeyException("Unrecognised columnKey: " + columnKey); } // now fetch the row data - need to bear in mind that the row // structure may not have an entry for the column key, but that we // have already checked that the key is valid for the 2D structure int row = getRowIndex(rowKey); if (row >= 0) { DefaultKeyedValues rowData = this.rows.get(row); int col = rowData.getIndex(columnKey); return (col >= 0 ? rowData.getValue(col) : null); } else { throw new UnknownKeyException("Unrecognised rowKey: " + rowKey); } } /** * Adds a value to the table. Performs the same function as * #setValue(Number, Comparable, Comparable). * * @param value the value (<code>null</code> permitted). * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #setValue(Number, Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ public void addValue(Number value, Comparable rowKey, Comparable columnKey) { // defer argument checking setValue(value, rowKey, columnKey); } /** * Adds or updates a value. * * @param value the value (<code>null</code> permitted). * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #addValue(Number, Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ public void setValue(Number value, Comparable rowKey, Comparable columnKey) { DefaultKeyedValues row; int rowIndex = getRowIndex(rowKey); if (rowIndex >= 0) { row = this.rows.get(rowIndex); } else { row = new DefaultKeyedValues(); if (this.sortRowKeys) { rowIndex = -rowIndex - 1; this.rowKeys.add(rowIndex, rowKey); this.rows.add(rowIndex, row); } else { this.rowKeys.add(rowKey); this.rows.add(row); } } row.setValue(columnKey, value); int columnIndex = this.columnKeys.indexOf(columnKey); if (columnIndex < 0) { this.columnKeys.add(columnKey); } } /** * Removes a value from the table by setting it to <code>null</code>. If * all the values in the specified row and/or column are now * <code>null</code>, the row and/or column is removed from the table. * * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #addValue(Number, Comparable, Comparable) */ public void removeValue(Comparable rowKey, Comparable columnKey) { setValue(null, rowKey, columnKey); // 1. check whether the row is now empty. boolean allNull = true; int rowIndex = getRowIndex(rowKey); DefaultKeyedValues row = this.rows.get(rowIndex); for (int item = 0, itemCount = row.getItemCount(); item < itemCount; item++) { if (row.getValue(item) != null) { allNull = false; break; } } if (allNull) { this.rowKeys.remove(rowIndex); this.rows.remove(rowIndex); } // 2. check whether the column is now empty. allNull = true; //int columnIndex = getColumnIndex(columnKey); for (DefaultKeyedValues rowItem : this.rows) { int columnIndex = rowItem.getIndex(columnKey); if (columnIndex >= 0 && rowItem.getValue(columnIndex) != null) { allNull = false; break; } } if (allNull) { for (DefaultKeyedValues rowItem : this.rows) { int columnIndex = rowItem.getIndex(columnKey); if (columnIndex >= 0) { rowItem.removeValue(columnIndex); } } this.columnKeys.remove(columnKey); } } /** * Removes a row. * * @param rowIndex the row index. * * @see #removeRow(Comparable) * @see #removeColumn(int) */ public void removeRow(int rowIndex) { this.rowKeys.remove(rowIndex); this.rows.remove(rowIndex); } /** * Removes a row from the table. * * @param rowKey the row key (<code>null</code> not permitted). * * @see #removeRow(int) * @see #removeColumn(Comparable) * * @throws UnknownKeyException if <code>rowKey</code> is not defined in the * table. */ public void removeRow(Comparable rowKey) { if (rowKey == null) { throw new IllegalArgumentException("Null 'rowKey' argument."); } int index = getRowIndex(rowKey); if (index >= 0) { removeRow(index); } else { throw new UnknownKeyException("Unknown key: " + rowKey); } } /** * Removes a column. * * @param columnIndex the column index. * * @see #removeColumn(Comparable) * @see #removeRow(int) */ public void removeColumn(int columnIndex) { Comparable columnKey = getColumnKey(columnIndex); removeColumn(columnKey); } /** * Removes a column from the table. * * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if the table does not contain a column with * the specified key. * @throws IllegalArgumentException if <code>columnKey</code> is * <code>null</code>. * * @see #removeColumn(int) * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } if (!this.columnKeys.contains(columnKey)) { throw new UnknownKeyException("Unknown key: " + columnKey); } for (DefaultKeyedValues rowData : this.rows) { int index = rowData.getIndex(columnKey); if (index >= 0) { rowData.removeValue(columnKey); } } this.columnKeys.remove(columnKey); } /** * Clears all the data and associated keys. */ public void clear() { this.rowKeys.clear(); this.columnKeys.clear(); this.rows.clear(); } /** * Tests if this object is equal to another. * * @param o the other object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object o) { if (o == null) { return false; } if (o == this) { return true; } if (!(o instanceof KeyedValues2D)) { return false; } KeyedValues2D kv2D = (KeyedValues2D) o; if (!getRowKeys().equals(kv2D.getRowKeys())) { return false; } if (!getColumnKeys().equals(kv2D.getColumnKeys())) { return false; } int rowCount = getRowCount(); if (rowCount != kv2D.getRowCount()) { return false; } int colCount = getColumnCount(); if (colCount != kv2D.getColumnCount()) { return false; } for (int r = 0; r < rowCount; r++) { for (int c = 0; c < colCount; c++) { Number v1 = getValue(r, c); Number v2 = kv2D.getValue(r, c); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; result = this.rowKeys.hashCode(); result = 29 * result + this.columnKeys.hashCode(); result = 29 * result + this.rows.hashCode(); return result; } /** * Returns a clone. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { DefaultKeyedValues2D clone = (DefaultKeyedValues2D) super.clone(); // for the keys, a shallow copy should be fine because keys // should be immutable... clone.columnKeys = new java.util.ArrayList<Comparable>(this.columnKeys); clone.rowKeys = new java.util.ArrayList<Comparable>(this.rowKeys); // but the row data requires a deep copy clone.rows = ObjectUtilities.deepClone(this.rows); return clone; } }
18,215
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedObjects.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedObjects.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * KeyedObjects.java * ----------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 31-Oct-2002 : Version 1 (DG); * 11-Jan-2005 : Minor tidy up (DG); * 28-Sep-2007 : Clean up equals() method (DG); * 03-Oct-2007 : Make method behaviour consistent with DefaultKeyedValues (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.PublicCloneable; /** * A collection of (key, object) pairs. */ public class KeyedObjects implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 1321582394193530984L; /** Storage for the data. */ private List<KeyedObject> data; /** * Creates a new collection (initially empty). */ public KeyedObjects() { this.data = new java.util.ArrayList<KeyedObject>(); } /** * Returns the number of items (values) in the collection. * * @return The item count. */ public int getItemCount() { return this.data.size(); } /** * Returns an object from the list. * * @param item the item index (zero-based). * * @return The object (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ public Object getObject(int item) { Object result = null; KeyedObject kobj = this.data.get(item); if (kobj != null) { result = kobj.getObject(); } return result; } /** * Returns the key at the specified position in the list. * * @param index the item index (zero-based). * * @return The row key. * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. * * @see #getIndex(Comparable) */ public Comparable getKey(int index) { Comparable result = null; KeyedObject item = this.data.get(index); if (item != null) { result = item.getKey(); } return result; } /** * Returns the index for a given key, or <code>-1</code>. * * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @see #getKey(int) */ public int getIndex(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } int i = 0; for (KeyedObject ko : this.data) { if (ko.getKey().equals(key)) { return i; } i++; } return -1; } /** * Returns a list containing all the keys in the list. * * @return The keys (never <code>null</code>). */ public List<Comparable> getKeys() { List<Comparable> result = new java.util.ArrayList<Comparable>(); for (KeyedObject ko : this.data) { result.add(ko.getKey()); } return result; } /** * Returns the object for a given key. If the key is not recognised, the * method should return <code>null</code>. * * @param key the key. * * @return The object (possibly <code>null</code>). * * @see #addObject(Comparable, Object) */ public Object getObject(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key + ") is not recognised."); } return getObject(index); } /** * Adds a new object to the collection, or overwrites an existing object. * This is the same as the {@link #setObject(Comparable, Object)} method. * * @param key the key. * @param object the object. * * @see #getObject(Comparable) */ public void addObject(Comparable key, Object object) { setObject(key, object); } /** * Replaces an existing object, or adds a new object to the collection. * This is the same as the {@link #addObject(Comparable, Object)} * method. * * @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 = this.data.get(keyIndex); ko.setObject(object); } else { KeyedObject ko = new KeyedObject(key, object); this.data.add(ko); } } /** * 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 */ public void insertValue(int position, Comparable key, Object value) { if (position < 0 || position > this.data.size()) { throw new IllegalArgumentException("'position' out of bounds."); } if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } 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); } } /** * Removes a value from the collection. * * @param index the index of the item to remove. * * @see #removeValue(Comparable) */ public void removeValue(int index) { this.data.remove(index); } /** * Removes a value from the collection. * * @param key the key (<code>null</code> not permitted). * * @see #removeValue(int) * * @throws UnknownKeyException if the key is not recognised. */ public void removeValue(Comparable key) { // defer argument checking int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key.toString() + ") is not recognised."); } removeValue(index); } /** * Clears all values from the collection. * * @since 1.0.7 */ public void clear() { this.data.clear(); } /** * Returns a clone of this object. Keys in the list should be immutable * and are not cloned. Objects in the list are cloned only if they * implement {@link PublicCloneable}. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { KeyedObjects clone = (KeyedObjects) super.clone(); clone.data = new java.util.ArrayList<KeyedObject>(); for (KeyedObject ko : this.data) { clone.data.add((KeyedObject) ko.clone()); } return clone; } /** * Tests this object for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof KeyedObjects)) { return false; } KeyedObjects that = (KeyedObjects) obj; int count = getItemCount(); if (count != that.getItemCount()) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Object o1 = getObject(i); Object o2 = that.getObject(i); if (o1 == null) { if (o2 != null) { return false; } } else { if (!o1.equals(o2)) { return false; } } } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { return (this.data != null ? this.data.hashCode() : 0); } }
10,142
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Values2D.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/Values2D.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * Values2D.java * ------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 28-Oct-2002 : Version 1 (DG); * */ package org.jfree.data; /** * A general purpose interface that can be used to access a table of values. */ public interface Values2D { /** * Returns the number of rows in the table. * * @return The row count. */ public int getRowCount(); /** * Returns the number of columns in the table. * * @return The column count. */ public int getColumnCount(); /** * Returns a value from the table. * * @param row the row index (zero-based). * @param column the column index (zero-based). * * @return The value (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if the <code>row</code> * or <code>column</code> is out of bounds. */ public Number getValue(int row, int column); }
2,308
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Value.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/Value.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------- * Value.java * ---------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 28-Oct-2002 : Version 1 (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.base (DG); * */ package org.jfree.data; /** * A general purpose interface for accessing a value. */ public interface Value { /** * Returns the value. * * @return The value (possibly <code>null</code>). */ public Number getValue(); }
1,806
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultKeyedValues.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/DefaultKeyedValues.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * DefaultKeyedValues.java * ----------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Thomas Morgner; * * Changes: * -------- * 31-Oct-2002 : Version 1 (DG); * 11-Feb-2003 : Fixed bug in getValue(key) method for unrecognised key (DG); * 05-Mar-2003 : Added methods to sort stored data 'by key' or 'by value' (DG); * 13-Mar-2003 : Implemented Serializable (DG); * 08-Apr-2003 : Modified removeValue(Comparable) method to fix bug 717049 (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 27-Aug-2003 : Moved SortOrder from org.jfree.data --> org.jfree.util (DG); * 09-Feb-2004 : Modified getIndex() method - see bug report 893256 (DG); * 15-Sep-2004 : Updated clone() method and added PublicCloneable * interface (DG); * 25-Nov-2004 : Small update to the clone() implementation (DG); * 24-Feb-2005 : Added methods addValue(Comparable, double) and * setValue(Comparable, double) for convenience (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 31-Jul-2006 : Added a clear() method (DG); * 01-Aug-2006 : Added argument check to getIndex() method (DG); * 30-Apr-2007 : Added insertValue() methods (DG); * 31-Oct-2007 : Performance improvements by using separate lists for keys and * values (TM); * 21-Nov-2007 : Fixed bug in removeValue() method from previous patch (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.SortOrder; /** * An ordered list of (key, value) items. This class provides a default * implementation of the {@link KeyedValues} interface. */ public class DefaultKeyedValues implements KeyedValues, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 8468154364608194797L; /** Storage for the keys. */ private List<Comparable> keys; /** Storage for the values. */ private List<Number> values; /** * Contains (key, Integer) mappings, where the Integer is the index for * the key in the list. */ private Map<Comparable, Integer> indexMap; /** * Creates a new collection (initially empty). */ public DefaultKeyedValues() { this.keys = new ArrayList<Comparable>(); this.values = new ArrayList<Number>(); this.indexMap = new HashMap<Comparable, Integer>(); } /** * Returns the number of items (values) in the collection. * * @return The item count. */ @Override public int getItemCount() { return this.indexMap.size(); } /** * Returns a value. * * @param item the item of interest (zero-based index). * * @return The value (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ @Override public Number getValue(int item) { return this.values.get(item); } /** * Returns a key. * * @param index the item index (zero-based). * * @return The row key. * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. */ @Override public Comparable getKey(int index) { return this.keys.get(index); } /** * Returns the index for a given key. * * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is not recognised. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ @Override public int getIndex(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } final Integer i = this.indexMap.get(key); if (i == null) { return -1; // key not found } return i; } /** * Returns the keys for the values in the collection. * * @return The keys (never <code>null</code>). */ @Override public List<Comparable> getKeys() { return new ArrayList<Comparable>(this.keys); } /** * Returns the value for a given key. * * @param key the key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @throws UnknownKeyException if the key is not recognised. * * @see #getValue(int) */ @Override public Number getValue(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("Key not found: " + key); } return getValue(index); } /** * Updates an existing value, or adds a new value to the collection. * * @param key the key (<code>null</code> not permitted). * @param value the value. * * @see #addValue(Comparable, Number) */ public void addValue(Comparable key, double value) { addValue(key, new Double(value)); } /** * Adds a new value to the collection, or updates an existing value. * This method passes control directly to the * {@link #setValue(Comparable, Number)} method. * * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public void addValue(Comparable key, Number value) { setValue(key, value); } /** * Updates an existing value, or adds a new value to the collection. * * @param key the key (<code>null</code> not permitted). * @param value the value. */ public void setValue(Comparable key, double value) { setValue(key, new Double(value)); } /** * Updates an existing value, or adds a new value to the collection. * * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public void setValue(Comparable key, Number value) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } int keyIndex = getIndex(key); if (keyIndex >= 0) { this.keys.set(keyIndex, key); this.values.set(keyIndex, value); } else { this.keys.add(key); this.values.add(value); this.indexMap.put(key, this.keys.size() - 1); } } /** * 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 0 to getItemCount()). * @param key the key (<code>null</code> not permitted). * @param value the value. * * @since 1.0.6 */ public void insertValue(int position, Comparable key, double value) { insertValue(position, key, new Double(value)); } /** * 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 0 to getItemCount()). * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * * @since 1.0.6 */ public void insertValue(int position, Comparable key, Number value) { if (position < 0 || position > getItemCount()) { throw new IllegalArgumentException("'position' out of bounds."); } if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } int pos = getIndex(key); if (pos == position) { this.keys.set(pos, key); this.values.set(pos, value); } else { if (pos >= 0) { this.keys.remove(pos); this.values.remove(pos); } this.keys.add(position, key); this.values.add(position, value); rebuildIndex(); } } /** * Rebuilds the key to indexed-position mapping after an positioned insert * or a remove operation. */ private void rebuildIndex () { this.indexMap.clear(); for (int i = 0; i < this.keys.size(); i++) { final Comparable key = this.keys.get(i); this.indexMap.put(key, i); } } /** * Removes a value from the collection. * * @param index the index of the item to remove (in the range * <code>0</code> to <code>getItemCount() - 1</code>). * * @throws IndexOutOfBoundsException if <code>index</code> is not within * the specified range. */ public void removeValue(int index) { this.keys.remove(index); this.values.remove(index); rebuildIndex(); } /** * Removes a value from the collection. * * @param key the item key (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * @throws UnknownKeyException if <code>key</code> is not recognised. */ public void removeValue(Comparable key) { int index = getIndex(key); if (index < 0) { throw new UnknownKeyException("The key (" + key + ") is not recognised."); } removeValue(index); } /** * Clears all values from the collection. * * @since 1.0.2 */ public void clear() { this.keys.clear(); this.values.clear(); this.indexMap.clear(); } /** * Sorts the items in the list by key. * * @param order the sort order (<code>null</code> not permitted). */ public void sortByKeys(SortOrder order) { final int size = this.keys.size(); final DefaultKeyedValue[] data = new DefaultKeyedValue[size]; for (int i = 0; i < size; i++) { data[i] = new DefaultKeyedValue(this.keys.get(i), this.values.get(i)); } Comparator<KeyedValue> comparator = new KeyedValueComparator( KeyedValueComparatorType.BY_KEY, order); Arrays.sort(data, comparator); clear(); for (final DefaultKeyedValue value : data) { addValue(value.getKey(), value.getValue()); } } /** * Sorts the items in the list by value. If the list contains * <code>null</code> values, they will sort to the end of the list, * irrespective of the sort order. * * @param order the sort order (<code>null</code> not permitted). */ public void sortByValues(SortOrder order) { final int size = this.keys.size(); final DefaultKeyedValue[] data = new DefaultKeyedValue[size]; for (int i = 0; i < size; i++) { data[i] = new DefaultKeyedValue(this.keys.get(i), this.values.get(i)); } Comparator<KeyedValue> comparator = new KeyedValueComparator( KeyedValueComparatorType.BY_VALUE, order); Arrays.sort(data, comparator); clear(); for (final DefaultKeyedValue value : data) { addValue(value.getKey(), value.getValue()); } } /** * Tests if this object is equal to another. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof KeyedValues)) { return false; } KeyedValues that = (KeyedValues) obj; int count = getItemCount(); if (count != that.getItemCount()) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Number v1 = getValue(i); Number v2 = that.getValue(i); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { return (this.keys != null ? this.keys.hashCode() : 0); } /** * Returns a clone. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses might. */ @Override public Object clone() throws CloneNotSupportedException { DefaultKeyedValues clone = (DefaultKeyedValues) super.clone(); clone.keys = ObjectUtilities.clone(this.keys); clone.values = ObjectUtilities.clone(this.values); clone.indexMap = ObjectUtilities.clone(this.indexMap); return clone; } }
14,958
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DomainOrder.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/DomainOrder.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * DomainOrder.java * ---------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 29-Jul-2004 : Version 1 (DG); * */ package org.jfree.data; /** * Used to indicate sorting order if any (ascending, descending or none). */ public enum DomainOrder { /** No order. */ NONE("DomainOrder.NONE"), /** Ascending order. */ ASCENDING("DomainOrder.ASCENDING"), /** Descending order. */ DESCENDING("DomainOrder.DESCENDING"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private DomainOrder(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,206
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyToGroupMap.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyToGroupMap.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * KeyToGroupMap.java * ------------------ * (C) Copyright 2004-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Apr-2004 : Version 1 (DG); * 07-Jul-2004 : Added a group list to ensure group index is consistent, fixed * cloning problem (DG); * 18-Aug-2005 : Added casts in clone() method to suppress 1.5 compiler * warnings - see patch 1260587 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; /** * A class that maps keys (instances of <code>Comparable</code>) to groups. */ public class KeyToGroupMap implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -2228169345475318082L; /** The default group. */ private Comparable defaultGroup; /** The groups. */ private List<Comparable> groups; /** A mapping between keys and groups. */ private Map<Comparable, Comparable> keyToGroupMap; /** * Creates a new map with a default group named 'Default Group'. */ public KeyToGroupMap() { this("Default Group"); } /** * Creates a new map with the specified default group. * * @param defaultGroup the default group (<code>null</code> not permitted). */ public KeyToGroupMap(Comparable defaultGroup) { if (defaultGroup == null) { throw new IllegalArgumentException("Null 'defaultGroup' argument."); } this.defaultGroup = defaultGroup; this.groups = new ArrayList<Comparable>(); this.keyToGroupMap = new HashMap<Comparable, Comparable>(); } /** * Returns the number of groups in the map. * * @return The number of groups in the map. */ public int getGroupCount() { return this.groups.size() + 1; } /** * Returns a list of the groups (always including the default group) in the * map. The returned list is independent of the map, so altering the list * will have no effect. * * @return The groups (never <code>null</code>). */ public List<Comparable> getGroups() { List<Comparable> result = new ArrayList<Comparable>(); result.add(this.defaultGroup); for (Comparable group : this.groups) { if (!result.contains(group)) { result.add(group); } } return result; } /** * Returns the index for the group. * * @param group the group. * * @return The group index (or -1 if the group is not represented within * the map). */ public int getGroupIndex(Comparable group) { int result = this.groups.indexOf(group); if (result < 0) { if (this.defaultGroup.equals(group)) { result = 0; } } else { result = result + 1; } return result; } /** * Returns the group that a key is mapped to. * * @param key the key (<code>null</code> not permitted). * * @return The group (never <code>null</code>, returns the default group if * there is no mapping for the specified key). */ public Comparable getGroup(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } Comparable result = this.defaultGroup; Comparable group = this.keyToGroupMap.get(key); if (group != null) { result = group; } return result; } /** * Maps a key to a group. * * @param key the key (<code>null</code> not permitted). * @param group the group (<code>null</code> permitted, clears any * existing mapping). */ public void mapKeyToGroup(Comparable key, Comparable group) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } Comparable currentGroup = getGroup(key); if (!currentGroup.equals(this.defaultGroup)) { if (!currentGroup.equals(group)) { int count = getKeyCount(currentGroup); if (count == 1) { this.groups.remove(currentGroup); } } } if (group == null) { this.keyToGroupMap.remove(key); } else { if (!this.groups.contains(group)) { if (!this.defaultGroup.equals(group)) { this.groups.add(group); } } this.keyToGroupMap.put(key, group); } } /** * Returns the number of keys mapped to the specified group. This method * won't always return an accurate result for the default group, since * explicit mappings are not required for this group. * * @param group the group (<code>null</code> not permitted). * * @return The key count. */ public int getKeyCount(Comparable group) { if (group == null) { throw new IllegalArgumentException("Null 'group' argument."); } int result = 0; for (Comparable g : this.keyToGroupMap.values()) { if (group.equals(g)) { result++; } } return result; } /** * Tests the map for equality against an arbitrary object. * * @param obj the object to test against (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof KeyToGroupMap)) { return false; } KeyToGroupMap that = (KeyToGroupMap) obj; if (!ObjectUtilities.equal(this.defaultGroup, that.defaultGroup)) { return false; } if (!this.keyToGroupMap.equals(that.keyToGroupMap)) { return false; } return true; } /** * Returns a clone of the map. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning the * map. */ @Override public Object clone() throws CloneNotSupportedException { KeyToGroupMap result = (KeyToGroupMap) super.clone(); result.defaultGroup = KeyToGroupMap.clone(this.defaultGroup); result.groups = (List<Comparable>) KeyToGroupMap.clone(this.groups); result.keyToGroupMap = KeyToGroupMap.clone(this.keyToGroupMap); return result; } /** * Attempts to clone the specified object using reflection. * * @param object the object (<code>null</code> permitted). * * @return The cloned object, or the original object if cloning failed. */ private static <T> T clone(T object) { if (object == null) { return null; } Class c = object.getClass(); T result = null; try { Method m = c.getMethod("clone", (Class[]) null); if (Modifier.isPublic(m.getModifiers())) { try { result = (T) m.invoke(object, (Object[]) null); } catch (InvocationTargetException e) { throw new RuntimeException("Could not clone object", e); } catch (IllegalAccessException e) { throw new RuntimeException("Could not clone object", e); } } } catch (NoSuchMethodException e) { result = object; } return result; } /** * Returns a clone of the list. * * @param list the list. * * @return A clone of the list. * * @throws CloneNotSupportedException if the list could not be cloned. */ private static <T> Collection<T> clone(Collection<T> list) throws CloneNotSupportedException { Collection<T> result = null; if (list != null) { try { List<T> clone = (List<T>) list.getClass().newInstance(); for (T aList : list) { clone.add(KeyToGroupMap.clone(aList)); } result = clone; } catch (Exception e) { throw new CloneNotSupportedException("Exception."); } } return result; } }
10,254
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValue.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/KeyedValue.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * KeyedValue.java * --------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 31-Oct-2002 : Version 1 (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.base (DG); * */ package org.jfree.data; /** * A (key, value) pair. * * @see DefaultKeyedValue */ public interface KeyedValue extends Value { /** * Returns the key associated with the value. The key returned by this * method should be immutable. * * @return The key (never <code>null</code>). */ public Comparable getKey(); }
1,921
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ComparableObjectItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/ComparableObjectItem.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * ComparableObjectItem.java * ------------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 19-Oct-2006 : New class, based on XYDataItem (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; /** * Represents one (Comparable, Object) data item for use in a * {@link ComparableObjectSeries}. * * @since 1.0.3 */ public class ComparableObjectItem implements Cloneable, Comparable<ComparableObjectItem>, Serializable { /** For serialization. */ private static final long serialVersionUID = 2751513470325494890L; /** The x-value. */ private Comparable x; /** The y-value. */ private Object obj; /** * Constructs a new data item. * * @param x the x-value (<code>null</code> NOT permitted). * @param y the y-value (<code>null</code> permitted). */ public ComparableObjectItem(Comparable x, Object y) { if (x == null) { throw new IllegalArgumentException("Null 'x' argument."); } this.x = x; this.obj = y; } /** * Returns the x-value. * * @return The x-value (never <code>null</code>). */ protected Comparable getComparable() { return this.x; } /** * Returns the y-value. * * @return The y-value (possibly <code>null</code>). */ protected Object getObject() { return this.obj; } /** * Sets the y-value for this data item. Note that there is no * corresponding method to change the x-value. * * @param y the new y-value (<code>null</code> permitted). */ protected void setObject(Object y) { this.obj = y; } /** * Returns an integer indicating the order of this object relative to * another object. * <P> * For the order we consider only the x-value: * negative == "less-than", zero == "equal", positive == "greater-than". * * @param that the object being compared to. * * @return An integer indicating the order of this data pair object * relative to another object. */ @Override public int compareTo(ComparableObjectItem that) { return this.x.compareTo(that.x); } /** * Returns a clone of this object. * * @return A clone. * * @throws CloneNotSupportedException not thrown by this class, but * subclasses may differ. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Tests if this object is equal to another. * * @param obj the object to test against for equality (<code>null</code> * permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ComparableObjectItem)) { return false; } ComparableObjectItem that = (ComparableObjectItem) obj; if (!this.x.equals(that.x)) { return false; } if (!ObjectUtilities.equal(this.obj, that.obj)) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; result = this.x.hashCode(); result = 29 * result + (this.obj != null ? this.obj.hashCode() : 0); return result; } }
4,986
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/jdbc/package-info.java
/** * Dataset classes that fetch data from a database via JDBC. */ package org.jfree.data.jdbc;
98
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
JDBCCategoryDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/jdbc/JDBCCategoryDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * JDBCCategoryDataset.java * ------------------------ * (C) Copyright 2002-2008, by Bryan Scott and Contributors. * * Original Author: Bryan Scott; Andy; * Contributor(s): David Gilbert (for Object Refinery Limited); * Thomas Morgner; * * Changes * ------- * 26-Apr-2002 : Creation based on JdbcXYDataSet, using code contributed from * Andy; * 13-Aug-2002 : Updated Javadocs, import statements and formatting (DG); * 03-Sep-2002 : Added fix for bug 591385 (DG); * 18-Sep-2002 : Updated to support BIGINT (BS); * 16-Oct-2002 : Added fix for bug 586667 (DG); * 03-Feb-2003 : Added Types.DECIMAL (see bug report 677814) (DG); * 13-Jun-2003 : Added Types.TIME as suggest by Bryan Scott in the forum (DG); * 30-Jun-2003 : CVS Write test (BS); * 30-Jul-2003 : Added empty contructor and executeQuery(connection,string) * method (BS); * 29-Aug-2003 : Added a 'transpose' flag, so that data can be easily * transposed if required (DG); * 10-Sep-2003 : Added support for additional JDBC types (DG); * 24-Sep-2003 : Added clearing results from previous queries to executeQuery * following being highlighted on online forum (BS); * 02-Dec-2003 : Throwing exceptions allows to handle errors, removed default * constructor, as without a connection, a query can never be * executed (TM); * 04-Dec-2003 : Added missing Javadocs (DG); * ------------- JFREECHART 1.0.0 --------------------------------------------- * 08-Mar-2006 : Fixed bug 1445748 where an exception is thrown if * executeQuery() is called more than once (DG); * */ package org.jfree.data.jdbc; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Types; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; /** * A {@link CategoryDataset} implementation over a database JDBC result set. * The dataset is populated via a call to {@link #executeQuery(String)} with * the string SQL query. The SQL query must return at least two columns. The * first column will be the category name and remaining columns values (each * column represents a series). Subsequent calls to * {@link #executeQuery(String)} will refresh the dataset. * <p> * The database connectionMetadata is read-only and no write back facility exists. * <p> * NOTE: Many people have found this class too restrictive in general use. * For the greatest flexibility, please consider writing your own code to read * data from a <code>ResultSet</code> and populate a * {@link DefaultCategoryDataset} directly. */ public class JDBCCategoryDataset extends DefaultCategoryDataset { /** For serialization. */ static final long serialVersionUID = -3080395327918844965L; /** The database connectionMetadata. */ private transient Connection connection; /** * A flag the controls whether or not the table is transposed. The default * is 'true' because this provides the behaviour described in the * documentation. */ private boolean transpose = true; /** * Creates a new dataset with a database connectionMetadata. * * @param url the URL of the database connectionMetadata. * @param driverName the database driver class name. * @param user the database user. * @param passwd the database user's password. * * @throws ClassNotFoundException if the driver cannot be found. * @throws SQLException if there is an error obtaining a connectionMetadata to the * database. */ public JDBCCategoryDataset(String url, String driverName, String user, String passwd) throws ClassNotFoundException, SQLException { Class.forName(driverName); this.connection = DriverManager.getConnection(url, user, passwd); } /** * Create a new dataset with the given database connectionMetadata. * * @param connection the database connectionMetadata. */ public JDBCCategoryDataset(Connection connection) { if (connection == null) { throw new NullPointerException("A connectionMetadata must be supplied."); } this.connection = connection; } /** * Creates a new dataset with the given database connectionMetadata, and executes * the supplied query to populate the dataset. * * @param connection the connectionMetadata. * @param query the query. * * @throws SQLException if there is a problem executing the query. */ public JDBCCategoryDataset(Connection connection, String query) throws SQLException { this(connection); executeQuery(query); } /** * Returns a flag that controls whether or not the table values are * transposed when added to the dataset. * * @return A boolean. */ public boolean getTranspose() { return this.transpose; } /** * Sets a flag that controls whether or not the table values are transposed * when added to the dataset. * * @param transpose the flag. */ public void setTranspose(boolean transpose) { this.transpose = transpose; } /** * Populates the dataset by executing the supplied query against the * existing database connectionMetadata. If no connectionMetadata exists then no action * is taken. * <p> * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query. * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(String query) throws SQLException { executeQuery(this.connection, query); } /** * Populates the dataset by executing the supplied query against the * existing database connectionMetadata. If no connectionMetadata exists then no action * is taken. * <p> * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param con the connectionMetadata. * @param query the query. * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { PreparedStatement statement = null; ResultSet resultSet = null; try { statement = con.prepareStatement(query); resultSet = statement.executeQuery(); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount < 2) { throw new SQLException( "JDBCCategoryDataset.executeQuery() : insufficient columns " + "returned from the database."); } // Remove any previous old data int i = getRowCount(); while (--i >= 0) { removeRow(i); } while (resultSet.next()) { // first column contains the row key... Comparable rowKey = resultSet.getString(1); for (int column = 2; column <= columnCount; column++) { Comparable columnKey = metaData.getColumnName(column); int columnType = metaData.getColumnType(column); switch (columnType) { case Types.TINYINT: case Types.SMALLINT: case Types.INTEGER: case Types.BIGINT: case Types.FLOAT: case Types.DOUBLE: case Types.DECIMAL: case Types.NUMERIC: case Types.REAL: { Number value = (Number) resultSet.getObject(column); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } break; } case Types.DATE: case Types.TIME: case Types.TIMESTAMP: { Date date = (Date) resultSet.getObject(column); Number value = date.getTime(); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } break; } case Types.CHAR: case Types.VARCHAR: case Types.LONGVARCHAR: { String string = (String) resultSet.getObject(column); try { Number value = Double.valueOf(string); if (this.transpose) { setValue(value, columnKey, rowKey); } else { setValue(value, rowKey, columnKey); } } catch (NumberFormatException e) { // suppress (value defaults to null) } break; } default: // not a value, can't use it (defaults to null) break; } } } fireDatasetChanged(); } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { // report this? } } if (statement != null) { try { statement.close(); } catch (Exception e) { // report this? } } } } }
12,151
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
JDBCPieDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/jdbc/JDBCPieDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * JDBCPieDataset.java * ------------------- * (C) Copyright 2002-2009, by Bryan Scott and Contributors. * * Original Author: Bryan Scott; Andy * Contributor(s): David Gilbert (for Object Refinery Limited); * Thomas Morgner; * * Changes * ------- * 26-Apr-2002 : Creation based on JdbcXYDataSet, but extending * DefaultPieDataset (BS); * 24-Jun-2002 : Removed unnecessary import and local variable (DG); * 13-Aug-2002 : Updated Javadoc comments and imports, removed default * constructor (DG); * 18-Sep-2002 : Updated to support BIGINT (BS); * 21-Jan-2003 : Renamed JdbcPieDataset --> JDBCPieDataset (DG); * 03-Feb-2003 : Added Types.DECIMAL (see bug report 677814) (DG); * 05-Jun-2003 : Updated to support TIME, optimised executeQuery method (BS); * 30-Jul-2003 : Added empty contructor and executeQuery(connection,string) * method (BS); * 02-Dec-2003 : Throwing exceptions allows to handle errors, removed default * constructor, as without a connection, a query can never be * executed (TM); * 04-Dec-2003 : Added missing Javadocs (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 19-May-2009 : Fixed FindBugs warnings, patch by Michal Wozniak (DG); * */ package org.jfree.data.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; /** * A {@link PieDataset} that reads data from a database via JDBC. * <P> * A query should be supplied that returns data in two columns, the first * containing VARCHAR data, and the second containing numerical data. The * data is cached in-memory and can be refreshed at any time. */ public class JDBCPieDataset extends DefaultPieDataset { /** For serialization. */ static final long serialVersionUID = -8753216855496746108L; /** The database connectionMetadata. */ private transient Connection connection; /** * Creates a new JDBCPieDataset and establishes a new database connectionMetadata. * * @param url the URL of the database connectionMetadata. * @param driverName the database driver class name. * @param user the database user. * @param password the database users password. * * @throws ClassNotFoundException if the driver cannot be found. * @throws SQLException if there is a problem obtaining a database * connectionMetadata. */ public JDBCPieDataset(String url, String driverName, String user, String password) throws SQLException, ClassNotFoundException { Class.forName(driverName); this.connection = DriverManager.getConnection(url, user, password); } /** * Creates a new JDBCPieDataset using a pre-existing database connectionMetadata. * <P> * The dataset is initially empty, since no query has been supplied yet. * * @param con the database connectionMetadata. */ public JDBCPieDataset(Connection con) { if (con == null) { throw new NullPointerException("A connectionMetadata must be supplied."); } this.connection = con; } /** * Creates a new JDBCPieDataset using a pre-existing database connectionMetadata. * <P> * The dataset is initialised with the supplied query. * * @param con the database connectionMetadata. * @param query the database connectionMetadata. * * @throws SQLException if there is a problem executing the query. */ public JDBCPieDataset(Connection con, String query) throws SQLException { this(con); executeQuery(query); } /** * ExecuteQuery will attempt execute the query passed to it against the * existing database connectionMetadata. If no connectionMetadata exists then no action * is taken. * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed. * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(String query) throws SQLException { executeQuery(this.connection, query); } /** * ExecuteQuery will attempt execute the query passed to it against the * existing database connectionMetadata. If no connectionMetadata exists then no action * is taken. * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed * @param con the connectionMetadata the query is to be executed against * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { PreparedStatement statement = null; ResultSet resultSet = null; try { statement = con.prepareStatement(query); resultSet = statement.executeQuery(); ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); if (columnCount != 2) { throw new SQLException( "Invalid sql generated. PieDataSet requires 2 columns only" ); } int columnType = metaData.getColumnType(2); double value; while (resultSet.next()) { Comparable key = resultSet.getString(1); switch (columnType) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIGINT: value = resultSet.getDouble(2); setValue(key, value); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: Timestamp date = resultSet.getTimestamp(2); value = date.getTime(); setValue(key, value); break; default: System.err.println( "JDBCPieDataset - unknown data type"); break; } } fireDatasetChanged(); } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } if (statement != null) { try { statement.close(); } catch (Exception e) { System.err.println("JDBCPieDataset: swallowing exception."); } } } } /** * Close the database connectionMetadata */ public void close() { try { this.connection.close(); } catch (Exception e) { System.err.println("JdbcXYDataset: swallowing exception."); } } }
9,128
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
JDBCXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/jdbc/JDBCXYDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * JDBCXYDataset.java * ------------------ * (C) Copyright 2002-2009, by Bryan Scott and Contributors. * * Original Author: Bryan Scott; * Contributor(s): David Gilbert (for Object Refinery Limited); * Eric Alexander; * * * Changes * ------- * 14-Mar-2002 : Version 1 contributed by Bryan Scott (DG); * 19-Apr-2002 : Updated executeQuery, to close cursors and to improve support * for types. * 26-Apr-2002 : Renamed JdbcXYDataset to better fit in with the existing data * source conventions. * 26-Apr-2002 : Changed to extend AbstractDataset. * 13-Aug-2002 : Updated Javadoc comments and imports (DG); * 18-Sep-2002 : Updated to support BIGINT (BS); * 21-Jan-2003 : Renamed JdbcXYDataset --> JDBCXYDataset (DG); * 01-Jul-2003 : Added support to query whether a timeseries (BS); * 30-Jul-2003 : Added empty contructor and executeQuery(connection,string) * method (BS); * 24-Sep-2003 : Added a check to ensure at least two valid columns are * returned by the query in executeQuery as suggest in online * forum by anonymous (BS); * 02-Dec-2003 : Throwing exceptions allows to handle errors, removed default * constructor, as without a connection, a query can never be * executed. * 16-Mar-2004 : Added check for null values (EA); * 05-May-2004 : Now extends AbstractXYDataset (DG); * 21-May-2004 : Implemented TableXYDataset, added support for SMALLINT and * fixed bug in code that determines the min and max values (see * bug id 938138) (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 18-Nov-2004 : Updated for changes in RangeInfo interface (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 17-Oct-2006 : Deprecated unused methods - see bug 1578293 (DG); * 19-May-2009 : Fixed FindBugs warnings, patch by Michal Wozniak (DG); * */ package org.jfree.data.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.general.Dataset; import org.jfree.data.xy.AbstractXYDataset; import org.jfree.data.xy.TableXYDataset; import org.jfree.data.xy.XYDataset; /** * This class provides an {@link XYDataset} implementation over a database * JDBC result set. The dataset is populated via a call to executeQuery with * the string sql query. The sql query must return at least two columns. * The first column will be the x-axis and remaining columns y-axis values. * executeQuery can be called a number of times. * * The database connectionMetadata is read-only and no write back facility exists. */ public class JDBCXYDataset extends AbstractXYDataset implements XYDataset, TableXYDataset, RangeInfo { /** The database connectionMetadata. */ private transient Connection connection; /** Column names. */ private String[] columnNames = {}; /** Rows. */ private List<List<Number>> rows; /** The maximum y value of the returned result set */ private double maxValue = 0.0; /** The minimum y value of the returned result set */ private double minValue = 0.0; /** Is this dataset a timeseries ? */ private boolean isTimeSeries = false; /** * Creates a new JDBCXYDataset (initially empty) with no database * connectionMetadata. */ private JDBCXYDataset() { this.rows = new ArrayList<List<Number>>(); } /** * Creates a new dataset (initially empty) and establishes a new database * connectionMetadata. * * @param url URL of the database connectionMetadata. * @param driverName the database driver class name. * @param user the database user. * @param password the database user's password. * * @throws ClassNotFoundException if the driver cannot be found. * @throws SQLException if there is a problem connecting to the database. */ public JDBCXYDataset(String url, String driverName, String user, String password) throws SQLException, ClassNotFoundException { this(); Class.forName(driverName); this.connection = DriverManager.getConnection(url, user, password); } /** * Creates a new dataset (initially empty) using the specified database * connectionMetadata. * * @param con the database connectionMetadata. * * @throws SQLException if there is a problem connecting to the database. */ public JDBCXYDataset(Connection con) throws SQLException { this(); this.connection = con; } /** * Creates a new dataset using the specified database connectionMetadata, and * populates it using data obtained with the supplied query. * * @param con the connectionMetadata. * @param query the SQL query. * * @throws SQLException if there is a problem executing the query. */ public JDBCXYDataset(Connection con, String query) throws SQLException { this(con); executeQuery(query); } /** * Returns <code>true</code> if the dataset represents time series data, * and <code>false</code> otherwise. * * @return A boolean. */ public boolean isTimeSeries() { return this.isTimeSeries; } /** * Sets a flag that indicates whether or not the data represents a time * series. * * @param timeSeries the new value of the flag. */ public void setTimeSeries(boolean timeSeries) { this.isTimeSeries = timeSeries; } /** * ExecuteQuery will attempt execute the query passed to it against the * existing database connectionMetadata. If no connectionMetadata exists then no action * is taken. * * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed. * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(String query) throws SQLException { executeQuery(this.connection, query); } /** * ExecuteQuery will attempt execute the query passed to it against the * provided database connectionMetadata. If connectionMetadata is null then no action is * taken. * * The results from the query are extracted and cached locally, thus * applying an upper limit on how many rows can be retrieved successfully. * * @param query the query to be executed. * @param con the connectionMetadata the query is to be executed against. * * @throws SQLException if there is a problem executing the query. */ public void executeQuery(Connection con, String query) throws SQLException { if (con == null) { throw new SQLException( "There is no database to execute the query." ); } ResultSet resultSet = null; PreparedStatement statement = null; try { statement = con.prepareStatement(query); resultSet = statement.executeQuery(); ResultSetMetaData metaData = resultSet.getMetaData(); int numberOfColumns = metaData.getColumnCount(); int numberOfValidColumns = 0; int [] columnTypes = new int[numberOfColumns]; for (int column = 0; column < numberOfColumns; column++) { try { int type = metaData.getColumnType(column + 1); switch (type) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIT: case Types.DATE: case Types.TIME: case Types.TIMESTAMP: case Types.BIGINT: case Types.SMALLINT: ++numberOfValidColumns; columnTypes[column] = type; break; default: columnTypes[column] = Types.NULL; break; } } catch (SQLException e) { columnTypes[column] = Types.NULL; throw e; } } if (numberOfValidColumns <= 1) { throw new SQLException( "Not enough valid columns where generated by query." ); } /// First column is X data this.columnNames = new String[numberOfValidColumns - 1]; /// Get the column names and cache them. int currentColumn = 0; for (int column = 1; column < numberOfColumns; column++) { if (columnTypes[column] != Types.NULL) { this.columnNames[currentColumn] = metaData.getColumnLabel(column + 1); ++currentColumn; } } // Might need to add, to free memory from any previous result sets if (this.rows != null) { for (List<Number> row : this.rows) { row.clear(); } this.rows.clear(); } // Are we working with a time series. switch (columnTypes[0]) { case Types.DATE: case Types.TIME: case Types.TIMESTAMP: this.isTimeSeries = true; break; default : this.isTimeSeries = false; break; } // Get all rows. // rows = new ArrayList(); while (resultSet.next()) { List<Number> newRow = new ArrayList<Number>(); for (int column = 0; column < numberOfColumns; column++) { Object xObject = resultSet.getObject(column + 1); switch (columnTypes[column]) { case Types.NUMERIC: case Types.REAL: case Types.INTEGER: case Types.DOUBLE: case Types.FLOAT: case Types.DECIMAL: case Types.BIGINT: case Types.SMALLINT: newRow.add((Number)xObject); break; case Types.DATE: case Types.TIME: case Types.TIMESTAMP: newRow.add(((Date) xObject).getTime()); break; case Types.NULL: break; default: columnTypes[column] = Types.NULL; break; } } this.rows.add(newRow); } /// a kludge to make everything work when no rows returned if (this.rows.size() == 0) { List<Number> newRow = new ArrayList<Number>(); for (int column = 0; column < numberOfColumns; column++) { if (columnTypes[column] != Types.NULL) { newRow.add(0); } } this.rows.add(newRow); } /// Determine max and min values. if (this.rows.size() < 1) { this.maxValue = 0.0; this.minValue = 0.0; } else { this.maxValue = Double.NEGATIVE_INFINITY; this.minValue = Double.POSITIVE_INFINITY; for (List<Number> row : this.rows) { for (int column = 1; column < numberOfColumns; column++) { Object testValue = row.get(column); if (testValue != null) { double test = ((Number) testValue).doubleValue(); if (test < this.minValue) { this.minValue = test; } if (test > this.maxValue) { this.maxValue = test; } } } } } fireDatasetChanged(); // Tell the listeners a new table has arrived. } finally { if (resultSet != null) { try { resultSet.close(); } catch (Exception e) { // TODO: is this a good idea? } } if (statement != null) { try { statement.close(); } catch (Exception e) { // TODO: is this a good idea? } } } } /** * Returns the x-value for the specified series and item. The * implementation is responsible for ensuring that the x-values are * presented in ascending order. * * @param seriesIndex the series (zero-based index). * @param itemIndex the item (zero-based index). * * @return The x-value * * @see XYDataset */ @Override public Number getX(int seriesIndex, int itemIndex) { ArrayList row = (ArrayList) this.rows.get(itemIndex); return (Number) row.get(0); } /** * Returns the y-value for the specified series and item. * * @param seriesIndex the series (zero-based index). * @param itemIndex the item (zero-based index). * * @return The yValue value * * @see XYDataset */ @Override public Number getY(int seriesIndex, int itemIndex) { ArrayList row = (ArrayList) this.rows.get(itemIndex); return (Number) row.get(seriesIndex + 1); } /** * Returns the number of items in the specified series. * * @param seriesIndex the series (zero-based index). * * @return The itemCount value * * @see XYDataset */ @Override public int getItemCount(int seriesIndex) { return this.rows.size(); } /** * Returns the number of items in all series. This method is defined by * the {@link TableXYDataset} interface. * * @return The item count. */ @Override public int getItemCount() { return getItemCount(0); } /** * Returns the number of series in the dataset. * * @return The seriesCount value * * @see XYDataset * @see Dataset */ @Override public int getSeriesCount() { return this.columnNames.length; } /** * Returns the key for the specified series. * * @param seriesIndex the series (zero-based index). * * @return The seriesName value * * @see XYDataset * @see Dataset */ @Override public Comparable getSeriesKey(int seriesIndex) { if ((seriesIndex < this.columnNames.length) && (this.columnNames[seriesIndex] != null)) { return this.columnNames[seriesIndex]; } else { return ""; } } /** * Close the database connectionMetadata */ public void close() { try { this.connection.close(); } catch (Exception e) { // silently ignore } } /** * Returns the minimum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The minimum value. */ @Override public double getRangeLowerBound(boolean includeInterval) { return this.minValue; } /** * Returns the maximum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The maximum value. */ @Override public double getRangeUpperBound(boolean includeInterval) { return this.maxValue; } /** * Returns the range of the values in this dataset's range. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range. */ @Override public Range getRangeBounds(boolean includeInterval) { return new Range(this.minValue, this.maxValue); } }
18,808
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/io/package-info.java
/** * Miscellaneous support for input/output of data. */ package org.jfree.data.io;
86
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CSV.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/io/CSV.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------- * CSV.java * -------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 24-Nov-2003 : Version 1 (DG); * */ package org.jfree.data.io; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.util.List; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; /** * A utility class for reading {@link CategoryDataset} data from a CSV file. * This initial version is very basic, and won't handle errors in the data * file very gracefully. */ public class CSV { /** The field delimiter. */ private char fieldDelimiter; /** The text delimiter. */ private char textDelimiter; /** * Creates a new CSV reader where the field delimiter is a comma, and the * text delimiter is a double-quote. */ public CSV() { this(',', '"'); } /** * Creates a new reader with the specified field and text delimiters. * * @param fieldDelimiter the field delimiter (usually a comma, semi-colon, * colon, tab or space). * @param textDelimiter the text delimiter (usually a single or double * quote). */ public CSV(char fieldDelimiter, char textDelimiter) { this.fieldDelimiter = fieldDelimiter; this.textDelimiter = textDelimiter; } /** * Reads a {@link CategoryDataset} from a CSV file or input source. * * @param in the input source. * * @return A category dataset. * * @throws IOException if there is an I/O problem. */ public CategoryDataset readCategoryDataset(Reader in) throws IOException { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); BufferedReader reader = new BufferedReader(in); List<String> columnKeys = null; int lineIndex = 0; String line = reader.readLine(); while (line != null) { if (lineIndex == 0) { // first line contains column keys columnKeys = extractColumnKeys(line); } else { // remaining lines contain a row key and data values extractRowKeyAndData(line, dataset, columnKeys); } line = reader.readLine(); lineIndex++; } return dataset; } /** * Extracts the column keys from a string. * * @param line a line from the input file. * * @return A list of column keys. */ private List<String> extractColumnKeys(String line) { List<String> keys = new java.util.ArrayList<String>(); int fieldIndex = 0; int start = 0; for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == this.fieldDelimiter) { if (fieldIndex > 0) { // first field is ignored, since // column 0 is for row keys String key = line.substring(start, i); keys.add(removeStringDelimiters(key)); } start = i + 1; fieldIndex++; } } String key = line.substring(start, line.length()); keys.add(removeStringDelimiters(key)); return keys; } /** * Extracts the row key and data for a single line from the input source. * * @param line the line from the input source. * @param dataset the dataset to be populated. * @param columnKeys the column keys. */ private void extractRowKeyAndData(String line, DefaultCategoryDataset dataset, List<String> columnKeys) { Comparable rowKey = null; int fieldIndex = 0; int start = 0; for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == this.fieldDelimiter) { if (fieldIndex == 0) { // first field contains the row key String key = line.substring(start, i); rowKey = removeStringDelimiters(key); } else { // remaining fields contain values Double value = Double.valueOf( removeStringDelimiters(line.substring(start, i)) ); dataset.addValue( value, rowKey, columnKeys.get(fieldIndex - 1) ); } start = i + 1; fieldIndex++; } } Double value = Double.valueOf( removeStringDelimiters(line.substring(start, line.length())) ); dataset.addValue( value, rowKey, columnKeys.get(fieldIndex - 1) ); } /** * Removes the string delimiters from a key (as well as any white space * outside the delimiters). * * @param key the key (including delimiters). * * @return The key without delimiters. */ private String removeStringDelimiters(String key) { String k = key.trim(); if (k.charAt(0) == this.textDelimiter) { k = k.substring(1); } if (k.charAt(k.length() - 1) == this.textDelimiter) { k = k.substring(0, k.length() - 1); } return k; } }
6,725
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Series.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/Series.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------- * Series.java * ----------- * (C) Copyright 2001-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 29-Nov-2001 : Added cloning and property change support (DG); * 30-Jan-2002 : Added a description attribute and changed the constructors to * protected (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Implemented Serializable (DG); * 01-May-2003 : Added equals() method (DG); * 26-Jun-2003 : Changed listener list to use EventListenerList - see bug * 757027 (DG); * 15-Oct-2003 : Added a flag to control whether or not change events are sent * to registered listeners (DG); * 19-May-2005 : Made abstract (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 04-May-2006 : Updated API docs (DG); * 26-Sep-2007 : Added isEmpty() and getItemCount() methods (DG); * 16-Oct-2011 : Added vetoable property change support for series name (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.general; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.beans.VetoableChangeSupport; import java.io.Serializable; import javax.swing.event.EventListenerList; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; /** * Base class representing a data series. Subclasses are left to implement the * actual data structures. * <P> * The series has two properties ("Key" and "Description") for which you can * register a <code>PropertyChangeListener</code>. * <P> * You can also register a {@link SeriesChangeListener} to receive notification * of changes to the series data. */ public abstract class Series implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -6906561437538683581L; /** The key for the series. */ private Comparable key; /** A description of the series. */ private String description; /** Storage for registered change listeners. */ private EventListenerList listeners; /** Object to support property change notification. */ private PropertyChangeSupport propertyChangeSupport; /** Object to support property change notification. */ private VetoableChangeSupport vetoableChangeSupport; /** A flag that controls whether or not changes are notified. */ private boolean notify; /** * Creates a new series with the specified key. * * @param key the series key (<code>null</code> not permitted). */ protected Series(Comparable key) { this(key, null); } /** * Creates a new series with the specified key and description. * * @param key the series key (<code>null</code> NOT permitted). * @param description the series description (<code>null</code> permitted). */ protected Series(Comparable key, String description) { ParamChecks.nullNotPermitted(key, "key"); this.key = key; this.description = description; this.listeners = new EventListenerList(); this.propertyChangeSupport = new PropertyChangeSupport(this); this.vetoableChangeSupport = new VetoableChangeSupport(this); this.notify = true; } /** * Returns the key for the series. * * @return The series key (never <code>null</code>). * * @see #setKey(Comparable) */ public Comparable getKey() { return this.key; } /** * Sets the key for the series and sends a <code>VetoableChangeEvent</code> * (with the property name "Key") to all registered listeners. If the * change is vetoed by a listener, this method will throw an * IllegalArgumentException. * * @param key the key (<code>null</code> not permitted). * * @see #getKey() */ public void setKey(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); Comparable old = this.key; try { // if this series belongs to a dataset, the dataset might veto the // change if it results in two series within the dataset having the // same key this.vetoableChangeSupport.fireVetoableChange("Key", old, key); this.key = key; } catch (PropertyVetoException e) { throw new IllegalArgumentException(e); } } /** * Returns a description of the series. * * @return The series description (possibly <code>null</code>). * * @see #setDescription(String) */ public String getDescription() { return this.description; } /** * Sets the description of the series and sends a * <code>PropertyChangeEvent</code> to all registered listeners. * * @param description the description (<code>null</code> permitted). * * @see #getDescription() */ public void setDescription(String description) { String old = this.description; this.description = description; this.propertyChangeSupport.firePropertyChange("Description", old, description); } /** * Returns the flag that controls whether or not change events are sent to * registered listeners. * * @return A boolean. * * @see #setNotify(boolean) */ public boolean getNotify() { return this.notify; } /** * Sets the flag that controls whether or not change events are sent to * registered listeners. * * @param notify the new value of the flag. * * @see #getNotify() */ public void setNotify(boolean notify) { if (this.notify != notify) { this.notify = notify; fireSeriesChanged(); } } /** * Returns <code>true</code> if the series contains no data items, and * <code>false</code> otherwise. * * @return A boolean. * * @since 1.0.7 */ public boolean isEmpty() { return (getItemCount() == 0); } /** * Returns the number of data items in the series. * * @return The number of data items in the series. */ public abstract int getItemCount(); /** * Returns a clone of the series. * <P> * Notes: * <ul> * <li>No need to clone the name or description, since String object is * immutable.</li> * <li>We set the listener list to empty, since the listeners did not * register with the clone.</li> * <li>Same applies to the PropertyChangeSupport instance.</li> * </ul> * * @return A clone of the series. * * @throws CloneNotSupportedException not thrown by this class, but * subclasses may differ. */ @Override public Object clone() throws CloneNotSupportedException { Series clone = (Series) super.clone(); clone.listeners = new EventListenerList(); clone.propertyChangeSupport = new PropertyChangeSupport(clone); clone.vetoableChangeSupport = new VetoableChangeSupport(clone); return clone; } /** * Tests the series for equality with another object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Series)) { return false; } Series that = (Series) obj; if (!getKey().equals(that.getKey())) { return false; } if (!ObjectUtilities.equal(getDescription(), that.getDescription())) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; result = this.key.hashCode(); result = 29 * result + (this.description != null ? this.description.hashCode() : 0); return result; } /** * Registers an object with this series, to receive notification whenever * the series changes. * <P> * Objects being registered must implement the {@link SeriesChangeListener} * interface. * * @param listener the listener to register. */ public void addChangeListener(SeriesChangeListener listener) { this.listeners.add(SeriesChangeListener.class, listener); } /** * Deregisters an object, so that it not longer receives notification * whenever the series changes. * * @param listener the listener to deregister. */ public void removeChangeListener(SeriesChangeListener listener) { this.listeners.remove(SeriesChangeListener.class, listener); } /** * General method for signalling to registered listeners that the series * has been changed. */ public void fireSeriesChanged() { if (this.notify) { notifyListeners(new SeriesChangeEvent(this)); } } /** * Sends a change event to all registered listeners. * * @param event contains information about the event that triggered the * notification. */ protected void notifyListeners(SeriesChangeEvent event) { Object[] listenerList = this.listeners.getListenerList(); for (int i = listenerList.length - 2; i >= 0; i -= 2) { if (listenerList[i] == SeriesChangeListener.class) { ((SeriesChangeListener) listenerList[i + 1]).seriesChanged( event); } } } /** * Adds a property change listener to the series. * * @param listener the listener. */ public void addPropertyChangeListener(PropertyChangeListener listener) { this.propertyChangeSupport.addPropertyChangeListener(listener); } /** * Removes a property change listener from the series. * * @param listener the listener. */ public void removePropertyChangeListener(PropertyChangeListener listener) { this.propertyChangeSupport.removePropertyChangeListener(listener); } /** * Fires a property change event. * * @param property the property key. * @param oldValue the old value. * @param newValue the new value. */ protected void firePropertyChange(String property, Object oldValue, Object newValue) { this.propertyChangeSupport.firePropertyChange(property, oldValue, newValue); } /** * Adds a vetoable property change listener to the series. * * @param listener the listener. * * @since 1.0.14 */ public void addVetoableChangeListener(VetoableChangeListener listener) { this.vetoableChangeSupport.addVetoableChangeListener(listener); } /** * Removes a vetoable property change listener from the series. * * @param listener the listener. * * @since 1.0.14 */ public void removeVetoableChangeListener(VetoableChangeListener listener) { this.vetoableChangeSupport.removeVetoableChangeListener(listener); } /** * Fires a vetoable property change event. * * @param property the property key. * @param oldValue the old value. * @param newValue the new value. */ protected void fireVetoableChange(String property, Object oldValue, Object newValue) throws PropertyVetoException { this.vetoableChangeSupport.fireVetoableChange(property, oldValue, newValue); } }
13,215
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SelectionChangeListener.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/SelectionChangeListener.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * SelectionChangeListener.java * ---------------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.general; import java.util.EventListener; import org.jfree.data.extension.DatasetCursor; /** * A listener that wants to be informed about changes of the selection state of data items * * @author zinsmaie */ public interface SelectionChangeListener<CURSOR extends DatasetCursor> extends EventListener { /** * called if the selection state of at least one observed data item changes * @param event */ public void selectionChanged(SelectionChangeEvent<CURSOR> event); }
2,020
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetGroup.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DatasetGroup.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * DatasetGroup.java * ----------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 07-Oct-2002 : Version 1 (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 20-Aug-2003 : Implemented Cloneable (DG); * */ package org.jfree.data.general; import java.io.Serializable; /** * A class that is used to group datasets (currently not used for any specific * purpose). */ public class DatasetGroup implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -3640642179674185688L; /** The group id. */ private String id; /** * Constructs a new group. */ public DatasetGroup() { super(); this.id = "NOID"; } /** * Creates a new group with the specified id. * * @param id the identification for the group. */ public DatasetGroup(String id) { if (id == null) { throw new IllegalArgumentException("Null 'id' argument."); } this.id = id; } /** * Returns the identification string for this group. * * @return The identification string. */ public String getID() { return this.id; } /** * Clones the group. * * @return A clone. * * @throws CloneNotSupportedException not by this class. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DatasetGroup)) { return false; } DatasetGroup that = (DatasetGroup) obj; if (!this.id.equals(that.id)) { return false; } return true; } }
3,365
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SeriesChangeEvent.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/SeriesChangeEvent.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * SeriesChangeEvent.java * ---------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 18-Aug-2003 : Implemented Serializable (DG); * */ package org.jfree.data.general; import java.io.Serializable; import java.util.EventObject; /** * An event with details of a change to a series. */ public class SeriesChangeEvent extends EventObject implements Serializable { /** For serialization. */ private static final long serialVersionUID = 1593866085210089052L; /** * Constructs a new event. * * @param source the source of the change event. */ public SeriesChangeEvent(Object source) { super(source); } }
2,082
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/PieDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * PieDataset.java * --------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Sam (oldman); * * Changes * ------- * 17-Nov-2001 : Version 1 (DG); * 22-Jan-2002 : Removed the getCategoryCount() method, updated Javadoc * comments (DG); * 18-Apr-2002 : getCategories() now returns List instead of Set (oldman); * 23-Oct-2002 : Reorganised the code: PieDataset now extends KeyedValues * interface (DG); * 04-Mar-2003 : Now just replicates the KeyedValuesDataset interface (DG); * */ package org.jfree.data.general; import org.jfree.data.KeyedValues; /** * A general purpose dataset where values are associated with keys. As the * name suggests, you can use this dataset to supply data for pie charts (refer * to the {@link org.jfree.chart.plot.PiePlot} class). */ public interface PieDataset extends KeyedValues, Dataset { // no new methods added. }
2,249
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValuesDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/KeyedValuesDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * KeyedValuesDataset.java * ----------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 05-Mar-2003 : Version 1 (DG); * 24-Apr-2003 : Switched places with PieDataset (DG); * */ package org.jfree.data.general; /** * A dataset containing (key, value) data items. */ public interface KeyedValuesDataset extends PieDataset { // no new methods required }
1,759
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LabelChangeListener.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/LabelChangeListener.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * LabelChangeListener.java * ------------------------ * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.general; import java.util.EventListener; import org.jfree.data.extension.DatasetCursor; /** * A listener that wants to be informed about changes of the label attribute of * data items * * @author zinsmaie */ public interface LabelChangeListener<CURSOR extends DatasetCursor> extends EventListener { /** * called if at least one label of an observed data item changes * @param event */ public void labelChanged(LabelChangeEvent<CURSOR> event); }
1,999
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LabelChangeEvent.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/LabelChangeEvent.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * LabelChangeEvent.java * --------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.general; import java.util.EventObject; import org.jfree.data.extension.DatasetCursor; import org.jfree.data.extension.DatasetLabelExtension; import org.jfree.data.extension.DatasetSelectionExtension; /** * A change event that notifies about a change to the labeling of data items * * @author zinsmaie */ public class LabelChangeEvent<CURSOR extends DatasetCursor> extends EventObject { /** a generated serial id */ private static final long serialVersionUID = 2289987249349231381L; /** * Constructs a new event. * * @param source the source of the event aka the label extension that * changed (the object has to be of type DatasetLabelExtension and * must not be null!) */ public LabelChangeEvent(Object labelExtension) { super(labelExtension); } /** * @return the label selection extension that triggered the event. */ public DatasetSelectionExtension<CURSOR> getLabelExtension() { if (this.getSource() instanceof DatasetLabelExtension) { return (DatasetSelectionExtension<CURSOR>) this.getSource(); } //implementation error return null; } }
2,704
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SeriesException.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/SeriesException.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * SeriesException.java * -------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 26-Mar-2002 : Modified to extend RuntimeException rather than Exception (DG); * 18-Aug-2003 : Implemented Serializable (DG); * */ package org.jfree.data.general; import java.io.Serializable; /** * A general purpose exception class for data series. */ public class SeriesException extends RuntimeException implements Serializable { /** For serialization. */ private static final long serialVersionUID = -3667048387550852940L; /** * Constructs a new series exception. * * @param message a message describing the exception. */ public SeriesException(String message) { super(message); } }
2,151
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ValueDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/ValueDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * ValueDataset.java * ----------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 27-Mar-2003 : Version 1 (DG); * */ package org.jfree.data.general; import org.jfree.data.Value; /** * An interface for a dataset that returns a single value. */ public interface ValueDataset extends Value, Dataset { // no additional methods required }
1,731
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValueDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/KeyedValueDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * KeyedValueDataset.java * ---------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 13-Mar-2003 : Version 1 (DG); * */ package org.jfree.data.general; import org.jfree.data.KeyedValue; /** * A dataset containing a single value. */ public interface KeyedValueDataset extends KeyedValue, Dataset { // no new methods required }
1,735
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetChangeEvent.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DatasetChangeEvent.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * DatasetChangeEvent.java * ----------------------- * (C) Copyright 2000-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes (from 24-Aug-2001) * -------------------------- * 24-Aug-2001 : Added standard source header. Fixed DOS encoding problem (DG); * 15-Oct-2001 : Move to new package (com.jrefinery.data.*) (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 11-Jun-2002 : Separated the event source from the dataset to cover the case * where the dataset is changed to null in the Plot class. * Updated Javadocs (DG); * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 05-Oct-2004 : Minor Javadoc updates (DG); * */ package org.jfree.data.general; /** * A change event that encapsulates information about a change to a dataset. */ public class DatasetChangeEvent extends java.util.EventObject { /** * The dataset that generated the change event. */ private Dataset dataset; /** * Constructs a new event. The source is either the dataset or the * {@link org.jfree.chart.plot.Plot} class. The dataset can be * <code>null</code> (in this case the source will be the * {@link org.jfree.chart.plot.Plot} class). * * @param source the source of the event. * @param dataset the dataset that generated the event (<code>null</code> * permitted). */ public DatasetChangeEvent(Object source, Dataset dataset) { super(source); this.dataset = dataset; } /** * Returns the dataset that generated the event. Note that the dataset * may be <code>null</code> since adding a <code>null</code> dataset to a * plot will generated a change event. * * @return The dataset (possibly <code>null</code>). */ public Dataset getDataset() { return this.dataset; } }
3,227
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Dataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/Dataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------ * Dataset.java * ------------ * (C) Copyright 2000-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes (from 18-Sep-2001) * -------------------------- * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG); * 15-Oct-2001 : Moved to a new package (com.jrefinery.data.*) (DG); * 22-Oct-2001 : Changed name to Dataset.java (DG); * 17-Nov-2001 : Added getLegendItemCount() and getLegendItemLabels() methods, * created SeriesDataset interface and transferred series related * methods out (DG); * 22-Jan-2002 : Reconsidered (and removed) the getLegendItemCount() and * getLegendItemLabels() methods...leave this to client code (DG); * 27-Sep-2002 : Added get/setDatasetGroup() methods (DG); * 10-Jan-2003 : Updated Javadocs (DG); * */ package org.jfree.data.general; /** * The base interface for data sets. * <P> * All datasets are required to support the {@link DatasetChangeEvent} * mechanism by allowing listeners to register and receive notification of any * changes to the dataset. * <P> * In addition, all datasets must belong to one (and only one) * {@link DatasetGroup}. The group object maintains a reader-writer lock * which provides synchronised access to the datasets in multi-threaded code. */ public interface Dataset { /** * Registers an object for notification of changes to the dataset. * * @param listener the object to register. */ public void addChangeListener(DatasetChangeListener listener); /** * Deregisters an object for notification of changes to the dataset. * * @param listener the object to deregister. */ public void removeChangeListener(DatasetChangeListener listener); /** * Returns the dataset group. * * @return The dataset group. */ public DatasetGroup getGroup(); /** * Sets the dataset group. * * @param group the dataset group. */ public void setGroup(DatasetGroup group); }
3,346
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultValueDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DefaultValueDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * DefaultValueDataset.java * ------------------------ * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 27-Mar-2003 : Version 1 (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 03-Mar-2005 : Implemented PublicCloneable (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 30-Jan-2007 : Added explicit super() call in constructor (for clarity) (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.general; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; /** * A dataset that stores a single value (that is possibly <code>null</code>). * This class provides a default implementation of the {@link ValueDataset} * interface. */ public class DefaultValueDataset extends AbstractDataset implements ValueDataset, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 8137521217249294891L; /** The value. */ private Number value; /** * Constructs a new dataset, initially empty. */ public DefaultValueDataset() { this(null); } /** * Creates a new dataset with the specified value. * * @param value the value. */ public DefaultValueDataset(double value) { this(new Double(value)); } /** * Creates a new dataset with the specified value. * * @param value the initial value (<code>null</code> permitted). */ public DefaultValueDataset(Number value) { super(); this.value = value; } /** * Returns the value. * * @return The value (possibly <code>null</code>). */ @Override public Number getValue() { return this.value; } /** * Sets the value and sends a {@link DatasetChangeEvent} to all registered * listeners. * * @param value the new value (<code>null</code> permitted). */ public void setValue(Number value) { this.value = value; notifyListeners(new DatasetChangeEvent(this, this)); } /** * Tests this dataset for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj instanceof ValueDataset) { ValueDataset vd = (ValueDataset) obj; return ObjectUtilities.equal(this.value, vd.getValue()); } return false; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { return (this.value != null ? this.value.hashCode() : 0); } }
4,217
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultKeyedValueDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DefaultKeyedValueDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------------- * DefaultKeyedValueDataset.java * ----------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 27-Mar-2003 : Version 1 (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.general; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; import org.jfree.data.DefaultKeyedValue; import org.jfree.data.KeyedValue; /** * A default implementation of the {@link KeyedValueDataset} interface. */ public class DefaultKeyedValueDataset extends AbstractDataset implements KeyedValueDataset, Serializable { /** For serialization. */ private static final long serialVersionUID = -8149484339560406750L; /** Storage for the data. */ private KeyedValue data; /** * Constructs a new dataset, initially empty. */ public DefaultKeyedValueDataset() { this(null); } /** * Creates a new dataset with the specified initial value. * * @param key the key. * @param value the value (<code>null</code> permitted). */ public DefaultKeyedValueDataset(Comparable key, Number value) { this(new DefaultKeyedValue(key, value)); } /** * Creates a new dataset that uses the data from a {@link KeyedValue} * instance. * * @param data the data (<code>null</code> permitted). */ public DefaultKeyedValueDataset(KeyedValue data) { this.data = data; } /** * Returns the key associated with the value, or <code>null</code> if the * dataset has no data item. * * @return The key. */ @Override public Comparable getKey() { Comparable result = null; if (this.data != null) { result = this.data.getKey(); } return result; } /** * Returns the value. * * @return The value (possibly <code>null</code>). */ @Override public Number getValue() { Number result = null; if (this.data != null) { result = this.data.getValue(); } return result; } /** * Updates the value. * * @param value the new value (<code>null</code> permitted). */ public void updateValue(Number value) { if (this.data == null) { throw new RuntimeException("updateValue: can't update null."); } setValue(this.data.getKey(), value); } /** * Sets the value for the dataset and sends a {@link DatasetChangeEvent} to * all registered listeners. * * @param key the key. * @param value the value (<code>null</code> permitted). */ public void setValue(Comparable key, Number value) { this.data = new DefaultKeyedValue(key, value); notifyListeners(new DatasetChangeEvent(this, this)); } /** * Tests this dataset for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof KeyedValueDataset)) { return false; } KeyedValueDataset that = (KeyedValueDataset) obj; if (this.data == null) { if (that.getKey() != null || that.getValue() != null) { return false; } return true; } if (!ObjectUtilities.equal(this.data.getKey(), that.getKey())) { return false; } if (!ObjectUtilities.equal(this.data.getValue(), that.getValue())) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { return (this.data != null ? this.data.hashCode() : 0); } /** * Creates a clone of the dataset. * * @return A clone. * * @throws CloneNotSupportedException This class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { DefaultKeyedValueDataset clone = (DefaultKeyedValueDataset) super.clone(); return clone; } }
5,751
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
KeyedValues2DDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/KeyedValues2DDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * KeyedValues2DDataset.java * ----------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 13-Mar-2003 : Version 1 (DG); * 23-Apr-2003 : Switched CategoryDataset and KeyedValues2DDataset so that * CategoryDataset is the super interface (DG); * */ package org.jfree.data.general; import org.jfree.data.category.CategoryDataset; /** * A dataset containing (key, value) data items. This dataset is equivalent * to a {@link CategoryDataset} and is included for completeness only. */ public interface KeyedValues2DDataset extends CategoryDataset { // no new methods required }
1,998
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultKeyedValuesDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DefaultKeyedValuesDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * DefaultKeyedValuesDataset.java * ------------------------------ * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Mar-2003 : Version 1 (DG); * 13-Mar-2003 : Implemented Serializable (DG); * */ package org.jfree.data.general; /** * A default implementation of the {@link KeyedValuesDataset} interface. * This is an alias for {@link DefaultPieDataset}. */ public class DefaultKeyedValuesDataset extends DefaultPieDataset implements KeyedValuesDataset { /** For serialization. */ private static final long serialVersionUID = 306264413152815781L; // no new methods }
1,986
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/AbstractDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * AbstractDataset.java * -------------------- * (C)opyright 2000-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Nicolas Brodu (for Astrium and EADS Corporate Research * Center); * * Changes (from 21-Aug-2001) * -------------------------- * 21-Aug-2001 : Added standard header. Fixed DOS encoding problem (DG); * 18-Sep-2001 : Updated e-mail address in header (DG); * 15-Oct-2001 : Moved to new package (com.jrefinery.data.*) (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 17-Nov-2001 : Changed constructor from public to protected, created new * AbstractSeriesDataset class and transferred series-related * methods, updated Javadoc comments (DG); * 04-Mar-2002 : Updated import statements (DG); * 11-Jun-2002 : Updated for change in the event constructor (DG); * 07-Aug-2002 : Changed listener list to use * javax.swing.event.EventListenerList (DG); * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 27-Mar-2003 : Implemented Serializable (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 08-Sep-2003 : Serialization fixes (NB); * 11-Sep-2003 : Cloning Fixes (NB); * 01-Jun-2005 : Added hasListener() method for unit testing (DG); * */ package org.jfree.data.general; import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.ObjectInputValidation; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.EventListener; import java.util.List; import javax.swing.event.EventListenerList; /** * An abstract implementation of the {@link Dataset} interface, containing a * mechanism for registering change listeners. */ public abstract class AbstractDataset implements Dataset, Cloneable, Serializable, ObjectInputValidation { /** For serialization. */ private static final long serialVersionUID = 1918768939869230744L; /** The group that the dataset belongs to. */ private DatasetGroup group; /** Storage for registered change listeners. */ private transient EventListenerList listenerList; /** * Constructs a dataset. By default, the dataset is assigned to its own * group. */ protected AbstractDataset() { this.group = new DatasetGroup(); this.listenerList = new EventListenerList(); } /** * Returns the dataset group for the dataset. * * @return The group (never <code>null</code>). * * @see #setGroup(DatasetGroup) */ @Override public DatasetGroup getGroup() { return this.group; } /** * Sets the dataset group for the dataset. * * @param group the group (<code>null</code> not permitted). * * @see #getGroup() */ @Override public void setGroup(DatasetGroup group) { if (group == null) { throw new IllegalArgumentException("Null 'group' argument."); } this.group = group; } /** * Registers an object to receive notification of changes to the dataset. * * @param listener the object to register. * * @see #removeChangeListener(DatasetChangeListener) */ @Override public void addChangeListener(DatasetChangeListener listener) { this.listenerList.add(DatasetChangeListener.class, listener); } /** * Deregisters an object so that it no longer receives notification of * changes to the dataset. * * @param listener the object to deregister. * * @see #addChangeListener(DatasetChangeListener) */ @Override public void removeChangeListener(DatasetChangeListener listener) { this.listenerList.remove(DatasetChangeListener.class, listener); } /** * Returns <code>true</code> if the specified object is registered with * the dataset as a listener. Most applications won't need to call this * method, it exists mainly for use by unit testing code. * * @param listener the listener. * * @return A boolean. * * @see #addChangeListener(DatasetChangeListener) * @see #removeChangeListener(DatasetChangeListener) */ public boolean hasListener(EventListener listener) { List<Object> list = Arrays.asList(this.listenerList.getListenerList()); return list.contains(listener); } /** * Notifies all registered listeners that the dataset has changed. * * @see #addChangeListener(DatasetChangeListener) */ protected void fireDatasetChanged() { notifyListeners(new DatasetChangeEvent(this, this)); } /** * Notifies all registered listeners that the dataset has changed. * * @param event contains information about the event that triggered the * notification. * * @see #addChangeListener(DatasetChangeListener) * @see #removeChangeListener(DatasetChangeListener) */ protected void notifyListeners(DatasetChangeEvent event) { Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == DatasetChangeListener.class) { ((DatasetChangeListener) listeners[i + 1]).datasetChanged( event); } } } /** * Returns a clone of the dataset. The cloned dataset will NOT include the * {@link DatasetChangeListener} references that have been registered with * this dataset. * * @return A clone. * * @throws CloneNotSupportedException if the dataset does not support * cloning. */ @Override public Object clone() throws CloneNotSupportedException { AbstractDataset clone = (AbstractDataset) super.clone(); clone.listenerList = new EventListenerList(); return clone; } /** * Handles serialization. * * @param stream the output stream. * * @throws IOException if there is an I/O problem. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); } /** * Restores a serialized object. * * @param stream the input stream. * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.listenerList = new EventListenerList(); stream.registerValidation(this, 10); // see comments about priority of // 10 in validateObject() } /** * Validates the object. We use this opportunity to call listeners who have * registered during the deserialization process, as listeners are not * serialized. This method is called by the serialization system after the * entire graph is read. * * This object has registered itself to the system with a priority of 10. * Other callbacks may register with a higher priority number to be called * before this object, or with a lower priority number to be called after * the listeners were notified. * * All listeners are supposed to have register by now, either in their * readObject or validateObject methods. Notify them that this dataset has * changed. * * @exception InvalidObjectException If the object cannot validate itself. */ @Override public void validateObject() throws InvalidObjectException { fireDatasetChanged(); } }
9,116
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SelectionChangeEvent.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/SelectionChangeEvent.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * SelectionChangeEvent.java * ------------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.general; import java.util.EventObject; import org.jfree.data.extension.DatasetCursor; import org.jfree.data.extension.DatasetSelectionExtension; /** * A change event that notifies about a change to the selection state of data * items. */ public class SelectionChangeEvent<CURSOR extends DatasetCursor> extends EventObject { /** a generated serial id*/ private static final long serialVersionUID = 5217307402196957331L; /** * Constructs a new event. * * @param source the source of the event aka the selection extension that * changed (the object has to be of type DatasetSelectionExtension and * must not be null!) */ public SelectionChangeEvent(Object selectionExtension) { super(selectionExtension); } /** * @return the selection selection extension that triggered the event. */ public DatasetSelectionExtension<CURSOR> getSelectionExtension() { if (this.getSource() instanceof DatasetSelectionExtension) { return (DatasetSelectionExtension<CURSOR>)this.getSource(); } //implementation error return null; } }
2,699
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WaferMapDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/WaferMapDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * WaferMapDataset.java * -------------------- * (C)opyright 2003-2008, by Robert Redburn and Contributors. * * Original Author: Robert Redburn; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 25-Nov-2003 : Version 1 contributed by Robert Redburn (with some * modifications to match style conventions) (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); * */ package org.jfree.data.general; import java.util.Set; import java.util.TreeSet; import org.jfree.data.DefaultKeyedValues2D; /** * A dataset that can be used with the {@link org.jfree.chart.plot.WaferMapPlot} * class. */ public class WaferMapDataset extends AbstractDataset { /** * Storage structure for the data values (row key is chipx, column is * chipy) */ private DefaultKeyedValues2D data; /** wafer x dimension */ private int maxChipX; /** wafer y dimension */ private int maxChipY; /** space to draw between chips */ private double chipSpace; /** maximum value in this dataset */ private Double maxValue; /** minimum value in this dataset */ private Double minValue; /** default chip spacing */ private static final double DEFAULT_CHIP_SPACE = 1d; /** * Creates a new dataset using the default chipspace. * * @param maxChipX the wafer x-dimension. * @param maxChipY the wafer y-dimension. */ public WaferMapDataset(int maxChipX, int maxChipY) { this(maxChipX, maxChipY, null); } /** * Creates a new dataset. * * @param maxChipX the wafer x-dimension. * @param maxChipY the wafer y-dimension. * @param chipSpace the space between chips. */ public WaferMapDataset(int maxChipX, int maxChipY, Number chipSpace) { this.maxValue = Double.NEGATIVE_INFINITY; this.minValue = Double.POSITIVE_INFINITY; this.data = new DefaultKeyedValues2D(); this.maxChipX = maxChipX; this.maxChipY = maxChipY; if (chipSpace == null) { this.chipSpace = DEFAULT_CHIP_SPACE; } else { this.chipSpace = chipSpace.doubleValue(); } } /** * Sets a value in the dataset. * * @param value the value. * @param chipx the x-index for the chip. * @param chipy the y-index for the chip. */ public void addValue(Number value, Comparable chipx, Comparable chipy) { setValue(value, chipx, chipy); } /** * Adds a value to the dataset. * * @param v the value. * @param x the x-index. * @param y the y-index. */ public void addValue(int v, int x, int y) { setValue((double) v, x, y); } /** * Sets a value in the dataset and updates min and max value entries. * * @param value the value. * @param chipx the x-index. * @param chipy the y-index. */ public void setValue(Number value, Comparable chipx, Comparable chipy) { this.data.setValue(value, chipx, chipy); if (isMaxValue(value)) { this.maxValue = (Double) value; } if (isMinValue(value)) { this.minValue = (Double) value; } } /** * Returns the number of unique values. * * @return The number of unique values. */ public int getUniqueValueCount() { return getUniqueValues().size(); } /** * Returns the set of unique values. * * @return The set of unique values. */ public Set<Number> getUniqueValues() { Set<Number> unique = new TreeSet<Number>(); //step through all the values and add them to the hash for (int r = 0; r < this.data.getRowCount(); r++) { for (int c = 0; c < this.data.getColumnCount(); c++) { Number value = this.data.getValue(r, c); if (value != null) { unique.add(value); } } } return unique; } /** * Returns the data value for a chip. * * @param chipx the x-index. * @param chipy the y-index. * * @return The data value. */ public Number getChipValue(int chipx, int chipy) { return getChipValue(Integer.valueOf(chipx), Integer.valueOf(chipy)); } /** * Returns the value for a given chip x and y or null. * * @param chipx the x-index. * @param chipy the y-index. * * @return The data value. */ public Number getChipValue(Comparable chipx, Comparable chipy) { int rowIndex = this.data.getRowIndex(chipx); if (rowIndex < 0) { return null; } int colIndex = this.data.getColumnIndex(chipy); if (colIndex < 0) { return null; } return this.data.getValue(rowIndex, colIndex); } /** * Tests to see if the passed value is larger than the stored maxvalue. * * @param check the number to check. * * @return A boolean. */ public boolean isMaxValue(Number check) { if (check.doubleValue() > this.maxValue) { return true; } return false; } /** * Tests to see if the passed value is smaller than the stored minvalue. * * @param check the number to check. * * @return A boolean. */ public boolean isMinValue(Number check) { if (check.doubleValue() < this.minValue) { return true; } return false; } /** * Returns the maximum value stored in the dataset. * * @return The maximum value. */ public Number getMaxValue() { return this.maxValue; } /** * Returns the minimum value stored in the dataset. * * @return The minimum value. */ public Number getMinValue() { return this.minValue; } /** * Returns the wafer x-dimension. * * @return The number of chips in the x-dimension. */ public int getMaxChipX() { return this.maxChipX; } /** * Sets wafer x dimension. * * @param maxChipX the number of chips in the x-dimension. */ public void setMaxChipX(int maxChipX) { this.maxChipX = maxChipX; } /** * Returns the number of chips in the y-dimension. * * @return The number of chips. */ public int getMaxChipY() { return this.maxChipY; } /** * Sets the number of chips in the y-dimension. * * @param maxChipY the number of chips. */ public void setMaxChipY(int maxChipY) { this.maxChipY = maxChipY; } /** * Returns the space to draw between chips. * * @return The space. */ public double getChipSpace() { return this.chipSpace; } /** * Sets the space to draw between chips. * * @param space the space. */ public void setChipSpace(double space) { this.chipSpace = space; } }
8,449
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultKeyedValues2DDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DefaultKeyedValues2DDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * DefaultKeyedValues2DDataset.java * -------------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 13-Mar-2003 : Version 1 (copied from DefaultCategoryDataset) (DG); * 23-Apr-2003 : Moved implementation into the DefaultCategoryDataset * class (DG); * */ package org.jfree.data.general; import java.io.Serializable; import org.jfree.data.category.DefaultCategoryDataset; /** * A default implementation of the {@link KeyedValues2DDataset} interface. * */ public class DefaultKeyedValues2DDataset extends DefaultCategoryDataset implements KeyedValues2DDataset, Serializable { /** For serialization. */ private static final long serialVersionUID = 4288210771905990424L; // no new methods }
2,144
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
HeatMapUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/HeatMapUtilities.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * HeatMapUtilities.java * --------------------- * (C) Copyright 2009, 2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 28-Jan-2009 : Version 1 (DG); * */ package org.jfree.data.general; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.image.BufferedImage; import org.jfree.chart.renderer.PaintScale; import org.jfree.chart.util.ParamChecks; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * A utility class for the {@link HeatMapDataset}. * * @since 1.0.13 */ public abstract class HeatMapUtilities { /** * Returns a dataset containing one series that holds a copy of the (x, z) * data from one row (y-index) of the specified dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param row the row (y) index. * @param seriesName the series name/key (<code>null</code> not permitted). * * @return The dataset. */ public static XYDataset extractRowFromHeatMapDataset(HeatMapDataset dataset, int row, Comparable seriesName) { XYSeries series = new XYSeries(seriesName); int cols = dataset.getXSampleCount(); for (int c = 0; c < cols; c++) { series.add(dataset.getXValue(c), dataset.getZValue(c, row)); } XYSeriesCollection result = new XYSeriesCollection(series); return result; } /** * Returns a dataset containing one series that holds a copy of the (y, z) * data from one column (x-index) of the specified dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param column the column (x) index. * @param seriesName the series name (<code>null</code> not permitted). * * @return The dataset. */ public static XYDataset extractColumnFromHeatMapDataset( HeatMapDataset dataset, int column, Comparable seriesName) { XYSeries series = new XYSeries(seriesName); int rows = dataset.getYSampleCount(); for (int r = 0; r < rows; r++) { series.add(dataset.getYValue(r), dataset.getZValue(column, r)); } XYSeriesCollection result = new XYSeriesCollection(series); return result; } /** * Creates an image that displays the values from the specified dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param paintScale the paint scale for the z-values (<code>null</code> * not permitted). * * @return A buffered image. */ public static BufferedImage createHeatMapImage(HeatMapDataset dataset, PaintScale paintScale) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(paintScale, "paintScale"); int xCount = dataset.getXSampleCount(); int yCount = dataset.getYSampleCount(); BufferedImage image = new BufferedImage(xCount, yCount, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); for (int xIndex = 0; xIndex < xCount; xIndex++) { for (int yIndex = 0; yIndex < yCount; yIndex++) { double z = dataset.getZValue(xIndex, yIndex); Paint p = paintScale.getPaint(z); g2.setPaint(p); g2.fillRect(xIndex, yCount - yIndex - 1, 1, 1); } } return image; } }
4,836
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultHeatMapDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DefaultHeatMapDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * DefaultHeatMapDataset.java * -------------------------- * (C) Copyright 2009-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 28-Jan-2009 : Version 1 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.general; import java.io.Serializable; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DataUtilities; /** * A default implementation of the {@link HeatMapDataset} interface. * * @since 1.0.13 */ public class DefaultHeatMapDataset extends AbstractDataset implements HeatMapDataset, Cloneable, PublicCloneable, Serializable { /** The number of samples in this dataset for the x-dimension. */ private int xSamples; /** The number of samples in this dataset for the y-dimension. */ private int ySamples; /** The minimum x-value in the dataset. */ private double minX; /** The maximum x-value in the dataset. */ private double maxX; /** The minimum y-value in the dataset. */ private double minY; /** The maximum y-value in the dataset. */ private double maxY; /** Storage for the z-values. */ private double[][] zValues; /** * Creates a new dataset where all the z-values are initially 0. This is * a fixed size array of z-values. * * @param xSamples the number of x-values. * @param ySamples the number of y-values * @param minX the minimum x-value in the dataset. * @param maxX the maximum x-value in the dataset. * @param minY the minimum y-value in the dataset. * @param maxY the maximum y-value in the dataset. */ public DefaultHeatMapDataset(int xSamples, int ySamples, double minX, double maxX, double minY, double maxY) { if (xSamples < 1) { throw new IllegalArgumentException("Requires 'xSamples' > 0"); } if (ySamples < 1) { throw new IllegalArgumentException("Requires 'ySamples' > 0"); } if (Double.isInfinite(minX) || Double.isNaN(minX)) { throw new IllegalArgumentException("'minX' cannot be INF or NaN."); } if (Double.isInfinite(maxX) || Double.isNaN(maxX)) { throw new IllegalArgumentException("'maxX' cannot be INF or NaN."); } if (Double.isInfinite(minY) || Double.isNaN(minY)) { throw new IllegalArgumentException("'minY' cannot be INF or NaN."); } if (Double.isInfinite(maxY) || Double.isNaN(maxY)) { throw new IllegalArgumentException("'maxY' cannot be INF or NaN."); } this.xSamples = xSamples; this.ySamples = ySamples; this.minX = minX; this.maxX = maxX; this.minY = minY; this.maxY = maxY; this.zValues = new double[xSamples][]; for (int x = 0; x < xSamples; x++) { this.zValues[x] = new double[ySamples]; } } /** * Returns the number of x values across the width of the dataset. The * values are evenly spaced between {@link #getMinimumXValue()} and * {@link #getMaximumXValue()}. * * @return The number of x-values (always > 0). */ @Override public int getXSampleCount() { return this.xSamples; } /** * Returns the number of y values (or samples) for the dataset. The * values are evenly spaced between {@link #getMinimumYValue()} and * {@link #getMaximumYValue()}. * * @return The number of y-values (always > 0). */ @Override public int getYSampleCount() { return this.ySamples; } /** * Returns the lowest x-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The lowest x-value represented in this dataset. */ @Override public double getMinimumXValue() { return this.minX; } /** * Returns the highest x-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The highest x-value represented in this dataset. */ @Override public double getMaximumXValue() { return this.maxX; } /** * Returns the lowest y-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The lowest y-value represented in this dataset. */ @Override public double getMinimumYValue() { return this.minY; } /** * Returns the highest y-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The highest y-value represented in this dataset. */ @Override public double getMaximumYValue() { return this.maxY; } /** * A convenience method that returns the x-value for the given index. * * @param xIndex the xIndex. * * @return The x-value. */ @Override public double getXValue(int xIndex) { double x = this.minX + (this.maxX - this.minX) * (xIndex / (double) this.xSamples); return x; } /** * A convenience method that returns the y-value for the given index. * * @param yIndex the yIndex. * * @return The y-value. */ @Override public double getYValue(int yIndex) { double y = this.minY + (this.maxY - this.minY) * (yIndex / (double) this.ySamples); return y; } /** * Returns the z-value at the specified sample position in the dataset. * For a missing or unknown value, this method should return Double.NAN. * * @param xIndex the position of the x sample in the dataset. * @param yIndex the position of the y sample in the dataset. * * @return The z-value. */ @Override public double getZValue(int xIndex, int yIndex) { return this.zValues[xIndex][yIndex]; } /** * Returns the z-value at the specified sample position in the dataset. * In this implementation, where the underlying values are stored in an * array of double primitives, you should avoid using this method and * use {@link #getZValue(int, int)} instead. * * @param xIndex the position of the x sample in the dataset. * @param yIndex the position of the y sample in the dataset. * * @return The z-value. */ @Override public Number getZ(int xIndex, int yIndex) { return getZValue(xIndex, yIndex); } /** * Updates a z-value in the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param xIndex the x-index. * @param yIndex the y-index. * @param z the new z-value. */ public void setZValue(int xIndex, int yIndex, double z) { setZValue(xIndex, yIndex, z, true); } /** * Updates a z-value in the dataset and, if requested, sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param xIndex the x-index. * @param yIndex the y-index. * @param z the new z-value. * @param notify notify listeners? */ public void setZValue(int xIndex, int yIndex, double z, boolean notify) { this.zValues[xIndex][yIndex] = z; if (notify) { fireDatasetChanged(); } } /** * Tests this dataset for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DefaultHeatMapDataset)) { return false; } DefaultHeatMapDataset that = (DefaultHeatMapDataset) obj; if (this.xSamples != that.xSamples) { return false; } if (this.ySamples != that.ySamples) { return false; } if (this.minX != that.minX) { return false; } if (this.maxX != that.maxX) { return false; } if (this.minY != that.minY) { return false; } if (this.maxY != that.maxY) { return false; } if (!DataUtilities.equal(this.zValues, that.zValues)) { return false; } // can't find any differences return true; } /** * Returns an independent copy of this dataset. * * @return A clone. * * @throws java.lang.CloneNotSupportedException */ @Override public Object clone() throws CloneNotSupportedException { DefaultHeatMapDataset clone = (DefaultHeatMapDataset) super.clone(); clone.zValues = DataUtilities.clone(this.zValues); return clone; } }
10,446
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SeriesDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/SeriesDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * SeriesDataset.java * ------------------ * (C) Copyright 2000-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 17-Nov-2001 : Version 1 (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 19-May-2005 : Changed getSeriesName() --> getSeriesKey() and added indexOf() * method (DG); * */ package org.jfree.data.general; import org.jfree.data.category.CategoryDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.IntervalXYZDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYZDataset; /** * The interface for a dataset consisting of one or many series of data. * * @see CategoryDataset * @see IntervalXYDataset * @see IntervalXYZDataset * @see XYDataset * @see XYZDataset */ public interface SeriesDataset extends Dataset { /** * Returns the number of series in the dataset. * * @return The series count. */ public int getSeriesCount(); /** * Returns the key for a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * * @return The key for the series. */ public Comparable getSeriesKey(int series); /** * Returns the index of the series with the specified key, or -1 if there * is no such series in the dataset. * * @param seriesKey the series key (<code>null</code> permitted). * * @return The index, or -1. */ public int indexOf(Comparable seriesKey); }
2,883
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
HeatMapDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/HeatMapDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * HeatMapDataset.java * ------------------- * (C) Copyright 2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 28-Jan-2009 : Version 1 (DG); * */ package org.jfree.data.general; /** * A dataset that represents a rectangular grid of (x, y, z) values. The x * and y values appear at regular intervals in the dataset, while the z-values * can take any value (including <code>null</code> for unknown values). * * @since 1.0.13 */ public interface HeatMapDataset { /** * Returns the number of x values across the width of the dataset. The * values are evenly spaced between {@link #getMinimumXValue()} and * {@link #getMaximumXValue()}. * * @return The number of x-values (always > 0). */ public int getXSampleCount(); /** * Returns the number of y values (or samples) for the dataset. The * values are evenly spaced between {@link #getMinimumYValue()} and * {@link #getMaximumYValue()}. * * @return The number of y-values (always > 0). */ public int getYSampleCount(); /** * Returns the lowest x-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The lowest x-value represented in this dataset. */ public double getMinimumXValue(); /** * Returns the highest x-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The highest x-value represented in this dataset. */ public double getMaximumXValue(); /** * Returns the lowest y-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The lowest y-value represented in this dataset. */ public double getMinimumYValue(); /** * Returns the highest y-value represented in this dataset. A requirement * of this interface is that this method must never return infinite or * Double.NAN values. * * @return The highest y-value represented in this dataset. */ public double getMaximumYValue(); /** * A convenience method that returns the x-value for the given index. * * @param xIndex the xIndex. * * @return The x-value. */ public double getXValue(int xIndex); /** * A convenience method that returns the y-value for the given index. * * @param yIndex the yIndex. * * @return The y-value. */ public double getYValue(int yIndex); /** * Returns the z-value at the specified sample position in the dataset. * For a missing or unknown value, this method should return Double.NAN. * * @param xIndex the position of the x sample in the dataset. * @param yIndex the position of the y sample in the dataset. * * @return The z-value. */ public double getZValue(int xIndex, int yIndex); /** * Returns the z-value at the specified sample position in the dataset. * This method can return <code>null</code> to indicate a missing/unknown * value. * <br><br> * Bear in mind that the class implementing this interface may * store its data using primitives rather than objects, so calling this * method may require a new <code>Number</code> object to be allocated... * for this reason, it is generally preferable to use the * {@link #getZValue(int, int)} method unless you *know* that the dataset * implementation stores the z-values using objects. * * @param xIndex the position of the x sample in the dataset. * @param yIndex the position of the y sample in the dataset. * * @return The z-value (possibly <code>null</code>). */ public Number getZ(int xIndex, int yIndex); }
5,327
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DatasetUtilities.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * DatasetUtilities.java * --------------------- * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrzej Porebski (bug fix); * Jonathan Nash (bug fix); * Richard Atkinson; * Andreas Schroeder; * Rafal Skalny (patch 1925366); * Jerome David (patch 2131001); * Peter Kolb (patch 2791407); * Martin Hoeller (patch 2952086); * * Changes (from 18-Sep-2001) * -------------------------- * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 15-Nov-2001 : Moved to package com.jrefinery.data.* in the JCommon class * library (DG); * Changed to handle null values from datasets (DG); * Bug fix (thanks to Andrzej Porebski) - initial value now set * to positive or negative infinity when iterating (DG); * 22-Nov-2001 : Datasets with containing no data now return null for min and * max calculations (DG); * 13-Dec-2001 : Extended to handle HighLowDataset and IntervalXYDataset (DG); * 15-Feb-2002 : Added getMinimumStackedRangeValue() and * getMaximumStackedRangeValue() (DG); * 28-Feb-2002 : Renamed Datasets.java --> DatasetUtilities.java (DG); * 18-Mar-2002 : Fixed bug in min/max domain calculation for datasets that * implement the CategoryDataset interface AND the XYDataset * interface at the same time. Thanks to Jonathan Nash for the * fix (DG); * 23-Apr-2002 : Added getDomainExtent() and getRangeExtent() methods (DG); * 13-Jun-2002 : Modified range measurements to handle * IntervalCategoryDataset (DG); * 12-Jul-2002 : Method name change in DomainInfo interface (DG); * 30-Jul-2002 : Added pie dataset summation method (DG); * 01-Oct-2002 : Added a method for constructing an XYDataset from a Function2D * instance (DG); * 24-Oct-2002 : Amendments required following changes to the CategoryDataset * interface (DG); * 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG); * 04-Mar-2003 : Added isEmpty(XYDataset) method (DG); * 05-Mar-2003 : Added a method for creating a CategoryDataset from a * KeyedValues instance (DG); * 15-May-2003 : Renamed isEmpty --> isEmptyOrNull (DG); * 25-Jun-2003 : Added limitPieDataset methods (RA); * 26-Jun-2003 : Modified getDomainExtent() method to accept null datasets (DG); * 27-Jul-2003 : Added getStackedRangeExtent(TableXYDataset data) (RA); * 18-Aug-2003 : getStackedRangeExtent(TableXYDataset data) now handles null * values (RA); * 02-Sep-2003 : Added method to check for null or empty PieDataset (DG); * 18-Sep-2003 : Fix for bug 803660 (getMaximumRangeValue for * CategoryDataset) (DG); * 20-Oct-2003 : Added getCumulativeRangeExtent() method (DG); * 09-Jan-2003 : Added argument checking code to the createCategoryDataset() * method (DG); * 23-Mar-2004 : Fixed bug in getMaximumStackedRangeValue() method (DG); * 31-Mar-2004 : Exposed the extent iteration algorithms to use one of them and * applied noninstantiation pattern (AS); * 11-May-2004 : Renamed getPieDatasetTotal --> calculatePieDatasetTotal (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with getYValue(); * 24-Aug-2004 : Added argument checks to createCategoryDataset() method (DG); * 04-Oct-2004 : Renamed ArrayUtils --> ArrayUtilities (DG); * 06-Oct-2004 : Renamed findDomainExtent() --> findDomainBounds(), * findRangeExtent() --> findRangeBounds() (DG); * 07-Jan-2005 : Renamed findStackedRangeExtent() --> findStackedRangeBounds(), * findCumulativeRangeExtent() --> findCumulativeRangeBounds(), * iterateXYRangeExtent() --> iterateXYRangeBounds(), * removed deprecated methods (DG); * 03-Feb-2005 : The findStackedRangeBounds() methods now return null for * empty datasets (DG); * 03-Mar-2005 : Moved createNumberArray() and createNumberArray2D() methods * from DatasetUtilities --> DataUtilities (DG); * 22-Sep-2005 : Added new findStackedRangeBounds() method that takes base * argument (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 15-Mar-2007 : Added calculateStackTotal() method (DG); * 27-Mar-2008 : Fixed bug in findCumulativeRangeBounds() method (DG); * 28-Mar-2008 : Fixed sample count in sampleFunction2D() method, renamed * iterateXYRangeBounds() --> iterateRangeBounds(XYDataset), and * fixed a bug in findRangeBounds(XYDataset, false) (DG); * 28-Mar-2008 : Applied a variation of patch 1925366 (from Rafal Skalny) for * slightly more efficient iterateRangeBounds() methods (DG); * 08-Apr-2008 : Fixed typo in iterateRangeBounds() (DG); * 08-Oct-2008 : Applied patch 2131001 by Jerome David, with some modifications * and additions and some new unit tests (DG); * 12-Feb-2009 : Added sampleFunction2DToSeries() method (DG); * 27-Mar-2009 : Added new methods to find domain and range bounds taking into * account hidden series (DG); * 01-Apr-2009 : Handle a StatisticalCategoryDataset in * iterateToFindRangeBounds() (DG); * 16-May-2009 : Patch 2791407 - fix iterateToFindRangeBounds for * MultiValueCategoryDataset (PK); * 10-Sep-2009 : Fix bug 2849731 for IntervalCategoryDataset (DG); * 16-Feb-2010 : Patch 2952086 - find z-bounds (MH); * */ package org.jfree.data.general; import java.util.ArrayList; import java.util.List; import org.jfree.chart.util.ArrayUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.data.DomainInfo; import org.jfree.data.DomainOrder; import org.jfree.data.KeyToGroupMap; import org.jfree.data.KeyedValues; import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.CategoryRangeInfo; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.category.IntervalCategoryDataset; import org.jfree.data.function.Function2D; import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset; import org.jfree.data.statistics.BoxAndWhiskerXYDataset; import org.jfree.data.statistics.MultiValueCategoryDataset; import org.jfree.data.statistics.StatisticalCategoryDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.OHLCDataset; import org.jfree.data.xy.TableXYDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYDomainInfo; import org.jfree.data.xy.XYRangeInfo; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.data.xy.XYZDataset; /** * A collection of useful static methods relating to datasets. */ public final class DatasetUtilities { /** * Private constructor for non-instanceability. */ private DatasetUtilities() { // now try to instantiate this ;-) } /** * Calculates the total of all the values in a {@link PieDataset}. If * the dataset contains negative or <code>null</code> values, they are * ignored. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The total. */ public static double calculatePieDatasetTotal(PieDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); List<Comparable> keys = dataset.getKeys(); double totalValue = 0; for (Comparable current : keys) { if (current != null) { Number value = dataset.getValue(current); double v = 0.0; if (value != null) { v = value.doubleValue(); } if (v > 0) { totalValue = totalValue + v; } } } return totalValue; } /** * Creates a pie dataset from a table dataset by taking all the values * for a single row. * * @param dataset the dataset (<code>null</code> not permitted). * @param rowKey the row key. * * @return A pie dataset. */ public static PieDataset createPieDatasetForRow(CategoryDataset dataset, Comparable rowKey) { int row = dataset.getRowIndex(rowKey); return createPieDatasetForRow(dataset, row); } /** * Creates a pie dataset from a table dataset by taking all the values * for a single row. * * @param dataset the dataset (<code>null</code> not permitted). * @param row the row (zero-based index). * * @return A pie dataset. */ public static PieDataset createPieDatasetForRow(CategoryDataset dataset, int row) { DefaultPieDataset result = new DefaultPieDataset(); int columnCount = dataset.getColumnCount(); for (int current = 0; current < columnCount; current++) { Comparable columnKey = dataset.getColumnKey(current); result.setValue(columnKey, dataset.getValue(row, current)); } return result; } /** * Creates a pie dataset from a table dataset by taking all the values * for a single column. * * @param dataset the dataset (<code>null</code> not permitted). * @param columnKey the column key. * * @return A pie dataset. */ public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, Comparable columnKey) { int column = dataset.getColumnIndex(columnKey); return createPieDatasetForColumn(dataset, column); } /** * Creates a pie dataset from a {@link CategoryDataset} by taking all the * values for a single column. * * @param dataset the dataset (<code>null</code> not permitted). * @param column the column (zero-based index). * * @return A pie dataset. */ public static PieDataset createPieDatasetForColumn(CategoryDataset dataset, int column) { DefaultPieDataset result = new DefaultPieDataset(); int rowCount = dataset.getRowCount(); for (int i = 0; i < rowCount; i++) { Comparable rowKey = dataset.getRowKey(i); result.setValue(rowKey, dataset.getValue(i, column)); } return result; } /** * Creates a new pie dataset based on the supplied dataset, but modified * by aggregating all the low value items (those whose value is lower * than the <code>percentThreshold</code>) into a single item with the * key "Other". * * @param source the source dataset (<code>null</code> not permitted). * @param key a new key for the aggregated items (<code>null</code> not * permitted). * @param minimumPercent the percent threshold. * * @return The pie dataset with (possibly) aggregated items. */ public static PieDataset createConsolidatedPieDataset(PieDataset source, Comparable key, double minimumPercent) { return DatasetUtilities.createConsolidatedPieDataset(source, key, minimumPercent, 2); } /** * Creates a new pie dataset based on the supplied dataset, but modified * by aggregating all the low value items (those whose value is lower * than the <code>percentThreshold</code>) into a single item. The * aggregated items are assigned the specified key. Aggregation only * occurs if there are at least <code>minItems</code> items to aggregate. * * @param source the source dataset (<code>null</code> not permitted). * @param key the key to represent the aggregated items. * @param minimumPercent the percent threshold (ten percent is 0.10). * @param minItems only aggregate low values if there are at least this * many. * * @return The pie dataset with (possibly) aggregated items. */ public static PieDataset createConsolidatedPieDataset(PieDataset source, Comparable key, double minimumPercent, int minItems) { DefaultPieDataset result = new DefaultPieDataset(); double total = DatasetUtilities.calculatePieDatasetTotal(source); // Iterate and find all keys below threshold percentThreshold List<Comparable> keys = source.getKeys(); List<Comparable> otherKeys = new ArrayList<Comparable>(); for (Comparable currentKey : keys) { Number dataValue = source.getValue(currentKey); if (dataValue != null) { double value = dataValue.doubleValue(); if (value / total < minimumPercent) { otherKeys.add(currentKey); } } } // Create new dataset with keys above threshold percentThreshold double otherValue = 0; for (Comparable currentKey : keys) { Number dataValue = source.getValue(currentKey); if (dataValue != null) { if (otherKeys.contains(currentKey) && otherKeys.size() >= minItems) { // Do not add key to dataset otherValue += dataValue.doubleValue(); } else { // Add key to dataset result.setValue(currentKey, dataValue); } } } // Add other category if applicable if (otherKeys.size() >= minItems) { result.setValue(key, otherValue); } return result; } /** * Creates a {@link CategoryDataset} that contains a copy of the data in an * array (instances of <code>Double</code> are created to represent the * data items). * <p> * Row and column keys are created by appending 0, 1, 2, ... to the * supplied prefixes. * * @param rowKeyPrefix the row key prefix. * @param columnKeyPrefix the column key prefix. * @param data the data. * * @return The dataset. */ public static CategoryDataset createCategoryDataset(String rowKeyPrefix, String columnKeyPrefix, double[][] data) { DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int r = 0; r < data.length; r++) { String rowKey = rowKeyPrefix + (r + 1); for (int c = 0; c < data[r].length; c++) { String columnKey = columnKeyPrefix + (c + 1); result.addValue(new Double(data[r][c]), rowKey, columnKey); } } return result; } /** * Creates a {@link CategoryDataset} that contains a copy of the data in * an array. * <p> * Row and column keys are created by appending 0, 1, 2, ... to the * supplied prefixes. * * @param rowKeyPrefix the row key prefix. * @param columnKeyPrefix the column key prefix. * @param data the data. * * @return The dataset. */ public static CategoryDataset createCategoryDataset(String rowKeyPrefix, String columnKeyPrefix, Number[][] data) { DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int r = 0; r < data.length; r++) { String rowKey = rowKeyPrefix + (r + 1); for (int c = 0; c < data[r].length; c++) { String columnKey = columnKeyPrefix + (c + 1); result.addValue(data[r][c], rowKey, columnKey); } } return result; } /** * Creates a {@link CategoryDataset} that contains a copy of the data in * an array (instances of <code>Double</code> are created to represent the * data items). * <p> * Row and column keys are taken from the supplied arrays. * * @param rowKeys the row keys (<code>null</code> not permitted). * @param columnKeys the column keys (<code>null</code> not permitted). * @param data the data. * * @return The dataset. */ public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, Comparable[] columnKeys, double[][] data) { ParamChecks.nullNotPermitted(rowKeys, "rowKeys"); ParamChecks.nullNotPermitted(columnKeys, "columnKeys"); if (ArrayUtilities.hasDuplicateItems(rowKeys)) { throw new IllegalArgumentException("Duplicate items in 'rowKeys'."); } if (ArrayUtilities.hasDuplicateItems(columnKeys)) { throw new IllegalArgumentException( "Duplicate items in 'columnKeys'."); } if (rowKeys.length != data.length) { throw new IllegalArgumentException( "The number of row keys does not match the number of rows in " + "the data array."); } int columnCount = 0; for (double[] aData : data) { columnCount = Math.max(columnCount, aData.length); } if (columnKeys.length != columnCount) { throw new IllegalArgumentException( "The number of column keys does not match the number of " + "columns in the data array."); } // now do the work... DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int r = 0; r < data.length; r++) { Comparable rowKey = rowKeys[r]; for (int c = 0; c < data[r].length; c++) { Comparable columnKey = columnKeys[c]; result.addValue(new Double(data[r][c]), rowKey, columnKey); } } return result; } /** * Creates a {@link CategoryDataset} by copying the data from the supplied * {@link KeyedValues} instance. * * @param rowKey the row key (<code>null</code> not permitted). * @param rowData the row data (<code>null</code> not permitted). * * @return A dataset. */ public static CategoryDataset createCategoryDataset(Comparable rowKey, KeyedValues rowData) { ParamChecks.nullNotPermitted(rowKey, "rowKey"); ParamChecks.nullNotPermitted(rowData, "rowData"); DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int i = 0; i < rowData.getItemCount(); i++) { result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i)); } return result; } /** * Creates an {@link XYDataset} by sampling the specified function over a * fixed range. * * @param f the function (<code>null</code> not permitted). * @param start the start value for the range. * @param end the end value for the range. * @param samples the number of sample points (must be > 1). * @param seriesKey the key to give the resulting series * (<code>null</code> not permitted). * * @return A dataset. */ public static XYDataset sampleFunction2D(Function2D f, double start, double end, int samples, Comparable seriesKey) { // defer argument checking XYSeries series = sampleFunction2DToSeries(f, start, end, samples, seriesKey); XYSeriesCollection collection = new XYSeriesCollection(series); return collection; } /** * Creates an {@link XYSeries} by sampling the specified function over a * fixed range. * * @param f the function (<code>null</code> not permitted). * @param start the start value for the range. * @param end the end value for the range. * @param samples the number of sample points (must be > 1). * @param seriesKey the key to give the resulting series * (<code>null</code> not permitted). * * @return A series. * * @since 1.0.13 */ public static XYSeries sampleFunction2DToSeries(Function2D f, double start, double end, int samples, Comparable seriesKey) { ParamChecks.nullNotPermitted(f, "f"); ParamChecks.nullNotPermitted(seriesKey, "seriesKey"); if (start >= end) { throw new IllegalArgumentException("Requires 'start' < 'end'."); } if (samples < 2) { throw new IllegalArgumentException("Requires 'samples' > 1"); } XYSeries series = new XYSeries(seriesKey); double step = (end - start) / (samples - 1); for (int i = 0; i < samples; i++) { double x = start + (step * i); series.add(x, f.getValue(x)); } return series; } /** * Returns <code>true</code> if the dataset is empty (or <code>null</code>), * and <code>false</code> otherwise. * * @param dataset the dataset (<code>null</code> permitted). * * @return A boolean. */ public static boolean isEmptyOrNull(PieDataset dataset) { if (dataset == null) { return true; } int itemCount = dataset.getItemCount(); if (itemCount == 0) { return true; } for (int item = 0; item < itemCount; item++) { Number y = dataset.getValue(item); if (y != null) { double yy = y.doubleValue(); if (yy > 0.0) { return false; } } } return true; } /** * Returns <code>true</code> if the dataset is empty (or <code>null</code>), * and <code>false</code> otherwise. * * @param dataset the dataset (<code>null</code> permitted). * * @return A boolean. */ public static boolean isEmptyOrNull(CategoryDataset dataset) { if (dataset == null) { return true; } int rowCount = dataset.getRowCount(); int columnCount = dataset.getColumnCount(); if (rowCount == 0 || columnCount == 0) { return true; } for (int r = 0; r < rowCount; r++) { for (int c = 0; c < columnCount; c++) { if (dataset.getValue(r, c) != null) { return false; } } } return true; } /** * Returns <code>true</code> if the dataset is empty (or <code>null</code>), * and <code>false</code> otherwise. * * @param dataset the dataset (<code>null</code> permitted). * * @return A boolean. */ public static boolean isEmptyOrNull(XYDataset dataset) { if (dataset != null) { for (int s = 0; s < dataset.getSeriesCount(); s++) { if (dataset.getItemCount(s) > 0) { return false; } } } return true; } /** * Returns the range of values in the domain (x-values) of a dataset. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range of values (possibly <code>null</code>). */ public static Range findDomainBounds(XYDataset dataset) { return findDomainBounds(dataset, true); } /** * Returns the range of values in the domain (x-values) of a dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval determines whether or not the x-interval is taken * into account (only applies if the dataset is an * {@link IntervalXYDataset}). * * @return The range of values (possibly <code>null</code>). */ public static Range findDomainBounds(XYDataset dataset, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result; // if the dataset implements DomainInfo, life is easier if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; result = info.getDomainBounds(includeInterval); } else { result = iterateDomainBounds(dataset, includeInterval); } return result; } /** * Returns the bounds of the x-values in the specified <code>dataset</code> * taking into account only the visible series and including any x-interval * if requested. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> * not permitted). * @param includeInterval include the x-interval (if any)? * * @return The bounds (or <code>null</code> if the dataset contains no * values. * * @since 1.0.13 */ public static Range findDomainBounds(XYDataset dataset, List<Comparable> visibleSeriesKeys, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof XYDomainInfo) { XYDomainInfo info = (XYDomainInfo) dataset; result = info.getDomainBounds(visibleSeriesKeys, includeInterval); } else { result = iterateToFindDomainBounds(dataset, visibleSeriesKeys, includeInterval); } return result; } /** * Iterates over the items in an {@link XYDataset} to find * the range of x-values. If the dataset is an instance of * {@link IntervalXYDataset}, the starting and ending x-values * will be used for the bounds calculation. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). */ public static Range iterateDomainBounds(XYDataset dataset) { return iterateDomainBounds(dataset, true); } /** * Iterates over the items in an {@link XYDataset} to find * the range of x-values. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines, for an * {@link IntervalXYDataset}, whether the x-interval or just the * x-value is used to determine the overall range. * * @return The range (possibly <code>null</code>). */ public static Range iterateDomainBounds(XYDataset dataset, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); double lvalue; double uvalue; if (includeInterval && dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = intervalXYData.getXValue(series, item); lvalue = intervalXYData.getStartXValue(series, item); uvalue = intervalXYData.getEndXValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, lvalue); } if (!Double.isNaN(uvalue)) { minimum = Math.min(minimum, uvalue); maximum = Math.max(maximum, uvalue); } } } } else { for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { lvalue = dataset.getXValue(series, item); uvalue = lvalue; if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, uvalue); } } } } if (minimum > maximum) { return null; } else { return new Range(minimum, maximum); } } /** * Returns the range of values in the range for the dataset. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). */ public static Range findRangeBounds(CategoryDataset dataset) { return findRangeBounds(dataset, true); } /** * Returns the range of values in the range for the dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (possibly <code>null</code>). */ public static Range findRangeBounds(CategoryDataset dataset, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; result = info.getRangeBounds(includeInterval); } else { result = iterateRangeBounds(dataset, includeInterval); } return result; } /** * Finds the bounds of the y-values in the specified dataset, including * only those series that are listed in visibleSeriesKeys. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the keys for the visible series * (<code>null</code> not permitted). * @param includeInterval include the y-interval (if the dataset has a * y-interval). * * @return The data bounds. * * @since 1.0.13 */ public static Range findRangeBounds(CategoryDataset dataset, List<Comparable> visibleSeriesKeys, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); Range result; if (dataset instanceof CategoryRangeInfo) { CategoryRangeInfo info = (CategoryRangeInfo) dataset; result = info.getRangeBounds(visibleSeriesKeys, includeInterval); } else { result = iterateToFindRangeBounds(dataset, visibleSeriesKeys, includeInterval); } return result; } /** * Returns the range of values in the range for the dataset. This method * is the partner for the {@link #findDomainBounds(XYDataset)} method. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). */ public static Range findRangeBounds(XYDataset dataset) { return findRangeBounds(dataset, true); } /** * Returns the range of values in the range for the dataset. This method * is the partner for the {@link #findDomainBounds(XYDataset, boolean)} * method. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (possibly <code>null</code>). */ public static Range findRangeBounds(XYDataset dataset, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; result = info.getRangeBounds(includeInterval); } else { result = iterateRangeBounds(dataset, includeInterval); } return result; } /** * Finds the bounds of the y-values in the specified dataset, including * only those series that are listed in visibleSeriesKeys, and those items * whose x-values fall within the specified range. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the keys for the visible series * (<code>null</code> not permitted). * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval include the y-interval (if the dataset has a * y-interval). * * @return The data bounds. * * @since 1.0.13 */ public static Range findRangeBounds(XYDataset dataset, List<Comparable> visibleSeriesKeys, Range xRange, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof XYRangeInfo) { XYRangeInfo info = (XYRangeInfo) dataset; result = info.getRangeBounds(visibleSeriesKeys, xRange, includeInterval); } else { result = iterateToFindRangeBounds(dataset, visibleSeriesKeys, xRange, includeInterval); } return result; } /** * Iterates over the data item of the category dataset to find * the range bounds. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). * * @since 1.0.10 */ public static Range iterateRangeBounds(CategoryDataset dataset) { return iterateRangeBounds(dataset, true); } /** * Iterates over the data item of the category dataset to find * the range bounds. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (possibly <code>null</code>). * * @since 1.0.10 */ public static Range iterateRangeBounds(CategoryDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int rowCount = dataset.getRowCount(); int columnCount = dataset.getColumnCount(); if (includeInterval && dataset instanceof IntervalCategoryDataset) { // handle the special case where the dataset has y-intervals that // we want to measure IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; Number value, lvalue, uvalue; for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { value = icd.getValue(row, column); double v; if ((value != null) && !Double.isNaN(v = value.doubleValue())) { minimum = Math.min(v, minimum); maximum = Math.max(v, maximum); } lvalue = icd.getStartValue(row, column); if (lvalue != null && !Double.isNaN(v = lvalue.doubleValue())) { minimum = Math.min(v, minimum); maximum = Math.max(v, maximum); } uvalue = icd.getEndValue(row, column); if (uvalue != null && !Double.isNaN(v = uvalue.doubleValue())) { minimum = Math.min(v, minimum); maximum = Math.max(v, maximum); } } } } else { // handle the standard case (plain CategoryDataset) for (int row = 0; row < rowCount; row++) { for (int column = 0; column < columnCount; column++) { Number value = dataset.getValue(row, column); if (value != null) { double v = value.doubleValue(); if (!Double.isNaN(v)) { minimum = Math.min(minimum, v); maximum = Math.max(maximum, v); } } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Iterates over the data item of the category dataset to find * the range bounds. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * @param visibleSeriesKeys the visible series keys. * * @return The range (possibly <code>null</code>). * * @since 1.0.13 */ public static Range iterateToFindRangeBounds(CategoryDataset dataset, List<Comparable> visibleSeriesKeys, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int columnCount = dataset.getColumnCount(); if (includeInterval && dataset instanceof BoxAndWhiskerCategoryDataset) { // handle special case of BoxAndWhiskerDataset BoxAndWhiskerCategoryDataset bx = (BoxAndWhiskerCategoryDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.getRowIndex(seriesKey); int itemCount = dataset.getColumnCount(); for (int item = 0; item < itemCount; item++) { Number lvalue = bx.getMinRegularValue(series, item); if (lvalue == null) { lvalue = bx.getValue(series, item); } Number uvalue = bx.getMaxRegularValue(series, item); if (uvalue == null) { uvalue = bx.getValue(series, item); } if (lvalue != null) { minimum = Math.min(minimum, lvalue.doubleValue()); } if (uvalue != null) { maximum = Math.max(maximum, uvalue.doubleValue()); } } } } else if (includeInterval && dataset instanceof IntervalCategoryDataset) { // handle the special case where the dataset has y-intervals that // we want to measure IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; Number lvalue, uvalue; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.getRowIndex(seriesKey); for (int column = 0; column < columnCount; column++) { lvalue = icd.getStartValue(series, column); uvalue = icd.getEndValue(series, column); if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) { minimum = Math.min(minimum, lvalue.doubleValue()); } if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) { maximum = Math.max(maximum, uvalue.doubleValue()); } } } } else if (includeInterval && dataset instanceof MultiValueCategoryDataset) { // handle the special case where the dataset has y-intervals that // we want to measure MultiValueCategoryDataset mvcd = (MultiValueCategoryDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.getRowIndex(seriesKey); for (int column = 0; column < columnCount; column++) { List<Number> values = mvcd.getValues(series, column); for (Number o : values) { double v = o.doubleValue(); if (!Double.isNaN(v)) { minimum = Math.min(minimum, v); maximum = Math.max(maximum, v); } } } } } else if (includeInterval && dataset instanceof StatisticalCategoryDataset) { // handle the special case where the dataset has y-intervals that // we want to measure StatisticalCategoryDataset scd = (StatisticalCategoryDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.getRowIndex(seriesKey); for (int column = 0; column < columnCount; column++) { Number meanN = scd.getMeanValue(series, column); if (meanN != null) { double std = 0.0; Number stdN = scd.getStdDevValue(series, column); if (stdN != null) { std = stdN.doubleValue(); if (Double.isNaN(std)) { std = 0.0; } } double mean = meanN.doubleValue(); if (!Double.isNaN(mean)) { minimum = Math.min(minimum, mean - std); maximum = Math.max(maximum, mean + std); } } } } } else { // handle the standard case (plain CategoryDataset) for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.getRowIndex(seriesKey); for (int column = 0; column < columnCount; column++) { Number value = dataset.getValue(series, column); if (value != null) { double v = value.doubleValue(); if (!Double.isNaN(v)) { minimum = Math.min(minimum, v); maximum = Math.max(maximum, v); } } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Iterates over the data item of the xy dataset to find * the range bounds. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). * * @since 1.0.10 */ public static Range iterateRangeBounds(XYDataset dataset) { return iterateRangeBounds(dataset, true); } /** * Iterates over the data items of the xy dataset to find * the range bounds. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines, for an * {@link IntervalXYDataset}, whether the y-interval or just the * y-value is used to determine the overall range. * * @return The range (possibly <code>null</code>). * * @since 1.0.10 */ public static Range iterateRangeBounds(XYDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); // handle three cases by dataset type if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = ixyd.getYValue(series, item); double lvalue = ixyd.getStartYValue(series, item); double uvalue = ixyd.getEndYValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); maximum = Math.max(maximum, lvalue); } if (!Double.isNaN(uvalue)) { minimum = Math.min(minimum, uvalue); maximum = Math.max(maximum, uvalue); } } } } else if (includeInterval && dataset instanceof OHLCDataset) { // handle special case of OHLCDataset OHLCDataset ohlc = (OHLCDataset) dataset; for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double lvalue = ohlc.getLowValue(series, item); double uvalue = ohlc.getHighValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } else { // standard case - plain XYDataset for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = dataset.getYValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Returns the range of values in the z-dimension for the dataset. This * method is the partner for the {@link #findRangeBounds(XYDataset)} * and {@link #findDomainBounds(XYDataset)} methods. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). */ public static Range findZBounds(XYZDataset dataset) { return findZBounds(dataset, true); } /** * Returns the range of values in the z-dimension for the dataset. This * method is the partner for the * {@link #findRangeBounds(XYDataset, boolean)} and * {@link #findDomainBounds(XYDataset, boolean)} methods. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * z-interval is taken into account. * * @return The range (possibly <code>null</code>). */ public static Range findZBounds(XYZDataset dataset, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result = iterateZBounds(dataset, includeInterval); return result; } /** * Finds the bounds of the z-values in the specified dataset, including * only those series that are listed in visibleSeriesKeys, and those items * whose x-values fall within the specified range. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the keys for the visible series * (<code>null</code> not permitted). * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval include the z-interval (if the dataset has a * z-interval). * * @return The data bounds. */ public static Range findZBounds(XYZDataset dataset, List<Comparable> visibleSeriesKeys, Range xRange, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result = iterateToFindZBounds(dataset, visibleSeriesKeys, xRange, includeInterval); return result; } /** * Iterates over the data item of the xyz dataset to find * the z-dimension bounds. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (possibly <code>null</code>). */ public static Range iterateZBounds(XYZDataset dataset) { return iterateZBounds(dataset, true); } /** * Iterates over the data items of the xyz dataset to find * the z-dimension bounds. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval include the z-interval (if the dataset has a * z-interval. * * @return The range (possibly <code>null</code>). */ public static Range iterateZBounds(XYZDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = dataset.getZValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Returns the range of x-values in the specified dataset for the * data items belonging to the visible series. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> not * permitted). * @param includeInterval a flag that determines whether or not the * y-interval for the dataset is included (this only applies if the * dataset is an instance of IntervalXYDataset). * * @return The x-range (possibly <code>null</code>). * * @since 1.0.13 */ public static Range iterateToFindDomainBounds(XYDataset dataset, List<Comparable> visibleSeriesKeys, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double lvalue = ixyd.getStartXValue(series, item); double uvalue = ixyd.getEndXValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } else { // standard case - plain XYDataset for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); if (!Double.isNaN(x)) { minimum = Math.min(minimum, x); maximum = Math.max(maximum, x); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Returns the range of y-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> not * permitted). * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval for the dataset is included (this only applies if the * dataset is an instance of IntervalXYDataset). * * @return The y-range (possibly <code>null</code>). * * @since 1.0.13 */ public static Range iterateToFindRangeBounds(XYDataset dataset, List<Comparable> visibleSeriesKeys, Range xRange, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); ParamChecks.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; // handle three cases by dataset type if (includeInterval && dataset instanceof OHLCDataset) { // handle special case of OHLCDataset OHLCDataset ohlc = (OHLCDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = ohlc.getXValue(series, item); if (xRange.contains(x)) { double lvalue = ohlc.getLowValue(series, item); double uvalue = ohlc.getHighValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } } else if (includeInterval && dataset instanceof BoxAndWhiskerXYDataset) { // handle special case of BoxAndWhiskerXYDataset BoxAndWhiskerXYDataset bx = (BoxAndWhiskerXYDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = bx.getXValue(series, item); if (xRange.contains(x)) { Number lvalue = bx.getMinRegularValue(series, item); Number uvalue = bx.getMaxRegularValue(series, item); if (lvalue != null) { minimum = Math.min(minimum, lvalue.doubleValue()); } if (uvalue != null) { maximum = Math.max(maximum, uvalue.doubleValue()); } } } } } else if (includeInterval && dataset instanceof IntervalXYDataset) { // handle special case of IntervalXYDataset IntervalXYDataset ixyd = (IntervalXYDataset) dataset; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = ixyd.getXValue(series, item); if (xRange.contains(x)) { double lvalue = ixyd.getStartYValue(series, item); double uvalue = ixyd.getEndYValue(series, item); if (!Double.isNaN(lvalue)) { minimum = Math.min(minimum, lvalue); } if (!Double.isNaN(uvalue)) { maximum = Math.max(maximum, uvalue); } } } } } else { // standard case - plain XYDataset for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(y)) { minimum = Math.min(minimum, y); maximum = Math.max(maximum, y); } } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Returns the range of z-values in the specified dataset for the * data items belonging to the visible series and with x-values in the * given range. * * @param dataset the dataset (<code>null</code> not permitted). * @param visibleSeriesKeys the visible series keys (<code>null</code> not * permitted). * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * z-interval for the dataset is included (this only applies if the * dataset has an interval, which is currently not supported). * * @return The y-range (possibly <code>null</code>). */ public static Range iterateToFindZBounds(XYZDataset dataset, List<Comparable> visibleSeriesKeys, Range xRange, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys"); ParamChecks.nullNotPermitted(xRange, "xRange"); double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; for (Comparable seriesKey : visibleSeriesKeys) { int series = dataset.indexOf(seriesKey); int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double z = dataset.getZValue(series, item); if (xRange.contains(x)) { if (!Double.isNaN(z)) { minimum = Math.min(minimum, z); maximum = Math.max(maximum, z); } } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } } /** * Finds the minimum domain (or X) value for the specified dataset. This * is easy if the dataset implements the {@link DomainInfo} interface (a * good idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. * <p> * Returns <code>null</code> if all the data values in the dataset are * <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value (possibly <code>null</code>). */ public static Number findMinimumDomainValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result; // if the dataset implements DomainInfo, life is easy if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; return info.getDomainLowerBound(true); } else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getStartXValue(series, item); } else { value = dataset.getXValue(series, item); } if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { result = null; } else { result = minimum; } } return result; } /** * Returns the maximum domain value for the specified dataset. This is * easy if the dataset implements the {@link DomainInfo} interface (a good * idea if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). */ public static Number findMaximumDomainValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result; // if the dataset implements DomainInfo, life is easy if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; return info.getDomainUpperBound(true); } // hasn't implemented DomainInfo, so iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getEndXValue(series, item); } else { value = dataset.getXValue(series, item); } if (!Double.isNaN(value)) { maximum = Math.max(maximum, value); } } } if (maximum == Double.NEGATIVE_INFINITY) { result = null; } else { result = maximum; } } return result; } /** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value (possibly <code>null</code>). */ public static Number findMinimumRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return new Double(info.getRangeLowerBound(true)); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getStartValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { minimum = Math.min(minimum, value.doubleValue()); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return minimum; } } } /** * Returns the minimum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the minimum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values in the dataset are * <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value (possibly <code>null</code>). */ public static Number findMinimumRangeValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return info.getRangeLowerBound(true); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double minimum = Double.POSITIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getStartYValue(series, item); } else if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; value = highLowData.getLowValue(series, item); } else { value = dataset.getYValue(series, item); } if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return minimum; } } } /** * Returns the maximum range value for the specified dataset. This is easy * if the dataset implements the {@link RangeInfo} interface (a good idea * if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values are <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). */ public static Number findMaximumRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return info.getRangeUpperBound(true); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getRowCount(); int itemCount = dataset.getColumnCount(); for (int series = 0; series < seriesCount; series++) { for (int item = 0; item < itemCount; item++) { Number value; if (dataset instanceof IntervalCategoryDataset) { IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset; value = icd.getEndValue(series, item); } else { value = dataset.getValue(series, item); } if (value != null) { maximum = Math.max(maximum, value.doubleValue()); } } } if (maximum == Double.NEGATIVE_INFINITY) { return null; } else { return maximum; } } } /** * Returns the maximum range value for the specified dataset. This is * easy if the dataset implements the {@link RangeInfo} interface (a good * idea if there is an efficient way to determine the maximum value). * Otherwise, it involves iterating over the entire data-set. Returns * <code>null</code> if all the data values are <code>null</code>. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). */ public static Number findMaximumRangeValue(XYDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); // work out the minimum value... if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; return info.getRangeUpperBound(true); } // hasn't implemented RangeInfo, so we'll have to iterate... else { double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value; if (dataset instanceof IntervalXYDataset) { IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset; value = intervalXYData.getEndYValue(series, item); } else if (dataset instanceof OHLCDataset) { OHLCDataset highLowData = (OHLCDataset) dataset; value = highLowData.getHighValue(series, item); } else { value = dataset.getYValue(series, item); } if (!Double.isNaN(value)) { maximum = Math.max(maximum, value); } } } if (maximum == Double.NEGATIVE_INFINITY) { return null; } else { return maximum; } } } /** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range (<code>null</code> if the dataset contains no values). */ public static Range findStackedRangeBounds(CategoryDataset dataset) { return findStackedRangeBounds(dataset, 0.0); } /** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset (<code>null</code> not permitted). * @param base the base value for the bars. * * @return The range (<code>null</code> if the dataset contains no values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, double base) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result = null; double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double positive = base; double negative = base; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { double value = number.doubleValue(); if (value > 0.0) { positive = positive + value; } if (value < 0.0) { negative = negative + value; // '+', remember value is negative } } } minimum = Math.min(minimum, negative); maximum = Math.max(maximum, positive); } if (minimum <= maximum) { result = new Range(minimum, maximum); } return result; } /** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset (<code>null</code> not permitted). * @param map a structure that maps series to groups. * * @return The value range (<code>null</code> if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { ParamChecks.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // create an array holding the group indices for each series... int[] groupIndex = new int[dataset.getRowCount()]; for (int i = 0; i < dataset.getRowCount(); i++) { groupIndex[i] = map.getGroupIndex(map.getGroup( dataset.getRowKey(i))); } // minimum and maximum for each group... int groupCount = map.getGroupCount(); double[] minimum = new double[groupCount]; double[] maximum = new double[groupCount]; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double[] positive = new double[groupCount]; double[] negative = new double[groupCount]; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { positive[groupIndex[series]] = positive[groupIndex[series]] + value; } if (value < 0.0) { negative[groupIndex[series]] = negative[groupIndex[series]] + value; // '+', remember value is negative } } } for (int g = 0; g < groupCount; g++) { minimum[g] = Math.min(minimum[g], negative[g]); maximum[g] = Math.max(maximum[g], positive[g]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; } /** * Returns the minimum value in the dataset range, assuming that values in * each category are "stacked". * * @param dataset the dataset (<code>null</code> not permitted). * * @return The minimum value. * * @see #findMaximumStackedRangeValue(CategoryDataset) */ public static Number findMinimumStackedRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result = null; boolean hasValidData = false; double minimum = 0.0; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double total = 0.0; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value < 0.0) { total = total + value; // '+', remember value is negative } } } minimum = Math.min(minimum, total); } if (hasValidData) { result = minimum; } return result; } /** * Returns the maximum value in the dataset range, assuming that values in * each category are "stacked". * * @param dataset the dataset (<code>null</code> not permitted). * * @return The maximum value (possibly <code>null</code>). * * @see #findMinimumStackedRangeValue(CategoryDataset) */ public static Number findMaximumStackedRangeValue(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); Number result = null; boolean hasValidData = false; double maximum = 0.0; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double total = 0.0; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { total = total + value; } } } maximum = Math.max(maximum, total); } if (hasValidData) { result = maximum; } return result; } /** * Returns the minimum and maximum values for the dataset's range, * assuming that the series are stacked. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range ([0.0, 0.0] if the dataset contains no values). */ public static Range findStackedRangeBounds(TableXYDataset dataset) { return findStackedRangeBounds(dataset, 0.0); } /** * Returns the minimum and maximum values for the dataset's range, * assuming that the series are stacked, using the specified base value. * * @param dataset the dataset (<code>null</code> not permitted). * @param base the base value. * * @return The range (<code>null</code> if the dataset contains no values). */ public static Range findStackedRangeBounds(TableXYDataset dataset, double base) { ParamChecks.nullNotPermitted(dataset, "dataset"); double minimum = base; double maximum = base; for (int itemNo = 0; itemNo < dataset.getItemCount(); itemNo++) { double positive = base; double negative = base; int seriesCount = dataset.getSeriesCount(); for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) { double y = dataset.getYValue(seriesNo, itemNo); if (!Double.isNaN(y)) { if (y > 0.0) { positive += y; } else { negative += y; } } } if (positive > maximum) { maximum = positive; } if (negative < minimum) { minimum = negative; } } if (minimum <= maximum) { return new Range(minimum, maximum); } else { return null; } } /** * Calculates the total for the y-values in all series for a given item * index. * * @param dataset the dataset (<code>null</code> not permitted). * @param item the item index. * * @return The total. * * @since 1.0.5 */ public static double calculateStackTotal(TableXYDataset dataset, int item) { double total = 0.0; int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { double value = dataset.getYValue(s, item); if (!Double.isNaN(value)) { total = total + value; } } return total; } /** * Calculates the range of values for a dataset where each item is the * running total of the items for the current series. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The range. * * @see #findRangeBounds(CategoryDataset) */ public static Range findCumulativeRangeBounds(CategoryDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); boolean allItemsNull = true; // we'll set this to false if there is at // least one non-null data item... double minimum = 0.0; double maximum = 0.0; for (int row = 0; row < dataset.getRowCount(); row++) { double runningTotal = 0.0; for (int column = 0; column <= dataset.getColumnCount() - 1; column++) { Number n = dataset.getValue(row, column); if (n != null) { allItemsNull = false; double value = n.doubleValue(); if (!Double.isNaN(value)) { runningTotal = runningTotal + value; minimum = Math.min(minimum, runningTotal); maximum = Math.max(maximum, runningTotal); } } } } if (!allItemsNull) { return new Range(minimum, maximum); } else { return null; } } /** * Returns the interpolated value of y that corresponds to the specified * x-value in the given series. If the x-value falls outside the range of * x-values for the dataset, this method returns <code>Double.NaN</code>. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index. * @param x the x-value. * * @return The y value. * * @since 1.0.16 */ public static double findYValue(XYDataset dataset, int series, double x) { // delegate null check on dataset int[] indices = findItemIndicesForX(dataset, series, x); if (indices[0] == -1) { return Double.NaN; } if (indices[0] == indices[1]) { return dataset.getYValue(series, indices[0]); } double x0 = dataset.getXValue(series, indices[0]); double x1 = dataset.getXValue(series, indices[1]); double y0 = dataset.getYValue(series, indices[0]); double y1 = dataset.getYValue(series, indices[1]); return y0 + (y1 - y0) * (x - x0) / (x1 - x0); } /** * Finds the indices of the the items in the dataset that span the * specified x-value. There are three cases for the return value: * <ul> * <li>there is an exact match for the x-value at index i * (returns <code>int[] {i, i}</code>);</li> * <li>the x-value falls between two (adjacent) items at index i and i+1 * (returns <code>int[] {i, i+1}</code>);</li> * <li>the x-value falls outside the domain bounds, in which case the * method returns <code>int[] {-1, -1}</code>.</li> * </ul> * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index. * @param x the x-value. * * @return The indices of the two items that span the x-value. * * @since 1.0.16 * * @see #findYValue(org.jfree.data.xy.XYDataset, int, double) */ public static int[] findItemIndicesForX(XYDataset dataset, int series, double x) { ParamChecks.nullNotPermitted(dataset, "dataset"); int itemCount = dataset.getItemCount(series); if (itemCount == 0) { return new int[] {-1, -1}; } if (itemCount == 1) { if (x == dataset.getXValue(series, 0)) { return new int[] {0, 0}; } else { return new int[] {-1, -1}; } } if (dataset.getDomainOrder() == DomainOrder.ASCENDING) { int low = 0; int high = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > x) { return new int[] {-1, -1}; } if (lowValue == x) { return new int[] {low, low}; } double highValue = dataset.getXValue(series, high); if (highValue < x) { return new int[] {-1, -1}; } if (highValue == x) { return new int[] {high, high}; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (x == midV) { return new int[] {mid, mid}; } if (midV < x) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return new int[] {low, high}; } else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) { int high = 0; int low = itemCount - 1; double lowValue = dataset.getXValue(series, low); if (lowValue > x) { return new int[] {-1, -1}; } double highValue = dataset.getXValue(series, high); if (highValue < x) { return new int[] {-1, -1}; } int mid = (low + high) / 2; while (high - low > 1) { double midV = dataset.getXValue(series, mid); if (x == midV) { return new int[] {mid, mid}; } if (midV < x) { low = mid; } else { high = mid; } mid = (low + high) / 2; } return new int[] {low, high}; } else { // we don't know anything about the ordering of the x-values, // so we iterate until we find the first crossing of x (if any) // we know there are at least 2 items in the series at this point double prev = dataset.getXValue(series, 0); if (x == prev) { return new int[] {0, 0}; // exact match on first item } for (int i = 1; i < itemCount; i++) { double next = dataset.getXValue(series, i); if (x == next) { return new int[] {i, i}; // exact match } if ((x > prev && x < next) || (x < prev && x > next)) { return new int[] {i - 1, i}; // spanning match } } return new int[] {-1, -1}; // no crossing of x } } }
92,292
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SeriesChangeListener.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/SeriesChangeListener.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * SeriesChangeListener.java * ------------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 26-Jun-2003 : Now extends EventListener so we can use the EventListenerList * mechanism (DG); * */ package org.jfree.data.general; import java.util.EventListener; /** * Methods for receiving notification of changes to a data series. */ public interface SeriesChangeListener extends EventListener { /** * Called when an observed series changes in some way. * * @param event information about the change. */ public void seriesChanged(SeriesChangeEvent event); }
2,034
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetChangeListener.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DatasetChangeListener.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * DatasetChangeListener.java * -------------------------- * (C) Copyright 2000-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes (from 24-Aug-2001) * -------------------------- * 24-Aug-2001 : Added standard source header. Fixed DOS encoding problem (DG); * 15-Oct-2001 : Moved to new package (com.jrefinery.data.*) (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 07-Aug-2002 : Now extends EventListener (DG); * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */ package org.jfree.data.general; import java.util.EventListener; /** * The interface that must be supported by classes that wish to receive * notification of changes to a dataset. */ public interface DatasetChangeListener extends EventListener { /** * Receives notification of an dataset change event. * * @param event information about the event. */ public void datasetChanged(DatasetChangeEvent event); }
2,300
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultPieDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/DefaultPieDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * DefaultPieDataset.java * ---------------------- * (C) Copyright 2001-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Sam (oldman); * * Changes * ------- * 17-Nov-2001 : Version 1 (DG); * 22-Jan-2002 : Removed legend methods from dataset implementations (DG); * 07-Apr-2002 : Modified implementation to guarantee data sequence to remain * in the order categories are added (oldman); * 23-Oct-2002 : Added getCategory(int) method and getItemCount() method, in * line with changes to the PieDataset interface (DG); * 04-Feb-2003 : Changed underlying data storage to DefaultKeyedValues (DG); * 04-Mar-2003 : Inserted DefaultKeyedValuesDataset class into hierarchy (DG); * 24-Apr-2003 : Switched places with DefaultKeyedValuesDataset (DG); * 18-Aug-2003 : Implemented Cloneable (DG); * 03-Mar-2005 : Implemented PublicCloneable (DG); * 29-Jun-2005 : Added remove() method (DG); * ------------- JFREECHART 1.0.0 --------------------------------------------- * 31-Jul-2006 : Added a clear() method to clear all values from the * dataset (DG); * 28-Sep-2006 : Added sortByKeys() and sortByValues() methods (DG); * 30-Apr-2007 : Added new insertValues() methods (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.general; import java.io.Serializable; import java.util.Collections; import java.util.List; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.SortOrder; import org.jfree.data.DefaultKeyedValues; import org.jfree.data.KeyedValues; import org.jfree.data.UnknownKeyException; /** * A default implementation of the {@link PieDataset} interface. */ public class DefaultPieDataset extends AbstractDataset implements PieDataset, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 2904745139106540618L; /** Storage for the data. */ private DefaultKeyedValues data; /** * Constructs a new dataset, initially empty. */ public DefaultPieDataset() { this.data = new DefaultKeyedValues(); } /** * Creates a new dataset by copying data from a {@link KeyedValues} * instance. * * @param data the data (<code>null</code> not permitted). */ public DefaultPieDataset(KeyedValues data) { if (data == null) { throw new IllegalArgumentException("Null 'data' argument."); } this.data = new DefaultKeyedValues(); for (int i = 0; i < data.getItemCount(); i++) { this.data.addValue(data.getKey(i), data.getValue(i)); } } /** * Returns the number of items in the dataset. * * @return The item count. */ @Override public int getItemCount() { return this.data.getItemCount(); } /** * Returns the categories in the dataset. The returned list is * unmodifiable. * * @return The categories in the dataset. */ @Override public List<Comparable> getKeys() { return Collections.unmodifiableList(this.data.getKeys()); } /** * Returns the key for the specified item, or <code>null</code>. * * @param item the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The key, or <code>null</code>. * * @throws IndexOutOfBoundsException if <code>item</code> is not in the * specified range. */ @Override public Comparable getKey(int item) { return this.data.getKey(item); } /** * Returns the index for a key, or -1 if the key is not recognised. * * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ @Override public int getIndex(Comparable key) { return this.data.getIndex(key); } /** * Returns a value. * * @param item the value index. * * @return The value (possibly <code>null</code>). */ @Override public Number getValue(int item) { Number result = null; if (getItemCount() > item) { result = this.data.getValue(item); } return result; } /** * Returns the data value associated with a key. * * @param key the key (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). * * @throws UnknownKeyException if the key is not recognised. */ @Override public Number getValue(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } return this.data.getValue(key); } /** * Sets the data value for a key and sends a {@link DatasetChangeEvent} to * all registered listeners. * * @param key the key (<code>null</code> not permitted). * @param value the value. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public void setValue(Comparable key, Number value) { this.data.setValue(key, value); fireDatasetChanged(); } /** * Sets the data value for a key and sends a {@link DatasetChangeEvent} to * all registered listeners. * * @param key the key (<code>null</code> not permitted). * @param value the value. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public void setValue(Comparable key, double value) { setValue(key, new Double(value)); } /** * 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. After the change * is made, this methods sends a {@link DatasetChangeEvent} to all * registered listeners. * * @param position the position (in the range 0 to getItemCount()). * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * * @since 1.0.6 */ public void insertValue(int position, Comparable key, double value) { insertValue(position, key, new Double(value)); } /** * 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. After the change * is made, this methods sends a {@link DatasetChangeEvent} to all * registered listeners. * * @param position the position (in the range 0 to getItemCount()). * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * * @since 1.0.6 */ public void insertValue(int position, Comparable key, Number value) { this.data.insertValue(position, key, value); fireDatasetChanged(); } /** * Removes an item from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param key the key (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. */ public void remove(Comparable key) { this.data.removeValue(key); fireDatasetChanged(); } /** * Clears all data from this dataset and sends a {@link DatasetChangeEvent} * to all registered listeners (unless the dataset was already empty). * * @since 1.0.2 */ public void clear() { if (getItemCount() > 0) { this.data.clear(); fireDatasetChanged(); } } /** * Sorts the dataset's items by key and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param order the sort order (<code>null</code> not permitted). * * @since 1.0.3 */ public void sortByKeys(SortOrder order) { this.data.sortByKeys(order); fireDatasetChanged(); } /** * Sorts the dataset's items by value and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param order the sort order (<code>null</code> not permitted). * * @since 1.0.3 */ public void sortByValues(SortOrder order) { this.data.sortByValues(order); fireDatasetChanged(); } /** * Tests if this object is equal to another. * * @param obj the other object. * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PieDataset)) { return false; } PieDataset that = (PieDataset) obj; int count = getItemCount(); if (that.getItemCount() != count) { return false; } for (int i = 0; i < count; i++) { Comparable k1 = getKey(i); Comparable k2 = that.getKey(i); if (!k1.equals(k2)) { return false; } Number v1 = getValue(i); Number v2 = that.getValue(i); if (v1 == null) { if (v2 != null) { return false; } } else { if (!v1.equals(v2)) { return false; } } } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { return this.data.hashCode(); } /** * Returns a clone of the dataset. * * @return A clone. * * @throws CloneNotSupportedException This class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { DefaultPieDataset clone = (DefaultPieDataset) super.clone(); clone.data = (DefaultKeyedValues) this.data.clone(); return clone; } }
11,738
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractSeriesDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/general/AbstractSeriesDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * AbstractSeriesDataset.java * -------------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 17-Nov-2001 : Version 1 (DG); * 28-Mar-2002 : Implemented SeriesChangeListener interface (DG); * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 04-Feb-2003 : Removed redundant methods (DG); * 27-Mar-2003 : Implemented Serializable (DG); * */ package org.jfree.data.general; import java.io.Serializable; /** * An abstract implementation of the {@link SeriesDataset} interface, * containing a mechanism for registering change listeners. */ public abstract class AbstractSeriesDataset extends AbstractDataset implements SeriesDataset, SeriesChangeListener, Serializable { /** For serialization. */ private static final long serialVersionUID = -6074996219705033171L; /** * Creates a new dataset. */ protected AbstractSeriesDataset() { super(); } /** * Returns the number of series in the dataset. * * @return The series count. */ @Override public abstract int getSeriesCount(); /** * Returns the key for a series. * <p> * If <code>series</code> is not within the specified range, the * implementing method should throw an {@link IndexOutOfBoundsException} * (preferred) or an {@link IllegalArgumentException}. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * * @return The series key. */ @Override public abstract Comparable getSeriesKey(int series); /** * Returns the index of the named series, or -1. * * @param seriesKey the series key (<code>null</code> permitted). * * @return The index. */ @Override public int indexOf(Comparable seriesKey) { int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { if (getSeriesKey(s).equals(seriesKey)) { return s; } } return -1; } /** * Called when a series belonging to the dataset changes. * * @param event information about the change. */ @Override public void seriesChanged(SeriesChangeEvent event) { fireDatasetChanged(); } }
3,678
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYCoordinate.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYCoordinate.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * XYCoordinate.java * ----------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jan-2007 : Version 1 (DG); * 25-May-2007 : Moved from experimental to the main source tree (DG); * */ package org.jfree.data.xy; import java.io.Serializable; /** * Represents an (x, y) coordinate. * * @since 1.0.6 */ public class XYCoordinate implements Comparable, Serializable { /** The x-coordinate. */ private double x; /** The y-coordinate. */ private double y; /** * Creates a new coordinate for the point (0.0, 0.0). */ public XYCoordinate() { this(0.0, 0.0); } /** * Creates a new coordinate for the point (x, y). * * @param x the x-coordinate. * @param y the y-coordinate. */ public XYCoordinate(double x, double y) { this.x = x; this.y = y; } /** * Returns the x-coordinate. * * @return The x-coordinate. */ public double getX() { return this.x; } /** * Returns the y-coordinate. * * @return The y-coordinate. */ public double getY() { return this.y; } /** * Tests this coordinate for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYCoordinate)) { return false; } XYCoordinate that = (XYCoordinate) obj; if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; long temp = Double.doubleToLongBits(this.x); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y); result = 37 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a string representation of this instance, primarily for * debugging purposes. * * @return A string. */ @Override public String toString() { return "(" + this.x + ", " + this.y + ")"; } /** * Compares this instance against an arbitrary object. * * @param obj the object (<code>null</code> not permitted). * * @return An integer indicating the relative order of the items. */ @Override public int compareTo(Object obj) { if (!(obj instanceof XYCoordinate)) { throw new IllegalArgumentException("Incomparable object."); } XYCoordinate that = (XYCoordinate) obj; if (this.x > that.x) { return 1; } else if (this.x < that.x) { return -1; } else { if (this.y > that.y) { return 1; } else if (this.y < that.y) { return -1; } } return 0; } }
4,601
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryTableXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/CategoryTableXYDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * CategoryTableXYDataset.java * --------------------------- * (C) Copyright 2004-2012, by Andreas Schroeder and Contributors. * * Original Author: Andreas Schroeder; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 31-Mar-2004 : Version 1 (AS); * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG); * 15-Jul-2004 : Switched interval access method names (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * 17-Nov-2004 : Updates required by changes to DomainInfo interface (DG); * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); * 05-Oct-2005 : Made the interval delegate a dataset change listener (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 22-Apr-2008 : Implemented PublicCloneable, and fixed clone() method (DG); * 18-Oct-2011 : Fixed bug 3190615 - added clear() method (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DefaultKeyedValues2D; import org.jfree.data.DomainInfo; import org.jfree.data.Range; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; /** * An implementation variant of the {@link TableXYDataset} where every series * shares the same x-values (required for generating stacked area charts). * This implementation uses a {@link DefaultKeyedValues2D} Object as backend * implementation and is hence more "category oriented" than the {@link * DefaultTableXYDataset} implementation. * <p> * This implementation provides no means to remove data items yet. * This is due to the lack of such facility in the DefaultKeyedValues2D class. * <p> * This class also implements the {@link IntervalXYDataset} interface, but this * implementation is provisional. */ public class CategoryTableXYDataset extends AbstractIntervalXYDataset implements TableXYDataset, IntervalXYDataset, DomainInfo, PublicCloneable { /** * The backing data structure. */ private DefaultKeyedValues2D values; /** A delegate for controlling the interval width. */ private IntervalXYDelegate intervalDelegate; /** * Creates a new empty CategoryTableXYDataset. */ public CategoryTableXYDataset() { this.values = new DefaultKeyedValues2D(true); this.intervalDelegate = new IntervalXYDelegate(this); addChangeListener(this.intervalDelegate); } /** * Adds a data item to this dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param x the x value. * @param y the y value. * @param seriesName the name of the series to add the data item. */ public void add(double x, double y, String seriesName) { add(x, y, seriesName, true); } /** * Adds a data item to this dataset and, if requested, sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param x the x value. * @param y the y value. * @param seriesName the name of the series to add the data item. * @param notify notify listeners? */ public void add(Number x, Number y, String seriesName, boolean notify) { this.values.addValue(y, (Comparable) x, seriesName); if (notify) { fireDatasetChanged(); } } /** * Removes a value from the dataset. * * @param x the x-value. * @param seriesName the series name. */ public void remove(double x, String seriesName) { remove(x, seriesName, true); } /** * Removes an item from the dataset. * * @param x the x-value. * @param seriesName the series name. * @param notify notify listeners? */ public void remove(Number x, String seriesName, boolean notify) { this.values.removeValue((Comparable) x, seriesName); if (notify) { fireDatasetChanged(); } } /** * Clears all data from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @since 1.0.14 */ public void clear() { this.values.clear(); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.values.getColumnCount(); } /** * Returns the key for a series. * * @param series the series index (zero-based). * * @return The key for a series. */ @Override public Comparable getSeriesKey(int series) { return this.values.getColumnKey(series); } /** * Returns the number of x values in the dataset. * * @return The item count. */ @Override public int getItemCount() { return this.values.getRowCount(); } /** * Returns the number of items in the specified series. * Returns the same as {@link CategoryTableXYDataset#getItemCount()}. * * @param series the series index (zero-based). * * @return The item count. */ @Override public int getItemCount(int series) { return getItemCount(); // all series have the same number of items in // this dataset } /** * Returns the x-value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public Number getX(int series, int item) { return (Number) this.values.getRowKey(item); } /** * Returns the starting X value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The starting X value. */ @Override public Number getStartX(int series, int item) { return this.intervalDelegate.getStartX(series, item); } /** * Returns the ending X value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The ending X value. */ @Override public Number getEndX(int series, int item) { return this.intervalDelegate.getEndX(series, item); } /** * Returns the y-value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The y value (possibly <code>null</code>). */ @Override public Number getY(int series, int item) { return this.values.getValue(item, series); } /** * Returns the starting Y value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The starting Y value. */ @Override public Number getStartY(int series, int item) { return getY(series, item); } /** * Returns the ending Y value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The ending Y value. */ @Override public Number getEndY(int series, int item) { return getY(series, item); } /** * Returns the minimum x-value in the dataset. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The minimum value. */ @Override public double getDomainLowerBound(boolean includeInterval) { return this.intervalDelegate.getDomainLowerBound(includeInterval); } /** * Returns the maximum x-value in the dataset. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The maximum value. */ @Override public double getDomainUpperBound(boolean includeInterval) { return this.intervalDelegate.getDomainUpperBound(includeInterval); } /** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The range. */ @Override public Range getDomainBounds(boolean includeInterval) { if (includeInterval) { return this.intervalDelegate.getDomainBounds(includeInterval); } else { return DatasetUtilities.iterateDomainBounds(this, includeInterval); } } /** * Returns the interval position factor. * * @return The interval position factor. */ public double getIntervalPositionFactor() { return this.intervalDelegate.getIntervalPositionFactor(); } /** * Sets the interval position factor. Must be between 0.0 and 1.0 inclusive. * If the factor is 0.5, the gap is in the middle of the x values. If it * is lesser than 0.5, the gap is farther to the left and if greater than * 0.5 it gets farther to the right. * * @param d the new interval position factor. */ public void setIntervalPositionFactor(double d) { this.intervalDelegate.setIntervalPositionFactor(d); fireDatasetChanged(); } /** * Returns the full interval width. * * @return The interval width to use. */ public double getIntervalWidth() { return this.intervalDelegate.getIntervalWidth(); } /** * Sets the interval width to a fixed value, and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param d the new interval width (must be > 0). */ public void setIntervalWidth(double d) { this.intervalDelegate.setFixedIntervalWidth(d); fireDatasetChanged(); } /** * Returns whether the interval width is automatically calculated or not. * * @return whether the width is automatically calculated or not. */ public boolean isAutoWidth() { return this.intervalDelegate.isAutoWidth(); } /** * Sets the flag that indicates whether the interval width is automatically * calculated or not. * * @param b the flag. */ public void setAutoWidth(boolean b) { this.intervalDelegate.setAutoWidth(b); fireDatasetChanged(); } /** * Tests this dataset for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (!(obj instanceof CategoryTableXYDataset)) { return false; } CategoryTableXYDataset that = (CategoryTableXYDataset) obj; if (!this.intervalDelegate.equals(that.intervalDelegate)) { return false; } if (!this.values.equals(that.values)) { return false; } return true; } /** * Returns an independent copy of this dataset. * * @return A clone. * * @throws CloneNotSupportedException if there is some reason that cloning * cannot be performed. */ @Override public Object clone() throws CloneNotSupportedException { CategoryTableXYDataset clone = (CategoryTableXYDataset) super.clone(); clone.values = (DefaultKeyedValues2D) this.values.clone(); clone.intervalDelegate = new IntervalXYDelegate(clone); // need to configure the intervalDelegate to match the original clone.intervalDelegate.setFixedIntervalWidth(getIntervalWidth()); clone.intervalDelegate.setAutoWidth(isAutoWidth()); clone.intervalDelegate.setIntervalPositionFactor( getIntervalPositionFactor()); return clone; } }
13,528
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YisSymbolic.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/YisSymbolic.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * YisSymbolic.java * ---------------- * (C) Copyright 2006-2008, by Anthony Boulestreau and Contributors. * * Original Author: Anthony Boulestreau; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes (from 21-Aug-2001) * -------------------------- * 29-Mar-2002 : First version (AB); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.xy; /** * Represent a data set where Y is a symbolic values. Each symbolic value is * linked with an Integer. */ public interface YisSymbolic { /** * Returns the list of symbolic values. * * @return The symbolic values. */ public String[] getYSymbolicValues(); /** * Returns the symbolic value of the data set specified by * <CODE>series</CODE> and <CODE>item</CODE> parameters. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The symbolic value. */ public String getYSymbolicValue(int series, int item); /** * Returns the symbolic value linked with the specified * <CODE>Integer</CODE>. * * @param val value of the integer linked with the symbolic value. * * @return The symbolic value. */ public String getYSymbolicValue(Integer val); }
2,721
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultXYDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * DefaultXYDataset.java * --------------------- * (C) Copyright 2006-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 06-Jul-2006 : Version 1 (DG); * 02-Nov-2006 : Fixed a problem with adding a new series with the same key * as an existing series (see bug 1589392) (DG); * 25-Jan-2007 : Implemented PublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DomainOrder; import org.jfree.data.general.DatasetChangeEvent; /** * A default implementation of the {@link XYDataset} interface that stores * data values in arrays of double primitives. * * @since 1.0.2 */ public class DefaultXYDataset extends AbstractXYDataset implements XYDataset, PublicCloneable { /** * Storage for the series keys. This list must be kept in sync with the * seriesList. */ private List<Comparable> seriesKeys; /** * Storage for the series in the dataset. We use a list because the * order of the series is significant. This list must be kept in sync * with the seriesKeys list. */ private List<double[][]> seriesList; /** * Creates a new <code>DefaultXYDataset</code> instance, initially * containing no data. */ public DefaultXYDataset() { this.seriesKeys = new java.util.ArrayList<Comparable>(); this.seriesList = new java.util.ArrayList<double[][]>(); } /** * Returns the number of series in the dataset. * * @return The series count. */ @Override public int getSeriesCount() { return this.seriesList.size(); } /** * Returns the key for a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * * @return The key for the series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.seriesKeys.get(series); } /** * Returns the index of the series with the specified key, or -1 if there * is no such series in the dataset. * * @param seriesKey the series key (<code>null</code> permitted). * * @return The index, or -1. */ @Override public int indexOf(Comparable seriesKey) { return this.seriesKeys.indexOf(seriesKey); } /** * Returns the order of the domain (x-) values in the dataset. In this * implementation, we cannot guarantee that the x-values are ordered, so * this method returns <code>DomainOrder.NONE</code>. * * @return <code>DomainOrder.NONE</code>. */ @Override public DomainOrder getDomainOrder() { return DomainOrder.NONE; } /** * Returns the number of items in the specified series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public int getItemCount(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } double[][] seriesArray = this.seriesList.get(series); return seriesArray[0].length; } /** * Returns the x-value for an item within a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item index (in the range <code>0</code> to * <code>getItemCount(series)</code>). * * @return The x-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> or <code>item</code> is not * within the specified range. * * @see #getX(int, int) */ @Override public double getXValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[0][item]; } /** * Returns the x-value for an item within a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item index (in the range <code>0</code> to * <code>getItemCount(series)</code>). * * @return The x-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> or <code>item</code> is not * within the specified range * * @see #getXValue(int, int) */ @Override public Number getX(int series, int item) { return getXValue(series, item); } /** * Returns the y-value for an item within a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item index (in the range <code>0</code> to * <code>getItemCount(series)</code>). * * @return The y-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> or <code>item</code> is not * within the specified range. * * @see #getY(int, int) */ @Override public double getYValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[1][item]; } /** * Returns the y-value for an item within a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item index (in the range <code>0</code> to * <code>getItemCount(series)</code>). * * @return The y-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> or <code>item</code> is not * within the specified range. * * @see #getX(int, int) */ @Override public Number getY(int series, int item) { return getYValue(series, item); } /** * Adds a series or if a series with the same key already exists replaces * the data for that series, then sends a {@link DatasetChangeEvent} to * all registered listeners. * * @param seriesKey the series key (<code>null</code> not permitted). * @param data the data (must be an array with length 2, containing two * arrays of equal length, the first containing the x-values and the * second containing the y-values). */ public void addSeries(Comparable seriesKey, double[][] data) { if (seriesKey == null) { throw new IllegalArgumentException( "The 'seriesKey' cannot be null."); } if (data == null) { throw new IllegalArgumentException("The 'data' is null."); } if (data.length != 2) { throw new IllegalArgumentException( "The 'data' array must have length == 2."); } if (data[0].length != data[1].length) { throw new IllegalArgumentException( "The 'data' array must contain two arrays with equal length."); } int seriesIndex = indexOf(seriesKey); if (seriesIndex == -1) { // add a new series this.seriesKeys.add(seriesKey); this.seriesList.add(data); } else { // replace an existing series this.seriesList.remove(seriesIndex); this.seriesList.add(seriesIndex, data); } notifyListeners(new DatasetChangeEvent(this, this)); } /** * Removes a series from the dataset, then sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param seriesKey the series key (<code>null</code> not permitted). * */ public void removeSeries(Comparable seriesKey) { int seriesIndex = indexOf(seriesKey); if (seriesIndex >= 0) { this.seriesKeys.remove(seriesIndex); this.seriesList.remove(seriesIndex); notifyListeners(new DatasetChangeEvent(this, this)); } } /** * Tests this <code>DefaultXYDataset</code> instance for equality with an * arbitrary object. This method returns <code>true</code> if and only if: * <ul> * <li><code>obj</code> is not <code>null</code>;</li> * <li><code>obj</code> is an instance of * <code>DefaultXYDataset</code>;</li> * <li>both datasets have the same number of series, each containing * exactly the same values.</li> * </ul> * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DefaultXYDataset)) { return false; } DefaultXYDataset that = (DefaultXYDataset) obj; if (!this.seriesKeys.equals(that.seriesKeys)) { return false; } for (int i = 0; i < this.seriesList.size(); i++) { double[][] d1 = this.seriesList.get(i); double[][] d2 = that.seriesList.get(i); double[] d1x = d1[0]; double[] d2x = d2[0]; if (!Arrays.equals(d1x, d2x)) { return false; } double[] d1y = d1[1]; double[] d2y = d2[1]; if (!Arrays.equals(d1y, d2y)) { return false; } } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result; result = this.seriesKeys.hashCode(); result = 29 * result + this.seriesList.hashCode(); return result; } /** * Creates an independent copy of this dataset. * * @return The cloned dataset. * * @throws CloneNotSupportedException if there is a problem cloning the * dataset (for instance, if a non-cloneable object is used for a * series key). */ @Override public Object clone() throws CloneNotSupportedException { DefaultXYDataset clone = (DefaultXYDataset) super.clone(); clone.seriesKeys = new java.util.ArrayList<Comparable>(this.seriesKeys); clone.seriesList = new ArrayList<double[][]>(this.seriesList.size()); for (int i = 0; i < this.seriesList.size(); i++) { double[][] data = this.seriesList.get(i); double[] x = data[0]; double[] y = data[1]; double[] xx = new double[x.length]; double[] yy = new double[y.length]; System.arraycopy(x, 0, xx, 0, x.length); System.arraycopy(y, 0, yy, 0, y.length); clone.seriesList.add(i, new double[][] {xx, yy}); } return clone; } }
12,711
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYBarDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYBarDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * XYBarDataset.java * ----------------- * (C) Copyright 2004-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 02-Mar-2004 : Version 1 (DG); * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 25-Jan-2007 : Added some accessor methods, plus new equals() and clone() * overrides (DG); * 30-Jan-2007 : Added method overrides to prevent unnecessary object * creation (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; /** * A dataset wrapper class that converts a standard {@link XYDataset} into an * {@link IntervalXYDataset} suitable for use in creating XY bar charts. */ public class XYBarDataset extends AbstractIntervalXYDataset implements IntervalXYDataset, DatasetChangeListener, PublicCloneable { /** The underlying dataset. */ private XYDataset underlying; /** The bar width. */ private double barWidth; /** * Creates a new dataset. * * @param underlying the underlying dataset (<code>null</code> not * permitted). * @param barWidth the width of the bars. */ public XYBarDataset(XYDataset underlying, double barWidth) { this.underlying = underlying; this.underlying.addChangeListener(this); this.barWidth = barWidth; } /** * Returns the underlying dataset that was specified via the constructor. * * @return The underlying dataset (never <code>null</code>). * * @since 1.0.4 */ public XYDataset getUnderlyingDataset() { return this.underlying; } /** * Returns the bar width. * * @return The bar width. * * @see #setBarWidth(double) * @since 1.0.4 */ public double getBarWidth() { return this.barWidth; } /** * Sets the bar width and sends a {@link DatasetChangeEvent} to all * registered listeners. * * @param barWidth the bar width. * * @see #getBarWidth() * @since 1.0.4 */ public void setBarWidth(double barWidth) { this.barWidth = barWidth; notifyListeners(new DatasetChangeEvent(this, this)); } /** * Returns the number of series in the dataset. * * @return The series count. */ @Override public int getSeriesCount() { return this.underlying.getSeriesCount(); } /** * Returns the key for a series. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * * @return The series key. */ @Override public Comparable getSeriesKey(int series) { return this.underlying.getSeriesKey(series); } /** * Returns the number of items in a series. * * @param series the series index (zero-based). * * @return The item count. */ @Override public int getItemCount(int series) { return this.underlying.getItemCount(series); } /** * Returns the x-value for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The x-value. * * @see #getXValue(int, int) */ @Override public Number getX(int series, int item) { return this.underlying.getX(series, item); } /** * Returns the x-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. * * @see #getX(int, int) */ @Override public double getXValue(int series, int item) { return this.underlying.getXValue(series, item); } /** * Returns the y-value for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The y-value (possibly <code>null</code>). * * @see #getYValue(int, int) */ @Override public Number getY(int series, int item) { return this.underlying.getY(series, item); } /** * Returns the y-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. * * @see #getY(int, int) */ @Override public double getYValue(int series, int item) { return this.underlying.getYValue(series, item); } /** * Returns the starting X value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public Number getStartX(int series, int item) { Number result = null; Number xnum = this.underlying.getX(series, item); if (xnum != null) { result = xnum.doubleValue() - this.barWidth / 2.0; } return result; } /** * Returns the starting x-value (as a double primitive) for an item within * a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. * * @see #getXValue(int, int) */ @Override public double getStartXValue(int series, int item) { return getXValue(series, item) - this.barWidth / 2.0; } /** * Returns the ending X value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public Number getEndX(int series, int item) { Number result = null; Number xnum = this.underlying.getX(series, item); if (xnum != null) { result = xnum.doubleValue() + this.barWidth / 2.0; } return result; } /** * Returns the ending x-value (as a double primitive) for an item within * a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. * * @see #getXValue(int, int) */ @Override public double getEndXValue(int series, int item) { return getXValue(series, item) + this.barWidth / 2.0; } /** * Returns the starting Y value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public Number getStartY(int series, int item) { return this.underlying.getY(series, item); } /** * Returns the starting y-value (as a double primitive) for an item within * a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. * * @see #getYValue(int, int) */ @Override public double getStartYValue(int series, int item) { return getYValue(series, item); } /** * Returns the ending Y value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public Number getEndY(int series, int item) { return this.underlying.getY(series, item); } /** * Returns the ending y-value (as a double primitive) for an item within * a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. * * @see #getYValue(int, int) */ @Override public double getEndYValue(int series, int item) { return getYValue(series, item); } /** * Receives notification of an dataset change event. * * @param event information about the event. */ @Override public void datasetChanged(DatasetChangeEvent event) { notifyListeners(event); } /** * Tests this dataset for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYBarDataset)) { return false; } XYBarDataset that = (XYBarDataset) obj; if (!this.underlying.equals(that.underlying)) { return false; } if (this.barWidth != that.barWidth) { return false; } return true; } /** * Returns an independent copy of the dataset. Note that: * <ul> * <li>the underlying dataset is only cloned if it implements the * {@link PublicCloneable} interface;</li> * <li>the listeners registered with this dataset are not carried over to * the cloned dataset.</li> * </ul> * * @return An independent copy of the dataset. * * @throws CloneNotSupportedException if the dataset cannot be cloned for * any reason. */ @Override public Object clone() throws CloneNotSupportedException { XYBarDataset clone = (XYBarDataset) super.clone(); if (this.underlying instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.underlying; clone.underlying = (XYDataset) pc.clone(); } return clone; } }
11,476
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XIntervalSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XIntervalSeries.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * XIntervalSeries.java * -------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * 11-Apr-2008 : Added getXLowValue() and getXHighValue() methods (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; import org.jfree.data.ComparableObjectSeries; /** * A list of (x, x-low, x-high, y) data items. * * @since 1.0.3 * * @see XIntervalSeriesCollection */ public class XIntervalSeries extends ComparableObjectSeries { /** * Creates a new empty series. By default, items added to the series will * be sorted into ascending order by x-value, and duplicate x-values will * be allowed (these defaults can be modified with another constructor. * * @param key the series key (<code>null</code> not permitted). */ public XIntervalSeries(Comparable key) { this(key, true, true); } /** * Constructs a new xy-series that contains no data. You can specify * whether or not duplicate x-values are allowed for the series. * * @param key the series key (<code>null</code> not permitted). * @param autoSort a flag that controls whether or not the items in the * series are sorted. * @param allowDuplicateXValues a flag that controls whether duplicate * x-values are allowed. */ public XIntervalSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) { super(key, autoSort, allowDuplicateXValues); } /** * Adds a data item to the series. * * @param x the x-value. * @param y the y-value. * @param xLow the lower bound of the y-interval. * @param xHigh the upper bound of the y-interval. */ public void add(double x, double xLow, double xHigh, double y) { super.add(new XIntervalDataItem(x, xLow, xHigh, y), true); } /** * Returns the x-value for the specified item. * * @param index the item index. * * @return The x-value (never <code>null</code>). */ public Number getX(int index) { XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); return item.getX(); } /** * Returns the lower bound of the x-interval for the specified item. * * @param index the item index. * * @return The lower bound of the x-interval. * * @since 1.0.10 */ public double getXLowValue(int index) { XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); return item.getXLowValue(); } /** * Returns the upper bound of the x-interval for the specified item. * * @param index the item index. * * @return The upper bound of the x-interval. * * @since 1.0.10 */ public double getXHighValue(int index) { XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); return item.getXHighValue(); } /** * Returns the y-value for the specified item. * * @param index the item index. * * @return The y-value. */ public double getYValue(int index) { XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); return item.getYValue(); } /** * Returns the data item at the specified index. * * @param index the item index. * * @return The data item. */ @Override public ComparableObjectItem getDataItem(int index) { return super.getDataItem(index); } }
4,961
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/VectorXYDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * VectorXYDataset.java * -------------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jan-2007 : Version 1 (DG); * 24-May-2007 : Renamed getDeltaXValue() as getVectorXValue(), and likewise * for getDeltaYValue(), and replaced getDeltaX()/getDeltaY() * with getVector() (DG); * 25-May-2007 : Moved from experimental to the main source tree (DG); * */ package org.jfree.data.xy; /** * An extension of the {@link XYDataset} interface that allows a vector to be * defined at a specific (x, y) location. * * @since 1.0.6 */ public interface VectorXYDataset extends XYDataset { /** * Returns the x-component of the vector for an item in a series. * * @param series the series index. * @param item the item index. * * @return The x-component of the vector. */ public double getVectorXValue(int series, int item); /** * Returns the y-component of the vector for an item in a series. * * @param series the series index. * @param item the item index. * * @return The y-component of the vector. */ public double getVectorYValue(int series, int item); /** * Returns the vector for an item in a series. Depending on the particular * dataset implementation, this may involve creating a new {@link Vector} * instance --- if you are just interested in the x and y components, * use the {@link #getVectorXValue(int, int)} and * {@link #getVectorYValue(int, int)} methods instead. * * @param series the series index. * @param item the item index. * * @return The vector (possibly <code>null</code>). */ public Vector getVector(int series, int item); }
3,143
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/package-info.java
/** * A package containing the {@link org.jfree.data.xy.XYDataset} interface and related classes. */ package org.jfree.data.xy;
130
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYSeries.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * XYSeries.java * ------------- * (C) Copyright 2001-2012, Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Aaron Metzger; * Jonathan Gabbai; * Richard Atkinson; * Michel Santos; * Ted Schwartz (fix for bug 1955483); * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 03-Apr-2002 : Added an add(double, double) method (DG); * 29-Apr-2002 : Added a clear() method (ARM); * 06-Jun-2002 : Updated Javadoc comments (DG); * 29-Aug-2002 : Modified to give user control over whether or not duplicate * x-values are allowed (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 11-Nov-2002 : Added maximum item count, code contributed by Jonathan * Gabbai (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 04-Aug-2003 : Added getItems() method (DG); * 15-Aug-2003 : Changed 'data' from private to protected, added new add() * methods with a 'notify' argument (DG); * 22-Sep-2003 : Added getAllowDuplicateXValues() method (RA); * 29-Jan-2004 : Added autoSort attribute, based on a contribution by * Michel Santos - see patch 886740 (DG); * 03-Feb-2004 : Added indexOf() method (DG); * 16-Feb-2004 : Added remove() method (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * 21-Feb-2005 : Added update(Number, Number) and addOrUpdate(Number, Number) * methods (DG); * 03-May-2005 : Added a new constructor, fixed the setMaximumItemCount() * method to remove items (and notify listeners) if necessary, * fixed the add() and addOrUpdate() methods to handle unsorted * series (DG); * ------------- JFreeChart 1.0.x --------------------------------------------- * 11-Jan-2005 : Renamed update(int, Number) --> updateByIndex() (DG); * 15-Jan-2007 : Added toArray() method (DG); * 31-Oct-2007 : Implemented faster hashCode() (DG); * 22-Nov-2007 : Reimplemented clone() (DG); * 01-May-2008 : Fixed bug 1955483 in addOrUpdate() method, thanks to * Ted Schwartz (DG); * 24-Nov-2008 : Further fix for 1955483 (DG); * 06-Mar-2009 : Added minX, maxX, minY and maxY fields (DG); * 10-Jun-2009 : Make clones to isolate XYDataItem instances used * for data storage (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.Collections; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.data.general.Series; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesException; /** * Represents a sequence of zero or more data items in the form (x, y). By * default, items in the series will be sorted into ascending order by x-value, * and duplicate x-values are permitted. Both the sorting and duplicate * defaults can be changed in the constructor. Y-values can be * <code>null</code> to represent missing values. */ public class XYSeries extends Series implements Cloneable, Serializable { /** For serialization. */ static final long serialVersionUID = -5908509288197150436L; // In version 0.9.12, in response to several developer requests, I changed // the 'data' attribute from 'private' to 'protected', so that others can // make subclasses that work directly with the underlying data structure. /** Storage for the data items in the series. */ protected List<XYDataItem> data; /** The maximum number of items for the series. */ private int maximumItemCount = Integer.MAX_VALUE; /** * A flag that controls whether the items are automatically sorted * (by x-value ascending). */ private boolean autoSort; /** A flag that controls whether or not duplicate x-values are allowed. */ private boolean allowDuplicateXValues; /** The lowest x-value in the series, excluding Double.NaN values. */ private double minX; /** The highest x-value in the series, excluding Double.NaN values. */ private double maxX; /** The lowest y-value in the series, excluding Double.NaN values. */ private double minY; /** The highest y-value in the series, excluding Double.NaN values. */ private double maxY; /** * Creates a new empty series. By default, items added to the series will * be sorted into ascending order by x-value, and duplicate x-values will * be allowed (these defaults can be modified with another constructor). * * @param key the series key (<code>null</code> not permitted). */ public XYSeries(Comparable key) { this(key, true, true); } /** * Constructs a new empty series, with the auto-sort flag set as requested, * and duplicate values allowed. * * @param key the series key (<code>null</code> not permitted). * @param autoSort a flag that controls whether or not the items in the * series are sorted. */ public XYSeries(Comparable key, boolean autoSort) { this(key, autoSort, true); } /** * Constructs a new xy-series that contains no data. You can specify * whether or not duplicate x-values are allowed for the series. * * @param key the series key (<code>null</code> not permitted). * @param autoSort a flag that controls whether or not the items in the * series are sorted. * @param allowDuplicateXValues a flag that controls whether duplicate * x-values are allowed. */ public XYSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) { super(key); this.data = new java.util.ArrayList<XYDataItem>(); this.autoSort = autoSort; this.allowDuplicateXValues = allowDuplicateXValues; this.minX = Double.NaN; this.maxX = Double.NaN; this.minY = Double.NaN; this.maxY = Double.NaN; } /** * Returns the smallest x-value in the series, ignoring any Double.NaN * values. This method returns Double.NaN if there is no smallest x-value * (for example, when the series is empty). * * @return The smallest x-value. * * @see #getMaxX() * * @since 1.0.13 */ public double getMinX() { return this.minX; } /** * Returns the largest x-value in the series, ignoring any Double.NaN * values. This method returns Double.NaN if there is no largest x-value * (for example, when the series is empty). * * @return The largest x-value. * * @see #getMinX() * * @since 1.0.13 */ public double getMaxX() { return this.maxX; } /** * Returns the smallest y-value in the series, ignoring any null and * Double.NaN values. This method returns Double.NaN if there is no * smallest y-value (for example, when the series is empty). * * @return The smallest y-value. * * @see #getMaxY() * * @since 1.0.13 */ public double getMinY() { return this.minY; } /** * Returns the largest y-value in the series, ignoring any Double.NaN * values. This method returns Double.NaN if there is no largest y-value * (for example, when the series is empty). * * @return The largest y-value. * * @see #getMinY() * * @since 1.0.13 */ public double getMaxY() { return this.maxY; } /** * Updates the cached values for the minimum and maximum data values. * * @param item the item added (<code>null</code> not permitted). * * @since 1.0.13 */ private void updateBoundsForAddedItem(XYDataItem item) { double x = item.getXValue(); this.minX = minIgnoreNaN(this.minX, x); this.maxX = maxIgnoreNaN(this.maxX, x); if (item.getY() != null) { double y = item.getYValue(); this.minY = minIgnoreNaN(this.minY, y); this.maxY = maxIgnoreNaN(this.maxY, y); } } /** * Updates the cached values for the minimum and maximum data values on * the basis that the specified item has just been removed. * * @param item the item added (<code>null</code> not permitted). * * @since 1.0.13 */ private void updateBoundsForRemovedItem(XYDataItem item) { boolean itemContributesToXBounds = false; boolean itemContributesToYBounds = false; double x = item.getXValue(); if (!Double.isNaN(x)) { if (x <= this.minX || x >= this.maxX) { itemContributesToXBounds = true; } } if (item.getY() != null) { double y = item.getYValue(); if (!Double.isNaN(y)) { if (y <= this.minY || y >= this.maxY) { itemContributesToYBounds = true; } } } if (itemContributesToYBounds) { findBoundsByIteration(); } else if (itemContributesToXBounds) { if (getAutoSort()) { this.minX = getX(0).doubleValue(); this.maxX = getX(getItemCount() - 1).doubleValue(); } else { findBoundsByIteration(); } } } /** * Finds the bounds of the x and y values for the series, by iterating * through all the data items. * * @since 1.0.13 */ private void findBoundsByIteration() { this.minX = Double.NaN; this.maxX = Double.NaN; this.minY = Double.NaN; this.maxY = Double.NaN; for (XYDataItem item : this.data) { updateBoundsForAddedItem(item); } } /** * Returns the flag that controls whether the items in the series are * automatically sorted. There is no setter for this flag, it must be * defined in the series constructor. * * @return A boolean. */ public boolean getAutoSort() { return this.autoSort; } /** * Returns a flag that controls whether duplicate x-values are allowed. * This flag can only be set in the constructor. * * @return A boolean. */ public boolean getAllowDuplicateXValues() { return this.allowDuplicateXValues; } /** * Returns the number of items in the series. * * @return The item count. * * @see #getItems() */ @Override public int getItemCount() { return this.data.size(); } /** * Returns the list of data items for the series (the list contains * {@link XYDataItem} objects and is unmodifiable). * * @return The list of data items. */ public List<XYDataItem> getItems() { return Collections.unmodifiableList(this.data); } /** * Returns the maximum number of items that will be retained in the series. * The default value is <code>Integer.MAX_VALUE</code>. * * @return The maximum item count. * * @see #setMaximumItemCount(int) */ public int getMaximumItemCount() { return this.maximumItemCount; } /** * Sets the maximum number of items that will be retained in the series. * If you add a new item to the series such that the number of items will * exceed the maximum item count, then the first element in the series is * automatically removed, ensuring that the maximum item count is not * exceeded. * <p> * Typically this value is set before the series is populated with data, * but if it is applied later, it may cause some items to be removed from * the series (in which case a {@link SeriesChangeEvent} will be sent to * all registered listeners). * * @param maximum the maximum number of items for the series. */ public void setMaximumItemCount(int maximum) { this.maximumItemCount = maximum; int remove = this.data.size() - maximum; if (remove > 0) { this.data.subList(0, remove).clear(); findBoundsByIteration(); fireSeriesChanged(); } } /** * Adds a data item to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. * * @param item the (x, y) item (<code>null</code> not permitted). */ public void add(XYDataItem item) { // argument checking delegated... add(item, true); } /** * Adds a data item to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. * * @param x the x value. * @param y the y value. */ public void add(double x, double y) { add(new Double(x), new Double(y), true); } /** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param x the x value. * @param y the y value. * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ public void add(double x, double y, boolean notify) { add(new Double(x), new Double(y), notify); } /** * Adds a data item to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. The unusual pairing of parameter types is to * make it easier to add <code>null</code> y-values. * * @param x the x value. * @param y the y value (<code>null</code> permitted). */ public void add(double x, Number y) { add(new Double(x), y); } /** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. The unusual * pairing of parameter types is to make it easier to add null y-values. * * @param x the x value. * @param y the y value (<code>null</code> permitted). * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ public void add(double x, Number y, boolean notify) { add(new Double(x), y, notify); } /** * Adds a new data item to the series (in the correct position if the * <code>autoSort</code> flag is set for the series) and sends a * {@link SeriesChangeEvent} to all registered listeners. * <P> * 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). * * @throws SeriesException if the x-value is a duplicate and the * <code>allowDuplicateXValues</code> flag is not set for this series. */ public void add(Number x, Number y) { // argument checking delegated... add(x, y, true); } /** * Adds new data to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * <P> * 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. */ public void add(Number x, Number y, boolean notify) { // delegate argument checking to XYDataItem... XYDataItem item = new XYDataItem(x, y); add(item, notify); } /** * Adds a data item to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the (x, y) item (<code>null</code> not permitted). * @param notify a flag that controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ public void add(XYDataItem item, boolean notify) { ParamChecks.nullNotPermitted(item, "item"); item = item.copy(); if (this.autoSort) { int index = Collections.binarySearch(this.data, item); if (index < 0) { this.data.add(-index - 1, item); } else { if (this.allowDuplicateXValues) { // need to make sure we are adding *after* any duplicates int size = this.data.size(); while (index < size && item.compareTo( this.data.get(index)) == 0) { index++; } if (index < this.data.size()) { this.data.add(index, item); } else { this.data.add(item); } } else { throw new SeriesException("X-value already exists."); } } } else { if (!this.allowDuplicateXValues) { // can't allow duplicate values, so we need to check whether // there is an item with the given x-value already int index = indexOf(item.getX()); if (index >= 0) { throw new SeriesException("X-value already exists."); } } this.data.add(item); } updateBoundsForAddedItem(item); if (getItemCount() > this.maximumItemCount) { XYDataItem removed = this.data.remove(0); updateBoundsForRemovedItem(removed); } if (notify) { fireSeriesChanged(); } } /** * Deletes a range of items from the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param start the start index (zero-based). * @param end the end index (zero-based). */ public void delete(int start, int end) { this.data.subList(start, end + 1).clear(); findBoundsByIteration(); fireSeriesChanged(); } /** * Removes the item at the specified index and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the index. * * @return The item removed. */ public XYDataItem remove(int index) { XYDataItem removed = this.data.remove(index); updateBoundsForRemovedItem(removed); fireSeriesChanged(); return removed; } /** * Removes an item with the specified x-value and sends a * {@link SeriesChangeEvent} to all registered listeners. Note that when * a series permits multiple items with the same x-value, this method * could remove any one of the items with that x-value. * * @param x the x-value. * @return The item removed. */ public XYDataItem remove(Number x) { return remove(indexOf(x)); } /** * Removes all data items from the series and sends a * {@link SeriesChangeEvent} to all registered listeners. */ public void clear() { if (this.data.size() > 0) { this.data.clear(); this.minX = Double.NaN; this.maxX = Double.NaN; this.minY = Double.NaN; this.maxY = Double.NaN; fireSeriesChanged(); } } /** * Return the data item with the specified index. * * @param index the index. * * @return The data item with the specified index. */ public XYDataItem getDataItem(int index) { XYDataItem item = this.data.get(index); return item.copy(); } /** * Return the data item with the specified index. * * @param index the index. * * @return The data item with the specified index. * * @since 1.0.14 */ XYDataItem getRawDataItem(int index) { return this.data.get(index); } /** * Returns the x-value at the specified index. * * @param index the index (zero-based). * * @return The x-value (never <code>null</code>). */ public Number getX(int index) { return getRawDataItem(index).getX(); } /** * Returns the y-value at the specified index. * * @param index the index (zero-based). * * @return The y-value (possibly <code>null</code>). */ public Number getY(int index) { return getRawDataItem(index).getY(); } /** * A function to find the minimum of two values, but ignoring any * Double.NaN values. * * @param a the first value. * @param b the second value. * * @return The minimum of the two values. */ private double minIgnoreNaN(double a, double b) { if (Double.isNaN(a)) { return b; } if (Double.isNaN(b)) { return a; } return Math.min(a, b); } /** * A function to find the maximum of two values, but ignoring any * Double.NaN values. * * @param a the first value. * @param b the second value. * * @return The maximum of the two values. */ private double maxIgnoreNaN(double a, double b) { if (Double.isNaN(a)) { return b; } if (Double.isNaN(b)) { return a; } return Math.max(a, b); } /** * Updates the value of an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the item (zero based index). * @param y the new value (<code>null</code> permitted). * * @since 1.0.1 */ public void updateByIndex(int index, Number y) { XYDataItem item = getRawDataItem(index); // figure out if we need to iterate through all the y-values boolean iterate = false; double oldY = item.getYValue(); if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } item.setY(y); if (iterate) { findBoundsByIteration(); } else if (y != null) { double yy = y.doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } fireSeriesChanged(); } /** * Updates an item in the series. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). * * @throws SeriesException if there is no existing item with the specified * x-value. */ public void update(Number x, Number y) { int index = indexOf(x); if (index < 0) { throw new SeriesException("No observation for x = " + x); } updateByIndex(index, y); } /** * Adds or updates an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param x the x-value. * @param y the y-value. * * @return The item that was overwritten, if any. * * @since 1.0.10 */ public XYDataItem addOrUpdate(double x, double y) { return addOrUpdate(new Double(x), new Double(y)); } /** * Adds or updates an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten. */ public XYDataItem addOrUpdate(Number x, Number y) { // defer argument checking return addOrUpdate(new XYDataItem(x, y)); } /** * Adds or updates an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the data item (<code>null</code> not permitted). * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten. * * @since 1.0.14 */ public XYDataItem addOrUpdate(XYDataItem item) { ParamChecks.nullNotPermitted(item, "item"); if (this.allowDuplicateXValues) { add(item); return null; } // if we get to here, we know that duplicate X values are not permitted XYDataItem overwritten = null; int index = indexOf(item.getX()); if (index >= 0) { XYDataItem existing = this.data.get(index); overwritten = existing.copy(); // figure out if we need to iterate through all the y-values boolean iterate = false; double oldY = existing.getYValue(); if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } existing.setY(item.getY()); if (iterate) { findBoundsByIteration(); } else if (item.getY() != null) { double yy = item.getY().doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } } else { // if the series is sorted, the negative index is a result from // Collections.binarySearch() and tells us where to insert the // new item...otherwise it will be just -1 and we should just // append the value to the list... item = item.copy(); if (this.autoSort) { this.data.add(-index - 1, item); } else { this.data.add(item); } updateBoundsForAddedItem(item); // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { XYDataItem removed = this.data.remove(0); updateBoundsForRemovedItem(removed); } } fireSeriesChanged(); return overwritten; } /** * 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. * * @param x the x-value (<code>null</code> not permitted). * * @return The index. */ public int indexOf(Number x) { if (this.autoSort) { return Collections.binarySearch(this.data, new XYDataItem(x, null)); } else { for (int i = 0; i < this.data.size(); i++) { XYDataItem item = this.data.get(i); if (item.getX().equals(x)) { return i; } } return -1; } } /** * Returns a new array containing the x and y values from this series. * * @return A new array containing the x and y values from this series. * * @since 1.0.4 */ public double[][] toArray() { int itemCount = getItemCount(); double[][] result = new double[2][itemCount]; for (int i = 0; i < itemCount; i++) { result[0][i] = this.getX(i).doubleValue(); Number y = getY(i); if (y != null) { result[1][i] = y.doubleValue(); } else { result[1][i] = Double.NaN; } } return result; } /** * Returns a clone of the series. * * @return A clone of the series. * * @throws CloneNotSupportedException if there is a cloning problem. */ @Override public Object clone() throws CloneNotSupportedException { XYSeries clone = (XYSeries) super.clone(); clone.data = ObjectUtilities.deepClone(this.data); return clone; } /** * Creates a new series by copying a subset of the data in this time series. * * @param start the index of the first item to copy. * @param end the index of the last item to copy. * * @return A series containing a copy of this series from start until end. * * @throws CloneNotSupportedException if there is a cloning problem. */ public XYSeries createCopy(int start, int end) throws CloneNotSupportedException { XYSeries copy = (XYSeries) super.clone(); copy.data = new java.util.ArrayList<XYDataItem>(); if (this.data.size() > 0) { for (int index = start; index <= end; index++) { XYDataItem item = this.data.get(index); XYDataItem clone = (XYDataItem) item.clone(); try { copy.add(clone); } catch (SeriesException e) { throw new RuntimeException("Unable to add cloned data item.", e); } } } return copy; } /** * Tests this series for equality with an arbitrary object. * * @param obj the object to test against for equality * (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYSeries)) { return false; } if (!super.equals(obj)) { return false; } XYSeries that = (XYSeries) obj; if (this.maximumItemCount != that.maximumItemCount) { return false; } if (this.autoSort != that.autoSort) { return false; } if (this.allowDuplicateXValues != that.allowDuplicateXValues) { return false; } if (!ObjectUtilities.equal(this.data, that.data)) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result = super.hashCode(); // it is too slow to look at every data item, so let's just look at // the first, middle and last items... int count = getItemCount(); if (count > 0) { XYDataItem item = getRawDataItem(0); result = 29 * result + item.hashCode(); } if (count > 1) { XYDataItem item = getRawDataItem(count - 1); result = 29 * result + item.hashCode(); } if (count > 2) { XYDataItem item = getRawDataItem(count / 2); result = 29 * result + item.hashCode(); } result = 29 * result + this.maximumItemCount; result = 29 * result + (this.autoSort ? 1 : 0); result = 29 * result + (this.allowDuplicateXValues ? 1 : 0); return result; } }
32,829
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractIntervalXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/AbstractIntervalXYDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * AbstractIntervalXYDataset.java * ------------------------------ * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited). * Contributor(s): -; * * Changes * ------- * 05-May-2004 : Version 1 (DG); * 15-Jul-2004 : Switched getStartX() and getStartXValue() methods and * others (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * */ package org.jfree.data.xy; /** * An base class that you can use to create new implementations of the * {@link IntervalXYDataset} interface. */ public abstract class AbstractIntervalXYDataset extends AbstractXYDataset implements IntervalXYDataset { /** * Returns the start x-value (as a double primitive) for an item within a * series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public double getStartXValue(int series, int item) { double result = Double.NaN; Number x = getStartX(series, item); if (x != null) { result = x.doubleValue(); } return result; } /** * Returns the end x-value (as a double primitive) for an item within a * series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public double getEndXValue(int series, int item) { double result = Double.NaN; Number x = getEndX(series, item); if (x != null) { result = x.doubleValue(); } return result; } /** * Returns the start y-value (as a double primitive) for an item within a * series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public double getStartYValue(int series, int item) { double result = Double.NaN; Number y = getStartY(series, item); if (y != null) { result = y.doubleValue(); } return result; } /** * Returns the end y-value (as a double primitive) for an item within a * series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ @Override public double getEndYValue(int series, int item) { double result = Double.NaN; Number y = getEndY(series, item); if (y != null) { result = y.doubleValue(); } return result; } }
3,985
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IntervalXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/IntervalXYDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * IntervalXYDataset.java * ---------------------- * (C) Copyright 2001-2009, by Object Refinery Limited and Contributors. * * Original Author: Mark Watson (www.markwatson.com); * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 18-Oct-2001 : Version 1, thanks to Mark Watson (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc (DG); * 06-May-2004 : Added methods that return double primitives (DG); * 15-Sep-2009 : Added clarifications to API docs (DG); * */ package org.jfree.data.xy; /** * An extension of the {@link XYDataset} interface that allows an x-interval * and a y-interval to be defined. Note that the x and y values defined * by the parent interface are NOT required to fall within these intervals. * This interface is used to support (among other things) bar plots against * numerical axes. */ public interface IntervalXYDataset extends XYDataset { /** * Returns the lower bound of the x-interval for the specified series and * item. If this lower bound is specified, it should be less than or * equal to the upper bound of the interval (if one is specified). * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The lower bound of the x-interval (<code>null</code> permitted). */ public Number getStartX(int series, int item); /** * Returns the lower bound of the x-interval (as a double primitive) for * the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The lower bound of the x-interval. * * @see #getStartX(int, int) */ public double getStartXValue(int series, int item); /** * Returns the upper bound of the x-interval for the specified series and * item. If this upper bound is specified, it should be greater than or * equal to the lower bound of the interval (if one is specified). * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The upper bound of the x-interval (<code>null</code> permitted). */ public Number getEndX(int series, int item); /** * Returns the upper bound of the x-interval (as a double primitive) for * the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The upper bound of the x-interval. * * @see #getEndX(int, int) */ public double getEndXValue(int series, int item); /** * Returns the lower bound of the y-interval for the specified series and * item. If this lower bound is specified, it should be less than or * equal to the upper bound of the interval (if one is specified). * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The lower bound of the y-interval (<code>null</code> permitted). */ public Number getStartY(int series, int item); /** * Returns the lower bound of the y-interval (as a double primitive) for * the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The lower bound of the y-interval. * * @see #getStartY(int, int) */ public double getStartYValue(int series, int item); /** * Returns the upper bound of the y-interval for the specified series and * item. If this upper bound is specified, it should be greater than or * equal to the lower bound of the interval (if one is specified). * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The upper bound of the y-interval (<code>null</code> permitted). */ public Number getEndY(int series, int item); /** * Returns the upper bound of the y-interval (as a double primitive) for * the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The upper bound of the y-interval. * * @see #getEndY(int, int) */ public double getEndYValue(int series, int item); }
5,712
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WindDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/WindDataset.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * WindDataset.java * ---------------- * (C) Copyright 2001-2008, by Achilleus Mantzios and Contributors. * * Original Author: Achilleus Mantzios; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 06-Feb-2002 : Version 1, based on code contributed by Achilleus * Mantzios (DG); * */ package org.jfree.data.xy; /** * Interface for a dataset that supplies wind intensity and direction values * observed at various points in time. */ public interface WindDataset extends XYDataset { /** * Returns the wind direction (should be in the range 0 to 12, * corresponding to the positions on an upside-down clock face). * * @param series the series (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item (in the range <code>0</code> to * <code>getItemCount(series) - 1</code>). * * @return The wind direction. */ public Number getWindDirection(int series, int item); /** * Returns the wind force on the Beaufort scale (0 to 12). See: * <p> * http://en.wikipedia.org/wiki/Beaufort_scale * * @param series the series (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * @param item the item (in the range <code>0</code> to * <code>getItemCount(series) - 1</code>). * * @return The wind force. */ public Number getWindForce(int series, int item); }
2,753
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Vector.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/Vector.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------- * Vector.java * ----------- * (C) Copyright 2007, 2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jan-2007 : Version 1 (DG); * 24-May-2007 : Added getLength() and getAngle() methods, thanks to * matinh (DG); * 25-May-2007 : Moved from experimental to the main source tree (DG); * */ package org.jfree.data.xy; import java.io.Serializable; /** * A vector. * * @since 1.0.6 */ public class Vector implements Serializable { /** The vector x. */ private double x; /** The vector y. */ private double y; /** * Creates a new instance of <code>Vector</code>. * * @param x the x-component. * @param y the y-component. */ public Vector(double x, double y) { this.x = x; this.y = y; } /** * Returns the x-value. * * @return The x-value. */ public double getX() { return this.x; } /** * Returns the y-value. * * @return The y-value. */ public double getY() { return this.y; } /** * Returns the length of the vector. * * @return The vector length. */ public double getLength() { return Math.sqrt((this.x * this.x) + (this.y * this.y)); } /** * Returns the angle of the vector. * * @return The angle of the vector. */ public double getAngle() { return Math.atan2(this.y, this.x); } /** * Tests this vector for equality with an arbitrary object. * * @param obj the object (<code>null</code> not permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Vector)) { return false; } Vector that = (Vector) obj; if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; long temp = Double.doubleToLongBits(this.x); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y); result = 37 * result + (int) (temp ^ (temp >>> 32)); return result; } }
3,782
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z