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
XYDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYDataItem.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.] * * --------------- * XYDataItem.java * --------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 05-Aug-2003 : Renamed XYDataPair --> XYDataItem (DG); * 03-Feb-2004 : Fixed bug in equals() method (DG); * 21-Feb-2005 : Added setY(double) method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 30-Nov-2007 : Implemented getXValue() and getYValue(), plus toString() for * debugging use (DG); * 10-Jun-2009 : Reimplemented cloning (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; /** * Represents one (x, y) data item for an {@link XYSeries}. Note that * subclasses are REQUIRED to support cloning. */ public class XYDataItem implements Cloneable, Comparable<XYDataItem>, Serializable { /** For serialization. */ private static final long serialVersionUID = 2751513470325494890L; /** The x-value (<code>null</code> not permitted). */ private Number x; /** The y-value. */ private Number y; /** * 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 XYDataItem(Number x, Number y) { if (x == null) { throw new IllegalArgumentException("Null 'x' argument."); } this.x = x; this.y = y; } /** * Constructs a new data item. * * @param x the x-value. * @param y the y-value. */ public XYDataItem(double x, double y) { this(new Double(x), new Double(y)); } /** * Returns the x-value. * * @return The x-value (never <code>null</code>). */ public Number getX() { return this.x; } /** * Returns the x-value as a double primitive. * * @return The x-value. * * @see #getX() * @see #getYValue() * * @since 1.0.9 */ public double getXValue() { // this.x is not allowed to be null... return this.x.doubleValue(); } /** * Returns the y-value. * * @return The y-value (possibly <code>null</code>). */ public Number getY() { return this.y; } /** * Returns the y-value as a double primitive. * * @return The y-value. * * @see #getY() * @see #getXValue() * * @since 1.0.9 */ public double getYValue() { double result = Double.NaN; if (this.y != null) { result = this.y.doubleValue(); } return result; } /** * 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. */ public void setY(double y) { setY(new Double(y)); } /** * 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). */ public void setY(Number y) { this.y = 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 dataItem the object being compared to. * * @return An integer indicating the order of this data pair object * relative to another object. */ @Override public int compareTo(XYDataItem dataItem) { int result; double compare = this.x.doubleValue() - dataItem.getX().doubleValue(); if (compare > 0.0) { result = 1; } else { if (compare < 0.0) { result = -1; } else { result = 0; } } return result; } /** * Returns a clone of this object. * * @return A clone. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } public XYDataItem copy() { try { return (XYDataItem) clone(); } catch (CloneNotSupportedException e) { return null; } } /** * 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 XYDataItem)) { return false; } XYDataItem that = (XYDataItem) obj; if (!this.x.equals(that.x)) { return false; } if (!ObjectUtilities.equal(this.y, that.y)) { 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.y != null ? this.y.hashCode() : 0); return result; } /** * Returns a string representing this instance, primarily for debugging * use. * * @return A string. */ @Override public String toString() { return "[" + getXValue() + ", " + getYValue() + "]"; } }
6,978
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XIntervalSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XIntervalSeriesCollection.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.] * * ------------------------------ * XIntervalSeriesCollection.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); * 27-Nov-2006 : Added clone() override (DG); * 18-Jan-2008 : Added removeSeries() and removeAllSeries() methods (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DatasetChangeEvent; /** * A collection of {@link XIntervalSeries} objects. * * @since 1.0.3 * * @see XIntervalSeries */ public class XIntervalSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, PublicCloneable, Serializable { /** Storage for the data series. */ private List<XIntervalSeries> data; /** * Creates a new instance of <code>XIntervalSeriesCollection</code>. */ public XIntervalSeriesCollection() { this.data = new java.util.ArrayList<XIntervalSeries>(); } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(XIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a series from the collection. * * @param series the series index (zero-based). * * @return The series. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ public XIntervalSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.data.get(series); } /** * 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 a series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ @Override public int getItemCount(int series) { // defer argument checking return getSeries(series).getItemCount(); } /** * Returns the x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getX(int series, int item) { XIntervalSeries s = this.data.get(series); XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item); return di.getX(); } /** * 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) { XIntervalSeries s = this.data.get(series); return s.getXLowValue(item); } /** * Returns the end x-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 getEndXValue(int series, int item) { XIntervalSeries s = this.data.get(series); return s.getXHighValue(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. */ @Override public double getYValue(int series, int item) { XIntervalSeries s = this.data.get(series); return s.getYValue(item); } /** * Returns the y-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The y-value. */ @Override public Number getY(int series, int item) { XIntervalSeries s = this.data.get(series); XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item); return di.getYValue(); } /** * Returns the start x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getStartX(int series, int item) { XIntervalSeries s = this.data.get(series); XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item); return di.getXLowValue(); } /** * Returns the end x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getEndX(int series, int item) { XIntervalSeries s = this.data.get(series); XIntervalDataItem di = (XIntervalDataItem) s.getDataItem(item); return di.getXHighValue(); } /** * Returns the start y-value for an item within a series. This method * maps directly to {@link #getY(int, int)}. * * @param series the series index. * @param item the item index. * * @return The start y-value. */ @Override public Number getStartY(int series, int item) { return getY(series, item); } /** * Returns the end y-value for an item within a series. This method * maps directly to {@link #getY(int, int)}. * * @param series the series index. * @param item the item index. * * @return The end y-value. */ @Override public Number getEndY(int series, int item) { return getY(series, item); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * * @since 1.0.10 */ public void removeSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds."); } XIntervalSeries ts = this.data.get(series); ts.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @since 1.0.10 */ public void removeSeries(XIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.10 */ public void removeAllSeries() { // Unregister the collection as a change listener to each series in // the collection. for (XIntervalSeries series : this.data) { series.removeChangeListener(this); } this.data.clear(); fireDatasetChanged(); } /** * 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 XIntervalSeriesCollection)) { return false; } XIntervalSeriesCollection that = (XIntervalSeriesCollection) obj; return ObjectUtilities.equal(this.data, that.data); } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem. */ @Override public Object clone() throws CloneNotSupportedException { XIntervalSeriesCollection clone = (XIntervalSeriesCollection) super.clone(); clone.data = (List) ObjectUtilities.deepClone(this.data); return clone; } }
10,880
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultWindDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultWindDataset.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.] * * ----------------------- * DefaultWindDataset.java * ----------------------- * (C) Copyright 2001-2012, 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); * 05-May-2004 : Now extends AbstractXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; import org.jfree.chart.util.PublicCloneable; /** * A default implementation of the {@link WindDataset} interface. */ public class DefaultWindDataset extends AbstractXYDataset implements WindDataset, PublicCloneable { /** The keys for the series. */ private List<String> seriesKeys; /** Storage for the series data. */ private List<List<WindDataItem>> allSeriesData; /** * Constructs a new, empty, dataset. Since there are currently no methods * to add data to an existing dataset, you should probably use a different * constructor. */ public DefaultWindDataset() { this.seriesKeys = new java.util.ArrayList<String>(); this.allSeriesData = new java.util.ArrayList<List<WindDataItem>>(); } /** * Constructs a dataset based on the specified data array. * * @param data the data (<code>null</code> not permitted). * * @throws NullPointerException if <code>data</code> is <code>null</code>. */ public DefaultWindDataset(Object[][][] data) { this(seriesNameListFromDataArray(data), data); } /** * Constructs a dataset based on the specified data array. * * @param seriesNames the names of the series (<code>null</code> not * permitted). * @param data the wind data. * * @throws NullPointerException if <code>seriesNames</code> is * <code>null</code>. */ public DefaultWindDataset(String[] seriesNames, Object[][][] data) { this(Arrays.asList(seriesNames), data); } /** * Constructs a dataset based on the specified data array. The array * can contain multiple series, each series can contain multiple items, * and each item is as follows: * <ul> * <li><code>data[series][item][0]</code> - the date (either a * <code>Date</code> or a <code>Number</code> that is the milliseconds * since 1-Jan-1970);</li> * <li><code>data[series][item][1]</code> - the wind direction (1 - 12, * like the numbers on a clock face);</li> * <li><code>data[series][item][2]</code> - the wind force (1 - 12 on the * Beaufort scale)</li> * </ul> * * @param seriesKeys the names of the series (<code>null</code> not * permitted). * @param data the wind dataset (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>seriesKeys</code> is * <code>null</code> or the number of series keys does not * match the number of series in the array. * @throws NullPointerException if <code>data</code> is <code>null</code>. */ public DefaultWindDataset(List<String> seriesKeys, Object[][][] data) { if (seriesKeys == null) { throw new IllegalArgumentException("Null 'seriesKeys' argument."); } if (seriesKeys.size() != data.length) { throw new IllegalArgumentException("The number of series keys does " + "not match the number of series in the data array."); } this.seriesKeys = seriesKeys; int seriesCount = data.length; this.allSeriesData = new java.util.ArrayList<List<WindDataItem>>(seriesCount); for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { List<WindDataItem> oneSeriesData = new java.util.ArrayList<WindDataItem>(); int maxItemCount = data[seriesIndex].length; for (int itemIndex = 0; itemIndex < maxItemCount; itemIndex++) { Object xObject = data[seriesIndex][itemIndex][0]; if (xObject != null) { Number xNumber; if (xObject instanceof Number) { xNumber = (Number) xObject; } else { if (xObject instanceof Date) { Date xDate = (Date) xObject; xNumber = xDate.getTime(); } else { xNumber = 0; } } Number windDir = (Number) data[seriesIndex][itemIndex][1]; Number windForce = (Number) data[seriesIndex][itemIndex][2]; oneSeriesData.add(new WindDataItem(xNumber, windDir, windForce)); } } Collections.sort(oneSeriesData); this.allSeriesData.add(seriesIndex, oneSeriesData); } } /** * Returns the number of series in the dataset. * * @return The series count. */ @Override public int getSeriesCount() { return this.allSeriesData.size(); } /** * Returns the number of items in a series. * * @param series the series (zero-based index). * * @return The item count. */ @Override public int getItemCount(int series) { if (series < 0 || series >= getSeriesCount()) { throw new IllegalArgumentException("Invalid series index: " + series); } List<WindDataItem> oneSeriesData = this.allSeriesData.get(series); return oneSeriesData.size(); } /** * Returns the key for a series. * * @param series the series (zero-based index). * * @return The series key. */ @Override public Comparable getSeriesKey(int series) { if (series < 0 || series >= getSeriesCount()) { throw new IllegalArgumentException("Invalid series index: " + series); } return this.seriesKeys.get(series); } /** * Returns the x-value for one item within a series. This should represent * a point in time, encoded as milliseconds in the same way as * java.util.Date. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The x-value for the item within the series. */ @Override public Number getX(int series, int item) { List<WindDataItem> oneSeriesData = this.allSeriesData.get(series); WindDataItem windItem = oneSeriesData.get(item); return windItem.getX(); } /** * Returns the y-value for one item within a series. This maps to the * {@link #getWindForce(int, int)} method and is implemented because * <code>WindDataset</code> is an extension of {@link XYDataset}. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The y-value for the item within the series. */ @Override public Number getY(int series, int item) { return getWindForce(series, item); } /** * Returns the wind direction for one item within a series. This is a * number between 0 and 12, like the numbers on an upside-down clock face. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The wind direction for the item within the series. */ @Override public Number getWindDirection(int series, int item) { List<WindDataItem> oneSeriesData = this.allSeriesData.get(series); WindDataItem windItem = oneSeriesData.get(item); return windItem.getWindDirection(); } /** * Returns the wind force for one item within a series. This is a number * between 0 and 12, as defined by the Beaufort scale. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The wind force for the item within the series. */ @Override public Number getWindForce(int series, int item) { List<WindDataItem> oneSeriesData = this.allSeriesData.get(series); WindDataItem windItem = oneSeriesData.get(item); return windItem.getWindForce(); } /** * Utility method for automatically generating series names. * * @param data the wind data (<code>null</code> not permitted). * * @return An array of <i>Series N</i> with N = { 1 .. data.length }. * * @throws NullPointerException if <code>data</code> is <code>null</code>. */ public static List<String> seriesNameListFromDataArray(Object[][] data) { int seriesCount = data.length; List<String> seriesNameList = new java.util.ArrayList<String>(seriesCount); for (int i = 0; i < seriesCount; i++) { seriesNameList.add("Series " + (i + 1)); } return seriesNameList; } /** * Checks this <code>WindDataset</code> 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>DefaultWindDataset</code>;</li> * <li>both datasets have the same number of series containing identical * values.</li> * <ul> * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof DefaultWindDataset)) { return false; } DefaultWindDataset that = (DefaultWindDataset) obj; if (!this.seriesKeys.equals(that.seriesKeys)) { return false; } if (!this.allSeriesData.equals(that.allSeriesData)) { return false; } return true; } } /** * A wind data item. */ class WindDataItem implements Comparable<WindDataItem>, Serializable { /** The x-value. */ private Number x; /** The wind direction. */ private Number windDir; /** The wind force. */ private Number windForce; /** * Creates a new wind data item. * * @param x the x-value. * @param windDir the direction. * @param windForce the force. */ public WindDataItem(Number x, Number windDir, Number windForce) { this.x = x; this.windDir = windDir; this.windForce = windForce; } /** * Returns the x-value. * * @return The x-value. */ public Number getX() { return this.x; } /** * Returns the wind direction. * * @return The wind direction. */ public Number getWindDirection() { return this.windDir; } /** * Returns the wind force. * * @return The wind force. */ public Number getWindForce() { return this.windForce; } /** * Compares this item to another object. * * @param item the other object. * * @return An int that indicates the relative comparison. */ @Override public int compareTo(WindDataItem item) { if (this.x.doubleValue() > item.x.doubleValue()) { return 1; } else if (this.x.equals(item.x)) { return 0; } else { return -1; } } /** * Tests this <code>WindDataItem</code> for equality with an arbitrary * object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (this == obj) { return false; } if (!(obj instanceof WindDataItem)) { return false; } WindDataItem that = (WindDataItem) obj; if (!this.x.equals(that.x)) { return false; } if (!this.windDir.equals(that.windDir)) { return false; } if (!this.windForce.equals(that.windForce)) { return false; } return true; } }
14,079
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYIntervalDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYIntervalDataItem.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.] * * ----------------------- * XYIntervalDataItem.java * ----------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; /** * An item representing data in the form (x, x-low, x-high, y, y-low, y-high). * * @since 1.0.3 */ public class XYIntervalDataItem extends ComparableObjectItem { /** * Creates a new instance of <code>XYIntervalItem</code>. * * @param x the x-value. * @param xLow the lower bound of the x-interval. * @param xHigh the upper bound of the x-interval. * @param y the y-value. * @param yLow the lower bound of the y-interval. * @param yHigh the upper bound of the y-interval. */ public XYIntervalDataItem(double x, double xLow, double xHigh, double y, double yLow, double yHigh) { super(x, new XYInterval(xLow, xHigh, y, yLow, yHigh)); } /** * Returns the x-value. * * @return The x-value (never <code>null</code>). */ public Double getX() { return (Double) getComparable(); } /** * Returns the y-value. * * @return The y-value. */ public double getYValue() { XYInterval interval = (XYInterval) getObject(); if (interval != null) { return interval.getY(); } else { return Double.NaN; } } /** * Returns the lower bound of the x-interval. * * @return The lower bound of the x-interval. */ public double getXLowValue() { XYInterval interval = (XYInterval) getObject(); if (interval != null) { return interval.getXLow(); } else { return Double.NaN; } } /** * Returns the upper bound of the x-interval. * * @return The upper bound of the x-interval. */ public double getXHighValue() { XYInterval interval = (XYInterval) getObject(); if (interval != null) { return interval.getXHigh(); } else { return Double.NaN; } } /** * Returns the lower bound of the y-interval. * * @return The lower bound of the y-interval. */ public double getYLowValue() { XYInterval interval = (XYInterval) getObject(); if (interval != null) { return interval.getYLow(); } else { return Double.NaN; } } /** * Returns the upper bound of the y-interval. * * @return The upper bound of the y-interval. */ public double getYHighValue() { XYInterval interval = (XYInterval) getObject(); if (interval != null) { return interval.getYHigh(); } else { return Double.NaN; } } }
4,244
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XisSymbolic.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XisSymbolic.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.] * * ---------------- * XisSymbolic.java * ---------------- * (C) Copyright 2006-2008, by Anthony Boulestreau and Contributors. * * Original Author: Anthony Boulestreau; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 29-Mar-2002 : First version (AB); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.xy; /** * Represent a data set where X is a symbolic values. Each symbolic value is * linked with an Integer. */ public interface XisSymbolic { /** * Returns the list of symbolic values. * * @return An array of symbolic values. */ public String[] getXSymbolicValues(); /** * Returns the symbolic value of the data set specified by * <CODE>series</CODE> and <CODE>item</CODE> parameters. * * @param series value of the serie. * @param item value of the item. * * @return The symbolic value. */ public String getXSymbolicValue(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 getXSymbolicValue(Integer val); }
2,599
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/VectorDataItem.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.] * * ------------------- * VectorDataItem.java * ------------------- * (C) Copyright 2007-2009, 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 getVector(), renamed getDeltaX() --> getVectorX(), * and likewise for getDeltaY() (DG); * 25-May-2007 : Moved from experimental to the main source tree (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; /** * A data item representing data in the form (x, y, deltaX, deltaY), intended * for use by the {@link VectorSeries} class. * * @since 1.0.6 */ public class VectorDataItem extends ComparableObjectItem { /** * Creates a new instance of <code>VectorDataItem</code>. * * @param x the x-value. * @param y the y-value. * @param deltaX the vector x. * @param deltaY the vector y. */ public VectorDataItem(double x, double y, double deltaX, double deltaY) { super(new XYCoordinate(x, y), new Vector(deltaX, deltaY)); } /** * Returns the x-value. * * @return The x-value (never <code>null</code>). */ public double getXValue() { XYCoordinate xy = (XYCoordinate) getComparable(); return xy.getX(); } /** * Returns the y-value. * * @return The y-value. */ public double getYValue() { XYCoordinate xy = (XYCoordinate) getComparable(); return xy.getY(); } /** * Returns the vector. * * @return The vector (possibly <code>null</code>). */ public Vector getVector() { return (Vector) getObject(); } /** * Returns the x-component for the vector. * * @return The x-component. */ public double getVectorX() { Vector vi = (Vector) getObject(); if (vi != null) { return vi.getX(); } else { return Double.NaN; } } /** * Returns the y-component for the vector. * * @return The y-component. */ public double getVectorY() { Vector vi = (Vector) getObject(); if (vi != null) { return vi.getY(); } else { return Double.NaN; } } }
3,584
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YIntervalSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/YIntervalSeriesCollection.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.] * * ------------------------------ * YIntervalSeriesCollection.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); * 27-Nov-2006 : Added clone() override (DG); * 20-Feb-2007 : Added getYValue(), getStartYValue() and getEndYValue() * methods (DG); * 18-Jan-2008 : Added removeSeries() and removeAllSeries() methods (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DatasetChangeEvent; /** * A collection of {@link YIntervalSeries} objects. * * @since 1.0.3 * * @see YIntervalSeries */ public class YIntervalSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, PublicCloneable, Serializable { /** Storage for the data series. */ private List<YIntervalSeries> data; /** * Creates a new instance of <code>YIntervalSeriesCollection</code>. */ public YIntervalSeriesCollection() { this.data = new java.util.ArrayList<YIntervalSeries>(); } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(YIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a series from the collection. * * @param series the series index (zero-based). * * @return The series. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ public YIntervalSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.data.get(series); } /** * 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 a series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ @Override public int getItemCount(int series) { // defer argument checking return getSeries(series).getItemCount(); } /** * Returns the x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getX(int series, int item) { YIntervalSeries s = this.data.get(series); return s.getX(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. */ @Override public double getYValue(int series, int item) { YIntervalSeries s = this.data.get(series); return s.getYValue(item); } /** * 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) { YIntervalSeries s = this.data.get(series); return s.getYLowValue(item); } /** * 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) { YIntervalSeries s = this.data.get(series); return s.getYHighValue(item); } /** * Returns the y-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The y-value. */ @Override public Number getY(int series, int item) { YIntervalSeries s = this.data.get(series); return s.getYValue(item); } /** * Returns the start x-value for an item within a series. This method * maps directly to {@link #getX(int, int)}. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getStartX(int series, int item) { return getX(series, item); } /** * Returns the end x-value for an item within a series. This method * maps directly to {@link #getX(int, int)}. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getEndX(int series, int item) { return getX(series, item); } /** * Returns the start y-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The start y-value. */ @Override public Number getStartY(int series, int item) { YIntervalSeries s = this.data.get(series); return s.getYLowValue(item); } /** * Returns the end y-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The end y-value. */ @Override public Number getEndY(int series, int item) { YIntervalSeries s = this.data.get(series); return s.getYHighValue(item); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * * @since 1.0.10 */ public void removeSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds."); } YIntervalSeries ts = this.data.get(series); ts.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @since 1.0.10 */ public void removeSeries(YIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.10 */ public void removeAllSeries() { // Unregister the collection as a change listener to each series in // the collection. for (YIntervalSeries series : this.data) { series.removeChangeListener(this); } this.data.clear(); fireDatasetChanged(); } /** * 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 YIntervalSeriesCollection)) { return false; } YIntervalSeriesCollection that = (YIntervalSeriesCollection) obj; return ObjectUtilities.equal(this.data, that.data); } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem. */ @Override public Object clone() throws CloneNotSupportedException { YIntervalSeriesCollection clone = (YIntervalSeriesCollection) super.clone(); clone.data = (List) ObjectUtilities.deepClone(this.data); return clone; } }
10,707
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYInterval.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYInterval.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.] * * --------------- * XYInterval.java * --------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import java.io.Serializable; /** * An xy-interval. This class is used internally by the * {@link XYIntervalDataItem} class. * * @since 1.0.3 */ public class XYInterval implements Serializable { /** The lower bound of the x-interval. */ private double xLow; /** The upper bound of the y-interval. */ private double xHigh; /** The y-value. */ private double y; /** The lower bound of the y-interval. */ private double yLow; /** The upper bound of the y-interval. */ private double yHigh; /** * Creates a new instance of <code>XYInterval</code>. * * @param xLow the lower bound of the x-interval. * @param xHigh the upper bound of the y-interval. * @param y the y-value. * @param yLow the lower bound of the y-interval. * @param yHigh the upper bound of the y-interval. */ public XYInterval(double xLow, double xHigh, double y, double yLow, double yHigh) { this.xLow = xLow; this.xHigh = xHigh; this.y = y; this.yLow = yLow; this.yHigh = yHigh; } /** * Returns the lower bound of the x-interval. * * @return The lower bound of the x-interval. */ public double getXLow() { return this.xLow; } /** * Returns the upper bound of the x-interval. * * @return The upper bound of the x-interval. */ public double getXHigh() { return this.xHigh; } /** * Returns the y-value. * * @return The y-value. */ public double getY() { return this.y; } /** * Returns the lower bound of the y-interval. * * @return The lower bound of the y-interval. */ public double getYLow() { return this.yLow; } /** * Returns the upper bound of the y-interval. * * @return The upper bound of the y-interval. */ public double getYHigh() { return this.yHigh; } /** * 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 XYInterval)) { return false; } XYInterval that = (XYInterval) obj; if (this.xLow != that.xLow) { return false; } if (this.xHigh != that.xHigh) { return false; } if (this.y != that.y) { return false; } if (this.yLow != that.yLow) { return false; } if (this.yHigh != that.yHigh) { return false; } return true; } }
4,337
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
NormalizedMatrixSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/NormalizedMatrixSeries.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.] * * --------------------------- * NormalizedMatrixSeries.java * --------------------------- * (C) Copyright 2003-2008, by Barak Naveh and Contributors. * * Original Author: Barak Naveh; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 10-Jul-2003 : Version 1 contributed by Barak Naveh (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.xy; /** * Represents a dense normalized matrix M[i,j] where each Mij item of the * matrix has a value (default is 0). When a matrix item is observed using * <code>getItem</code> method, it is normalized, that is, divided by the * total sum of all items. It can be also be scaled by setting a scale factor. */ public class NormalizedMatrixSeries extends MatrixSeries { /** The default scale factor. */ public static final double DEFAULT_SCALE_FACTOR = 1.0; /** * A factor that multiplies each item in this series when observed using * getItem method. */ private double m_scaleFactor = DEFAULT_SCALE_FACTOR; /** The sum of all items in this matrix */ private double m_totalSum; /** * Constructor for NormalizedMatrixSeries. * * @param name the series name. * @param rows the number of rows. * @param columns the number of columns. */ public NormalizedMatrixSeries(String name, int rows, int columns) { super(name, rows, columns); /* * we assum super is always initialized to all-zero matrix, so the * total sum should be 0 upon initialization. However, we set it to * Double.MIN_VALUE to get the same effect and yet avoid division by 0 * upon initialization. */ this.m_totalSum = Double.MIN_VALUE; } /** * Returns an item. * * @param itemIndex the index. * * @return The value. * * @see org.jfree.data.xy.MatrixSeries#getItem(int) */ @Override public Number getItem(int itemIndex) { int i = getItemRow(itemIndex); int j = getItemColumn(itemIndex); double mij = get(i, j) * this.m_scaleFactor; Number n = mij / this.m_totalSum; return n; } /** * Sets the factor that multiplies each item in this series when observed * using getItem mehtod. * * @param factor new factor to set. * * @see #DEFAULT_SCALE_FACTOR */ public void setScaleFactor(double factor) { this.m_scaleFactor = factor; // FIXME: this should generate a series change event } /** * Returns the factor that multiplies each item in this series when * observed using getItem mehtod. * * @return The factor */ public double getScaleFactor() { return this.m_scaleFactor; } /** * Updates the value of the specified item in this matrix series. * * @param i the row of the item. * @param j the column of the item. * @param mij the new value for the item. * * @see #get(int, int) */ @Override public void update(int i, int j, double mij) { this.m_totalSum -= get(i, j); this.m_totalSum += mij; super.update(i, j, mij); } /** * @see org.jfree.data.xy.MatrixSeries#zeroAll() */ @Override public void zeroAll() { this.m_totalSum = 0; super.zeroAll(); } }
4,672
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultIntervalXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultIntervalXYDataset.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.] * * ----------------------------- * DefaultIntervalXYDataset.java * ----------------------------- * (C) Copyright 2006-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 23-Oct-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); * 28-Nov-2006 : New override for clone() (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 10-Aug-2009 : Fixed typo in Javadocs - see bug 2830419 (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.ParamChecks; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DatasetChangeEvent; /** * A dataset that defines a range (interval) for both the x-values and the * y-values. This implementation uses six arrays to store the x, start-x, * end-x, y, start-y and end-y values. * <br><br> * An alternative implementation of the {@link IntervalXYDataset} interface * is provided by the {@link XYIntervalSeriesCollection} class. * * @since 1.0.3 */ public class DefaultIntervalXYDataset extends AbstractIntervalXYDataset implements 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>DefaultIntervalXYDataset</code> instance, initially * containing no data. */ public DefaultIntervalXYDataset() { 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 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> 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 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> 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[3][item]; } /** * Returns the starting 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 starting x-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getStartX(int, int) */ @Override public double getStartXValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[1][item]; } /** * Returns the ending 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 ending x-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getEndX(int, int) */ @Override public double getEndXValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[2][item]; } /** * Returns the starting 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 starting y-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getStartY(int, int) */ @Override public double getStartYValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[4][item]; } /** * Returns the ending 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 ending y-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getEndY(int, int) */ @Override public double getEndYValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[5][item]; } /** * Returns the ending 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 ending x-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getEndXValue(int, int) */ @Override public Number getEndX(int series, int item) { return getEndXValue(series, item); } /** * Returns the ending 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 ending y-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getEndYValue(int, int) */ @Override public Number getEndY(int series, int item) { return getEndYValue(series, item); } /** * Returns the starting 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 starting x-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getStartXValue(int, int) */ @Override public Number getStartX(int series, int item) { return getStartXValue(series, item); } /** * Returns the starting 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 starting y-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> is not * within the specified range. * * @see #getStartYValue(int, int) */ @Override public Number getStartY(int series, int item) { return getStartYValue(series, 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> 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> is not * within the specified range. * * @see #getYValue(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 6, containing six * arrays of equal length, the first three containing the x-values * (x, xLow and xHigh) and the last three containing the y-values * (y, yLow and yHigh)). */ public void addSeries(Comparable seriesKey, double[][] data) { ParamChecks.nullNotPermitted(seriesKey, "seriesKey"); ParamChecks.nullNotPermitted(seriesKey, "data"); if (data.length != 6) { throw new IllegalArgumentException( "The 'data' array must have length == 6."); } int length = data[0].length; if (length != data[1].length || length != data[2].length || length != data[3].length || length != data[4].length || length != data[5].length) { throw new IllegalArgumentException( "The 'data' array must contain six 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)); } /** * Tests this <code>DefaultIntervalXYDataset</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>DefaultIntervalXYDataset</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 DefaultIntervalXYDataset)) { return false; } DefaultIntervalXYDataset that = (DefaultIntervalXYDataset) 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[] d1xs = d1[1]; double[] d2xs = d2[1]; if (!Arrays.equals(d1xs, d2xs)) { return false; } double[] d1xe = d1[2]; double[] d2xe = d2[2]; if (!Arrays.equals(d1xe, d2xe)) { return false; } double[] d1y = d1[3]; double[] d2y = d2[3]; if (!Arrays.equals(d1y, d2y)) { return false; } double[] d1ys = d1[4]; double[] d2ys = d2[4]; if (!Arrays.equals(d1ys, d2ys)) { return false; } double[] d1ye = d1[5]; double[] d2ye = d2[5]; if (!Arrays.equals(d1ye, d2ye)) { 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; } /** * Returns a clone of this dataset. * * @return A clone. * * @throws CloneNotSupportedException if the dataset contains a series with * a key that cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { DefaultIntervalXYDataset clone = (DefaultIntervalXYDataset) 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[] xStart = data[1]; double[] xEnd = data[2]; double[] y = data[3]; double[] yStart = data[4]; double[] yEnd = data[5]; double[] xx = new double[x.length]; double[] xxStart = new double[xStart.length]; double[] xxEnd = new double[xEnd.length]; double[] yy = new double[y.length]; double[] yyStart = new double[yStart.length]; double[] yyEnd = new double[yEnd.length]; System.arraycopy(x, 0, xx, 0, x.length); System.arraycopy(xStart, 0, xxStart, 0, xStart.length); System.arraycopy(xEnd, 0, xxEnd, 0, xEnd.length); System.arraycopy(y, 0, yy, 0, y.length); System.arraycopy(yStart, 0, yyStart, 0, yStart.length); System.arraycopy(yEnd, 0, yyEnd, 0, yEnd.length); clone.seriesList.add(i, new double[][] {xx, xxStart, xxEnd, yy, yyStart, yyEnd}); } return clone; } }
18,528
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultTableXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultTableXYDataset.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.] * * -------------------------- * DefaultTableXYDataset.java * -------------------------- * (C) Copyright 2003-2012, by Richard Atkinson and Contributors. * * Original Author: Richard Atkinson; * Contributor(s): Jody Brownell; * David Gilbert (for Object Refinery Limited); * Andreas Schroeder; * * Changes: * -------- * 27-Jul-2003 : XYDataset that forces each series to have a value for every * X-point which is essential for stacked XY area charts (RA); * 18-Aug-2003 : Fixed event notification when removing and updating * series (RA); * 22-Sep-2003 : Functionality moved from TableXYDataset to * DefaultTableXYDataset (RA); * 23-Dec-2003 : Added patch for large datasets, submitted by Jody * Brownell (DG); * 16-Feb-2004 : Added pruning methods (DG); * 31-Mar-2004 : Provisional implementation of IntervalXYDataset (AS); * 01-Apr-2004 : Sound implementation of IntervalXYDataset (AS); * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * 05-Oct-2005 : Made the interval delegate a dataset listener (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 10-Jun-2009 : Simplified getX() and getY() (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DomainInfo; import org.jfree.data.Range; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.general.SeriesChangeEvent; /** * An {@link XYDataset} where every series shares the same x-values (required * for generating stacked area charts). */ public class DefaultTableXYDataset extends AbstractIntervalXYDataset implements TableXYDataset, IntervalXYDataset, DomainInfo, PublicCloneable { /** * Storage for the data - this list will contain zero, one or many * XYSeries objects. */ private List<XYSeries> data; /** Storage for the x values. */ private HashSet<Number> xPoints; /** A flag that controls whether or not events are propogated. */ private boolean propagateEvents = true; /** A flag that controls auto pruning. */ private boolean autoPrune = false; /** The delegate used to control the interval width. */ private IntervalXYDelegate intervalDelegate; /** * Creates a new empty dataset. */ public DefaultTableXYDataset() { this(false); } /** * Creates a new empty dataset. * * @param autoPrune a flag that controls whether or not x-values are * removed whenever the corresponding y-values are all * <code>null</code>. */ public DefaultTableXYDataset(boolean autoPrune) { this.autoPrune = autoPrune; this.data = new ArrayList<XYSeries>(); this.xPoints = new HashSet<Number>(); this.intervalDelegate = new IntervalXYDelegate(this, false); addChangeListener(this.intervalDelegate); } /** * Returns the flag that controls whether or not x-values are removed from * the dataset when the corresponding y-values are all <code>null</code>. * * @return A boolean. */ public boolean isAutoPrune() { return this.autoPrune; } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. The series should be configured to NOT * allow duplicate x-values. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(XYSeries series) { if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } if (series.getAllowDuplicateXValues()) { throw new IllegalArgumentException( "Cannot accept XYSeries that allow duplicate values. " + "Use XYSeries(seriesName, <sort>, false) constructor." ); } updateXPoints(series); this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Adds any unique x-values from 'series' to the dataset, and also adds any * x-values that are in the dataset but not in 'series' to the series. * * @param series the series (<code>null</code> not permitted). */ private void updateXPoints(XYSeries series) { if (series == null) { throw new IllegalArgumentException("Null 'series' not permitted."); } Set<Number> seriesXPoints = new HashSet<Number>(); boolean savedState = this.propagateEvents; this.propagateEvents = false; for (int itemNo = 0; itemNo < series.getItemCount(); itemNo++) { Number xValue = series.getX(itemNo); seriesXPoints.add(xValue); if (!this.xPoints.contains(xValue)) { this.xPoints.add(xValue); for (XYSeries dataSeries : this.data) { if (!dataSeries.equals(series)) { dataSeries.add(xValue, null); } } } } for (Number xPoint : this.xPoints) { if (!seriesXPoints.contains(xPoint)) { series.add(xPoint, null); } } this.propagateEvents = savedState; } /** * Updates the x-values for all the series in the dataset. */ public void updateXPoints() { this.propagateEvents = false; for (XYSeries aData : this.data) { updateXPoints(aData); } if (this.autoPrune) { prune(); } this.propagateEvents = true; } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns the number of x values in the dataset. * * @return The number of x values in the dataset. */ @Override public int getItemCount() { if (this.xPoints == null) { return 0; } else { return this.xPoints.size(); } } /** * Returns a series. * * @param series the series (zero-based index). * * @return The series (never <code>null</code>). */ public XYSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Index outside valid range."); } return this.data.get(series); } /** * Returns the key for a series. * * @param series the series (zero-based index). * * @return The key for a series. */ @Override public Comparable getSeriesKey(int series) { // check arguments...delegated return getSeries(series).getKey(); } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The number of items in the specified series. */ @Override public int getItemCount(int series) { // check arguments...delegated return getSeries(series).getItemCount(); } /** * Returns the x-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The x-value for the specified series and item. */ @Override public Number getX(int series, int item) { XYSeries s = this.data.get(series); return s.getX(item); } /** * Returns the starting X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param index the index of the item of interest (zero-based). * * @return The y-value for the specified series and item (possibly * <code>null</code>). */ @Override public Number getY(int series, int index) { XYSeries s = this.data.get(series); return s.getY(index); } /** * Returns the starting Y value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param item the item (zero-based index). * * @return The ending Y value. */ @Override public Number getEndY(int series, int item) { return getY(series, item); } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. */ public void removeAllSeries() { // Unregister the collection as a change listener to each series in // the collection. for (XYSeries series : this.data) { series.removeChangeListener(this); } // Remove all the series from the collection and notify listeners. this.data.clear(); this.xPoints.clear(); fireDatasetChanged(); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void removeSeries(XYSeries series) { // check arguments... if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } // remove the series... if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); if (this.data.size() == 0) { this.xPoints.clear(); } fireDatasetChanged(); } } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (zero based index). */ public void removeSeries(int series) { // check arguments... if ((series < 0) || (series > getSeriesCount())) { throw new IllegalArgumentException("Index outside valid range."); } // fetch the series, remove the change listener, then remove the series. XYSeries s = this.data.get(series); s.removeChangeListener(this); this.data.remove(series); if (this.data.size() == 0) { this.xPoints.clear(); } else if (this.autoPrune) { prune(); } fireDatasetChanged(); } /** * Removes the items from all series for a given x value. * * @param x the x-value. */ public void removeAllValuesForX(Number x) { if (x == null) { throw new IllegalArgumentException("Null 'x' argument."); } boolean savedState = this.propagateEvents; this.propagateEvents = false; for (XYSeries series : this.data) { series.remove(x); } this.propagateEvents = savedState; this.xPoints.remove(x); fireDatasetChanged(); } /** * Returns <code>true</code> if all the y-values for the specified x-value * are <code>null</code> and <code>false</code> otherwise. * * @param x the x-value. * * @return A boolean. */ protected boolean canPrune(Number x) { for (XYSeries series : this.data) { if (series.getY(series.indexOf(x)) != null) { return false; } } return true; } /** * Removes all x-values for which all the y-values are <code>null</code>. */ public void prune() { Set<Number> hs = (HashSet<Number>) this.xPoints.clone(); for (Number x : hs) { if (canPrune(x)) { removeAllValuesForX(x); } } } /** * This method receives notification when a series belonging to the dataset * changes. It responds by updating the x-points for the entire dataset * and sending a {@link DatasetChangeEvent} to all registered listeners. * * @param event information about the change. */ @Override public void seriesChanged(SeriesChangeEvent event) { if (this.propagateEvents) { updateXPoints(); fireDatasetChanged(); } } /** * Tests this collection 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 DefaultTableXYDataset)) { return false; } DefaultTableXYDataset that = (DefaultTableXYDataset) obj; if (this.autoPrune != that.autoPrune) { return false; } if (this.propagateEvents != that.propagateEvents) { return false; } if (!this.intervalDelegate.equals(that.intervalDelegate)) { 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; result = (this.data != null ? this.data.hashCode() : 0); result = 29 * result + (this.xPoints != null ? this.xPoints.hashCode() : 0); result = 29 * result + (this.propagateEvents ? 1 : 0); result = 29 * result + (this.autoPrune ? 1 : 0); return result; } /** * 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 { DefaultTableXYDataset clone = (DefaultTableXYDataset) super.clone(); int seriesCount = this.data.size(); clone.data = new java.util.ArrayList<XYSeries>(seriesCount); for (int i = 0; i < seriesCount; i++) { XYSeries series = this.data.get(i); clone.data.add((XYSeries)series.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()); clone.updateXPoints(); return clone; } /** * 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 A flag that determines whether or not the interval width is * automatically calculated. */ public boolean isAutoWidth() { return this.intervalDelegate.isAutoWidth(); } /** * Sets the flag that indicates whether the interval width is automatically * calculated or not. * * @param b a boolean. */ public void setAutoWidth(boolean b) { this.intervalDelegate.setAutoWidth(b); fireDatasetChanged(); } }
20,947
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDomainInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYDomainInfo.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.] * * ----------------- * XYDomainInfo.java * ----------------- * (C) Copyright 2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 27-Mar-2009 : Version 1 (DG); * */ package org.jfree.data.xy; import java.util.List; import org.jfree.data.Range; /** * An interface that can (optionally) be implemented by a dataset to assist in * determining the minimum and maximum x-values in the dataset. * * @since 1.0.13 */ public interface XYDomainInfo { /** * Returns the range of the values in this dataset's domain. * * @param visibleSeriesKeys the keys of the visible series * (<code>null</code> not permitted). * @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 getDomainBounds(List<Comparable> visibleSeriesKeys, boolean includeInterval); }
2,350
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IntervalXYDelegate.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/IntervalXYDelegate.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.] * * ----------------------- * IntervalXYDelegate.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); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * 04-Nov-2004 : Added argument check for setIntervalWidth() method (DG); * 17-Nov-2004 : New methods to reflect changes in DomainInfo (DG); * 11-Jan-2005 : Removed deprecated methods in preparation for the 1.0.0 * release (DG); * 21-Feb-2005 : Made public and added equals() method (DG); * 06-Oct-2005 : Implemented DatasetChangeListener to recalculate * autoIntervalWidth (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 06-Mar-2009 : Implemented hashCode() (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DomainInfo; import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.general.DatasetUtilities; /** * A delegate that handles the specification or automatic calculation of the * interval surrounding the x-values in a dataset. This is used to extend * a regular {@link XYDataset} to support the {@link IntervalXYDataset} * interface. * <p> * The decorator pattern was not used because of the several possibly * implemented interfaces of the decorated instance (e.g. * {@link TableXYDataset}, {@link RangeInfo}, {@link DomainInfo} etc.). * <p> * The width can be set manually or calculated automatically. The switch * autoWidth allows to determine which behavior is used. The auto width * calculation tries to find the smallest gap between two x-values in the * dataset. If there is only one item in the series, the auto width * calculation fails and falls back on the manually set interval width (which * is itself defaulted to 1.0). */ public class IntervalXYDelegate implements DatasetChangeListener, DomainInfo, Serializable, Cloneable, PublicCloneable { /** For serialization. */ private static final long serialVersionUID = -685166711639592857L; /** * The dataset to enhance. */ private XYDataset dataset; /** * A flag to indicate whether the width should be calculated automatically. */ private boolean autoWidth; /** * A value between 0.0 and 1.0 that indicates the position of the x-value * within the interval. */ private double intervalPositionFactor; /** * The fixed interval width (defaults to 1.0). */ private double fixedIntervalWidth; /** * The automatically calculated interval width. */ private double autoIntervalWidth; /** * Creates a new delegate that. * * @param dataset the underlying dataset (<code>null</code> not permitted). */ public IntervalXYDelegate(XYDataset dataset) { this(dataset, true); } /** * Creates a new delegate for the specified dataset. * * @param dataset the underlying dataset (<code>null</code> not permitted). * @param autoWidth a flag that controls whether the interval width is * calculated automatically. */ public IntervalXYDelegate(XYDataset dataset, boolean autoWidth) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } this.dataset = dataset; this.autoWidth = autoWidth; this.intervalPositionFactor = 0.5; this.autoIntervalWidth = Double.POSITIVE_INFINITY; this.fixedIntervalWidth = 1.0; } /** * Returns <code>true</code> if the interval width is automatically * calculated, and <code>false</code> otherwise. * * @return A boolean. */ public boolean isAutoWidth() { return this.autoWidth; } /** * Sets the flag that indicates whether the interval width is automatically * calculated. If the flag is set to <code>true</code>, the interval is * recalculated. * <p> * Note: recalculating the interval amounts to changing the data values * represented by the dataset. The calling dataset must fire an * appropriate {@link DatasetChangeEvent}. * * @param b a boolean. */ public void setAutoWidth(boolean b) { this.autoWidth = b; if (b) { this.autoIntervalWidth = recalculateInterval(); } } /** * Returns the interval position factor. * * @return The interval position factor. */ public double getIntervalPositionFactor() { return this.intervalPositionFactor; } /** * Sets the interval position factor. This controls how the interval is * aligned to the x-value. For a value of 0.5, the interval is aligned * with the x-value in the center. For a value of 0.0, the interval is * aligned with the x-value at the lower end of the interval, and for a * value of 1.0, the interval is aligned with the x-value at the upper * end of the interval. * <br><br> * Note that changing the interval position factor amounts to changing the * data values represented by the dataset. Therefore, the dataset that is * using this delegate is responsible for generating the * appropriate {@link DatasetChangeEvent}. * * @param d the new interval position factor (in the range * <code>0.0</code> to <code>1.0</code> inclusive). */ public void setIntervalPositionFactor(double d) { if (d < 0.0 || 1.0 < d) { throw new IllegalArgumentException( "Argument 'd' outside valid range."); } this.intervalPositionFactor = d; } /** * Returns the fixed interval width. * * @return The fixed interval width. */ public double getFixedIntervalWidth() { return this.fixedIntervalWidth; } /** * Sets the fixed interval width and, as a side effect, sets the * <code>autoWidth</code> flag to <code>false</code>. * <br><br> * Note that changing the interval width amounts to changing the data * values represented by the dataset. Therefore, the dataset * that is using this delegate is responsible for generating the * appropriate {@link DatasetChangeEvent}. * * @param w the width (negative values not permitted). */ public void setFixedIntervalWidth(double w) { if (w < 0.0) { throw new IllegalArgumentException("Negative 'w' argument."); } this.fixedIntervalWidth = w; this.autoWidth = false; } /** * Returns the interval width. This method will return either the * auto calculated interval width or the manually specified interval * width, depending on the {@link #isAutoWidth()} result. * * @return The interval width to use. */ public double getIntervalWidth() { if (isAutoWidth() && !Double.isInfinite(this.autoIntervalWidth)) { // everything is fine: autoWidth is on, and an autoIntervalWidth // was set. return this.autoIntervalWidth; } else { // either autoWidth is off or autoIntervalWidth was not set. return this.fixedIntervalWidth; } } /** * Returns the start value of the x-interval for an item within a series. * * @param series the series index. * @param item the item index. * * @return The start value of the x-interval (possibly <code>null</code>). * * @see #getStartXValue(int, int) */ public Number getStartX(int series, int item) { Number startX = null; Number x = this.dataset.getX(series, item); if (x != null) { startX = x.doubleValue() - (getIntervalPositionFactor() * getIntervalWidth()); } return startX; } /** * Returns the start value of the x-interval for an item within a series. * * @param series the series index. * @param item the item index. * * @return The start value of the x-interval. * * @see #getStartX(int, int) */ public double getStartXValue(int series, int item) { return this.dataset.getXValue(series, item) - getIntervalPositionFactor() * getIntervalWidth(); } /** * Returns the end value of the x-interval for an item within a series. * * @param series the series index. * @param item the item index. * * @return The end value of the x-interval (possibly <code>null</code>). * * @see #getEndXValue(int, int) */ public Number getEndX(int series, int item) { Number endX = null; Number x = this.dataset.getX(series, item); if (x != null) { endX = x.doubleValue() + ((1.0 - getIntervalPositionFactor()) * getIntervalWidth()); } return endX; } /** * Returns the end value of the x-interval for an item within a series. * * @param series the series index. * @param item the item index. * * @return The end value of the x-interval. * * @see #getEndX(int, int) */ public double getEndXValue(int series, int item) { return this.dataset.getXValue(series, item) + (1.0 - getIntervalPositionFactor()) * getIntervalWidth(); } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getLowerBound(); } return result; } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getUpperBound(); } return result; } /** * Returns the range of the values in the dataset's domain, including * or excluding the interval around each x-value as specified. * * @param includeInterval a flag that determines whether or not the * x-interval should be taken into account. * * @return The range. */ @Override public Range getDomainBounds(boolean includeInterval) { // first get the range without the interval, then expand it for the // interval width Range range = DatasetUtilities.findDomainBounds(this.dataset, false); if (includeInterval && range != null) { double lowerAdj = getIntervalWidth() * getIntervalPositionFactor(); double upperAdj = getIntervalWidth() - lowerAdj; range = new Range(range.getLowerBound() - lowerAdj, range.getUpperBound() + upperAdj); } return range; } /** * Handles events from the dataset by recalculating the interval if * necessary. * * @param e the event. */ @Override public void datasetChanged(DatasetChangeEvent e) { // TODO: by coding the event with some information about what changed // in the dataset, we could make the recalculation of the interval // more efficient in some cases (for instance, if the change is // just an update to a y-value, then the x-interval doesn't need // updating)... if (this.autoWidth) { this.autoIntervalWidth = recalculateInterval(); } } /** * Recalculate the minimum width "from scratch". * * @return The minimum width. */ private double recalculateInterval() { double result = Double.POSITIVE_INFINITY; int seriesCount = this.dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { result = Math.min(result, calculateIntervalForSeries(series)); } return result; } /** * Calculates the interval width for a given series. * * @param series the series index. * * @return The interval width. */ private double calculateIntervalForSeries(int series) { double result = Double.POSITIVE_INFINITY; int itemCount = this.dataset.getItemCount(series); if (itemCount > 1) { double prev = this.dataset.getXValue(series, 0); for (int item = 1; item < itemCount; item++) { double x = this.dataset.getXValue(series, item); result = Math.min(result, x - prev); prev = x; } } return result; } /** * Tests the delegate for equality with an arbitrary object. The * equality test considers two delegates to be equal if they would * calculate the same intervals for any given dataset (for this reason, the * dataset itself is NOT included in the equality test, because it is just * a reference back to the current 'owner' of the delegate). * * @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 IntervalXYDelegate)) { return false; } IntervalXYDelegate that = (IntervalXYDelegate) obj; if (this.autoWidth != that.autoWidth) { return false; } if (this.intervalPositionFactor != that.intervalPositionFactor) { return false; } if (this.fixedIntervalWidth != that.fixedIntervalWidth) { return false; } return true; } /** * @return A clone of this delegate. * * @throws CloneNotSupportedException if the object cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int hash = 5; hash = HashUtilities.hashCode(hash, this.autoWidth); hash = HashUtilities.hashCode(hash, this.intervalPositionFactor); hash = HashUtilities.hashCode(hash, this.fixedIntervalWidth); return hash; } }
16,641
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YIntervalSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/YIntervalSeries.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.] * * -------------------- * YIntervalSeries.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); * 20-Feb-2007 : Added getYHighValue() and getYLowValue() methods (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; import org.jfree.data.ComparableObjectSeries; /** * A list of (x, y, y-low, y-high) data items. * * @since 1.0.3 * * @see YIntervalSeriesCollection */ public class YIntervalSeries 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 YIntervalSeries(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 YIntervalSeries(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 yLow the lower bound of the y-interval. * @param yHigh the upper bound of the y-interval. */ public void add(double x, double y, double yLow, double yHigh) { super.add(new YIntervalDataItem(x, y, yLow, yHigh), 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) { YIntervalDataItem item = (YIntervalDataItem) getDataItem(index); return item.getX(); } /** * Returns the y-value for the specified item. * * @param index the item index. * * @return The y-value. */ public double getYValue(int index) { YIntervalDataItem item = (YIntervalDataItem) getDataItem(index); return item.getYValue(); } /** * Returns the lower bound of the Y-interval for the specified item in the * series. * * @param index the item index. * * @return The lower bound of the Y-interval. * * @since 1.0.5 */ public double getYLowValue(int index) { YIntervalDataItem item = (YIntervalDataItem) getDataItem(index); return item.getYLowValue(); } /** * Returns the upper bound of the y-interval for the specified item in the * series. * * @param index the item index. * * @return The upper bound of the y-interval. * * @since 1.0.5 */ public double getYHighValue(int index) { YIntervalDataItem item = (YIntervalDataItem) getDataItem(index); return item.getYHighValue(); } /** * 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); } }
5,001
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YWithXInterval.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/YWithXInterval.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.] * * ------------------- * YWithXInterval.java * ------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import java.io.Serializable; /** * A y-value plus the bounds for the related x-interval. This curious * combination exists as an implementation detail, to fit into the structure * of the ComparableObjectSeries class. It would have been possible to * simply reuse the {@link YInterval} class by assuming that the y-interval * in fact represents the x-interval, however I decided it was better to * duplicate some code in order to document the real intent. * * @since 1.0.3 */ public class YWithXInterval implements Serializable { /** The y-value. */ private double y; /** The lower bound of the x-interval. */ private double xLow; /** The upper bound of the x-interval. */ private double xHigh; /** * Creates a new instance of <code>YWithXInterval</code>. * * @param y the y-value. * @param xLow the lower bound of the x-interval. * @param xHigh the upper bound of the x-interval. */ public YWithXInterval(double y, double xLow, double xHigh) { this.y = y; this.xLow = xLow; this.xHigh = xHigh; } /** * Returns the y-value. * * @return The y-value. */ public double getY() { return this.y; } /** * Returns the lower bound of the x-interval. * * @return The lower bound of the x-interval. */ public double getXLow() { return this.xLow; } /** * Returns the upper bound of the x-interval. * * @return The upper bound of the x-interval. */ public double getXHigh() { return this.xHigh; } /** * 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 YWithXInterval)) { return false; } YWithXInterval that = (YWithXInterval) obj; if (this.y != that.y) { return false; } if (this.xLow != that.xLow) { return false; } if (this.xHigh != that.xHigh) { return false; } return true; } }
3,835
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XIntervalDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XIntervalDataItem.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.] * * ---------------------- * XIntervalDataItem.java * ---------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; /** * An item representing data in the form (x, x-low, x-high, y). * * @since 1.0.3 */ public class XIntervalDataItem extends ComparableObjectItem { /** * Creates a new instance of <code>XIntervalDataItem</code>. * * @param x the x-value. * @param xLow the lower bound of the x-interval. * @param xHigh the upper bound of the x-interval. * @param y the y-value. */ public XIntervalDataItem(double x, double xLow, double xHigh, double y) { super(x, new YWithXInterval(y, xLow, xHigh)); } /** * Returns the x-value. * * @return The x-value (never <code>null</code>). */ public Number getX() { return (Number) getComparable(); } /** * Returns the y-value. * * @return The y-value. */ public double getYValue() { YWithXInterval interval = (YWithXInterval) getObject(); if (interval != null) { return interval.getY(); } else { return Double.NaN; } } /** * Returns the lower bound of the x-interval. * * @return The lower bound of the x-interval. */ public double getXLowValue() { YWithXInterval interval = (YWithXInterval) getObject(); if (interval != null) { return interval.getXLow(); } else { return Double.NaN; } } /** * Returns the upper bound of the x-interval. * * @return The upper bound of the x-interval. */ public double getXHighValue() { YWithXInterval interval = (YWithXInterval) getObject(); if (interval != null) { return interval.getXHigh(); } else { return Double.NaN; } } }
3,374
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/VectorSeries.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.] * * ----------------- * VectorSeries.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 : Renamed getDeltaXValue() --> getVectorXValue(), and likewise * for getDeltaYValue() (DG); * 25-May-2007 : Added remove(int) and clear() methods, and moved from the * experimental to the main source tree (DG); * 27-Nov-2007 : Removed redundant clear() method (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; import org.jfree.data.ComparableObjectSeries; import org.jfree.data.general.SeriesChangeEvent; /** * A list of (x,y, deltaX, deltaY) data items. * * @since 1.0.6 * * @see VectorSeriesCollection */ public class VectorSeries extends ComparableObjectSeries { /** * Creates a new empty series. * * @param key the series key (<code>null</code> not permitted). */ public VectorSeries(Comparable key) { this(key, false, 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 VectorSeries(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 deltaX the vector x. * @param deltaY the vector y. */ public void add(double x, double y, double deltaX, double deltaY) { super.add(new VectorDataItem(x, y, deltaX, deltaY), true); } /** * Removes the item at the specified index and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the index. * * @return The item removed. */ @Override public ComparableObjectItem remove(int index) { VectorDataItem result = (VectorDataItem) this.data.remove(index); fireSeriesChanged(); return result; } /** * Returns the x-value for the specified item. * * @param index the item index. * * @return The x-value. */ public double getXValue(int index) { VectorDataItem item = (VectorDataItem) this.getDataItem(index); return item.getXValue(); } /** * Returns the y-value for the specified item. * * @param index the item index. * * @return The y-value. */ public double getYValue(int index) { VectorDataItem item = (VectorDataItem) getDataItem(index); return item.getYValue(); } /** * Returns the x-component of the vector for an item in the series. * * @param index the item index. * * @return The x-component of the vector. */ public double getVectorXValue(int index) { VectorDataItem item = (VectorDataItem) getDataItem(index); return item.getVectorX(); } /** * Returns the y-component of the vector for an item in the series. * * @param index the item index. * * @return The y-component of the vector. */ public double getVectorYValue(int index) { VectorDataItem item = (VectorDataItem) getDataItem(index); return item.getVectorY(); } /** * Returns the data item at the specified index. * * @param index the item index. * * @return The data item. */ @Override public ComparableObjectItem getDataItem(int index) { // overridden to make public return super.getDataItem(index); } }
5,345
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYSeriesCollection.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.] * * ----------------------- * XYSeriesCollection.java * ----------------------- * (C) Copyright 2001-2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Aaron Metzger; * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 03-Apr-2002 : Added change listener code (DG); * 29-Apr-2002 : Added removeSeries, removeAllSeries methods (ARM); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 04-Aug-2003 : Added getSeries() method (DG); * 31-Mar-2004 : Modified to use an XYIntervalDelegate. * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * 17-Nov-2004 : Updated for changes to DomainInfo interface (DG); * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); * 28-Mar-2005 : Fixed bug in getSeries(int) method (1170825) (DG); * 05-Oct-2005 : Made the interval delegate a dataset listener (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 27-Nov-2006 : Added clone() override (DG); * 08-May-2007 : Added indexOf(XYSeries) method (DG); * 03-Dec-2007 : Added getSeries(Comparable) method (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 27-Feb-2009 : Overridden getDomainOrder() to detect when all series are * sorted in ascending order (DG); * 06-Mar-2009 : Implemented RangeInfo (DG); * 06-Mar-2009 : Fixed equals() implementation (DG); * 10-Jun-2009 : Simplified code in getX() and getY() methods (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.io.Serializable; import java.util.Collections; import java.util.List; import org.jfree.chart.HashUtilities; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.ParamChecks; import org.jfree.data.DomainInfo; import org.jfree.data.DomainOrder; import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.UnknownKeyException; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.Series; /** * Represents a collection of {@link XYSeries} objects that can be used as a * dataset. */ public class XYSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, DomainInfo, RangeInfo, VetoableChangeListener, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -7590013825931496766L; /** The series that are included in the collection. */ private List<XYSeries> data; /** The interval delegate (used to calculate the start and end x-values). */ private IntervalXYDelegate intervalDelegate; /** * Constructs an empty dataset. */ public XYSeriesCollection() { this(null); } /** * Constructs a dataset and populates it with a single series. * * @param series the series (<code>null</code> ignored). */ public XYSeriesCollection(XYSeries series) { this.data = new java.util.ArrayList<XYSeries>(); this.intervalDelegate = new IntervalXYDelegate(this, false); addChangeListener(this.intervalDelegate); if (series != null) { this.data.add(series); series.addChangeListener(this); series.addVetoableChangeListener(this); } } /** * Returns the order of the domain (X) values, if this is known. * * @return The domain order. */ @Override public DomainOrder getDomainOrder() { int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { XYSeries s = getSeries(i); if (!s.getAutoSort()) { return DomainOrder.NONE; // we can't be sure of the order } } return DomainOrder.ASCENDING; } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @throws IllegalArgumentException if the key for the series is null or * not unique within the dataset. */ public void addSeries(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (getSeriesIndex(series.getKey()) >= 0) { throw new IllegalArgumentException( "This dataset already contains a series with the key " + series.getKey()); } this.data.add(series); series.addChangeListener(this); series.addVetoableChangeListener(this); fireDatasetChanged(); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series index (zero-based). */ public void removeSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds."); } XYSeries s = this.data.get(series); if (s != null) { removeSeries(s); } } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void removeSeries(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); series.removeVetoableChangeListener(this); this.data.remove(series); fireDatasetChanged(); } } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. */ public void removeAllSeries() { // Unregister the collection as a change listener to each series in // the collection. for (XYSeries series : this.data) { series.removeChangeListener(this); series.removeVetoableChangeListener(this); } this.data.clear(); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a list of all the series in the collection. * * @return The list (which is unmodifiable). */ public List<XYSeries> getSeries() { return Collections.unmodifiableList(this.data); } /** * Returns the index of the specified series, or -1 if that series is not * present in the dataset. * * @param series the series (<code>null</code> not permitted). * * @return The series index. * * @since 1.0.6 */ public int indexOf(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); return this.data.indexOf(series); } /** * Returns a series from the collection. * * @param series the series index (zero-based). * * @return The series. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ public XYSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.data.get(series); } /** * Returns a series from the collection. * * @param key the key (<code>null</code> not permitted). * * @return The series with the specified key. * * @throws UnknownKeyException if <code>key</code> is not found in the * collection. * * @since 1.0.9 */ public XYSeries getSeries(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); for (XYSeries series: this.data) { if (key.equals(series.getKey())) { return series; } } throw new UnknownKeyException("Key not found: " + key); } /** * 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 a series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Returns the index of the series with the specified key, or -1 if no * series has that key. * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.14 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { XYSeries series = this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ @Override public int getItemCount(int series) { // defer argument checking return getSeries(series).getItemCount(); } /** * Returns the x-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ @Override public Number getX(int series, int item) { XYSeries s = this.data.get(series); return s.getX(item); } /** * Returns the starting X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param index the index of the item of interest (zero-based). * * @return The value (possibly <code>null</code>). */ @Override public Number getY(int series, int index) { XYSeries s = this.data.get(series); return s.getY(index); } /** * Returns the starting Y value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param item the item (zero-based index). * * @return The ending Y value. */ @Override public Number getEndY(int series, int item) { return getY(series, item); } /** * Tests this collection 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 XYSeriesCollection)) { return false; } XYSeriesCollection that = (XYSeriesCollection) obj; if (!this.intervalDelegate.equals(that.intervalDelegate)) { return false; } return ObjectUtilities.equal(this.data, that.data); } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem. */ @Override public Object clone() throws CloneNotSupportedException { XYSeriesCollection clone = (XYSeriesCollection) super.clone(); clone.data = (List) ObjectUtilities.deepClone(this.data); clone.intervalDelegate = (IntervalXYDelegate) this.intervalDelegate.clone(); return clone; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int hash = 5; hash = HashUtilities.hashCode(hash, this.intervalDelegate); hash = HashUtilities.hashCode(hash, this.data); return hash; } /** * 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) { if (includeInterval) { return this.intervalDelegate.getDomainLowerBound(includeInterval); } double result = Double.NaN; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double lowX = series.getMinX(); if (Double.isNaN(result)) { result = lowX; } else { if (!Double.isNaN(lowX)) { result = Math.min(result, lowX); } } } return result; } /** * 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) { if (includeInterval) { return this.intervalDelegate.getDomainUpperBound(includeInterval); } else { double result = Double.NaN; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double hiX = series.getMaxX(); if (Double.isNaN(result)) { result = hiX; } else { if (!Double.isNaN(hiX)) { result = Math.max(result, hiX); } } } return result; } } /** * 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). */ @Override public Range getDomainBounds(boolean includeInterval) { if (includeInterval) { return this.intervalDelegate.getDomainBounds(includeInterval); } else { double lower = Double.POSITIVE_INFINITY; double upper = Double.NEGATIVE_INFINITY; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double minX = series.getMinX(); if (!Double.isNaN(minX)) { lower = Math.min(lower, minX); } double maxX = series.getMaxX(); if (!Double.isNaN(maxX)) { upper = Math.max(upper, maxX); } } if (lower > upper) { return null; } else { return new Range(lower, upper); } } } /** * Returns the interval width. This is used to calculate the start and end * x-values, if/when the dataset is used as an {@link IntervalXYDataset}. * * @return The interval width. */ public double getIntervalWidth() { return this.intervalDelegate.getIntervalWidth(); } /** * Sets the interval width and sends a {@link DatasetChangeEvent} to all * registered listeners. * * @param width the width (negative values not permitted). */ public void setIntervalWidth(double width) { if (width < 0.0) { throw new IllegalArgumentException("Negative 'width' argument."); } this.intervalDelegate.setFixedIntervalWidth(width); fireDatasetChanged(); } /** * Returns the interval position factor. * * @return The interval position factor. */ public double getIntervalPositionFactor() { return this.intervalDelegate.getIntervalPositionFactor(); } /** * Sets the interval position factor. This controls where the x-value is in * relation to the interval surrounding the x-value (0.0 means the x-value * will be positioned at the start, 0.5 in the middle, and 1.0 at the end). * * @param factor the factor. */ public void setIntervalPositionFactor(double factor) { this.intervalDelegate.setIntervalPositionFactor(factor); 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 a boolean. */ public void setAutoWidth(boolean b) { this.intervalDelegate.setAutoWidth(b); fireDatasetChanged(); } /** * Returns the range of the values in this dataset's range. * * @param includeInterval ignored. * * @return The range (or <code>null</code> if the dataset contains no * values). */ @Override public Range getRangeBounds(boolean includeInterval) { double lower = Double.POSITIVE_INFINITY; double upper = Double.NEGATIVE_INFINITY; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double minY = series.getMinY(); if (!Double.isNaN(minY)) { lower = Math.min(lower, minY); } double maxY = series.getMaxY(); if (!Double.isNaN(maxY)) { upper = Math.max(upper, maxY); } } if (lower > upper) { return null; } else { return new Range(lower, upper); } } /** * 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) { double result = Double.NaN; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double lowY = series.getMinY(); if (Double.isNaN(result)) { result = lowY; } else { if (!Double.isNaN(lowY)) { result = Math.min(result, lowY); } } } return result; } /** * 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) { double result = Double.NaN; int seriesCount = getSeriesCount(); for (int s = 0; s < seriesCount; s++) { XYSeries series = getSeries(s); double hiY = series.getMaxY(); if (Double.isNaN(result)) { result = hiY; } else { if (!Double.isNaN(hiY)) { result = Math.max(result, hiY); } } } return result; } /** * Receives notification that the key for one of the series in the * collection has changed, and vetos it if the key is already present in * the collection. * * @param e the event. * * @since 1.0.14 */ @Override public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException { // if it is not the series name, then we have no interest if (!"Key".equals(e.getPropertyName())) { return; } // to be defensive, let's check that the source series does in fact // belong to this collection Series s = (Series) e.getSource(); if (getSeriesIndex(s.getKey()) == -1) { throw new IllegalStateException("Receiving events from a series " + "that does not belong to this collection."); } // check if the new series name already exists for another series Comparable key = (Comparable) e.getNewValue(); if (getSeriesIndex(key) >= 0) { throw new PropertyVetoException("Duplicate key", e); } } }
23,946
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YIntervalDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/YIntervalDataItem.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.] * * ---------------------- * YIntervalDataItem.java * ---------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import org.jfree.data.ComparableObjectItem; /** * An item representing data in the form (x, y, y-low, y-high). * * @since 1.0.3 */ public class YIntervalDataItem extends ComparableObjectItem { /** * Creates a new instance of <code>YIntervalItem</code>. * * @param x the x-value. * @param y the y-value. * @param yLow the lower bound of the y-interval. * @param yHigh the upper bound of the y-interval. */ public YIntervalDataItem(double x, double y, double yLow, double yHigh) { super(x, new YInterval(y, yLow, yHigh)); } /** * Returns the x-value. * * @return The x-value (never <code>null</code>). */ public Double getX() { return (Double) getComparable(); } /** * Returns the y-value. * * @return The y-value. */ public double getYValue() { YInterval interval = (YInterval) getObject(); if (interval != null) { return interval.getY(); } else { return Double.NaN; } } /** * Returns the lower bound of the y-interval. * * @return The lower bound of the y-interval. */ public double getYLowValue() { YInterval interval = (YInterval) getObject(); if (interval != null) { return interval.getYLow(); } else { return Double.NaN; } } /** * Returns the upper bound of the y-interval. * * @return The upper bound of the y-interval. */ public double getYHighValue() { YInterval interval = (YInterval) getObject(); if (interval != null) { return interval.getYHigh(); } else { return Double.NaN; } } }
3,335
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultOHLCDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultOHLCDataset.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.] * * ----------------------- * DefaultOHLCDataset.java * ----------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Dec-2003 : Version 1 (DG); * 05-May-2004 : Now extends AbstractXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 29-Apr-2005 : Added equals() method (DG); * 22-Apr-2008 : Implemented PublicCloneable, and fixed cloning bug (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.util.Arrays; import java.util.Date; import org.jfree.chart.util.PublicCloneable; /** * A simple implementation of the {@link OHLCDataset} interface. This * implementation supports only one series. */ public class DefaultOHLCDataset extends AbstractXYDataset implements OHLCDataset, PublicCloneable { /** The series key. */ private Comparable key; /** Storage for the data items. */ private OHLCDataItem[] data; /** * Creates a new dataset. * * @param key the series key. * @param data the data items. */ public DefaultOHLCDataset(Comparable key, OHLCDataItem[] data) { this.key = key; this.data = data; } /** * Returns the series key. * * @param series the series index (ignored). * * @return The series key. */ @Override public Comparable getSeriesKey(int series) { return this.key; } /** * Returns the x-value for a data item. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The x-value. */ @Override public Number getX(int series, int item) { return this.data[item].getDate().getTime(); } /** * Returns the x-value for a data item as a date. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The x-value as a date. */ public Date getXDate(int series, int item) { return this.data[item].getDate(); } /** * Returns the y-value. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The y value. */ @Override public Number getY(int series, int item) { return getClose(series, item); } /** * Returns the high value. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The high value. */ @Override public Number getHigh(int series, int item) { return this.data[item].getHigh(); } /** * Returns the high-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 high-value. */ @Override public double getHighValue(int series, int item) { double result = Double.NaN; Number high = getHigh(series, item); if (high != null) { result = high.doubleValue(); } return result; } /** * Returns the low value. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The low value. */ @Override public Number getLow(int series, int item) { return this.data[item].getLow(); } /** * Returns the low-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 low-value. */ @Override public double getLowValue(int series, int item) { double result = Double.NaN; Number low = getLow(series, item); if (low != null) { result = low.doubleValue(); } return result; } /** * Returns the open value. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The open value. */ @Override public Number getOpen(int series, int item) { return this.data[item].getOpen(); } /** * Returns the open-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 open-value. */ @Override public double getOpenValue(int series, int item) { double result = Double.NaN; Number open = getOpen(series, item); if (open != null) { result = open.doubleValue(); } return result; } /** * Returns the close value. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The close value. */ @Override public Number getClose(int series, int item) { return this.data[item].getClose(); } /** * Returns the close-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 close-value. */ @Override public double getCloseValue(int series, int item) { double result = Double.NaN; Number close = getClose(series, item); if (close != null) { result = close.doubleValue(); } return result; } /** * Returns the trading volume. * * @param series the series index (ignored). * @param item the item index (zero-based). * * @return The trading volume. */ @Override public Number getVolume(int series, int item) { return this.data[item].getVolume(); } /** * Returns the volume-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 volume-value. */ @Override public double getVolumeValue(int series, int item) { double result = Double.NaN; Number volume = getVolume(series, item); if (volume != null) { result = volume.doubleValue(); } return result; } /** * Returns the series count. * * @return 1. */ @Override public int getSeriesCount() { return 1; } /** * Returns the item count for the specified series. * * @param series the series index (ignored). * * @return The item count. */ @Override public int getItemCount(int series) { return this.data.length; } /** * Sorts the data into ascending order by date. */ public void sortDataByDate() { Arrays.sort(this.data); } /** * 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 (this == obj) { return true; } if (!(obj instanceof DefaultOHLCDataset)) { return false; } DefaultOHLCDataset that = (DefaultOHLCDataset) obj; if (!this.key.equals(that.key)) { return false; } if (!Arrays.equals(this.data, that.data)) { return false; } return true; } /** * Returns an independent copy of this dataset. * * @return A clone. * * @throws CloneNotSupportedException */ @Override public Object clone() throws CloneNotSupportedException { DefaultOHLCDataset clone = (DefaultOHLCDataset) super.clone(); clone.data = new OHLCDataItem[this.data.length]; System.arraycopy(this.data, 0, clone.data, 0, this.data.length); return clone; } }
9,502
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractXYZDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/AbstractXYZDataset.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.] * * ----------------------- * AbstractXYZDataset.java * ----------------------- * (C) Copyright 2004-2012, 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 getZ() and getZValue() (DG); * */ package org.jfree.data.xy; /** * An base class that you can use to create new implementations of the * {@link XYZDataset} interface. */ public abstract class AbstractXYZDataset extends AbstractXYDataset implements XYZDataset { /** * Returns the z-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 z-value. */ @Override public double getZValue(int series, int item) { double result = Double.NaN; Number z = getZ(series, item); if (z != null) { result = z.doubleValue(); } return result; } }
2,301
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/OHLCDataItem.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.] * * ----------------- * OHLCDataItem.java * ----------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Dec-2003 : Version 1 (DG); * 29-Apr-2005 : Added equals() method (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.Date; /** * Represents a single (open-high-low-close) data item in * an {@link DefaultOHLCDataset}. This data item is commonly used * to summarise the trading activity of a financial commodity for * a fixed period (most often one day). */ public class OHLCDataItem implements Comparable, Serializable { /** For serialization. */ private static final long serialVersionUID = 7753817154401169901L; /** The date. */ private Date date; /** The open value. */ private Number open; /** The high value. */ private Number high; /** The low value. */ private Number low; /** The close value. */ private Number close; /** The trading volume (number of shares, contracts or whatever). */ private Number volume; /** * Creates a new item. * * @param date the date (<code>null</code> not permitted). * @param open the open value. * @param high the high value. * @param low the low value. * @param close the close value. * @param volume the volume. */ public OHLCDataItem(Date date, double open, double high, double low, double close, double volume) { if (date == null) { throw new IllegalArgumentException("Null 'date' argument."); } this.date = date; this.open = open; this.high = high; this.low = low; this.close = close; this.volume = volume; } /** * Returns the date that the data item relates to. * * @return The date (never <code>null</code>). */ public Date getDate() { return this.date; } /** * Returns the open value. * * @return The open value. */ public Number getOpen() { return this.open; } /** * Returns the high value. * * @return The high value. */ public Number getHigh() { return this.high; } /** * Returns the low value. * * @return The low value. */ public Number getLow() { return this.low; } /** * Returns the close value. * * @return The close value. */ public Number getClose() { return this.close; } /** * Returns the volume. * * @return The volume. */ public Number getVolume() { return this.volume; } /** * Checks 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 OHLCDataItem)) { return false; } OHLCDataItem that = (OHLCDataItem) obj; if (!this.date.equals(that.date)) { return false; } if (!this.high.equals(that.high)) { return false; } if (!this.low.equals(that.low)) { return false; } if (!this.open.equals(that.open)) { return false; } if (!this.close.equals(that.close)) { return false; } return true; } /** * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. * * @param object the object to compare to. * * @return A negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ @Override public int compareTo(Object object) { if (object instanceof OHLCDataItem) { OHLCDataItem item = (OHLCDataItem) object; return this.date.compareTo(item.date); } else { throw new ClassCastException("OHLCDataItem.compareTo()."); } } }
5,737
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IntervalXYZDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/IntervalXYZDataset.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.] * * ----------------------- * IntervalXYZDataset.java * ----------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 31-Oct-2001 : Version 1 (DG); * */ package org.jfree.data.xy; /** * An extension of the {@link XYZDataset} interface that allows a range of data * to be defined for any of the X values, the Y values, and the Z values. */ public interface IntervalXYZDataset extends XYZDataset { /** * Returns the starting X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The starting X value for the specified series and item. */ public Number getStartXValue(int series, int item); /** * Returns the ending X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The ending X value for the specified series and item. */ public Number getEndXValue(int series, int item); /** * Returns the starting Y value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The starting Y value for the specified series and item. */ public Number getStartYValue(int series, int item); /** * Returns the ending Y value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The ending Y value for the specified series and item. */ public Number getEndYValue(int series, int item); /** * Returns the starting Z value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The starting Z value for the specified series and item. */ public Number getStartZValue(int series, int item); /** * Returns the ending Z value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The ending Z value for the specified series and item. */ public Number getEndZValue(int series, int item); }
3,834
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYIntervalSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYIntervalSeriesCollection.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.] * * ------------------------------- * XYIntervalSeriesCollection.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); * 13-Feb-2007 : Provided a number of method overrides that enhance * performance, and added a proper clone() * implementation (DG); * 18-Jan-2008 : Added removeSeries() and removeAllSeries() methods (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DatasetChangeEvent; /** * A collection of {@link XYIntervalSeries} objects. * * @since 1.0.3 * * @see XYIntervalSeries */ public class XYIntervalSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, PublicCloneable, Serializable { /** Storage for the data series. */ private List<XYIntervalSeries> data; /** * Creates a new instance of <code>XIntervalSeriesCollection</code>. */ public XYIntervalSeriesCollection() { this.data = new java.util.ArrayList<XYIntervalSeries>(); } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(XYIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a series from the collection. * * @param series the series index (zero-based). * * @return The series. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ public XYIntervalSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.data.get(series); } /** * 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 a series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ @Override public int getItemCount(int series) { // defer argument checking return getSeries(series).getItemCount(); } /** * Returns the x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getX(int series, int item) { XYIntervalSeries s = this.data.get(series); return s.getX(item); } /** * 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) { XYIntervalSeries s = this.data.get(series); return s.getXLowValue(item); } /** * 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) { XYIntervalSeries s = this.data.get(series); return s.getXHighValue(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. */ @Override public double getYValue(int series, int item) { XYIntervalSeries s = this.data.get(series); return s.getYValue(item); } /** * 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) { XYIntervalSeries s = this.data.get(series); return s.getYLowValue(item); } /** * 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) { XYIntervalSeries s = this.data.get(series); return s.getYHighValue(item); } /** * Returns the y-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The y-value. */ @Override public Number getY(int series, int item) { return getYValue(series, item); } /** * Returns the start x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getStartX(int series, int item) { return getStartXValue(series, item); } /** * Returns the end x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public Number getEndX(int series, int item) { return getEndXValue(series, item); } /** * Returns the start y-value for an item within a series. This method * maps directly to {@link #getY(int, int)}. * * @param series the series index. * @param item the item index. * * @return The start y-value. */ @Override public Number getStartY(int series, int item) { return getStartYValue(series, item); } /** * Returns the end y-value for an item within a series. This method * maps directly to {@link #getY(int, int)}. * * @param series the series index. * @param item the item index. * * @return The end y-value. */ @Override public Number getEndY(int series, int item) { return getEndYValue(series, item); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * * @since 1.0.10 */ public void removeSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds."); } XYIntervalSeries ts = this.data.get(series); ts.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } /** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @since 1.0.10 */ public void removeSeries(XYIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.10 */ public void removeAllSeries() { // Unregister the collection as a change listener to each series in // the collection. for (XYIntervalSeries series : this.data) { series.removeChangeListener(this); } this.data.clear(); fireDatasetChanged(); } /** * 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 XYIntervalSeriesCollection)) { return false; } XYIntervalSeriesCollection that = (XYIntervalSeriesCollection) obj; return ObjectUtilities.equal(this.data, that.data); } /** * Returns a clone of this dataset. * * @return A clone of this dataset. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { XYIntervalSeriesCollection clone = (XYIntervalSeriesCollection) super.clone(); int seriesCount = getSeriesCount(); clone.data = new java.util.ArrayList<XYIntervalSeries>(seriesCount); for (int i = 0; i < this.data.size(); i++) { clone.data.set(i, (XYIntervalSeries) getSeries(i).clone()); } return clone; } }
11,674
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/VectorSeriesCollection.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.] * * --------------------------- * VectorSeriesCollection.java * --------------------------- * (C) Copyright 2007-2012, 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 indexOf(), removeSeries() and removeAllSeries() * methods (DG); * 25-May-2007 : Moved from experimental to the main source tree (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.general.DatasetChangeEvent; /** * A collection of {@link VectorSeries} objects. * * @since 1.0.6 */ public class VectorSeriesCollection extends AbstractXYDataset implements VectorXYDataset, PublicCloneable, Serializable { /** Storage for the data series. */ private List<VectorSeries> data; /** * Creates a new instance of <code>VectorSeriesCollection</code>. */ public VectorSeriesCollection() { this.data = new java.util.ArrayList<VectorSeries>(); } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(VectorSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Removes the specified series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @return A boolean indicating whether the series has actually been * removed. */ public boolean removeSeries(VectorSeries series) { ParamChecks.nullNotPermitted(series, "series"); boolean removed = this.data.remove(series); if (removed) { series.removeChangeListener(this); fireDatasetChanged(); } return removed; } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. */ public void removeAllSeries() { // deregister the collection as a change listener to each series in the // collection for (VectorSeries series : this.data) { series.removeChangeListener(this); } // remove all the series from the collection and notify listeners. this.data.clear(); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a series from the collection. * * @param series the series index (zero-based). * * @return The series. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ public VectorSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.data.get(series); } /** * 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 a series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Returns the index of the specified series, or -1 if that series is not * present in the dataset. * * @param series the series (<code>null</code> not permitted). * * @return The series index. */ public int indexOf(VectorSeries series) { ParamChecks.nullNotPermitted(series, "series"); return this.data.indexOf(series); } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ @Override public int getItemCount(int series) { // defer argument checking return getSeries(series).getItemCount(); } /** * Returns the x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public double getXValue(int series, int item) { VectorSeries s = this.data.get(series); VectorDataItem di = (VectorDataItem) s.getDataItem(item); return di.getXValue(); } /** * Returns the x-value for an item within a series. Note that this method * creates a new {@link Double} instance every time it is called---use * {@link #getXValue(int, int)} instead, if possible. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @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. * @param item the item index. * * @return The y-value. */ @Override public double getYValue(int series, int item) { VectorSeries s = this.data.get(series); VectorDataItem di = (VectorDataItem) s.getDataItem(item); return di.getYValue(); } /** * Returns the y-value for an item within a series. Note that this method * creates a new {@link Double} instance every time it is called---use * {@link #getYValue(int, int)} instead, if possible. * * @param series the series index. * @param item the item index. * * @return The y-value. */ @Override public Number getY(int series, int item) { return getYValue(series, item); } /** * Returns the vector for an item in a series. * * @param series the series index. * @param item the item index. * * @return The vector (possibly <code>null</code>). */ @Override public Vector getVector(int series, int item) { VectorSeries s = this.data.get(series); VectorDataItem di = (VectorDataItem) s.getDataItem(item); return di.getVector(); } /** * 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. */ @Override public double getVectorXValue(int series, int item) { VectorSeries s = this.data.get(series); VectorDataItem di = (VectorDataItem) s.getDataItem(item); return di.getVectorX(); } /** * 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. */ @Override public double getVectorYValue(int series, int item) { VectorSeries s = this.data.get(series); VectorDataItem di = (VectorDataItem) s.getDataItem(item); return di.getVectorY(); } /** * 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 VectorSeriesCollection)) { return false; } VectorSeriesCollection that = (VectorSeriesCollection) obj; return ObjectUtilities.equal(this.data, that.data); } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem. */ @Override public Object clone() throws CloneNotSupportedException { VectorSeriesCollection clone = (VectorSeriesCollection) super.clone(); clone.data = ObjectUtilities.deepClone(this.data); return clone; } }
10,219
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/AbstractXYDataset.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.] * * ---------------------- * AbstractXYDataset.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 getX() with getXValue() and getY() with * getYValue() (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * */ package org.jfree.data.xy; import org.jfree.data.DomainOrder; import org.jfree.data.general.AbstractSeriesDataset; /** * An base class that you can use to create new implementations of the * {@link XYDataset} interface. */ public abstract class AbstractXYDataset extends AbstractSeriesDataset implements XYDataset { /** * Returns the order of the domain (X) values. * * @return The domain order. */ @Override public DomainOrder getDomainOrder() { return DomainOrder.NONE; } /** * 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. */ @Override public double getXValue(int series, int item) { double result = Double.NaN; Number x = getX(series, item); if (x != null) { result = x.doubleValue(); } return result; } /** * 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. */ @Override public double getYValue(int series, int item) { double result = Double.NaN; Number y = getY(series, item); if (y != null) { result = y.doubleValue(); } return result; } }
3,188
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultHighLowDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultHighLowDataset.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.] * * -------------------------- * DefaultHighLowDataset.java * -------------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 21-Mar-2002 : Version 1 (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 06-May-2004 : Now extends AbstractXYDataset and added new methods from * HighLowDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 28-Nov-2006 : Added equals() method override (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.util.Arrays; import java.util.Date; import org.jfree.chart.util.PublicCloneable; /** * A simple implementation of the {@link OHLCDataset} interface. See also * the {@link DefaultOHLCDataset} class, which provides another implementation * that is very similar. */ public class DefaultHighLowDataset extends AbstractXYDataset implements OHLCDataset, PublicCloneable { /** The series key. */ private Comparable seriesKey; /** Storage for the dates. */ private Date[] date; /** Storage for the high values. */ private Number[] high; /** Storage for the low values. */ private Number[] low; /** Storage for the open values. */ private Number[] open; /** Storage for the close values. */ private Number[] close; /** Storage for the volume values. */ private Number[] volume; /** * Constructs a new high/low/open/close dataset. * <p> * The current implementation allows only one series in the dataset. * This may be extended in a future version. * * @param seriesKey the key for the series (<code>null</code> not * permitted). * @param date the dates (<code>null</code> not permitted). * @param high the high values (<code>null</code> not permitted). * @param low the low values (<code>null</code> not permitted). * @param open the open values (<code>null</code> not permitted). * @param close the close values (<code>null</code> not permitted). * @param volume the volume values (<code>null</code> not permitted). */ public DefaultHighLowDataset(Comparable seriesKey, Date[] date, double[] high, double[] low, double[] open, double[] close, double[] volume) { if (seriesKey == null) { throw new IllegalArgumentException("Null 'series' argument."); } if (date == null) { throw new IllegalArgumentException("Null 'date' argument."); } this.seriesKey = seriesKey; this.date = date; this.high = createNumberArray(high); this.low = createNumberArray(low); this.open = createNumberArray(open); this.close = createNumberArray(close); this.volume = createNumberArray(volume); } /** * Returns the key for the series stored in this dataset. * * @param series the index of the series (ignored, this dataset supports * only one series and this method always returns the key for series 0). * * @return The series key (never <code>null</code>). */ @Override public Comparable getSeriesKey(int series) { return this.seriesKey; } /** * Returns the x-value for one item in a series. The value returned is a * <code>Long</code> instance generated from the underlying * <code>Date</code> object. To avoid generating a new object instance, * you might prefer to call {@link #getXValue(int, int)}. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The x-value. * * @see #getXValue(int, int) * @see #getXDate(int, int) */ @Override public Number getX(int series, int item) { return this.date[item].getTime(); } /** * Returns the x-value for one item in a series, as a Date. * <p> * This method is provided for convenience only. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The x-value as a Date. * * @see #getX(int, int) */ public Date getXDate(int series, int item) { return this.date[item]; } /** * Returns the y-value for one item in a series. * <p> * This method (from the {@link XYDataset} interface) is mapped to the * {@link #getCloseValue(int, int)} method. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The y-value. * * @see #getYValue(int, int) */ @Override public Number getY(int series, int item) { return getClose(series, item); } /** * Returns the high-value for one item in a series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The high-value. * * @see #getHighValue(int, int) */ @Override public Number getHigh(int series, int item) { return this.high[item]; } /** * Returns the high-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 high-value. * * @see #getHigh(int, int) */ @Override public double getHighValue(int series, int item) { double result = Double.NaN; Number high = getHigh(series, item); if (high != null) { result = high.doubleValue(); } return result; } /** * Returns the low-value for one item in a series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The low-value. * * @see #getLowValue(int, int) */ @Override public Number getLow(int series, int item) { return this.low[item]; } /** * Returns the low-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 low-value. * * @see #getLow(int, int) */ @Override public double getLowValue(int series, int item) { double result = Double.NaN; Number low = getLow(series, item); if (low != null) { result = low.doubleValue(); } return result; } /** * Returns the open-value for one item in a series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The open-value. * * @see #getOpenValue(int, int) */ @Override public Number getOpen(int series, int item) { return this.open[item]; } /** * Returns the open-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 open-value. * * @see #getOpen(int, int) */ @Override public double getOpenValue(int series, int item) { double result = Double.NaN; Number open = getOpen(series, item); if (open != null) { result = open.doubleValue(); } return result; } /** * Returns the close-value for one item in a series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The close-value. * * @see #getCloseValue(int, int) */ @Override public Number getClose(int series, int item) { return this.close[item]; } /** * Returns the close-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 close-value. * * @see #getClose(int, int) */ @Override public double getCloseValue(int series, int item) { double result = Double.NaN; Number close = getClose(series, item); if (close != null) { result = close.doubleValue(); } return result; } /** * Returns the volume-value for one item in a series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The volume-value. * * @see #getVolumeValue(int, int) */ @Override public Number getVolume(int series, int item) { return this.volume[item]; } /** * Returns the volume-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 volume-value. * * @see #getVolume(int, int) */ @Override public double getVolumeValue(int series, int item) { double result = Double.NaN; Number volume = getVolume(series, item); if (volume != null) { result = volume.doubleValue(); } return result; } /** * Returns the number of series in the dataset. * <p> * This implementation only allows one series. * * @return The number of series. */ @Override public int getSeriesCount() { return 1; } /** * Returns the number of items in the specified series. * * @param series the index (zero-based) of the series. * * @return The number of items in the specified series. */ @Override public int getItemCount(int series) { return this.date.length; } /** * Tests this dataset for equality with an arbitrary instance. * * @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 DefaultHighLowDataset)) { return false; } DefaultHighLowDataset that = (DefaultHighLowDataset) obj; if (!this.seriesKey.equals(that.seriesKey)) { return false; } if (!Arrays.equals(this.date, that.date)) { return false; } if (!Arrays.equals(this.open, that.open)) { return false; } if (!Arrays.equals(this.high, that.high)) { return false; } if (!Arrays.equals(this.low, that.low)) { return false; } if (!Arrays.equals(this.close, that.close)) { return false; } if (!Arrays.equals(this.volume, that.volume)) { return false; } return true; } /** * Constructs an array of Number objects from an array of doubles. * * @param data the double values to convert (<code>null</code> not * permitted). * * @return The data as an array of Number objects. */ public static Number[] createNumberArray(double[] data) { Number[] result = new Number[data.length]; for (int i = 0; i < data.length; i++) { result[i] = data[i]; } return result; } }
13,047
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYDataset.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.] * * -------------- * XYDataset.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 : Renamed DataSource.java --> Dataset.java etc. (DG); * 17-Nov-2001 : Now extends SeriesDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 29-Jul-2004 : Added getDomainOrder() method (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * */ package org.jfree.data.xy; import org.jfree.data.DomainOrder; import org.jfree.data.general.SeriesDataset; /** * An interface through which data in the form of (x, y) items can be accessed. */ public interface XYDataset extends SeriesDataset { /** * Returns the order of the domain (or X) values returned by the dataset. * * @return The order (never <code>null</code>). */ public DomainOrder getDomainOrder(); /** * Returns the number of items in a series. * <br><br> * It is recommended that classes that implement this method should throw * an <code>IllegalArgumentException</code> if the <code>series</code> * argument is outside the specified range. * * @param series the series index (in the range <code>0</code> to * <code>getSeriesCount() - 1</code>). * * @return The item count. */ public int getItemCount(int series); /** * Returns the x-value for an item within a series. The x-values may or * may not be returned in ascending order, that is up to the class * implementing the interface. * * @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 (never <code>null</code>). */ public Number getX(int series, int 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. */ public double getXValue(int series, int 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 (possibly <code>null</code>). */ public Number getY(int series, int item); /** * Returns the y-value (as a double primitive) 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. */ public double getYValue(int series, int item); }
4,706
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDatasetTableModel.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYDatasetTableModel.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.] * * ------------------------ * XYDatasetTableModel.java * ------------------------ * (C)opyright 2003-2008, by Bryan Scott and Contributors. * * Original Author: Bryan Scott ; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 01-Jul-2003 : Version 1 contributed by Bryan Scott (DG); * 27-Apr-2005 : Change XYDataset --> TableXYDataset because the table model * assumes all series share the same x-values, and this is not * enforced by XYDataset. Also fixed bug 1191046, a problem * in the getValueAt() method (DG); * */ package org.jfree.data.xy; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; /** * A READ-ONLY wrapper around a {@link TableXYDataset} to convert it to a * table model for use in a JTable. The first column of the table shows the * x-values, the remaining columns show the y-values for each series (series 0 * appears in column 1, series 1 appears in column 2, etc). * <P> * TO DO: * <ul> * <li>implement proper naming for x axis (getColumnName)</li> * <li>implement setValueAt to remove READ-ONLY constraint (not sure how)</li> * </ul> */ public class XYDatasetTableModel extends AbstractTableModel implements TableModel, DatasetChangeListener { /** The dataset. */ TableXYDataset model = null; /** * Default constructor. */ public XYDatasetTableModel() { super(); } /** * Creates a new table model based on the specified dataset. * * @param dataset the dataset. */ public XYDatasetTableModel(TableXYDataset dataset) { this(); this.model = dataset; this.model.addChangeListener(this); } /** * Sets the model (dataset). * * @param dataset the dataset. */ public void setModel(TableXYDataset dataset) { this.model = dataset; this.model.addChangeListener(this); fireTableDataChanged(); } /** * Returns the number of rows. * * @return The row count. */ @Override public int getRowCount() { if (this.model == null) { return 0; } return this.model.getItemCount(); } /** * Gets the number of columns in the model. * * @return The number of columns in the model. */ @Override public int getColumnCount() { if (this.model == null) { return 0; } return this.model.getSeriesCount() + 1; } /** * Returns the column name. * * @param column the column index. * * @return The column name. */ @Override public String getColumnName(int column) { if (this.model == null) { return super.getColumnName(column); } if (column < 1) { return "X Value"; } else { return this.model.getSeriesKey(column - 1).toString(); } } /** * Returns a value of the specified cell. * Column 0 is the X axis, Columns 1 and over are the Y axis * * @param row the row number. * @param column the column number. * * @return The value of the specified cell. */ @Override public Object getValueAt(int row, int column) { if (this.model == null) { return null; } if (column < 1) { return this.model.getX(0, row); } else { return this.model.getY(column - 1, row); } } /** * Receives notification that the underlying dataset has changed. * * @param event the event * * @see DatasetChangeListener */ @Override public void datasetChanged(DatasetChangeEvent event) { fireTableDataChanged(); } /** * Returns a flag indicating whether or not the specified cell is editable. * * @param row the row number. * @param column the column number. * * @return <code>true</code> if the specified cell is editable. */ @Override public boolean isCellEditable(int row, int column) { return false; } /** * Updates the {@link XYDataset} if allowed. * * @param value the new value. * @param row the row. * @param column the column. */ @Override public void setValueAt(Object value, int row, int column) { if (isCellEditable(row, column)) { // XYDataset only provides methods for reading a dataset... } } // /** // * Run a demonstration of the table model interface. // * // * @param args ignored. // * // * @throws Exception when an error occurs. // */ // public static void main(String args[]) throws Exception { // JFrame frame = new JFrame(); // JPanel panel = new JPanel(); // panel.setLayout(new BorderLayout()); // // XYSeries s1 = new XYSeries("Series 1", true, false); // for (int i = 0; i < 10; i++) { // s1.add(i, Math.random()); // } // XYSeries s2 = new XYSeries("Series 2", true, false); // for (int i = 0; i < 15; i++) { // s2.add(i, Math.random()); // } // DefaultTableXYDataset dataset = new DefaultTableXYDataset(); // dataset.addSeries(s1); // dataset.addSeries(s2); // XYDatasetTableModel tablemodel = new XYDatasetTableModel(); // // tablemodel.setModel(dataset); // // JTable dataTable = new JTable(tablemodel); // JScrollPane scroll = new JScrollPane(dataTable); // scroll.setPreferredSize(new Dimension(600, 150)); // // JFreeChart chart = ChartFactory.createXYLineChart( // "XY Series Demo", // "X", "Y", dataset, PlotOrientation.VERTICAL, // true, // true, // false // ); // // ChartPanel stackChartPanel = new ChartPanel(chart); // // panel.add(stackChartPanel, BorderLayout.CENTER); // panel.add(scroll, BorderLayout.SOUTH); // // frame.setContentPane(panel); // frame.setSize(600, 500); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.show(); // RefineryUtilities.centerFrameOnScreen(frame); // } }
7,908
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/OHLCDataset.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.] * * ---------------- * OHLCDataset.java * ---------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Sylvain Vieujot; * * Changes (from 18-Sep-2001) * -------------------------- * 18-Sep-2001 : Updated header info (DG); * 16-Oct-2001 : Moved to package com.jrefinery.data.* (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 05-Feb-2002 : Added getVolumeValue() method, as requested by Sylvain * Vieujot (DG); * 05-May-2004 : Added methods that return double primitives (DG); * 26-Jul-2004 : Switched names of methods that return Number vs * primitives (DG); * 06-Sep-2004 : Renamed HighLowDataset --> OHLCDataset (DG); * */ package org.jfree.data.xy; /** * An interface that defines data in the form of (x, high, low, open, close) * tuples. */ public interface OHLCDataset extends XYDataset { /** * Returns the high-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ public Number getHigh(int series, int item); /** * Returns the high-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 high-value. */ public double getHighValue(int series, int item); /** * Returns the low-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ public Number getLow(int series, int item); /** * Returns the low-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 low-value. */ public double getLowValue(int series, int item); /** * Returns the open-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ public Number getOpen(int series, int item); /** * Returns the open-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 open-value. */ public double getOpenValue(int series, int item); /** * Returns the y-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ public Number getClose(int series, int item); /** * Returns the close-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 close-value. */ public double getCloseValue(int series, int item); /** * Returns the volume for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ public Number getVolume(int series, int item); /** * Returns the volume-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 volume-value. */ public double getVolumeValue(int series, int item); }
5,103
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultXYZDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/DefaultXYZDataset.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.] * * ---------------------- * DefaultXYZDataset.java * ---------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 12-Jul-2006 : Version 1 (DG); * 06-Oct-2006 : Fixed API doc warnings (DG); * 02-Nov-2006 : Fixed a problem with adding a new series with the same key * as an existing series (see bug 1589392) (DG); * 22-Apr-2008 : 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.ParamChecks; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DomainOrder; import org.jfree.data.general.DatasetChangeEvent; /** * A default implementation of the {@link XYZDataset} interface that stores * data values in arrays of double primitives. * * @since 1.0.2 */ public class DefaultXYZDataset extends AbstractXYZDataset implements XYZDataset, 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>DefaultXYZDataset</code> instance, initially * containing no data. */ public DefaultXYZDataset() { 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); } /** * Returns the z-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 z-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> or <code>item</code> is not * within the specified range. * * @see #getZ(int, int) */ @Override public double getZValue(int series, int item) { double[][] seriesData = this.seriesList.get(series); return seriesData[2][item]; } /** * Returns the z-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 z-value. * * @throws ArrayIndexOutOfBoundsException if <code>series</code> or <code>item</code> is not * within the specified range. * * @see #getZ(int, int) */ @Override public Number getZ(int series, int item) { return getZValue(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 3, containing three * arrays of equal length, the first containing the x-values, the * second containing the y-values and the third containing the * z-values). */ public void addSeries(Comparable seriesKey, double[][] data) { ParamChecks.nullNotPermitted(seriesKey, "seriesKey"); ParamChecks.nullNotPermitted(data, "data"); if (data.length != 3) { throw new IllegalArgumentException( "The 'data' array must have length == 3."); } if (data[0].length != data[1].length || data[0].length != data[2].length) { throw new IllegalArgumentException("The 'data' array must contain " + "three arrays all having the same 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 DefaultXYZDataset)) { return false; } DefaultXYZDataset that = (DefaultXYZDataset) 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; } double[] d1z = d1[2]; double[] d2z = d2[2]; if (!Arrays.equals(d1z, d2z)) { 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 { DefaultXYZDataset clone = (DefaultXYZDataset) 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[] z = data[2]; double[] xx = new double[x.length]; double[] yy = new double[y.length]; double[] zz = new double[z.length]; System.arraycopy(x, 0, xx, 0, x.length); System.arraycopy(y, 0, yy, 0, y.length); System.arraycopy(z, 0, zz, 0, z.length); clone.seriesList.add(i, new double[][] {xx, yy, zz}); } return clone; } }
14,394
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MatrixSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/MatrixSeries.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.] * * ----------------- * MatrixSeries.java * ----------------- * (C) Copyright 2003-2008, by Barak Naveh and Contributors. * * Original Author: Barak Naveh; * Contributor(s): David Gilbert (for Object Refinery Limited); * Zhitao Wang; * * Changes * ------- * 10-Jul-2003 : Version 1 contributed by Barak Naveh (DG); * 10-Feb-2004 : Fixed Checkstyle complaints (DG); * 21-May-2004 : Fixed bug 940188 - problem in getItemColumn() and * getItemRow() (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 27-Nov-2006 : Fixed bug in equals() method (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import org.jfree.data.general.Series; /** * Represents a dense matrix M[i,j] where each Mij item of the matrix has a * value (default is 0). */ public class MatrixSeries extends Series implements Serializable { /** For serialization. */ private static final long serialVersionUID = 7934188527308315704L; /** Series matrix values */ protected double[][] data; /** * Constructs a new matrix series. * <p> * By default, all matrix items are initialzed to 0. * </p> * * @param name series name (<code>null</code> not permitted). * @param rows the number of rows. * @param columns the number of columns. */ public MatrixSeries(String name, int rows, int columns) { super(name); this.data = new double[rows][columns]; zeroAll(); } /** * Returns the number of columns in this matrix series. * * @return The number of columns in this matrix series. */ public int getColumnsCount() { return this.data[0].length; } /** * Return the matrix item at the specified index. Note that this method * creates a new <code>Double</code> instance every time it is called. * * @param itemIndex item index. * * @return The matrix item at the specified index. * * @see #get(int, int) */ public Number getItem(int itemIndex) { int i = getItemRow(itemIndex); int j = getItemColumn(itemIndex); Number n = get(i, j); return n; } /** * Returns the column of the specified item. * * @param itemIndex the index of the item. * * @return The column of the specified item. */ public int getItemColumn(int itemIndex) { //assert itemIndex >= 0 && itemIndex < getItemCount(); return itemIndex % getColumnsCount(); } /** * Returns the number of items in the series. * * @return The item count. */ @Override public int getItemCount() { return getRowCount() * getColumnsCount(); } /** * Returns the row of the specified item. * * @param itemIndex the index of the item. * * @return The row of the specified item. */ public int getItemRow(int itemIndex) { //assert itemIndex >= 0 && itemIndex < getItemCount(); return itemIndex / getColumnsCount(); } /** * Returns the number of rows in this matrix series. * * @return The number of rows in this matrix series. */ public int getRowCount() { return this.data.length; } /** * Returns the value of the specified item in this matrix series. * * @param i the row of the item. * @param j the column of the item. * * @return The value of the specified item in this matrix series. * * @see #getItem(int) * @see #update(int, int, double) */ public double get(int i, int j) { return this.data[i][j]; } /** * Updates the value of the specified item in this matrix series. * * @param i the row of the item. * @param j the column of the item. * @param mij the new value for the item. * * @see #get(int, int) */ public void update(int i, int j, double mij) { this.data[i][j] = mij; fireSeriesChanged(); } /** * Sets all matrix values to zero and sends a * {@link org.jfree.data.general.SeriesChangeEvent} to all registered * listeners. */ public void zeroAll() { int rows = getRowCount(); int columns = getColumnsCount(); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { this.data[row][column] = 0.0; } } fireSeriesChanged(); } /** * Tests this object 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 MatrixSeries)) { return false; } MatrixSeries that = (MatrixSeries) obj; if (!(getRowCount() == that.getRowCount())) { return false; } if (!(getColumnsCount() == that.getColumnsCount())) { return false; } for (int r = 0; r < getRowCount(); r++) { for (int c = 0; c < getColumnsCount(); c++) { if (get(r, c) != that.get(r, c)) { return false; } } } return super.equals(obj); } }
6,765
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYIntervalSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYIntervalSeries.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.] * * --------------------- * XYIntervalSeries.java * --------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * 13-Feb-2007 : Added several new accessor 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, y-low, y-high) data items. * * @since 1.0.3 * * @see XYIntervalSeriesCollection */ public class XYIntervalSeries 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 XYIntervalSeries(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 XYIntervalSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) { super(key, autoSort, allowDuplicateXValues); } /** * Adds a data item to the series. * * @param x the x-value. * @param xLow the lower bound of the x-interval. * @param xHigh the upper bound of the x-interval. * @param y the y-value. * @param yLow the lower bound of the y-interval. * @param yHigh the upper bound of the y-interval. */ public void add(double x, double xLow, double xHigh, double y, double yLow, double yHigh) { super.add(new XYIntervalDataItem(x, xLow, xHigh, y, yLow, yHigh), 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) { XYIntervalDataItem item = (XYIntervalDataItem) getDataItem(index); return item.getX(); } /** * Returns the lower bound of the x-interval for the specified item in the * series. * * @param index the item index. * * @return The lower bound of the x-interval. * * @since 1.0.5 */ public double getXLowValue(int index) { XYIntervalDataItem item = (XYIntervalDataItem) getDataItem(index); return item.getXLowValue(); } /** * Returns the upper bound of the x-interval for the specified item in the * series. * * @param index the item index. * * @return The upper bound of the x-interval. * * @since 1.0.5 */ public double getXHighValue(int index) { XYIntervalDataItem item = (XYIntervalDataItem) 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) { XYIntervalDataItem item = (XYIntervalDataItem) getDataItem(index); return item.getYValue(); } /** * Returns the lower bound of the Y-interval for the specified item in the * series. * * @param index the item index. * * @return The lower bound of the Y-interval. * * @since 1.0.5 */ public double getYLowValue(int index) { XYIntervalDataItem item = (XYIntervalDataItem) getDataItem(index); return item.getYLowValue(); } /** * Returns the upper bound of the y-interval for the specified item in the * series. * * @param index the item index. * * @return The upper bound of the y-interval. * * @since 1.0.5 */ public double getYHighValue(int index) { XYIntervalDataItem item = (XYIntervalDataItem) getDataItem(index); return item.getYHighValue(); } /** * 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); } }
5,984
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TableXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/TableXYDataset.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.] * * ------------------- * TableXYDataset.java * ------------------- * (C) Copyright 2000-2008, by Richard Atkinson and Contributors. * * Original Author: Richard Atkinson; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 22-Sep-2003 : Changed to be an interface. Previous functionality moved to * DefaultTableXYDataset; * 16-Feb-2004 : Updated Javadocs (DG); * */ package org.jfree.data.xy; /** * A dataset containing one or more data series containing (x, y) data items, * where all series in the dataset share the same set of x-values. This is a * restricted form of the {@link XYDataset} interface (which allows independent * x-values between series). This is used primarily by the * {@link org.jfree.chart.renderer.xy.StackedXYAreaRenderer}. */ public interface TableXYDataset extends XYDataset { /** * Returns the number of items every series. * * @return The item count. */ public int getItemCount(); }
2,242
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYZDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYZDataset.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.] * * --------------- * XYZDataset.java * --------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 31-Oct-2001 : Initial version (DG); * 05-May-2004 : Added getZ() method; * 15-Jul-2004 : Switched getZ() and getZValue() methods (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.xy (DG); * */ package org.jfree.data.xy; /** * The interface through which JFreeChart obtains data in the form of (x, y, z) * items - used for XY and XYZ plots. */ public interface XYZDataset extends XYDataset { /** * Returns the z-value for the specified series and item. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The z-value (possibly <code>null</code>). */ public Number getZ(int series, int item); /** * Returns the z-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 z-value. */ public double getZValue(int series, int item); }
2,469
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YInterval.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/YInterval.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.] * * -------------- * YInterval.java * -------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import java.io.Serializable; /** * A y-interval. This class is used internally by the * {@link YIntervalDataItem} class. * * @since 1.0.3 */ public class YInterval implements Serializable { /** The y-value. */ private double y; /** The lower bound of the y-interval. */ private double yLow; /** The upper bound of the y-interval. */ private double yHigh; /** * Creates a new instance of <code>YInterval</code>. * * @param y the y-value. * @param yLow the lower bound of the y-interval. * @param yHigh the upper bound of the y-interval. */ public YInterval(double y, double yLow, double yHigh) { this.y = y; this.yLow = yLow; this.yHigh = yHigh; } /** * Returns the y-value. * * @return The y-value. */ public double getY() { return this.y; } /** * Returns the lower bound of the y-interval. * * @return The lower bound of the y-interval. */ public double getYLow() { return this.yLow; } /** * Returns the upper bound of the y-interval. * * @return The upper bound of the y-interval. */ public double getYHigh() { return this.yHigh; } /** * 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 YInterval)) { return false; } YInterval that = (YInterval) obj; if (this.y != that.y) { return false; } if (this.yLow != that.yLow) { return false; } if (this.yHigh != that.yHigh) { return false; } return true; } }
3,451
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MatrixSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/MatrixSeriesCollection.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.] * * --------------------------- * MatrixSeriesCollection.java * --------------------------- * (C) Copyright 2003-2012, by Barak Naveh and Contributors. * * Original Author: Barak Naveh; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 10-Jul-2003 : Version 1 contributed by Barak Naveh (DG); * 05-May-2004 : Now extends AbstractXYZDataset (DG); * 15-Jul-2004 : Switched getZ() and getZValue() methods (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 27-Nov-2006 : Added clone() override (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 22-Apr-2008 : Implemented PublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; /** * Represents a collection of {@link MatrixSeries} that can be used as a * dataset. * * @see org.jfree.data.xy.MatrixSeries */ public class MatrixSeriesCollection extends AbstractXYZDataset implements XYZDataset, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -3197705779242543945L; /** The series that are included in the collection. */ private List<MatrixSeries> seriesList; /** * Constructs an empty dataset. */ public MatrixSeriesCollection() { this(null); } /** * Constructs a dataset and populates it with a single matrix series. * * @param series the time series. */ public MatrixSeriesCollection(MatrixSeries series) { this.seriesList = new java.util.ArrayList<MatrixSeries>(); if (series != null) { this.seriesList.add(series); series.addChangeListener(this); } } /** * Returns the number of items in the specified series. * * @param seriesIndex zero-based series index. * * @return The number of items in the specified series. */ @Override public int getItemCount(int seriesIndex) { return getSeries(seriesIndex).getItemCount(); } /** * Returns the series having the specified index. * * @param seriesIndex zero-based series index. * * @return The series. * * @throws IllegalArgumentException */ public MatrixSeries getSeries(int seriesIndex) { if ((seriesIndex < 0) || (seriesIndex > getSeriesCount())) { throw new IllegalArgumentException("Index outside valid range."); } MatrixSeries series = this.seriesList.get(seriesIndex); return series; } /** * Returns the number of series in the collection. * * @return The number of series in the collection. */ @Override public int getSeriesCount() { return this.seriesList.size(); } /** * Returns the key for a series. * * @param seriesIndex zero-based series index. * * @return The key for a series. */ @Override public Comparable getSeriesKey(int seriesIndex) { return getSeries(seriesIndex).getKey(); } /** * Returns the j index value of the specified Mij matrix item in the * specified matrix series. * * @param seriesIndex zero-based series index. * @param itemIndex zero-based item index. * * @return The j index value for the specified matrix item. * * @see org.jfree.data.xy.XYDataset#getXValue(int, int) */ @Override public Number getX(int seriesIndex, int itemIndex) { MatrixSeries series = this.seriesList.get(seriesIndex); int x = series.getItemColumn(itemIndex); return x; // I know it's bad to create object. better idea? } /** * Returns the i index value of the specified Mij matrix item in the * specified matrix series. * * @param seriesIndex zero-based series index. * @param itemIndex zero-based item index. * * @return The i index value for the specified matrix item. * * @see org.jfree.data.xy.XYDataset#getYValue(int, int) */ @Override public Number getY(int seriesIndex, int itemIndex) { MatrixSeries series = this.seriesList.get(seriesIndex); int y = series.getItemRow(itemIndex); return y; // I know it's bad to create object. better idea? } /** * Returns the Mij item value of the specified Mij matrix item in the * specified matrix series. * * @param seriesIndex the series (zero-based index). * @param itemIndex zero-based item index. * * @return The Mij item value for the specified matrix item. * * @see org.jfree.data.xy.XYZDataset#getZValue(int, int) */ @Override public Number getZ(int seriesIndex, int itemIndex) { MatrixSeries series = this.seriesList.get(seriesIndex); Number z = series.getItem(itemIndex); return z; } /** * Adds a series to the collection. * <P> * Notifies all registered listeners that the dataset has changed. * </p> * * @param series the series. * * @throws IllegalArgumentException */ public void addSeries(MatrixSeries series) { // check arguments... if (series == null) { throw new IllegalArgumentException("Cannot add null series."); } // FIXME: Check that there isn't already a series with the same key // add the series... this.seriesList.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Tests this collection for equality with an arbitrary object. * * @param obj the object. * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (obj == this) { return true; } if (obj instanceof MatrixSeriesCollection) { MatrixSeriesCollection c = (MatrixSeriesCollection) obj; return ObjectUtilities.equal(this.seriesList, c.seriesList); } return false; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { return (this.seriesList != null ? this.seriesList.hashCode() : 0); } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem. */ @Override public Object clone() throws CloneNotSupportedException { MatrixSeriesCollection clone = (MatrixSeriesCollection) super.clone(); clone.seriesList = ObjectUtilities.deepClone(this.seriesList); return clone; } /** * Removes all the series from the collection. * <P> * Notifies all registered listeners that the dataset has changed. * </p> */ public void removeAllSeries() { // Unregister the collection as a change listener to each series in // the collection. for (MatrixSeries series : this.seriesList) { series.removeChangeListener(this); } // Remove all the series from the collection and notify listeners. this.seriesList.clear(); fireDatasetChanged(); } /** * Removes a series from the collection. * <P> * Notifies all registered listeners that the dataset has changed. * </p> * * @param series the series. * * @throws IllegalArgumentException */ public void removeSeries(MatrixSeries series) { // check arguments... if (series == null) { throw new IllegalArgumentException("Cannot remove null series."); } // remove the series... if (this.seriesList.contains(series)) { series.removeChangeListener(this); this.seriesList.remove(series); fireDatasetChanged(); } } /** * Removes a series from the collection. * <P> * Notifies all registered listeners that the dataset has changed. * * @param seriesIndex the series (zero based index). * * @throws IllegalArgumentException */ public void removeSeries(int seriesIndex) { // check arguments... if ((seriesIndex < 0) || (seriesIndex > getSeriesCount())) { throw new IllegalArgumentException("Index outside valid range."); } // fetch the series, remove the change listener, then remove the series. MatrixSeries series = this.seriesList.get(seriesIndex); series.removeChangeListener(this); this.seriesList.remove(seriesIndex); fireDatasetChanged(); } }
10,141
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYRangeInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/xy/XYRangeInfo.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.] * * ---------------- * XYRangeInfo.java * ---------------- * (C) Copyright 2009-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 27-Mar-2009 : Version 1 (DG); * */ package org.jfree.data.xy; import java.util.List; import org.jfree.data.Range; /** * An interface that can (optionally) be implemented by a dataset to assist in * determining the minimum and maximum y-values. * * @since 1.0.13 */ public interface XYRangeInfo { /** * Returns the range of the values in this dataset's range. * * @param visibleSeriesKeys the keys of the visible series. * @param xRange the x-range (<code>null</code> not permitted). * @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(List<Comparable> visibleSeriesKeys, Range xRange, boolean includeInterval); }
2,351
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/category/package-info.java
/** * A package containing the {@link org.jfree.data.category.CategoryDataset} interface and related classes. */ package org.jfree.data.category;
148
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IntervalCategoryDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/IntervalCategoryDataset.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.] * * ---------------------------- * IntervalCategoryDataset.java * ---------------------------- * (C) Copyright 2002-2008, by Eduard Martinescu and Contributors. * * Original Author: Eduard Martinescu; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 19-Mar-2002 : Version 1 contributed by Eduard Martinescu. The interface * name and method names have been renamed to be consistent with * existing interfaces (DG); * 06-Jun-2002 : Updated Javadoc comments (DG); * 24-Oct-2002 : Categories and series are now indexed by int or Comparable, * following changes made to the CategoryDataset interface (DG); * 12-May-2008 : Updated API docs (DG); * */ package org.jfree.data.category; /** * A category dataset that defines a value range for each series/category * combination. */ public interface IntervalCategoryDataset extends CategoryDataset { /** * Returns the start value for the interval for a given series and category. * * @param series the series (zero-based index). * @param category the category (zero-based index). * * @return The start value (possibly <code>null</code>). * * @see #getEndValue(int, int) */ public Number getStartValue(int series, int category); /** * Returns the start value for the interval for a given series and category. * * @param series the series key. * @param category the category key. * * @return The start value (possibly <code>null</code>). * * @see #getEndValue(Comparable, Comparable) */ public Number getStartValue(Comparable series, Comparable category); /** * Returns the end value for the interval for a given series and category. * * @param series the series (zero-based index). * @param category the category (zero-based index). * * @return The end value (possibly <code>null</code>). * * @see #getStartValue(int, int) */ public Number getEndValue(int series, int category); /** * Returns the end value for the interval for a given series and category. * * @param series the series key. * @param category the category key. * * @return The end value (possibly <code>null</code>). * * @see #getStartValue(Comparable, Comparable) */ public Number getEndValue(Comparable series, Comparable category); }
3,697
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SlidingCategoryDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/SlidingCategoryDataset.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.] * * --------------------------- * SlidingCategoryDataset.java * --------------------------- * (C) Copyright 2008-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-May-2008 : Version 1 (DG); * 15-Mar-2009 : Fixed bug in getColumnKeys() method (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.category; import java.util.Collections; import java.util.List; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.UnknownKeyException; import org.jfree.data.general.AbstractDataset; import org.jfree.data.general.DatasetChangeEvent; /** * A {@link CategoryDataset} implementation that presents a subset of the * categories in an underlying dataset. The index of the first "visible" * category can be modified, which provides a means of "sliding" through * the categories in the underlying dataset. * * @since 1.0.10 */ public class SlidingCategoryDataset extends AbstractDataset implements CategoryDataset { /** The underlying dataset. */ private CategoryDataset underlying; /** The index of the first category to present. */ private int firstCategoryIndex; /** The maximum number of categories to present. */ private int maximumCategoryCount; /** * Creates a new instance. * * @param underlying the underlying dataset (<code>null</code> not * permitted). * @param firstColumn the index of the first visible column from the * underlying dataset. * @param maxColumns the maximumColumnCount. */ public SlidingCategoryDataset(CategoryDataset underlying, int firstColumn, int maxColumns) { this.underlying = underlying; this.firstCategoryIndex = firstColumn; this.maximumCategoryCount = maxColumns; } /** * Returns the underlying dataset that was supplied to the constructor. * * @return The underlying dataset (never <code>null</code>). */ public CategoryDataset getUnderlyingDataset() { return this.underlying; } /** * Returns the index of the first visible category. * * @return The index. * * @see #setFirstCategoryIndex(int) */ public int getFirstCategoryIndex() { return this.firstCategoryIndex; } /** * Sets the index of the first category that should be used from the * underlying dataset, and sends a {@link DatasetChangeEvent} to all * registered listeners. * * @param first the index. * * @see #getFirstCategoryIndex() */ public void setFirstCategoryIndex(int first) { if (first < 0 || first >= this.underlying.getColumnCount()) { throw new IllegalArgumentException("Invalid index."); } this.firstCategoryIndex = first; fireDatasetChanged(); } /** * Returns the maximum category count. * * @return The maximum category count. * * @see #setMaximumCategoryCount(int) */ public int getMaximumCategoryCount() { return this.maximumCategoryCount; } /** * Sets the maximum category count and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param max the maximum. * * @see #getMaximumCategoryCount() */ public void setMaximumCategoryCount(int max) { if (max < 0) { throw new IllegalArgumentException("Requires 'max' >= 0."); } this.maximumCategoryCount = max; fireDatasetChanged(); } /** * Returns the index of the last column for this dataset, or -1. * * @return The index. */ private int lastCategoryIndex() { if (this.maximumCategoryCount == 0) { return -1; } return Math.min(this.firstCategoryIndex + this.maximumCategoryCount, this.underlying.getColumnCount()) - 1; } /** * Returns the index for the specified column key. * * @param key the key. * * @return The column index, or -1 if the key is not recognised. */ @Override public int getColumnIndex(Comparable key) { int index = this.underlying.getColumnIndex(key); if (index >= this.firstCategoryIndex && index <= lastCategoryIndex()) { return index - this.firstCategoryIndex; } return -1; // we didn't find the key } /** * 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. */ @Override public Comparable getColumnKey(int column) { return this.underlying.getColumnKey(column + this.firstCategoryIndex); } /** * Returns the column keys. * * @return The keys. * * @see #getColumnKey(int) */ @Override public List<Comparable> getColumnKeys() { List<Comparable> result = new java.util.ArrayList<Comparable>(); int last = lastCategoryIndex(); for (int i = this.firstCategoryIndex; i <= last; i++) { result.add(this.underlying.getColumnKey(i)); } return Collections.unmodifiableList(result); } /** * 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. */ @Override public int getRowIndex(Comparable key) { return this.underlying.getRowIndex(key); } /** * 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. */ @Override public Comparable getRowKey(int row) { return this.underlying.getRowKey(row); } /** * Returns the row keys. * * @return The keys. */ @Override public List<Comparable> getRowKeys() { return this.underlying.getRowKeys(); } /** * Returns the value for a pair of keys. * * @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>). * * @throws UnknownKeyException if either key is not defined in the dataset. */ @Override public Number getValue(Comparable rowKey, Comparable columnKey) { int r = getRowIndex(rowKey); int c = getColumnIndex(columnKey); if (c != -1) { return this.underlying.getValue(r, c + this.firstCategoryIndex); } else { throw new UnknownKeyException("Unknown columnKey: " + columnKey); } } /** * Returns the number of columns in the table. * * @return The column count. */ @Override public int getColumnCount() { int last = lastCategoryIndex(); if (last == -1) { return 0; } else { return Math.max(last - this.firstCategoryIndex + 1, 0); } } /** * Returns the number of rows in the table. * * @return The row count. */ @Override public int getRowCount() { return this.underlying.getRowCount(); } /** * 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>). */ @Override public Number getValue(int row, int column) { return this.underlying.getValue(row, column + this.firstCategoryIndex); } /** * Tests this <code>SlidingCategoryDataset</code> 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 SlidingCategoryDataset)) { return false; } SlidingCategoryDataset that = (SlidingCategoryDataset) obj; if (this.firstCategoryIndex != that.firstCategoryIndex) { return false; } if (this.maximumCategoryCount != that.maximumCategoryCount) { return false; } if (!this.underlying.equals(that.underlying)) { 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 { SlidingCategoryDataset clone = (SlidingCategoryDataset) super.clone(); if (this.underlying instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.underlying; clone.underlying = (CategoryDataset) pc.clone(); } return clone; } }
10,828
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/CategoryDataset.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.] * * -------------------- * CategoryDataset.java * -------------------- * (C) Copyright 2000-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * 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 : Updated Javadoc comments (DG); * 04-Mar-2002 : Updated import statement (DG); * 23-Oct-2002 : Reorganised code (DG); * 10-Jan-2003 : Updated Javadocs (DG); * 21-Jan-2003 : Merged with TableDataset (which only existed in CVS) (DG); * 13-Mar-2003 : Added KeyedValues2DDataset interface (DG); * 23-Apr-2003 : Switched CategoryDataset and KeyedValues2DDataset so that * CategoryDataset is the super interface (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.category (DG); * */ package org.jfree.data.category; import org.jfree.data.KeyedValues2D; import org.jfree.data.general.Dataset; /** * The interface for a dataset with one or more series, and values associated * with categories. * <P> * The categories are represented by <code>Comparable</code> instance, with the * category label being provided by the <code>toString</code> method. */ public interface CategoryDataset extends KeyedValues2D, Dataset { // no additional methods required }
2,789
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultCategoryDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/DefaultCategoryDataset.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.] * * --------------------------- * DefaultCategoryDataset.java * --------------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 21-Jan-2003 : Added standard header, and renamed DefaultCategoryDataset (DG); * 13-Mar-2003 : Inserted DefaultKeyedValues2DDataset into class hierarchy (DG); * 06-Oct-2003 : Added incrementValue() method (DG); * 05-Apr-2004 : Added clear() method (DG); * 18-Aug-2004 : Moved from org.jfree.data --> org.jfree.data.category (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 26-Feb-2007 : Updated API docs (DG); * 08-Mar-2007 : Implemented clone() (DG); * 09-May-2008 : Implemented PublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.category; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.DefaultKeyedValues2D; import org.jfree.data.UnknownKeyException; import org.jfree.data.general.AbstractDataset; import org.jfree.data.general.DatasetChangeEvent; /** * A default implementation of the {@link CategoryDataset} interface. */ public class DefaultCategoryDataset extends AbstractDataset implements CategoryDataset, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -8168173757291644622L; /** A storage structure for the data. */ private DefaultKeyedValues2D data; /** * Creates a new (empty) dataset. */ public DefaultCategoryDataset() { this.data = new DefaultKeyedValues2D(); } /** * Returns the number of rows in the table. * * @return The row count. * * @see #getColumnCount() */ @Override public int getRowCount() { return this.data.getRowCount(); } /** * Returns the number of columns in the table. * * @return The column count. * * @see #getRowCount() */ @Override public int getColumnCount() { return this.data.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>). * * @see #addValue(Number, Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ @Override public Number getValue(int row, int column) { return this.data.getValue(row, column); } /** * Returns the key for the specified row. * * @param row the row index (zero-based). * * @return The row key. * * @see #getRowIndex(Comparable) * @see #getRowKeys() * @see #getColumnKey(int) */ @Override public Comparable getRowKey(int row) { return this.data.getRowKey(row); } /** * Returns the row index for a given key. * * @param key the row key (<code>null</code> not permitted). * * @return The row index. * * @see #getRowKey(int) */ @Override public int getRowIndex(Comparable key) { // defer null argument check return this.data.getRowIndex(key); } /** * Returns the row keys. * * @return The keys. * * @see #getRowKey(int) */ @Override public List<Comparable> getRowKeys() { return this.data.getRowKeys(); } /** * Returns a column key. * * @param column the column index (zero-based). * * @return The column key. * * @see #getColumnIndex(Comparable) */ @Override public Comparable getColumnKey(int column) { return this.data.getColumnKey(column); } /** * Returns the column index for a given key. * * @param key the column key (<code>null</code> not permitted). * * @return The column index. * * @see #getColumnKey(int) */ @Override public int getColumnIndex(Comparable key) { // defer null argument check return this.data.getColumnIndex(key); } /** * Returns the column keys. * * @return The keys. * * @see #getColumnKey(int) */ @Override public List<Comparable> getColumnKeys() { return this.data.getColumnKeys(); } /** * Returns the value for a pair of keys. * * @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>). * * @throws UnknownKeyException if either key is not defined in the dataset. * * @see #addValue(Number, Comparable, Comparable) */ @Override public Number getValue(Comparable rowKey, Comparable columnKey) { return this.data.getValue(rowKey, columnKey); } /** * Adds a value to the table. Performs the same function as setValue(). * * @param value the value. * @param rowKey the row key. * @param columnKey the column key. * * @see #getValue(Comparable, Comparable) * @see #removeValue(Comparable, Comparable) */ public void addValue(Number value, Comparable rowKey, Comparable columnKey) { this.data.addValue(value, rowKey, columnKey); fireDatasetChanged(); } /** * Adds a value to the table. * * @param value the value. * @param rowKey the row key. * @param columnKey the column key. * * @see #getValue(Comparable, Comparable) */ public void addValue(double value, Comparable rowKey, Comparable columnKey) { addValue(new Double(value), rowKey, columnKey); } /** * Adds or updates a value in the table and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @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 #getValue(Comparable, Comparable) */ public void setValue(Number value, Comparable rowKey, Comparable columnKey) { this.data.setValue(value, rowKey, columnKey); fireDatasetChanged(); } /** * Adds or updates a value in the table and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param value the value. * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @see #getValue(Comparable, Comparable) */ public void setValue(double value, Comparable rowKey, Comparable columnKey) { setValue(new Double(value), rowKey, columnKey); } /** * Adds the specified value to an existing value in the dataset (if the * existing value is <code>null</code>, it is treated as if it were 0.0). * * @param value the value. * @param rowKey the row key (<code>null</code> not permitted). * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if either key is not defined in the dataset. */ public void incrementValue(double value, Comparable rowKey, Comparable columnKey) { double existing = 0.0; Number n = getValue(rowKey, columnKey); if (n != null) { existing = n.doubleValue(); } setValue(existing + value, rowKey, columnKey); } /** * Removes a value from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param rowKey the row key. * @param columnKey the column key. * * @see #addValue(Number, Comparable, Comparable) */ public void removeValue(Comparable rowKey, Comparable columnKey) { this.data.removeValue(rowKey, columnKey); fireDatasetChanged(); } /** * Removes a row from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param rowIndex the row index. * * @see #removeColumn(int) */ public void removeRow(int rowIndex) { this.data.removeRow(rowIndex); fireDatasetChanged(); } /** * Removes a row from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param rowKey the row key. * * @see #removeColumn(Comparable) */ public void removeRow(Comparable rowKey) { this.data.removeRow(rowKey); fireDatasetChanged(); } /** * Removes a column from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param columnIndex the column index. * * @see #removeRow(int) */ public void removeColumn(int columnIndex) { this.data.removeColumn(columnIndex); fireDatasetChanged(); } /** * Removes a column from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param columnKey the column key (<code>null</code> not permitted). * * @see #removeRow(Comparable) * * @throws UnknownKeyException if <code>columnKey</code> is not defined * in the dataset. */ public void removeColumn(Comparable columnKey) { this.data.removeColumn(columnKey); fireDatasetChanged(); } /** * Clears all data from the dataset and sends a {@link DatasetChangeEvent} * to all registered listeners. */ public void clear() { this.data.clear(); 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 CategoryDataset)) { return false; } CategoryDataset that = (CategoryDataset) obj; if (!getRowKeys().equals(that.getRowKeys())) { return false; } if (!getColumnKeys().equals(that.getColumnKeys())) { return false; } int rowCount = getRowCount(); int colCount = getColumnCount(); for (int r = 0; r < rowCount; r++) { for (int c = 0; c < colCount; c++) { Number v1 = getValue(r, c); Number v2 = that.getValue(r, c); if (v1 == null) { if (v2 != null) { return false; } } else if (!v1.equals(v2)) { return false; } } } return true; } /** * Returns a hash code for the dataset. * * @return A hash code. */ @Override public int hashCode() { return this.data.hashCode(); } /** * Returns a clone of the dataset. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning the * dataset. */ @Override public Object clone() throws CloneNotSupportedException { DefaultCategoryDataset clone = (DefaultCategoryDataset) super.clone(); clone.data = (DefaultKeyedValues2D) this.data.clone(); return clone; } }
13,105
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryToPieDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/CategoryToPieDataset.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.] * * ------------------------- * CategoryToPieDataset.java * ------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Christian W. Zuckschwerdt; * * Changes * ------- * 23-Jan-2003 : Version 1 (DG); * 30-Jul-2003 : Pass through DatasetChangeEvent (CZ); * 29-Jan-2004 : Replaced 'extract' int with TableOrder (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * ------------- JFREECHART 1.0.0 RELEASED ------------------------------------ * 26-Jul-2006 : Added serialVersionUID, changed constructor to allow null * for source, and added getSource(), getExtractType() and * getExtractIndex() methods - see feature request 1477915 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.category; import java.util.ArrayList; import java.util.List; import org.jfree.chart.util.TableOrder; import org.jfree.data.general.AbstractDataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.general.PieDataset; /** * A {@link PieDataset} implementation that obtains its data from one row or * column of a {@link CategoryDataset}. */ public class CategoryToPieDataset extends AbstractDataset implements PieDataset, DatasetChangeListener { /** For serialization. */ static final long serialVersionUID = 5516396319762189617L; /** The source. */ private CategoryDataset source; /** The extract type. */ private TableOrder extract; /** The row or column index. */ private int index; /** * An adaptor class that converts any {@link CategoryDataset} into a * {@link PieDataset}, by taking the values from a single row or column. * <p> * If <code>source</code> is <code>null</code>, the created dataset will * be empty. * * @param source the source dataset (<code>null</code> permitted). * @param extract extract data from rows or columns? (<code>null</code> * not permitted). * @param index the row or column index. */ public CategoryToPieDataset(CategoryDataset source, TableOrder extract, int index) { if (extract == null) { throw new IllegalArgumentException("Null 'extract' argument."); } this.source = source; if (this.source != null) { this.source.addChangeListener(this); } this.extract = extract; this.index = index; } /** * Returns the underlying dataset. * * @return The underlying dataset (possibly <code>null</code>). * * @since 1.0.2 */ public CategoryDataset getUnderlyingDataset() { return this.source; } /** * Returns the extract type, which determines whether data is read from * one row or one column of the underlying dataset. * * @return The extract type. * * @since 1.0.2 */ public TableOrder getExtractType() { return this.extract; } /** * Returns the index of the row or column from which to extract the data. * * @return The extract index. * * @since 1.0.2 */ public int getExtractIndex() { return this.index; } /** * Returns the number of items (values) in the collection. If the * underlying dataset is <code>null</code>, this method returns zero. * * @return The item count. */ @Override public int getItemCount() { int result = 0; if (this.source != null) { if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnCount(); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowCount(); } } return result; } /** * Returns a value from the dataset. * * @param item the item index (zero-based). * * @return The value (possibly <code>null</code>). * * @throws IndexOutOfBoundsException if <code>item</code> is not in the * range <code>0</code> to <code>getItemCount() - 1</code>. */ @Override public Number getValue(int item) { Number result = null; if (item < 0 || item >= getItemCount()) { // this will include the case where the underlying dataset is null throw new IndexOutOfBoundsException( "The 'item' index is out of bounds."); } if (this.extract == TableOrder.BY_ROW) { result = this.source.getValue(this.index, item); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getValue(item, this.index); } return result; } /** * Returns the key at the specified index. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The key. * * @throws IndexOutOfBoundsException if <code>index</code> is not in the * specified range. */ @Override public Comparable getKey(int index) { Comparable result = null; if (index < 0 || index >= getItemCount()) { // this includes the case where the underlying dataset is null throw new IndexOutOfBoundsException("Invalid 'index': " + index); } if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnKey(index); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowKey(index); } return result; } /** * Returns the index for a given key, or <code>-1</code> if there is no * such key. * * @param key the key. * * @return The index for the key, or <code>-1</code>. */ @Override public int getIndex(Comparable key) { int result = -1; if (this.source != null) { if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnIndex(key); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowIndex(key); } } return result; } /** * Returns the keys for the dataset. * <p> * If the underlying dataset is <code>null</code>, this method returns an * empty list. * * @return The keys. */ @Override public List<Comparable> getKeys() { List<Comparable> result = new ArrayList<Comparable>();// = Collections.EMPTY_LIST; if (this.source != null) { if (this.extract == TableOrder.BY_ROW) { result = this.source.getColumnKeys(); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getRowKeys(); } } return result; } /** * Returns the value for a given key. If the key is not recognised, the * method should return <code>null</code> (but note that <code>null</code> * can be associated with a valid key also). * * @param key the key. * * @return The value (possibly <code>null</code>). */ @Override public Number getValue(Comparable key) { Number result = null; int keyIndex = getIndex(key); if (keyIndex != -1) { if (this.extract == TableOrder.BY_ROW) { result = this.source.getValue(this.index, keyIndex); } else if (this.extract == TableOrder.BY_COLUMN) { result = this.source.getValue(keyIndex, this.index); } } return result; } /** * Sends a {@link DatasetChangeEvent} to all registered listeners, with * this (not the underlying) dataset as the source. * * @param event the event (ignored, a new event with this dataset as the * source is sent to the listeners). */ @Override public void datasetChanged(DatasetChangeEvent event) { fireDatasetChanged(); } /** * Tests this dataset for equality with an arbitrary object, returning * <code>true</code> if <code>obj</code> is a dataset containing the same * keys and values in the same order as this dataset. * * @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 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; } }
10,854
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultIntervalCategoryDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/DefaultIntervalCategoryDataset.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.] * * ----------------------------------- * DefaultIntervalCategoryDataset.java * ----------------------------------- * (C) Copyright 2002-2008, by Jeremy Bowman and Contributors. * * Original Author: Jeremy Bowman; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 29-Apr-2002 : Version 1, contributed by Jeremy Bowman (DG); * 24-Oct-2002 : Amendments for changes made to the dataset interface (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 08-Mar-2007 : Added equals() and clone() overrides (DG); * 25-Feb-2008 : Fix for the special case where the dataset is empty, see bug * 1897580 (DG) * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * */ package org.jfree.data.category; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.ResourceBundle; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.data.DataUtilities; import org.jfree.data.UnknownKeyException; import org.jfree.data.general.AbstractSeriesDataset; /** * A convenience class that provides a default implementation of the * {@link IntervalCategoryDataset} interface. * <p> * The standard constructor accepts data in a two dimensional array where the * first dimension is the series, and the second dimension is the category. */ public class DefaultIntervalCategoryDataset extends AbstractSeriesDataset implements IntervalCategoryDataset { /** The series keys. */ private Comparable[] seriesKeys; /** The category keys. */ private Comparable[] categoryKeys; /** Storage for the start value data. */ private Number[][] startData; /** Storage for the end value data. */ private Number[][] endData; /** * Creates a new dataset using the specified data values and automatically * generated series and category keys. * * @param starts the starting values for the intervals (<code>null</code> * not permitted). * @param ends the ending values for the intervals (<code>null</code> not * permitted). */ public DefaultIntervalCategoryDataset(double[][] starts, double[][] ends) { this(DataUtilities.createNumberArray2D(starts), DataUtilities.createNumberArray2D(ends)); } /** * Constructs a dataset and populates it with data from the array. * <p> * The arrays are indexed as data[series][category]. Series and category * names are automatically generated - you can change them using the * {@link #setSeriesKeys(Comparable[])} and * {@link #setCategoryKeys(Comparable[])} methods. * * @param starts the start values data. * @param ends the end values data. */ public DefaultIntervalCategoryDataset(Number[][] starts, Number[][] ends) { this(null, null, starts, ends); } /** * Constructs a DefaultIntervalCategoryDataset, populates it with data * from the arrays, and uses the supplied names for the series. * <p> * Category names are generated automatically ("Category 1", "Category 2", * etc). * * @param seriesNames the series names (if <code>null</code>, series names * will be generated automatically). * @param starts the start values data, indexed as data[series][category]. * @param ends the end values data, indexed as data[series][category]. */ public DefaultIntervalCategoryDataset(String[] seriesNames, Number[][] starts, Number[][] ends) { this(seriesNames, null, starts, ends); } /** * Constructs a DefaultIntervalCategoryDataset, populates it with data * from the arrays, and uses the supplied names for the series and the * supplied objects for the categories. * * @param seriesKeys the series keys (if <code>null</code>, series keys * will be generated automatically). * @param categoryKeys the category keys (if <code>null</code>, category * keys will be generated automatically). * @param starts the start values data, indexed as data[series][category]. * @param ends the end values data, indexed as data[series][category]. */ public DefaultIntervalCategoryDataset(Comparable[] seriesKeys, Comparable[] categoryKeys, Number[][] starts, Number[][] ends) { this.startData = starts; this.endData = ends; if (starts != null && ends != null) { String baseName = "org.jfree.data.resources.DataPackageResources"; ResourceBundle resources = ResourceBundleWrapper.getBundle( baseName); int seriesCount = starts.length; if (seriesCount != ends.length) { String errMsg = "DefaultIntervalCategoryDataset: the number " + "of series in the start value dataset does " + "not match the number of series in the end " + "value dataset."; throw new IllegalArgumentException(errMsg); } if (seriesCount > 0) { // set up the series names... if (seriesKeys != null) { if (seriesKeys.length != seriesCount) { throw new IllegalArgumentException( "The number of series keys does not " + "match the number of series in the data."); } this.seriesKeys = seriesKeys; } else { String prefix = resources.getString( "series.default-prefix") + " "; this.seriesKeys = generateKeys(seriesCount, prefix); } // set up the category names... int categoryCount = starts[0].length; if (categoryCount != ends[0].length) { String errMsg = "DefaultIntervalCategoryDataset: the " + "number of categories in the start value " + "dataset does not match the number of " + "categories in the end value dataset."; throw new IllegalArgumentException(errMsg); } if (categoryKeys != null) { if (categoryKeys.length != categoryCount) { throw new IllegalArgumentException( "The number of category keys does not match " + "the number of categories in the data."); } this.categoryKeys = categoryKeys; } else { String prefix = resources.getString( "categories.default-prefix") + " "; this.categoryKeys = generateKeys(categoryCount, prefix); } } else { this.seriesKeys = new Comparable[0]; this.categoryKeys = new Comparable[0]; } } } /** * Returns the number of series in the dataset (possibly zero). * * @return The number of series in the dataset. * * @see #getRowCount() * @see #getCategoryCount() */ @Override public int getSeriesCount() { int result = 0; if (this.startData != null) { result = this.startData.length; } return result; } /** * Returns a series index. * * @param seriesKey the series key. * * @return The series index. * * @see #getRowIndex(Comparable) * @see #getSeriesKey(int) */ public int getSeriesIndex(Comparable seriesKey) { int result = -1; for (int i = 0; i < this.seriesKeys.length; i++) { if (seriesKey.equals(this.seriesKeys[i])) { result = i; break; } } return result; } /** * Returns the name of the specified series. * * @param series the index of the required series (zero-based). * * @return The name of the specified series. * * @see #getSeriesIndex(Comparable) */ @Override public Comparable getSeriesKey(int series) { if ((series >= getSeriesCount()) || (series < 0)) { throw new IllegalArgumentException("No such series : " + series); } return this.seriesKeys[series]; } /** * Sets the names of the series in the dataset. * * @param seriesKeys the new keys (<code>null</code> not permitted, the * length of the array must match the number of series in the * dataset). * * @see #setCategoryKeys(Comparable[]) */ public void setSeriesKeys(Comparable[] seriesKeys) { if (seriesKeys == null) { throw new IllegalArgumentException("Null 'seriesKeys' argument."); } if (seriesKeys.length != getSeriesCount()) { throw new IllegalArgumentException( "The number of series keys does not match the data."); } this.seriesKeys = seriesKeys; fireDatasetChanged(); } /** * Returns the number of categories in the dataset. * * @return The number of categories in the dataset. * * @see #getColumnCount() */ public int getCategoryCount() { int result = 0; if (this.startData != null) { if (getSeriesCount() > 0) { result = this.startData[0].length; } } return result; } /** * Returns a list of the categories in the dataset. This method supports * the {@link CategoryDataset} interface. * * @return A list of the categories in the dataset. * * @see #getRowKeys() */ @Override public List<Comparable> getColumnKeys() { // the CategoryDataset interface expects a list of categories, but // we've stored them in an array... if (this.categoryKeys == null) { return new ArrayList<Comparable>(); } else { return Collections.unmodifiableList(Arrays.asList( this.categoryKeys)); } } /** * Sets the categories for the dataset. * * @param categoryKeys an array of objects representing the categories in * the dataset. * * @see #getRowKeys() * @see #setSeriesKeys(Comparable[]) */ public void setCategoryKeys(Comparable[] categoryKeys) { if (categoryKeys == null) { throw new IllegalArgumentException("Null 'categoryKeys' argument."); } if (categoryKeys.length != getCategoryCount()) { throw new IllegalArgumentException( "The number of categories does not match the data."); } for (Comparable categoryKey : categoryKeys) { if (categoryKey == null) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.setCategoryKeys(): " + "null category not permitted."); } } this.categoryKeys = categoryKeys; fireDatasetChanged(); } /** * Returns the data value for one category in a series. * <P> * This method is part of the CategoryDataset interface. Not particularly * meaningful for this class...returns the end value. * * @param series The required series (zero based index). * @param category The required category. * * @return The data value for one category in a series (null possible). * * @see #getEndValue(Comparable, Comparable) */ @Override public Number getValue(Comparable series, Comparable category) { int seriesIndex = getSeriesIndex(series); if (seriesIndex < 0) { throw new UnknownKeyException("Unknown 'series' key."); } int itemIndex = getColumnIndex(category); if (itemIndex < 0) { throw new UnknownKeyException("Unknown 'category' key."); } return getValue(seriesIndex, itemIndex); } /** * Returns the data value for one category in a series. * <P> * This method is part of the CategoryDataset interface. Not particularly * meaningful for this class...returns the end value. * * @param series the required series (zero based index). * @param category the required category. * * @return The data value for one category in a series (null possible). * * @see #getEndValue(int, int) */ @Override public Number getValue(int series, int category) { return getEndValue(series, category); } /** * Returns the start data value for one category in a series. * * @param series the required series. * @param category the required category. * * @return The start data value for one category in a series * (possibly <code>null</code>). * * @see #getStartValue(int, int) */ @Override public Number getStartValue(Comparable series, Comparable category) { int seriesIndex = getSeriesIndex(series); if (seriesIndex < 0) { throw new UnknownKeyException("Unknown 'series' key."); } int itemIndex = getColumnIndex(category); if (itemIndex < 0) { throw new UnknownKeyException("Unknown 'category' key."); } return getStartValue(seriesIndex, itemIndex); } /** * Returns the start data value for one category in a series. * * @param series the required series (zero based index). * @param category the required category. * * @return The start data value for one category in a series * (possibly <code>null</code>). * * @see #getStartValue(Comparable, Comparable) */ @Override public Number getStartValue(int series, int category) { // check arguments... if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.getValue(): " + "series index out of range."); } if ((category < 0) || (category >= getCategoryCount())) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.getValue(): " + "category index out of range."); } // fetch the value... return this.startData[series][category]; } /** * Returns the end data value for one category in a series. * * @param series the required series. * @param category the required category. * * @return The end data value for one category in a series (null possible). * * @see #getEndValue(int, int) */ @Override public Number getEndValue(Comparable series, Comparable category) { int seriesIndex = getSeriesIndex(series); if (seriesIndex < 0) { throw new UnknownKeyException("Unknown 'series' key."); } int itemIndex = getColumnIndex(category); if (itemIndex < 0) { throw new UnknownKeyException("Unknown 'category' key."); } return getEndValue(seriesIndex, itemIndex); } /** * Returns the end data value for one category in a series. * * @param series the required series (zero based index). * @param category the required category. * * @return The end data value for one category in a series (null possible). * * @see #getEndValue(Comparable, Comparable) */ @Override public Number getEndValue(int series, int category) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.getValue(): " + "series index out of range."); } if ((category < 0) || (category >= getCategoryCount())) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.getValue(): " + "category index out of range."); } return this.endData[series][category]; } /** * Sets the start data value for one category in a series. * * @param series the series (zero-based index). * @param category the category. * * @param value The value. * * @see #setEndValue(int, Comparable, Number) */ public void setStartValue(int series, Comparable category, Number value) { // does the series exist? if ((series < 0) || (series > getSeriesCount() - 1)) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.setValue: " + "series outside valid range."); } // is the category valid? int categoryIndex = getCategoryIndex(category); if (categoryIndex < 0) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.setValue: " + "unrecognised category."); } // update the data... this.startData[series][categoryIndex] = value; fireDatasetChanged(); } /** * Sets the end data value for one category in a series. * * @param series the series (zero-based index). * @param category the category. * * @param value the value. * * @see #setStartValue(int, Comparable, Number) */ public void setEndValue(int series, Comparable category, Number value) { // does the series exist? if ((series < 0) || (series > getSeriesCount() - 1)) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.setValue: " + "series outside valid range."); } // is the category valid? int categoryIndex = getCategoryIndex(category); if (categoryIndex < 0) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.setValue: " + "unrecognised category."); } // update the data... this.endData[series][categoryIndex] = value; fireDatasetChanged(); } /** * Returns the index for the given category. * * @param category the category (<code>null</code> not permitted). * * @return The index. * * @see #getColumnIndex(Comparable) */ public int getCategoryIndex(Comparable category) { int result = -1; for (int i = 0; i < this.categoryKeys.length; i++) { if (category.equals(this.categoryKeys[i])) { result = i; break; } } return result; } /** * Generates an array of keys, by appending a space plus an integer * (starting with 1) to the supplied prefix string. * * @param count the number of keys required. * @param prefix the name prefix. * * @return An array of <i>prefixN</i> with N = { 1 .. count}. */ private Comparable[] generateKeys(int count, String prefix) { Comparable[] result = new Comparable[count]; String name; for (int i = 0; i < count; i++) { name = prefix + (i + 1); result[i] = name; } return result; } /** * Returns a column key. * * @param column the column index. * * @return The column key. * * @see #getRowKey(int) */ @Override public Comparable getColumnKey(int column) { return this.categoryKeys[column]; } /** * Returns a column index. * * @param columnKey the column key (<code>null</code> not permitted). * * @return The column index. * * @see #getCategoryIndex(Comparable) */ @Override public int getColumnIndex(Comparable columnKey) { if (columnKey == null) { throw new IllegalArgumentException("Null 'columnKey' argument."); } return getCategoryIndex(columnKey); } /** * Returns a row index. * * @param rowKey the row key. * * @return The row index. * * @see #getSeriesIndex(Comparable) */ @Override public int getRowIndex(Comparable rowKey) { return getSeriesIndex(rowKey); } /** * Returns a list of the series in the dataset. This method supports the * {@link CategoryDataset} interface. * * @return A list of the series in the dataset. * * @see #getColumnKeys() */ @Override public List<Comparable> getRowKeys() { // the CategoryDataset interface expects a list of series, but // we've stored them in an array... if (this.seriesKeys == null) { return new java.util.ArrayList<Comparable>(); } else { return Collections.unmodifiableList(Arrays.asList(this.seriesKeys)); } } /** * Returns the name of the specified series. * * @param row the index of the required row/series (zero-based). * * @return The name of the specified series. * * @see #getColumnKey(int) */ @Override public Comparable getRowKey(int row) { if ((row >= getRowCount()) || (row < 0)) { throw new IllegalArgumentException( "The 'row' argument is out of bounds."); } return this.seriesKeys[row]; } /** * Returns the number of categories in the dataset. This method is part of * the {@link CategoryDataset} interface. * * @return The number of categories in the dataset. * * @see #getCategoryCount() * @see #getRowCount() */ @Override public int getColumnCount() { return this.categoryKeys.length; } /** * Returns the number of series in the dataset (possibly zero). * * @return The number of series in the dataset. * * @see #getSeriesCount() * @see #getColumnCount() */ @Override public int getRowCount() { return this.seriesKeys.length; } /** * 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 DefaultIntervalCategoryDataset)) { return false; } DefaultIntervalCategoryDataset that = (DefaultIntervalCategoryDataset) obj; if (!Arrays.equals(this.seriesKeys, that.seriesKeys)) { return false; } if (!Arrays.equals(this.categoryKeys, that.categoryKeys)) { return false; } if (!equal(this.startData, that.startData)) { return false; } if (!equal(this.endData, that.endData)) { return false; } // seem to be the same... return true; } /** * Returns a clone of this dataset. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning the * dataset. */ @Override public Object clone() throws CloneNotSupportedException { DefaultIntervalCategoryDataset clone = (DefaultIntervalCategoryDataset) super.clone(); clone.categoryKeys = this.categoryKeys.clone(); clone.seriesKeys = this.seriesKeys.clone(); clone.startData = clone(this.startData); clone.endData = clone(this.endData); return clone; } /** * Tests two double[][] arrays for equality. * * @param array1 the first array (<code>null</code> permitted). * @param array2 the second arrray (<code>null</code> permitted). * * @return A boolean. */ private static boolean equal(Number[][] array1, Number[][] array2) { if (array1 == null) { return (array2 == null); } if (array2 == null) { return false; } if (array1.length != array2.length) { return false; } for (int i = 0; i < array1.length; i++) { if (!Arrays.equals(array1[i], array2[i])) { return false; } } return true; } /** * Clones a two dimensional array of <code>Number</code> objects. * * @param array the array (<code>null</code> not permitted). * * @return A clone of the array. */ private static Number[][] clone(Number[][] array) { if (array == null) { throw new IllegalArgumentException("Null 'array' argument."); } Number[][] result = new Number[array.length][]; for (int i = 0; i < array.length; i++) { Number[] child = array[i]; Number[] copychild = new Number[child.length]; System.arraycopy(child, 0, copychild, 0, child.length); result[i] = copychild; } return result; } }
27,027
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryRangeInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/category/CategoryRangeInfo.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.] * * ---------------------- * CategoryRangeInfo.java * ---------------------- * (C) Copyright 2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 27-Mar-2009 : Version 1 (DG); * */ package org.jfree.data.category; import java.util.List; import org.jfree.data.Range; /** * An interface that can (optionally) be implemented by a dataset to assist in * determining the minimum and maximum y-values. * * @since 1.0.13 */ public interface CategoryRangeInfo { /** * Returns the range of the values in this dataset's range. * * @param visibleSeriesKeys the keys of the visible series. * @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(List visibleSeriesKeys, boolean includeInterval); }
2,280
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetLabelExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/DatasetLabelExtension.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.] * * -------------------------- * DatasetLabelExtension.java * -------------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; import org.jfree.data.general.SelectionChangeListener; /** * Extends a dataset such that each data item has an additional label attribute * that assigns a class to this item. Each item is part of exactly one label * class. * * @author zinsmaie */ public interface DatasetLabelExtension<CURSOR extends DatasetCursor> extends DatasetExtension, WithChangeListener<SelectionChangeListener<CURSOR>> { /** default class for not labeled data items. */ public final int NO_LABEL = -1; /** * @param cursor specifies the position of the data item * @return the label attribute of the data item */ public int getLabel(CURSOR cursor); /** * @param cursor specifies the position of the data item * @param label the new label value for the data item */ public void setLabel(CURSOR cursor, int label); }
2,417
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WithChangeListener.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/WithChangeListener.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.] * * ----------------------- * WithChangeListener.java * ----------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; import java.util.EventListener; import org.jfree.data.general.SelectionChangeEvent; /** * DatasetExtensions that support change listeners can implement this interface. * * @author zinsmaie */ public interface WithChangeListener<T extends EventListener> { /** * adds a change listener to the dataset extension<br> * <br> * The listener is triggered if if changes occur except * the notify flag is set to false (@link #setNotify(boolean)). * In the latter case a change event should be triggered as soon as the * notify flag is set to true again. * * @param listener */ public void addChangeListener(T listener); /** * removes a change listener from the dataset extension<br> * * @param listener */ public void removeChangeListener(T listener); /** * Sets a flag that controls whether or not listeners receive * {@link SelectionChangeEvent} notifications. * * @param notify If the flag is set to false the listeners are no longer * informed about changes. If the flag is set to true and some changes * occurred an event should be triggered. */ public void setNotify(boolean notify); /** * @return true if the notification flag is active */ public boolean isNotify(); }
2,870
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/DatasetExtension.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.] * * --------------------- * DatasetExtension.java * --------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; import java.io.Serializable; import org.jfree.data.extension.impl.DatasetExtensionManager; import org.jfree.data.general.Dataset; /** * Base interface for dataset extensions. A dataset extension typically stores * additional information for data items (for example * {@link DatasetSelectionExtension}). Dataset extensions can be implemented in * separate helper objects or as part of a datasets. This allows to extend * older dataset implementations.<br> * <br> * The {@link DatasetExtensionManager} class can be used to pair datasets and * external helper objects and allows to treat paired datasets the same way as * datasets that directly implement * a datasetextension. * * @author zinsmaie */ public interface DatasetExtension extends Serializable { /** * @return the dataset that is extended */ public Dataset getDataset(); }
2,392
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetIterator.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/DatasetIterator.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.] * * -------------------- * DatasetIterator.java * -------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; import java.io.Serializable; import java.util.Iterator; /** * Base interface for {@link DatasetCursor} based iterators. * * @author zinsmaie */ public interface DatasetIterator<CURSOR extends DatasetCursor> extends Iterator<CURSOR>, Serializable { }
1,777
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetCursor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/DatasetCursor.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.] * * ------------------ * DatasetCursor.java * ------------------ * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; import java.io.Serializable; /** * A marker interface for a dataset cursor. A cursor encapsulates * the position of an item in a dataset and provides methods to read and write * this position. A cursor can thus be used as pointer to a data item (by its * position not by reference) as long as the dataset remains unchanged. * * @author zinsmaie */ public interface DatasetCursor extends Serializable { }
1,924
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetSelectionExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/DatasetSelectionExtension.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.] * * ------------------------------ * DatasetSelectionExtension.java * ------------------------------ * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; import org.jfree.data.general.SelectionChangeListener; /** * Extends a dataset such that each data item has an additional selection state * (either true or false). * * @author zinsmaie */ public interface DatasetSelectionExtension<CURSOR extends DatasetCursor> extends DatasetExtension, WithChangeListener<SelectionChangeListener<CURSOR>> { /** * @param cursor specifies the position of the data item * @return true if the data item is selected */ public boolean isSelected(CURSOR cursor); /** * sets the selection state of a data item * @param cursor specifies the position of the data item */ public void setSelected(CURSOR cursor, boolean selected); /** * sets all data items to unselected */ public void clearSelection(); }
2,375
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IterableSelection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/IterableSelection.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.] * * ---------------------- * IterableSelection.java * ---------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; /** * Marks a {@link DatasetSelectionExtension} that provides iterators over all * data item positions and over the data item position of a all * (selected/unselected) items * * @author zinsmaie */ public interface IterableSelection<CURSOR extends DatasetCursor> { /** * @return an iterator over all data item positions */ public DatasetIterator<CURSOR> getIterator(); /** * @param selected * @return an iterator over the data item positions of all * (selected/unselected) items */ public DatasetIterator<CURSOR> getSelectionIterator(boolean selected); }
2,141
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IterableLabel.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/IterableLabel.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.] * * ------------------ * IterableLabel.java * ------------------ * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension; /** * A {@link DatasetLabelExtension} that provides iterators over all data item * positions and over the data item position of a defined label. * * @author zinsmaie */ public interface IterableLabel<CURSOR extends DatasetCursor> { /** * @return an iterator over all data item positions */ public DatasetIterator<CURSOR> getIterator(); /** * @param label * @return an iterator over all data item positions with a label * attribute equal to the specified parameter */ public DatasetIterator<CURSOR> getLabelIterator(int label); }
2,097
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieCursor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/PieCursor.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.] * * -------------- * PieCursor.java * -------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import org.jfree.data.extension.DatasetCursor; /** * A DatasetCursor implementation for pie datasets. * @author zinsmaie */ public class PieCursor<KEY extends Comparable<KEY>> implements DatasetCursor { /** a generated serial id */ private static final long serialVersionUID = -7031433882367850307L; /** stores the key of the section */ public KEY key; /** * creates a cursor without assigned position (the cursor will only * be valid if setPosition is called at some time) */ public PieCursor() { } /** * Default pie cursor constructor. Sets the cursor position to the * specified value. * * @param key */ public PieCursor(KEY key) { this.key = key; } /** * sets the cursor position to the specified value * @param key */ public void setPosition(KEY key) { this.key = key; } //depend on the implementation of comparable //if the key overrides hashCode and equals these methods will function //for the cursor (e.g. String, Integer, ...) @Override public int hashCode() { int result = 31 + ((key == null) ? 0 : key.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } @SuppressWarnings("rawtypes") PieCursor other = (PieCursor) obj; if (key == null) { if (other.key != null) { return false; } } else if (!key.equals(other.key)) { return false; } return true; } }
3,293
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetExtensionManager.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/DatasetExtensionManager.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.] * * ---------------------------- * DatasetExtensionManager.java * ---------------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import java.io.Serializable; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import org.jfree.data.extension.DatasetExtension; import org.jfree.data.general.Dataset; /** * Allows the handling of separate {@link DatasetExtension}. Pairs a dataset * and a DatasetExtension together and provides unified access to * DatasetExtensions regardless of their implementation (in a dataset or * separate). * * @author zinsmaie */ public class DatasetExtensionManager implements Serializable { /** a generated serial id */ private static final long serialVersionUID = 3727659792806462637L; /** * all separate extensions have to be registered here */ private HashMap<Dataset, List<DatasetExtension>> registeredExtensions = new HashMap<Dataset, List<DatasetExtension>>(); /** * Registers a separate dataset extension at the extension manager (the * extension is automatically paired with its dataset). * * @param extension */ public void registerDatasetExtension(DatasetExtension extension) { List<DatasetExtension> extensionList = registeredExtensions.get( extension.getDataset()); if (extensionList != null) { extensionList.add(extension); } else { extensionList = new LinkedList<DatasetExtension>(); extensionList.add(extension); registeredExtensions.put(extension.getDataset(), extensionList); } } /** * @param dataset * @param interfaceClass * @return true if a.) the dataset implements the interface class or b.) a * separate object that implements the interface for the dataset has * been registered. a is always checked before b */ public boolean supports(Dataset dataset, Class<? extends DatasetExtension> interfaceClass) { return getExtension(dataset, interfaceClass) != null; } /** * @param dataset * @param interfaceClass * @return the implementation of the interfaceClass for the specified * dataset or null if no supporting implementation could be found i.e. * the dataset does not implement the interface itself and there no * separate implementation has been registered for the dataset */ public <T extends DatasetExtension> T getExtension(Dataset dataset, Class<T> interfaceClass) { if (interfaceClass.isAssignableFrom(dataset.getClass())) { //the dataset supports the interface return interfaceClass.cast(dataset); } else { List<DatasetExtension> extensionList = registeredExtensions.get(dataset); if (extensionList != null) { for (DatasetExtension extension : extensionList) { if (interfaceClass.isAssignableFrom(extension.getClass())) { //the dataset does not support the extension but //a matching helper object is registered for the dataset return interfaceClass.cast(extension); } } } } return null; } }
4,830
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryCursor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/CategoryCursor.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.] * * ------------------- * CategoryCursor.java * ------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import org.jfree.data.extension.DatasetCursor; /** * A DatasetCursor implementation for category datasets. * * @author zinsmaie */ public class CategoryCursor<ROW_KEY extends Comparable<ROW_KEY>, COLUMN_KEY extends Comparable<COLUMN_KEY>> implements DatasetCursor { /** a generated serial id. */ private static final long serialVersionUID = 7086987028899208483L; /** stores the key of the row position */ public ROW_KEY rowKey; /** stores the key of the column position */ public COLUMN_KEY columnKey; /** * creates a cursor without assigned position (the cursor will only * be valid if setPosition is called at some time) */ public CategoryCursor() { } /** * Default category cursor constructor. Sets the cursor position to the * specified values. * * @param rowKey * @param columnKey */ public CategoryCursor(ROW_KEY rowKey, COLUMN_KEY columnKey) { this.rowKey = rowKey; this.columnKey = columnKey; } /** * Sets the cursor position to the specified values. * * @param rowKey * @param columnKey */ public void setPosition(ROW_KEY rowKey, COLUMN_KEY columnKey) { this.rowKey = rowKey; this.columnKey = columnKey; } //depend on the implementation of comparable //if the keys overrides hashCode and equals these methods will function //for the cursor (e.g. String, Integer, ...) @Override public int hashCode() { int result = 31 + ((columnKey == null) ? 0 : columnKey.hashCode()); result = 31 * result + ((rowKey == null) ? 0 : rowKey.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } @SuppressWarnings("rawtypes") CategoryCursor other = (CategoryCursor) obj; if (columnKey == null) { if (other.columnKey != null) { return false; } } else if (!columnKey.equals(other.columnKey)) { return false; } if (rowKey == null) { if (other.rowKey != null) { return false; } } else if (!rowKey.equals(other.rowKey)) { return false; } return true; } }
4,030
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDatasetSelectionExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/XYDatasetSelectionExtension.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.] * * -------------------------------- * XYDatasetSelectionExtension.java * -------------------------------- * (C) Copyright 2013, by Michael Zinsmaier and Contributors. * * Original Author: Michael Zinsmaier; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import org.jfree.data.extension.DatasetCursor; import org.jfree.data.extension.DatasetIterator; import org.jfree.data.extension.DatasetSelectionExtension; import org.jfree.data.extension.IterableSelection; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.SelectionChangeListener; import org.jfree.data.xy.XYDataset; import java.util.ArrayList; import java.util.Iterator; /** * Extends a xy dataset with a selection state for each data item. * * @author zinsmaie */ public class XYDatasetSelectionExtension extends AbstractDatasetSelectionExtension<XYCursor, XYDataset> implements IterableSelection<XYCursor> { /** A generated serial id. */ private static final long serialVersionUID = 4859712483757720877L; /** private ref to the stored dataset to avoid casting same as ({@link AbstractDatasetSelectionExtension#dataset})*/ private XYDataset dataset; /** * Storage for the selection attributes of the data items (one list for * each series). */ private ArrayList<Boolean>[] selectionData; /** * Creates a separate selection extension for the specified dataset. * * @param dataset the underlying dataset (<code>null</code> not permitted). */ @SuppressWarnings("unchecked") //can't instantiate selection data with //correct type (array limits) public XYDatasetSelectionExtension(XYDataset dataset) { super(dataset); this.dataset = dataset; //this.selectionData = new ArrayList[dataset.getSeriesCount()]; this.selectionData = new ArrayList[50]; initSelection(); } /** * Creates a separate selection extension for the specified dataset. And * adds an initial selection change listener, e.g. a plot that should be * redrawn on selection changes. * * @param dataset * @param initialListener */ public XYDatasetSelectionExtension(XYDataset dataset, SelectionChangeListener<XYCursor> initialListener) { super(dataset); addChangeListener(initialListener); } /** * A change of the underlying dataset clears the selection and * reinitializes it. * * @param event the event details. */ public void datasetChanged(DatasetChangeEvent event) { initSelection(); } /** * {@link DatasetSelectionExtension#isSelected(DatasetCursor)} */ public boolean isSelected(XYCursor cursor) { return (selectionData[cursor.series].get(cursor.item)); } /** * {@link DatasetSelectionExtension#setSelected(DatasetCursor, boolean)} */ public void setSelected(XYCursor cursor, boolean selected) { selectionData[cursor.series].set(cursor.item, Boolean.valueOf(selected)); notifyIfRequired(); } /** * {@link DatasetSelectionExtension#clearSelection()} */ public void clearSelection() { initSelection(); } /** * inits the selection attribute storage and sets all data items to unselected */ private void initSelection() { for (int i = 0; i < dataset.getSeriesCount(); i++) { selectionData[i] = new ArrayList<Boolean>(dataset.getItemCount(i)); for (int j = 0; j < dataset.getItemCount(i); j++) { selectionData[i].add(Boolean.FALSE); } } notifyIfRequired(); } // ITERATOR IMPLEMENTATION /** * {@link IterableSelection#getIterator()} */ public DatasetIterator<XYCursor> getIterator() { return new XYDatasetSelectionIterator(); } /** * {@link IterableSelection#getSelectionIterator(boolean)} */ public DatasetIterator<XYCursor> getSelectionIterator(boolean selected) { return new XYDatasetSelectionIterator(selected); } /** * Allows to iterate over all data items or the selected / unselected data * items. Provides on each iteration step a DatasetCursor that defines the * position of the data item. * * @author zinsmaie */ private class XYDatasetSelectionIterator implements DatasetIterator<XYCursor> { // could be improved wtr speed by storing selected elements directly // for faster access however storage efficiency would decrease /** A generated serial id. */ private static final long serialVersionUID = 125607273863837608L; /** current series position */ private int series = 0; /** current item position initialized before the start of the dataset */ private int item = -1; /** * return all data item positions (null), only the selected (true) or * only the unselected (false) */ private Boolean filter = null; /** * Creates an iterator over all data item positions. */ public XYDatasetSelectionIterator() { } /** * Creates an iterator that iterates either over all selected or all * unselected data item positions. * * @param selected if true the iterator will iterate over the selected * data item positions */ public XYDatasetSelectionIterator(boolean selected) { this.filter = Boolean.valueOf(selected); } /** {@link Iterator#hasNext() */ public boolean hasNext() { if (nextPosition()[0] != -1) { return true; } return false; } /** * {@link Iterator#next()} */ public XYCursor next() { int[] newPos = nextPosition(); this.series = newPos[0]; this.item = newPos[1]; return new XYCursor(this.series, this.item); } /** * iterator remove operation is not supported */ public void remove() { throw new UnsupportedOperationException(); } /** * Calculates the next position based on the current position * and the filter status. * @return an array holding the next position [series, item] */ private int[] nextPosition() { int pSeries = this.series; int pItem = this.item; while (pSeries < selectionData.length) { if ((pItem+1) >= selectionData[pSeries].size()) { pSeries++; pItem = -1; continue; } if (filter != null) { if (!(filter.equals(selectionData[pSeries].get(pItem + 1)))) { pItem++; continue; } } //success return new int[] {pSeries, (pItem+1)}; } return new int[] {-1,-1}; } } }
8,686
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYCursor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/XYCursor.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.] * * ------------- * XYCursor.java * ------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import org.jfree.data.extension.DatasetCursor; /** * A DatasetCursor implementation for xy datasets. * @author zinsmaie */ public class XYCursor implements DatasetCursor { /** a generated serial id */ private static final long serialVersionUID = -8005904310382047935L; /** stores the series position */ public int series; /** stores the item position */ public int item; /** * creates a cursor without assigned position (the cursor will only * be valid if setPosition is called at some time) */ public XYCursor() { } /** * Default xy cursor constructor. Sets the cursor position to the specified * values. * * @param series * @param item */ public XYCursor(int series, int item) { this.series = series; this.item = item; } /** * Sets the cursor position to the specified values. * @param series * @param item */ public void setPosition(int series, int item) { this.series = series; this.item = item; } //in contrast to the other cursor implementations //hasCode and equals for the XYCursor work guaranteed as expected @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + item; result = prime * result + series; return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } XYCursor other = (XYCursor) obj; if (item != other.item) { return false; } if (series != other.series) { return false; } return true; } }
3,383
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryDatasetSelectionExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/CategoryDatasetSelectionExtension.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.] * * -------------------------------------- * CategoryDatasetSelectionExtension.java * -------------------------------------- * (C) Copyright 2013, by Michael Zinsmaier. * * Original Author: Michael Zinsmaier; * Contributor(s): -; * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import java.util.Iterator; import org.jfree.data.DefaultKeyedValues2D; import org.jfree.data.category.CategoryDataset; import org.jfree.data.extension.DatasetCursor; import org.jfree.data.extension.DatasetIterator; import org.jfree.data.extension.DatasetSelectionExtension; import org.jfree.data.extension.IterableSelection; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.SelectionChangeListener; /** * Extends a category dataset with a selection state for each data item. * * @author zinsmaie */ public class CategoryDatasetSelectionExtension<ROW_KEY extends Comparable<ROW_KEY>, COLUMN_KEY extends Comparable<COLUMN_KEY>> extends AbstractDatasetSelectionExtension<CategoryCursor<ROW_KEY, COLUMN_KEY>, CategoryDataset> implements IterableSelection<CategoryCursor<ROW_KEY, COLUMN_KEY>> { /** a generated serial id */ private static final long serialVersionUID = 5138359490302459066L; /** * private ref to the stored dataset to avoid casting same as * ({@link AbstractDatasetSelectionExtension#dataset}) */ private CategoryDataset dataset; //could improve here by using own bool data structure /** storage for the selection attributes of the data items. */ private DefaultKeyedValues2D selectionData; /** defines true as byte value */ private final Number TRUE = new Byte((byte) 1); /** defines false as byte value */ private final Number FALSE = new Byte((byte) 0); /** * Creates a separate selection extension for the specified dataset. * * @param dataset the underlying dataset (<code>null</code> not permitted). */ public CategoryDatasetSelectionExtension(CategoryDataset dataset) { super(dataset); this.dataset = dataset; initSelection(); } /** * Creates a separate selection extension for the specified dataset. And * adds an initial selection change listener, e.g. a plot that should be * redrawn on selection changes. * * @param dataset * @param initialListener */ public CategoryDatasetSelectionExtension(CategoryDataset dataset, SelectionChangeListener<CategoryCursor<ROW_KEY, COLUMN_KEY>> initialListener) { super(dataset); addChangeListener(initialListener); } /** * Returns the selection status of the data item referenced by the * supplied cursor. * * @param cursor the cursor (<code>null</code> not permitted). * * @return The selection status. */ public boolean isSelected(CategoryCursor<ROW_KEY, COLUMN_KEY> cursor) { return (TRUE == this.selectionData.getValue(cursor.rowKey, cursor.columnKey)); } /** * {@link DatasetSelectionExtension#setSelected(DatasetCursor, boolean)} */ public void setSelected(CategoryCursor<ROW_KEY, COLUMN_KEY> cursor, boolean selected) { if (selected) { selectionData.setValue(TRUE, cursor.rowKey, cursor.columnKey); } else { selectionData.setValue(FALSE, cursor.rowKey, cursor.columnKey); } notifyIfRequired(); } /** * {@link DatasetSelectionExtension#clearSelection()} */ public void clearSelection() { initSelection(); } /** * Receives notification of a change to the underlying dataset, this is * handled by clearing the selection. * * @param event details of the change event. */ public void datasetChanged(DatasetChangeEvent event) { // TODO : we could in fact try to preserve the selection state of // items that still remain in the dataset. initSelection(); } /** * inits the selection attribute storage and sets all data items to * unselected */ private void initSelection() { this.selectionData = new DefaultKeyedValues2D(); for (int i = 0; i < dataset.getRowCount(); i++) { for (int j= 0; j < dataset.getColumnCount(); j++) { if (dataset.getValue(i, j) != null) { selectionData.addValue(FALSE, dataset.getRowKey(i), dataset.getColumnKey(j)); } } } notifyIfRequired(); } //ITERATOR /** * {@link IterableSelection#getIterator()} */ public DatasetIterator<CategoryCursor<ROW_KEY, COLUMN_KEY>> getIterator() { return new CategoryDatasetSelectionIterator(); } /** * {@link IterableSelection#getSelectionIterator(boolean)} */ public DatasetIterator<CategoryCursor<ROW_KEY, COLUMN_KEY>> getSelectionIterator(boolean selected) { return new CategoryDatasetSelectionIterator(selected); } /** * Allows to iterate over all data items or the selected / unselected data * items. Provides on each iteration step a DatasetCursor that defines the * position of the data item. * * @author zinsmaie */ private class CategoryDatasetSelectionIterator implements DatasetIterator<CategoryCursor<ROW_KEY, COLUMN_KEY>> { // could be improved wtr speed by storing selected elements directly for // faster access however storage efficiency would decrease /** a generated serial id */ private static final long serialVersionUID = -6861323401482698708L; /** current row position */ private int row = 0; /** * current column position initialized before the start of the * dataset */ private int column = -1; /** * return all data item positions (null), only the selected (true) or * only the unselected (false) */ private Boolean filter = null; /** * Creates an iterator over all data item positions */ public CategoryDatasetSelectionIterator() { } /** * Creates an iterator that iterates either over all selected or all * unselected data item positions. * * @param selected if true the iterator will iterate over the selected * data item positions */ public CategoryDatasetSelectionIterator(boolean selected) { this.filter = Boolean.valueOf(selected); } /** * {@link Iterator#hasNext() */ public boolean hasNext() { if (nextPosition()[0] != -1) { return true; } return false; } /** * {@link Iterator#next()} */ public CategoryCursor<ROW_KEY, COLUMN_KEY> next() { int[] newPos = nextPosition(); row = newPos[0]; column = newPos[1]; // category datasets are not yet typed therefore the cast is // necessary (and may fail) return new CategoryCursor<ROW_KEY, COLUMN_KEY>( (ROW_KEY) dataset.getRowKey(row), (COLUMN_KEY) dataset.getColumnKey(column)); } /** * Iterator remove operation is not supported. */ public void remove() { throw new UnsupportedOperationException(); } /** * Calculates the next position based on the current position * and the filter status. * * @return an array holding the next position [row, column] */ private int[] nextPosition() { int pRow = this.row; int pColumn = this.column; while (pRow < dataset.getRowCount()) { if ((pColumn+1) >= selectionData.getColumnCount()) { pRow++; pColumn = -1; continue; } if (filter != null) { if (!((filter.equals(Boolean.TRUE) && TRUE.equals( selectionData.getValue(pRow, (pColumn+1)))) || (filter.equals(Boolean.FALSE) && FALSE.equals( selectionData.getValue(pRow, (pColumn+1)))))) { pColumn++; continue; } } //success return new int[]{pRow, (pColumn+1)}; } return new int[]{-1,-1}; } } }
10,160
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractDatasetSelectionExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/AbstractDatasetSelectionExtension.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.] * * -------------------------------------- * AbstractDatasetSelectionExtension.java * -------------------------------------- * (C) Copyright 2013, by Michael Zinsmaier and Contributors. * * Original Author: Michael Zinsmaier; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import javax.swing.event.EventListenerList; import org.jfree.chart.util.ParamChecks; import org.jfree.data.extension.DatasetCursor; import org.jfree.data.extension.DatasetExtension; import org.jfree.data.extension.DatasetSelectionExtension; import org.jfree.data.extension.WithChangeListener; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.general.SelectionChangeEvent; import org.jfree.data.general.SelectionChangeListener; /** * Base class for separate selection extension implementations. Provides * notification handling and listener support. * * @author zinsmaie */ public abstract class AbstractDatasetSelectionExtension<CURSOR extends DatasetCursor, DATASET extends Dataset> implements DatasetSelectionExtension<CURSOR>, DatasetChangeListener { /** a generated serial id */ private static final long serialVersionUID = 4206903652292146757L; /** Storage for registered listeners. */ private transient EventListenerList listenerList = new EventListenerList(); /** notify flag {@link #isNotify()} */ private boolean notify; /** * dirty flag true if changes occurred is used to trigger a queued change * event if notify is reset to true. */ private boolean dirty; /** reference to the extended dataset */ private final DATASET dataset; /** * Creates a new instance. * * @param dataset the underlying dataset (<code>null</code> not permitted). */ public AbstractDatasetSelectionExtension(DATASET dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); this.dataset = dataset; this.dataset.addChangeListener(this); } /** * {@link DatasetExtension#getDataset} */ public DATASET getDataset() { return this.dataset; } /** * {@link DatasetSelectionExtension#addChangeListener(org.jfree.data.general.SelectionChangeListener) */ public void addChangeListener(SelectionChangeListener<CURSOR> listener) { this.notify = true; this.listenerList.add(SelectionChangeListener.class, listener); } /** * {@link WithChangeListener#removeChangeListener(EventListener)) */ public void removeChangeListener(SelectionChangeListener<CURSOR> listener) { this.listenerList.remove(SelectionChangeListener.class, listener); } /** * {@link WithChangeListener#setNotify(boolean)} */ public void setNotify(boolean notify) { if (this.notify != notify) { if (notify == false) { //switch notification temporary off this.dirty = false; } else { //switch notification on if (this.dirty == true) { notifyListeners(); } } this.notify = notify; } } /** * {@link WithChangeListener#isNotify()} */ public boolean isNotify() { return this.notify; } /** * can be called by subclasses to trigger notify events depending on the * notify flag. */ protected void notifyIfRequired() { if (this.notify) { notifyListeners(); } else { this.dirty = true; } } /** * notifies all registered listeners * @param event */ @SuppressWarnings("unchecked") //add method accepts only SelectionChangeListeners<CURSOR> private void notifyListeners() { Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == SelectionChangeListener.class) { ((SelectionChangeListener<CURSOR>) listeners[i + 1]) .selectionChanged(new SelectionChangeEvent<CURSOR>(this)); } } } }
5,570
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieDatasetSelectionExtension.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/extension/impl/PieDatasetSelectionExtension.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.] * * --------------------------------- * PieDatasetSelectionExtension.java * --------------------------------- * (C) Copyright 2013, by Michael Zinsmaier and Contributors. * * Original Author: Michael Zinsmaier; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 17-Sep-2013 : Version 1 (MZ); * */ package org.jfree.data.extension.impl; import java.util.HashMap; import org.jfree.data.UnknownKeyException; import org.jfree.data.extension.DatasetCursor; import org.jfree.data.extension.DatasetIterator; import org.jfree.data.extension.DatasetSelectionExtension; import org.jfree.data.extension.IterableSelection; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.PieDataset; import org.jfree.data.general.SelectionChangeListener; /** * Extends a pie dataset with a selection state for each data item. * * @author zinsmaie */ public class PieDatasetSelectionExtension<KEY extends Comparable<KEY>> extends AbstractDatasetSelectionExtension<PieCursor<KEY>, PieDataset> implements IterableSelection<PieCursor<KEY>> { /** a generated serial id */ private static final long serialVersionUID = -1735271052194147081L; /** * private ref to the stored dataset to avoid casting same as * ({@link AbstractDatasetSelectionExtension#dataset}) */ private PieDataset dataset; /** Storage for the selection attributes of the data items. */ private HashMap<KEY, Boolean> selectionData; /** * Creates a separate selection extension for the specified dataset. * @param dataset */ public PieDatasetSelectionExtension(PieDataset dataset) { super(dataset); this.dataset = dataset; initSelection(); } /** * Creates a separate selection extension for the specified dataset. And * adds an initial selection change listener, e.g. a plot that should be * redrawn on selection changes. * * @param dataset * @param initialListener */ public PieDatasetSelectionExtension(PieDataset dataset, SelectionChangeListener initialListener) { super(dataset); addChangeListener(initialListener); } /** * {@link DatasetSelectionExtension#isSelected(DatasetCursor)} */ public boolean isSelected(PieCursor<KEY> cursor) { Boolean b = this.selectionData.get(cursor.key); if (b == null) { throw new UnknownKeyException("Unrecognised key " + cursor.key); } return Boolean.TRUE.equals(b); } /** * {@link DatasetSelectionExtension#setSelected(DatasetCursor, boolean)} */ public void setSelected(PieCursor<KEY> cursor, boolean selected) { this.selectionData.put(cursor.key, Boolean.valueOf(selected)); notifyIfRequired(); } /** * {@link DatasetSelectionExtension#clearSelection()} */ public void clearSelection() { initSelection(); } /** * A change of the underlying dataset clears the selection and reinitializes * it */ public void datasetChanged(DatasetChangeEvent event) { initSelection(); } /** * Inits the selection attribute storage and sets all data items to * unselected. */ private void initSelection() { this.selectionData = new HashMap<KEY, Boolean>(); // pie datasets are not yet typed therefore the cast is necessary // (and may fail) for (Comparable key : this.dataset.getKeys()) { this.selectionData.put((KEY) key, Boolean.FALSE); } notifyIfRequired(); } //ITERATOR IMPLEMENTATION /** * {@link IterableSelection#getIterator()} */ public DatasetIterator<PieCursor<KEY>> getIterator() { return new PieDatasetSelectionIterator(); } /** * {@link IterableSelection#getSelectionIterator(boolean)} */ public DatasetIterator<PieCursor<KEY>> getSelectionIterator( boolean selected) { return new PieDatasetSelectionIterator(selected); } /** * Allows to iterate over all data items or the selected / unselected data * items. Provides on each iteration step a DatasetCursor that defines * the position of the data item. * * @author zinsmaie */ private class PieDatasetSelectionIterator implements DatasetIterator<PieCursor<KEY>> { // could be improved wtr speed by storing selected elements directly for // faster access however storage efficiency would decrease /** a generated serial id */ private static final long serialVersionUID = -9037547822331524470L; /** current section initialized before the start of the dataset */ private int section = -1; /** * return all data item positions (null), only the selected (true) or * only the unselected (false) */ private Boolean filter = null; /** * creates an iterator over all data item positions */ public PieDatasetSelectionIterator() { } /** * Creates an iterator that iterates either over all selected or all * unselected data item positions. * * @param selected if true the iterator will iterate over the selected * data item positions */ public PieDatasetSelectionIterator(boolean selected) { filter = Boolean.valueOf(selected); } /** {@link Iterator#hasNext() */ public boolean hasNext() { if (nextPosition() != -1) { return true; } return false; } /** * {@link Iterator#next()} */ public PieCursor<KEY> next() { this.section = nextPosition(); //pie datasets are not yet typed therefore the cast is necessary //(and may fail) KEY key = (KEY)dataset.getKey(this.section); return new PieCursor<KEY>(key); } /** * iterator remove operation is not supported */ public void remove() { throw new UnsupportedOperationException(); } /** * Calculates the next position based on the current position * and the filter status. * @return an array holding the next position section */ private int nextPosition() { int pSection = this.section; while ((pSection+1) < dataset.getItemCount()) { if (filter != null) { Comparable<?> key = dataset.getKey((pSection+1)); if (!(filter.equals(selectionData.get(key)))) { pSection++; continue; } } //success return (pSection+1); } return -1; } } }
8,359
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataPackageResources.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/resources/DataPackageResources.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.] * * ------------------------- * DataPackageResources.java * ------------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 21-Mar-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */ package org.jfree.data.resources; import java.util.ListResourceBundle; /** * A resource bundle that stores all the items that might need localisation. * */ public class DataPackageResources extends ListResourceBundle { /** * Returns the array of strings in the resource bundle. * * @return The localised resources. */ public Object[][] getContents() { return CONTENTS; } /** The resources to be localised. */ private static final Object[][] CONTENTS = { {"series.default-prefix", "Series"}, {"categories.default-prefix", "Category"}, }; }
2,206
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataPackageResources_fr.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/resources/DataPackageResources_fr.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.] * * ---------------------------- * DataPackageResources_fr.java * ---------------------------- * * Original Author: Anthony Boulestreau; * Contributor(s): -; * * Changes * ------- * 26-Mar-2002 : Version 1 (AB); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.resources; import java.util.ListResourceBundle; /** * A resource bundle that stores all the items that might need localisation. */ public class DataPackageResources_fr extends ListResourceBundle { /** * Returns the array of strings in the resource bundle. * * @return The localised resources. */ public Object[][] getContents() { return CONTENTS; } /** The resources to be localised. */ private static final Object[][] CONTENTS = { {"series.default-prefix", "S?ries"}, {"categories.default-prefix", "Cat?gorie"}, }; }
2,200
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/resources/package-info.java
/** * Resource bundles for items that require localisation. */ package org.jfree.data.resources;
99
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataPackageResources_ru.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/resources/DataPackageResources_ru.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.] * * ---------------------------- * DataPackageResources_ru.java * ---------------------------- * * Original Author: Sergey Bondarenko; * Contributor(s): -; * * Changes * ------- * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.resources; import java.util.ListResourceBundle; /** * A resource bundle that stores all the items that might need localisation. */ public class DataPackageResources_ru extends ListResourceBundle { /** * Returns the array of strings in the resource bundle. * * @return The localised resources. */ public Object[][] getContents() { return CONTENTS; } /** The resources to be localised. */ private static final Object[][] CONTENTS = { {"series.default-prefix", "?????"}, {"categories.default-prefix", "?????????"}, }; }
2,105
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataPackageResources_pl.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/resources/DataPackageResources_pl.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.] * * ---------------------------- * DataPackageResources_pl.java * ---------------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * Polish translation: Krzysztof Pa? ([email protected]) * * Changes * ------- * 21-Mar-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.resources; import java.util.ListResourceBundle; /** * A resource bundle that stores all the items that might need localisation. */ public class DataPackageResources_pl extends ListResourceBundle { /** * Returns the array of strings in the resource bundle. * * @return The localised resources. */ public Object[][] getContents() { return CONTENTS; } /** The resources to be localised. */ private static final Object[][] CONTENTS = { {"series.default-prefix", "Serie"}, {"categories.default-prefix", "Kategorie"}, }; }
2,349
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataPackageResources_es.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/resources/DataPackageResources_es.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.] * * ---------------------------- * DataPackageResources_es.java * ---------------------------- * (C) Copyright 2002-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Hans-Jurgen Greiner; * * Changes * ------- * 26-Mar-2002 : Version 1, translation by Hans-Jurgen Greiner (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.resources; import java.util.ListResourceBundle; /** * A resource bundle that stores all the items that might need localisation. */ public class DataPackageResources_es extends ListResourceBundle { /** * Returns the array of strings in the resource bundle. * * @return The localised resources. */ public Object[][] getContents() { return CONTENTS; } /** The resources to be localised. */ private static final Object[][] CONTENTS = { {"series.default-prefix", "Series"}, {"categories.default-prefix", "Categor?a"}, }; }
2,359
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DataPackageResources_de.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/resources/DataPackageResources_de.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.] * * ---------------------------- * DataPackageResources_de.java * ---------------------------- * (C) Copyright 2002-2008, by Object Refinery Limited and Contributors. * * Original Author: Thomas Meier; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 04-Apr-2002 : Version 1, translation by Thomas Meier (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.resources; import java.util.ListResourceBundle; /** * A resource bundle that stores all the items that might need localisation. */ public class DataPackageResources_de extends ListResourceBundle { /** * Returns the array of strings in the resource bundle. * * @return The localised resources. */ public Object[][] getContents() { return CONTENTS; } /** The resources to be localised. */ private static final Object[][] CONTENTS = { {"series.default-prefix", "Reihen"}, {"categories.default-prefix", "Kategorien"}, }; }
2,345
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
FixedMillisecond.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/FixedMillisecond.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.] * * --------------------- * FixedMillisecond.java * --------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 19-Mar-2002 : Version 1, based on original Millisecond implementation (DG); * 24-Jun-2002 : Removed unnecessary imports (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Oct-2006 : Added peg() method (DG); * 28-May-2008 : Fixed immutability problem (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; /** * Wrapper for a <code>java.util.Date</code> object that allows it to be used * as a {@link RegularTimePeriod}. This class is immutable, which is a * requirement for all {@link RegularTimePeriod} subclasses. */ public class FixedMillisecond extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = 7867521484545646931L; /** The millisecond. */ private long time; /** * Constructs a millisecond based on the current system time. */ public FixedMillisecond() { this(new Date()); } /** * Constructs a millisecond. * * @param millisecond the millisecond (same encoding as java.util.Date). */ public FixedMillisecond(long millisecond) { this(new Date(millisecond)); } /** * Constructs a millisecond. * * @param time the time. */ public FixedMillisecond(Date time) { this.time = time.getTime(); } /** * Returns the date/time. * * @return The date/time. */ public Date getTime() { return new Date(this.time); } /** * This method is overridden to do nothing. * * @param calendar ignored * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { // nothing to do } /** * Returns the millisecond preceding this one. * * @return The millisecond preceding this one. */ @Override public RegularTimePeriod previous() { RegularTimePeriod result = null; long t = this.time; if (t != Long.MIN_VALUE) { result = new FixedMillisecond(t - 1); } return result; } /** * Returns the millisecond following this one. * * @return The millisecond following this one. */ @Override public RegularTimePeriod next() { RegularTimePeriod result = null; long t = this.time; if (t != Long.MAX_VALUE) { result = new FixedMillisecond(t + 1); } return result; } /** * Tests the equality of this object against an arbitrary Object. * * @param object the object to compare * * @return A boolean. */ @Override public boolean equals(Object object) { if (object instanceof FixedMillisecond) { FixedMillisecond m = (FixedMillisecond) object; return this.time == m.getFirstMillisecond(); } else { return false; } } /** * Returns a hash code for this object instance. * * @return A hash code. */ @Override public int hashCode() { return (int) this.time; } /** * Returns an integer indicating the order of this Millisecond object * relative to the specified * object: negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; long difference; // CASE 1 : Comparing to another Second object // ------------------------------------------- if (o1 instanceof FixedMillisecond) { FixedMillisecond t1 = (FixedMillisecond) o1; difference = this.time - t1.time; if (difference > 0) { result = 1; } else { if (difference < 0) { result = -1; } else { result = 0; } } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Returns the first millisecond of the time period. * * @return The first millisecond of the time period. */ @Override public long getFirstMillisecond() { return this.time; } /** * Returns the first millisecond of the time period. * * @param calendar the calendar. * * @return The first millisecond of the time period. */ @Override public long getFirstMillisecond(Calendar calendar) { return this.time; } /** * Returns the last millisecond of the time period. * * @return The last millisecond of the time period. */ @Override public long getLastMillisecond() { return this.time; } /** * Returns the last millisecond of the time period. * * @param calendar the calendar. * * @return The last millisecond of the time period. */ @Override public long getLastMillisecond(Calendar calendar) { return this.time; } /** * Returns the millisecond closest to the middle of the time period. * * @return The millisecond closest to the middle of the time period. */ @Override public long getMiddleMillisecond() { return this.time; } /** * Returns the millisecond closest to the middle of the time period. * * @param calendar the calendar. * * @return The millisecond closest to the middle of the time period. */ @Override public long getMiddleMillisecond(Calendar calendar) { return this.time; } /** * Returns a serial index number for the millisecond. * * @return The serial index number. */ @Override public long getSerialIndex() { return this.time; } }
7,943
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Millisecond.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Millisecond.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.] * * ---------------- * Millisecond.java * ---------------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 19-Dec-2001 : Added new constructors as suggested by Paul English (DG); * 26-Feb-2002 : Added new getStart() and getEnd() methods (DG); * 29-Mar-2002 : Fixed bug in getStart(), getEnd() and compareTo() methods (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 04-Apr-2007 : In Millisecond(Date, TimeZone), peg milliseconds to the * specified zone (DG); * 06-Jun-2008 : Added handling for general RegularTimePeriod in compareTo() * method: * see http://www.jfree.org/phpBB2/viewtopic.php?t=24805 (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 02-Mar-2009 : Added new constructor with Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Represents a millisecond. This class is immutable, which is a requirement * for all {@link RegularTimePeriod} subclasses. */ public class Millisecond extends RegularTimePeriod implements Serializable, Comparable<TimePeriod> { /** For serialization. */ static final long serialVersionUID = -5316836467277638485L; /** A constant for the first millisecond in a second. */ public static final int FIRST_MILLISECOND_IN_SECOND = 0; /** A constant for the last millisecond in a second. */ public static final int LAST_MILLISECOND_IN_SECOND = 999; /** The day. */ private Day day; /** The hour in the day. */ private byte hour; /** The minute. */ private byte minute; /** The second. */ private byte second; /** The millisecond. */ private int millisecond; /** * The pegged millisecond. */ private long firstMillisecond; /** * Constructs a millisecond based on the current system time. */ public Millisecond() { this(new Date()); } /** * Constructs a millisecond. * * @param millisecond the millisecond (0-999). * @param second the second. */ public Millisecond(int millisecond, Second second) { this.millisecond = millisecond; this.second = (byte) second.getSecond(); this.minute = (byte) second.getMinute().getMinute(); this.hour = (byte) second.getMinute().getHourValue(); this.day = second.getMinute().getDay(); peg(Calendar.getInstance()); } /** * Creates a new millisecond. * * @param millisecond the millisecond (0-999). * @param second the second (0-59). * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Millisecond(int millisecond, int second, int minute, int hour, int day, int month, int year) { this(millisecond, new Second(second, minute, hour, day, month, year)); } /** * Constructs a new millisecond using the default time zone. * * @param time the time. * * @see #Millisecond(Date, TimeZone) */ public Millisecond(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a millisecond. * * @param time the date-time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.13 */ public Millisecond(Date time, TimeZone zone, Locale locale) { Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); this.millisecond = calendar.get(Calendar.MILLISECOND); this.second = (byte) calendar.get(Calendar.SECOND); this.minute = (byte) calendar.get(Calendar.MINUTE); this.hour = (byte) calendar.get(Calendar.HOUR_OF_DAY); this.day = new Day(time, zone, locale); peg(calendar); } /** * Returns the second. * * @return The second. */ public Second getSecond() { return new Second(this.second, this.minute, this.hour, this.day.getDayOfMonth(), this.day.getMonth(), this.day.getYear()); } /** * Returns the millisecond. * * @return The millisecond. */ public long getMillisecond() { return this.millisecond; } /** * Returns the first millisecond of the second. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the second. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the second. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the second. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.firstMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); } /** * Returns the millisecond preceding this one. * * @return The millisecond preceding this one. */ @Override public RegularTimePeriod previous() { RegularTimePeriod result = null; if (this.millisecond != FIRST_MILLISECOND_IN_SECOND) { result = new Millisecond(this.millisecond - 1, getSecond()); } else { Second previous = (Second) getSecond().previous(); if (previous != null) { result = new Millisecond(LAST_MILLISECOND_IN_SECOND, previous); } } return result; } /** * Returns the millisecond following this one. * * @return The millisecond following this one. */ @Override public RegularTimePeriod next() { RegularTimePeriod result = null; if (this.millisecond != LAST_MILLISECOND_IN_SECOND) { result = new Millisecond(this.millisecond + 1, getSecond()); } else { Second next = (Second) getSecond().next(); if (next != null) { result = new Millisecond(FIRST_MILLISECOND_IN_SECOND, next); } } return result; } /** * Returns a serial index number for the millisecond. * * @return The serial index number. */ @Override public long getSerialIndex() { long hourIndex = this.day.getSerialIndex() * 24L + this.hour; long minuteIndex = hourIndex * 60L + this.minute; long secondIndex = minuteIndex * 60L + this.second; return secondIndex * 1000L + this.millisecond; } /** * Tests the equality of this object against an arbitrary Object. * <P> * This method will return true ONLY if the object is a Millisecond object * representing the same millisecond as this instance. * * @param obj the object to compare * * @return <code>true</code> if milliseconds and seconds of this and object * are the same. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Millisecond)) { return false; } Millisecond that = (Millisecond) obj; if (this.millisecond != that.millisecond) { return false; } if (this.second != that.second) { return false; } if (this.minute != that.minute) { return false; } if (this.hour != that.hour) { return false; } if (!this.day.equals(that.day)) { return false; } return true; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hashcode. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.millisecond; result = 37 * result + getSecond().hashCode(); return result; } /** * Returns an integer indicating the order of this Millisecond object * relative to the specified object: * * negative == before, zero == same, positive == after. * * @param obj the object to compare * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod obj) { int result; long difference; // CASE 1 : Comparing to another Second object // ------------------------------------------- if (obj instanceof Millisecond) { Millisecond ms = (Millisecond) obj; difference = getFirstMillisecond() - ms.getFirstMillisecond(); if (difference > 0) { result = 1; } else { if (difference < 0) { result = -1; } else { result = 0; } } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { RegularTimePeriod rtp = (RegularTimePeriod) obj; final long thisVal = this.getFirstMillisecond(); final long anotherVal = rtp.getFirstMillisecond(); result = (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1)); } return result; } /** * Returns the first millisecond of the time period. * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the time period. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { int year = this.day.getYear(); int month = this.day.getMonth() - 1; int day = this.day.getDayOfMonth(); calendar.clear(); calendar.set(year, month, day, this.hour, this.minute, this.second); calendar.set(Calendar.MILLISECOND, this.millisecond); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the time period. * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the time period. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { return getFirstMillisecond(calendar); } }
13,557
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Day.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Day.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.] * * -------- * Day.java * -------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 15-Nov-2001 : Updated Javadoc comments (DG); * 04-Dec-2001 : Added static method to parse a string into a Day object (DG); * 19-Dec-2001 : Added new constructor as suggested by Paul English (DG); * 29-Jan-2002 : Changed getDay() method to getSerialDate() (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 19-Mar-2002 : Changed the API for the TimePeriod classes (DG); * 29-May-2002 : Fixed bug in equals method (DG); * 24-Jun-2002 : Removed unnecessary imports (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * 30-Sep-2004 : Replaced getTime().getTime() with getTimeInMillis() (DG); * 04-Nov-2004 : Reverted change of 30-Sep-2004, because it won't work for * JDK 1.3 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 02-Mar-2009 : Added new constructor with Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import org.jfree.chart.date.SerialDate; /** * Represents a single day in the range 1-Jan-1900 to 31-Dec-9999. This class * is immutable, which is a requirement for all {@link RegularTimePeriod} * subclasses. */ public class Day extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = -7082667380758962755L; /** A standard date formatter. */ protected static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); /** A date formatter for the default locale. */ protected static final DateFormat DATE_FORMAT_SHORT = DateFormat.getDateInstance(DateFormat.SHORT); /** A date formatter for the default locale. */ protected static final DateFormat DATE_FORMAT_MEDIUM = DateFormat.getDateInstance(DateFormat.MEDIUM); /** A date formatter for the default locale. */ protected static final DateFormat DATE_FORMAT_LONG = DateFormat.getDateInstance(DateFormat.LONG); /** The day (uses SerialDate for convenience). */ private SerialDate serialDate; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Creates a new instance, derived from the system date/time (and assuming * the default timezone). */ public Day() { this(new Date()); } /** * Constructs a new one day time period. * * @param day the day-of-the-month. * @param month the month (1 to 12). * @param year the year (1900 <= year <= 9999). */ public Day(int day, int month, int year) { this.serialDate = SerialDate.createInstance(day, month, year); peg(Calendar.getInstance()); } /** * Constructs a new one day time period. * * @param serialDate the day (<code>null</code> not permitted). */ public Day(SerialDate serialDate) { if (serialDate == null) { throw new IllegalArgumentException("Null 'serialDate' argument."); } this.serialDate = serialDate; peg(Calendar.getInstance()); } /** * Constructs a new instance, based on a particular date/time and the * default time zone. * * @param time the time (<code>null</code> not permitted). * * @see #Day(Date, TimeZone) */ public Day(Date time) { // defer argument checking... this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Constructs a new instance, based on a particular date/time and time zone. * * @param time the date/time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). */ public Day(Date time, TimeZone zone, Locale locale) { if (time == null) { throw new IllegalArgumentException("Null 'time' argument."); } if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } if (locale == null) { throw new IllegalArgumentException("Null 'locale' argument."); } Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); int d = calendar.get(Calendar.DAY_OF_MONTH); int m = calendar.get(Calendar.MONTH) + 1; int y = calendar.get(Calendar.YEAR); this.serialDate = SerialDate.createInstance(d, m, y); peg(calendar); } /** * Returns the day as a {@link SerialDate}. Note: the reference that is * returned should be an instance of an immutable {@link SerialDate} * (otherwise the caller could use the reference to alter the state of * this <code>Day</code> instance, and <code>Day</code> is supposed * to be immutable). * * @return The day as a {@link SerialDate}. */ public SerialDate getSerialDate() { return this.serialDate; } /** * Returns the year. * * @return The year. */ public int getYear() { return this.serialDate.getYYYY(); } /** * Returns the month. * * @return The month. */ public int getMonth() { return this.serialDate.getMonth(); } /** * Returns the day of the month. * * @return The day of the month. */ public int getDayOfMonth() { return this.serialDate.getDayOfMonth(); } /** * Returns the first millisecond of the day. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the day. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the day. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the day. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the day preceding this one. * * @return The day preceding this one. */ @Override public RegularTimePeriod previous() { int serial = this.serialDate.toSerial(); if (serial > SerialDate.SERIAL_LOWER_BOUND) { SerialDate yesterday = SerialDate.createInstance(serial - 1); return new Day(yesterday); } return null; } /** * Returns the day following this one, or <code>null</code> if some limit * has been reached. * * @return The day following this one, or <code>null</code> if some limit * has been reached. */ @Override public RegularTimePeriod next() { int serial = this.serialDate.toSerial(); if (serial < SerialDate.SERIAL_UPPER_BOUND) { SerialDate tomorrow = SerialDate.createInstance(serial + 1); return new Day(tomorrow); } return null; } /** * Returns a serial index number for the day. * * @return The serial index number. */ @Override public long getSerialIndex() { return this.serialDate.toSerial(); } /** * Returns the first millisecond of the day, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar calendar to use (<code>null</code> not permitted). * * @return The start of the day as milliseconds since 01-01-1970. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { int year = this.serialDate.getYYYY(); int month = this.serialDate.getMonth(); int day = this.serialDate.getDayOfMonth(); calendar.clear(); calendar.set(year, month - 1, day, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the day, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar calendar to use (<code>null</code> not permitted). * * @return The end of the day as milliseconds since 01-01-1970. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { int year = this.serialDate.getYYYY(); int month = this.serialDate.getMonth(); int day = this.serialDate.getDayOfMonth(); calendar.clear(); calendar.set(year, month - 1, day, 23, 59, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTimeInMillis(); } /** * Tests the equality of this Day object to an arbitrary object. Returns * true if the target is a Day instance or a SerialDate instance * representing the same day as this object. In all other cases, * returns false. * * @param obj the object (<code>null</code> permitted). * * @return A flag indicating whether or not an object is equal to this day. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Day)) { return false; } Day that = (Day) obj; if (!this.serialDate.equals(that.getSerialDate())) { return false; } return true; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { return this.serialDate.hashCode(); } /** * Returns an integer indicating the order of this Day object relative to * the specified object: * * negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Day object // ---------------------------------------- if (o1 instanceof Day) { Day d = (Day) o1; result = -d.getSerialDate().compare(this.serialDate); } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Returns a string representing the day. * * @return A string representing the day. */ @Override public String toString() { return this.serialDate.toString(); } /** * Parses the string argument as a day. * <P> * This method is required to recognise YYYY-MM-DD as a valid format. * Anything else, for now, is a bonus. * * @param s the date string to parse. * * @return <code>null</code> if the string does not contain any parseable * string, the day otherwise. */ public static Day parseDay(String s) { try { return new Day (Day.DATE_FORMAT.parse(s)); } catch (ParseException e1) { try { return new Day (Day.DATE_FORMAT_SHORT.parse(s)); } catch (ParseException e2) { // ignore } } return null; } }
14,791
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodValue.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimePeriodValue.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.] * * -------------------- * TimePeriodValue.java * -------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 22-Apr-2003 : Version 1 (DG); * 03-Oct-2006 : Added null argument check to constructor (DG); * 07-Apr-2008 : Added a toString() override for debugging (DG); * */ package org.jfree.data.time; import java.io.Serializable; /** * Represents a time period and an associated value. */ public class TimePeriodValue implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 3390443360845711275L; /** The time period. */ private TimePeriod period; /** The value associated with the time period. */ private Number value; /** * Constructs a new data item. * * @param period the time period (<code>null</code> not permitted). * @param value the value associated with the time period. * * @throws IllegalArgumentException if <code>period</code> is * <code>null</code>. */ public TimePeriodValue(TimePeriod period, Number value) { if (period == null) { throw new IllegalArgumentException("Null 'period' argument."); } this.period = period; this.value = value; } /** * Constructs a new data item. * * @param period the time period (<code>null</code> not permitted). * @param value the value associated with the time period. * * @throws IllegalArgumentException if <code>period</code> is * <code>null</code>. */ public TimePeriodValue(TimePeriod period, double value) { this(period, new Double(value)); } /** * Returns the time period. * * @return The time period (never <code>null</code>). */ public TimePeriod getPeriod() { return this.period; } /** * Returns the value. * * @return The value (possibly <code>null</code>). * * @see #setValue(Number) */ public Number getValue() { return this.value; } /** * Sets the value for this data item. * * @param value the new value (<code>null</code> permitted). * * @see #getValue() */ public void setValue(Number value) { this.value = value; } /** * Tests this object for equality with the target object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof TimePeriodValue)) { return false; } TimePeriodValue timePeriodValue = (TimePeriodValue) obj; if (this.period != null ? !this.period.equals(timePeriodValue.period) : timePeriodValue.period != null) { return false; } if (this.value != null ? !this.value.equals(timePeriodValue.value) : timePeriodValue.value != null) { return false; } return true; } /** * Returns a hash code value for the object. * * @return The hashcode */ @Override public int hashCode() { int result; result = (this.period != null ? this.period.hashCode() : 0); result = 29 * result + (this.value != null ? this.value.hashCode() : 0); return result; } /** * Clones the object. * <P> * Note: no need to clone the period or value since they are immutable * classes. * * @return A clone. */ @Override public Object clone() { Object clone = null; try { clone = super.clone(); } catch (CloneNotSupportedException e) { // won't get here... e.printStackTrace(); } return clone; } /** * Returns a string representing this instance, primarily for use in * debugging. * * @return A string. */ @Override public String toString() { return "TimePeriodValue[" + getPeriod() + "," + getValue() + "]"; } }
5,504
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeTableXYDataset.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimeTableXYDataset.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.] * * ----------------------- * TimeTableXYDataset.java * ----------------------- * (C) Copyright 2004-2012, by Andreas Schroeder and Contributors. * * Original Author: Andreas Schroeder; * Contributor(s): David Gilbert (for Object Refinery Limited); * Rob Eden; * * Changes * ------- * 01-Apr-2004 : Version 1 (AS); * 05-May-2004 : Now implements AbstractIntervalXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 15-Sep-2004 : Added getXPosition(), setXPosition(), equals() and * clone() (DG); * 17-Nov-2004 : Updated methods for changes in DomainInfo interface (DG); * 25-Nov-2004 : Added getTimePeriod(int) method (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * 27-Jan-2005 : Modified to use TimePeriod rather than RegularTimePeriod (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 25-Jul-2007 : Added clear() method by Rob Eden, see patch 1752205 (DG); * 04-Jun-2008 : Updated Javadocs (DG); * 26-May-2009 : Peg to time zone if RegularTimePeriod is used (DG); * 02-Nov-2009 : Changed String to Comparable in add methods (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.time; import java.util.Calendar; import java.util.List; import java.util.Locale; import java.util.TimeZone; 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.xy.AbstractIntervalXYDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.TableXYDataset; /** * A dataset for regular time periods that implements the * {@link TableXYDataset} interface. Note that the {@link TableXYDataset} * interface requires all series to share the same set of x-values. When * adding a new item <code>(x, y)</code> to one series, all other series * automatically get a new item <code>(x, null)</code> unless a non-null item * has already been specified. * * @see org.jfree.data.xy.TableXYDataset */ public class TimeTableXYDataset extends AbstractIntervalXYDataset implements Cloneable, PublicCloneable, IntervalXYDataset, DomainInfo, TableXYDataset { /** * The data structure to store the values. Each column represents * a series (elsewhere in JFreeChart rows are typically used for series, * but it doesn't matter that much since this data structure is private * and symmetrical anyway), each row contains values for the same * {@link RegularTimePeriod} (the rows are sorted into ascending order). */ private DefaultKeyedValues2D values; /** * A flag that indicates that the domain is 'points in time'. If this flag * is true, only the x-value (and not the x-interval) is used to determine * the range of values in the domain. */ private boolean domainIsPointsInTime; /** * The point within each time period that is used for the X value when this * collection is used as an {@link org.jfree.data.xy.XYDataset}. This can * be the start, middle or end of the time period. */ private TimePeriodAnchor xPosition; /** A working calendar (to recycle) */ private Calendar workingCalendar; /** * Creates a new dataset. */ public TimeTableXYDataset() { // defer argument checking this(TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a new dataset with the given time zone. * * @param zone the time zone to use (<code>null</code> not permitted). */ public TimeTableXYDataset(TimeZone zone) { // defer argument checking this(zone, Locale.getDefault()); } /** * Creates a new dataset with the given time zone and locale. * * @param zone the time zone to use (<code>null</code> not permitted). * @param locale the locale to use (<code>null</code> not permitted). */ public TimeTableXYDataset(TimeZone zone, Locale locale) { if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } if (locale == null) { throw new IllegalArgumentException("Null 'locale' argument."); } this.values = new DefaultKeyedValues2D(true); this.workingCalendar = Calendar.getInstance(zone, locale); this.xPosition = TimePeriodAnchor.START; } /** * Returns a flag that controls whether the domain is treated as 'points in * time'. * <P> * This flag is used when determining the max and min values for the domain. * If true, then only the x-values are considered for the max and min * values. If false, then the start and end x-values will also be taken * into consideration. * * @return The flag. * * @see #setDomainIsPointsInTime(boolean) */ public boolean getDomainIsPointsInTime() { return this.domainIsPointsInTime; } /** * Sets a flag that controls whether the domain is treated as 'points in * time', or time periods. A {@link DatasetChangeEvent} is sent to all * registered listeners. * * @param flag the new value of the flag. * * @see #getDomainIsPointsInTime() */ public void setDomainIsPointsInTime(boolean flag) { this.domainIsPointsInTime = flag; notifyListeners(new DatasetChangeEvent(this, this)); } /** * Returns the position within each time period that is used for the X * value. * * @return The anchor position (never <code>null</code>). * * @see #setXPosition(TimePeriodAnchor) */ public TimePeriodAnchor getXPosition() { return this.xPosition; } /** * Sets the position within each time period that is used for the X values, * then sends a {@link DatasetChangeEvent} to all registered listeners. * * @param anchor the anchor position (<code>null</code> not permitted). * * @see #getXPosition() */ public void setXPosition(TimePeriodAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.xPosition = anchor; notifyListeners(new DatasetChangeEvent(this, this)); } /** * Adds a new data item to the dataset and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param period the time period. * @param y the value for this period. * @param seriesName the name of the series to add the value. * * @see #remove(TimePeriod, Comparable) */ public void add(TimePeriod period, double y, Comparable seriesName) { add(period, y, seriesName, true); } /** * Adds a new data item to the dataset and, if requested, sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param period the time period (<code>null</code> not permitted). * @param y the value for this period (<code>null</code> permitted). * @param seriesName the name of the series to add the value * (<code>null</code> not permitted). * @param notify whether dataset listener are notified or not. * * @see #remove(TimePeriod, Comparable, boolean) */ public void add(TimePeriod period, Number y, Comparable seriesName, boolean notify) { // here's a quirk - the API has been defined in terms of a plain // TimePeriod, which cannot make use of the timezone and locale // specified in the constructor...so we only do the time zone // pegging if the period is an instanceof RegularTimePeriod if (period instanceof RegularTimePeriod) { RegularTimePeriod p = (RegularTimePeriod) period; p.peg(this.workingCalendar); } this.values.addValue(y, period, seriesName); if (notify) { fireDatasetChanged(); } } /** * Removes an existing data item from the dataset. * * @param period the (existing!) time period of the value to remove * (<code>null</code> not permitted). * @param seriesName the (existing!) series name to remove the value * (<code>null</code> not permitted). * * @see #add(TimePeriod, double, Comparable) */ public void remove(TimePeriod period, Comparable seriesName) { remove(period, seriesName, true); } /** * Removes an existing data item from the dataset and, if requested, * sends a {@link DatasetChangeEvent} to all registered listeners. * * @param period the (existing!) time period of the value to remove * (<code>null</code> not permitted). * @param seriesName the (existing!) series name to remove the value * (<code>null</code> not permitted). * @param notify whether dataset listener are notified or not. * * @see #add(TimePeriod, double, Comparable) */ public void remove(TimePeriod period, Comparable seriesName, boolean notify) { this.values.removeValue(period, seriesName); if (notify) { fireDatasetChanged(); } } /** * Removes all data items from the dataset and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.7 */ public void clear() { if (this.values.getRowCount() > 0) { this.values.clear(); fireDatasetChanged(); } } /** * Returns the time period for the specified item. Bear in mind that all * series share the same set of time periods. * * @param item the item index (0 <= i <= {@link #getItemCount()}). * * @return The time period. */ public TimePeriod getTimePeriod(int item) { return (TimePeriod) this.values.getRowKey(item); } /** * Returns the number of items in ALL series. * * @return The item count. */ @Override public int getItemCount() { return this.values.getRowCount(); } /** * Returns the number of items in a series. This is the same value * that is returned by {@link #getItemCount()} since all series * share the same x-values (time periods). * * @param series the series (zero-based index, ignored). * * @return The number of items within the series. */ @Override public int getItemCount(int series) { return getItemCount(); } /** * Returns the number of series in the dataset. * * @return The series count. */ @Override public int getSeriesCount() { return this.values.getColumnCount(); } /** * Returns the key for a series. * * @param series the series (zero-based index). * * @return The key for the series. */ @Override public Comparable getSeriesKey(int series) { return this.values.getColumnKey(series); } /** * Returns the x-value for an item within a series. The x-values may or * may not be returned in ascending order, that is up to the class * implementing the interface. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The x-value. */ @Override public Number getX(int series, int item) { return getXValue(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. */ @Override public double getXValue(int series, int item) { TimePeriod period = (TimePeriod) this.values.getRowKey(item); return getXValue(period); } /** * Returns the starting X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The starting X value for the specified series and item. * * @see #getStartXValue(int, int) */ @Override public Number getStartX(int series, int item) { return getStartXValue(series, item); } /** * 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) { TimePeriod period = (TimePeriod) this.values.getRowKey(item); return period.getStart().getTime(); } /** * Returns the ending X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item within a series (zero-based index). * * @return The ending X value for the specified series and item. * * @see #getEndXValue(int, int) */ @Override public Number getEndX(int series, int item) { return getEndXValue(series, item); } /** * 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) { TimePeriod period = (TimePeriod) this.values.getRowKey(item); return period.getEnd().getTime(); } /** * Returns the y-value for an item within a series. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @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 (zero-based index). * @param item the item within a series (zero-based index). * * @return The starting Y value for the specified series and item. */ @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 (zero-based index). * @param item the item within a series (zero-based index). * * @return The ending Y value for the specified series and item. */ @Override public Number getEndY(int series, int item) { return getY(series, item); } /** * Returns the x-value for a time period. * * @param period the time period. * * @return The x-value. */ private long getXValue(TimePeriod period) { long result = 0L; if (this.xPosition == TimePeriodAnchor.START) { result = period.getStart().getTime(); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { long t0 = period.getStart().getTime(); long t1 = period.getEnd().getTime(); result = t0 + (t1 - t0) / 2L; } else if (this.xPosition == TimePeriodAnchor.END) { result = period.getEnd().getTime(); } return result; } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getLowerBound(); } return result; } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getUpperBound(); } return result; } /** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that controls whether or not the * x-intervals are taken into account. * * @return The range. */ @Override public Range getDomainBounds(boolean includeInterval) { List<Comparable> keys = this.values.getRowKeys(); if (keys.isEmpty()) { return null; } TimePeriod first = (TimePeriod) keys.get(0); TimePeriod last = (TimePeriod) keys.get(keys.size() - 1); if (!includeInterval || this.domainIsPointsInTime) { return new Range(getXValue(first), getXValue(last)); } else { return new Range(first.getStart().getTime(), last.getEnd().getTime()); } } /** * 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 TimeTableXYDataset)) { return false; } TimeTableXYDataset that = (TimeTableXYDataset) obj; if (this.domainIsPointsInTime != that.domainIsPointsInTime) { return false; } if (this.xPosition != that.xPosition) { return false; } if (!this.workingCalendar.getTimeZone().equals( that.workingCalendar.getTimeZone()) ) { return false; } if (!this.values.equals(that.values)) { return false; } return true; } /** * Returns a clone of this dataset. * * @return A clone. * * @throws CloneNotSupportedException if the dataset cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { TimeTableXYDataset clone = (TimeTableXYDataset) super.clone(); clone.values = (DefaultKeyedValues2D) this.values.clone(); clone.workingCalendar = (Calendar) this.workingCalendar.clone(); return clone; } }
20,307
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriod.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimePeriod.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.] * * --------------- * TimePeriod.java * --------------- * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 10-Jan-2003 : Version 1 (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package (DG); * 27-Jan-2005 : Implemented Comparable (DG); * */ package org.jfree.data.time; import java.util.Date; /** * A period of time measured to millisecond precision using two instances of * <code>java.util.Date</code>. */ public interface TimePeriod extends Comparable<TimePeriod> { /** * Returns the start date/time. This will always be on or before the * end date. * * @return The start date/time (never <code>null</code>). */ public Date getStart(); /** * Returns the end date/time. This will always be on or after the * start date. * * @return The end date/time (never <code>null</code>). */ public Date getEnd(); }
2,263
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/time/package-info.java
/** * Interfaces and classes for time-related data. */ package org.jfree.data.time;
86
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodFormatException.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimePeriodFormatException.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.] * * ------------------------------ * TimePeriodFormatException.java * ------------------------------ * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 07-Dec-2001 : Version 1 (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package (DG); */ package org.jfree.data.time; /** * An exception that indicates an invalid format in a string representing a * time period. */ public class TimePeriodFormatException extends IllegalArgumentException { /** * Creates a new exception. * * @param message a message describing the exception. */ public TimePeriodFormatException(String message) { super(message); } }
2,009
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodValues.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimePeriodValues.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.] * * --------------------- * TimePeriodValues.java * --------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 22-Apr-2003 : Version 1 (DG); * 30-Jul-2003 : Added clone and equals methods while testing (DG); * 11-Mar-2005 : Fixed bug in bounds recalculation - see bug report * 1161329 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 03-Oct-2006 : Fixed NullPointerException in equals(), fire change event in * add() method, updated API docs (DG); * 07-Apr-2008 : Fixed bug with maxMiddleIndex in updateBounds() (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.ArrayList; 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 structure containing zero, one or many {@link TimePeriodValue} instances. * The time periods can overlap, and are maintained in the order that they are * added to the collection. * <p> * This is similar to the {@link TimeSeries} class, except that the time * periods can have irregular lengths. */ public class TimePeriodValues extends Series implements Serializable { /** For serialization. */ static final long serialVersionUID = -2210593619794989709L; /** Default value for the domain description. */ protected static final String DEFAULT_DOMAIN_DESCRIPTION = "Time"; /** Default value for the range description. */ protected static final String DEFAULT_RANGE_DESCRIPTION = "Value"; /** A description of the domain. */ private String domain; /** A description of the range. */ private String range; /** The list of data pairs in the series. */ private List<TimePeriodValue> data; /** Index of the time period with the minimum start milliseconds. */ private int minStartIndex = -1; /** Index of the time period with the maximum start milliseconds. */ private int maxStartIndex = -1; /** Index of the time period with the minimum middle milliseconds. */ private int minMiddleIndex = -1; /** Index of the time period with the maximum middle milliseconds. */ private int maxMiddleIndex = -1; /** Index of the time period with the minimum end milliseconds. */ private int minEndIndex = -1; /** Index of the time period with the maximum end milliseconds. */ private int maxEndIndex = -1; /** * Creates a new (empty) collection of time period values. * * @param name the name of the series (<code>null</code> not permitted). */ public TimePeriodValues(String name) { this(name, DEFAULT_DOMAIN_DESCRIPTION, DEFAULT_RANGE_DESCRIPTION); } /** * Creates a new time series that contains no data. * <P> * Descriptions can be specified for the domain and range. One situation * where this is helpful is when generating a chart for the time series - * axis labels can be taken from the domain and range description. * * @param name the name of the series (<code>null</code> not permitted). * @param domain the domain description. * @param range the range description. */ public TimePeriodValues(String name, String domain, String range) { super(name); this.domain = domain; this.range = range; this.data = new ArrayList<TimePeriodValue>(); } /** * Returns the domain description. * * @return The domain description (possibly <code>null</code>). * * @see #getRangeDescription() * @see #setDomainDescription(String) */ public String getDomainDescription() { return this.domain; } /** * Sets the domain description and fires a property change event (with the * property name <code>Domain</code> if the description changes). * * @param description the new description (<code>null</code> permitted). * * @see #getDomainDescription() */ public void setDomainDescription(String description) { String old = this.domain; this.domain = description; firePropertyChange("Domain", old, description); } /** * Returns the range description. * * @return The range description (possibly <code>null</code>). * * @see #getDomainDescription() * @see #setRangeDescription(String) */ public String getRangeDescription() { return this.range; } /** * Sets the range description and fires a property change event with the * name <code>Range</code>. * * @param description the new description (<code>null</code> permitted). * * @see #getRangeDescription() */ public void setRangeDescription(String description) { String old = this.range; this.range = description; firePropertyChange("Range", old, description); } /** * Returns the number of items in the series. * * @return The item count. */ @Override public int getItemCount() { return this.data.size(); } /** * Returns one data item for the series. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return One data item for the series. */ public TimePeriodValue getDataItem(int index) { return this.data.get(index); } /** * Returns the time period at the specified index. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The time period at the specified index. * * @see #getDataItem(int) */ public TimePeriod getTimePeriod(int index) { return getDataItem(index).getPeriod(); } /** * Returns the value at the specified index. * * @param index the item index (in the range <code>0</code> to * <code>getItemCount() - 1</code>). * * @return The value at the specified index (possibly <code>null</code>). * * @see #getDataItem(int) */ public Number getValue(int index) { return getDataItem(index).getValue(); } /** * Adds a data item to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. * * @param item the item (<code>null</code> not permitted). */ public void add(TimePeriodValue item) { if (item == null) { throw new IllegalArgumentException("Null item not allowed."); } this.data.add(item); updateBounds(item.getPeriod(), this.data.size() - 1); fireSeriesChanged(); } /** * Update the index values for the maximum and minimum bounds. * * @param period the time period. * @param index the index of the time period. */ private void updateBounds(TimePeriod period, int index) { long start = period.getStart().getTime(); long end = period.getEnd().getTime(); long middle = start + ((end - start) / 2); if (this.minStartIndex >= 0) { long minStart = getDataItem(this.minStartIndex).getPeriod() .getStart().getTime(); if (start < minStart) { this.minStartIndex = index; } } else { this.minStartIndex = index; } if (this.maxStartIndex >= 0) { long maxStart = getDataItem(this.maxStartIndex).getPeriod() .getStart().getTime(); if (start > maxStart) { this.maxStartIndex = index; } } else { this.maxStartIndex = index; } if (this.minMiddleIndex >= 0) { long s = getDataItem(this.minMiddleIndex).getPeriod().getStart() .getTime(); long e = getDataItem(this.minMiddleIndex).getPeriod().getEnd() .getTime(); long minMiddle = s + (e - s) / 2; if (middle < minMiddle) { this.minMiddleIndex = index; } } else { this.minMiddleIndex = index; } if (this.maxMiddleIndex >= 0) { long s = getDataItem(this.maxMiddleIndex).getPeriod().getStart() .getTime(); long e = getDataItem(this.maxMiddleIndex).getPeriod().getEnd() .getTime(); long maxMiddle = s + (e - s) / 2; if (middle > maxMiddle) { this.maxMiddleIndex = index; } } else { this.maxMiddleIndex = index; } if (this.minEndIndex >= 0) { long minEnd = getDataItem(this.minEndIndex).getPeriod().getEnd() .getTime(); if (end < minEnd) { this.minEndIndex = index; } } else { this.minEndIndex = index; } if (this.maxEndIndex >= 0) { long maxEnd = getDataItem(this.maxEndIndex).getPeriod().getEnd() .getTime(); if (end > maxEnd) { this.maxEndIndex = index; } } else { this.maxEndIndex = index; } } /** * Recalculates the bounds for the collection of items. */ private void recalculateBounds() { this.minStartIndex = -1; this.minMiddleIndex = -1; this.minEndIndex = -1; this.maxStartIndex = -1; this.maxMiddleIndex = -1; this.maxEndIndex = -1; for (int i = 0; i < this.data.size(); i++) { TimePeriodValue tpv = this.data.get(i); updateBounds(tpv.getPeriod(), i); } } /** * Adds a new data item to the series and sends a {@link SeriesChangeEvent} * to all registered listeners. * * @param period the time period (<code>null</code> not permitted). * @param value the value. * * @see #add(TimePeriod, Number) */ public void add(TimePeriod period, double value) { TimePeriodValue item = new TimePeriodValue(period, value); add(item); } /** * Adds a new data item to the series and sends a {@link SeriesChangeEvent} * to all registered listeners. * * @param period the time period (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public void add(TimePeriod period, Number value) { TimePeriodValue item = new TimePeriodValue(period, value); add(item); } /** * Updates (changes) the value of a data item and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the index of the data item to update. * @param value the new value (<code>null</code> not permitted). */ public void update(int index, Number value) { TimePeriodValue item = getDataItem(index); item.setValue(value); fireSeriesChanged(); } /** * Deletes data from start until end index (end inclusive) and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param start the index of the first period to delete. * @param end the index of the last period to delete. */ public void delete(int start, int end) { for (int i = 0; i <= (end - start); i++) { this.data.remove(start); } recalculateBounds(); fireSeriesChanged(); } /** * 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 TimePeriodValues)) { return false; } if (!super.equals(obj)) { return false; } TimePeriodValues that = (TimePeriodValues) obj; if (!ObjectUtilities.equal(this.getDomainDescription(), that.getDomainDescription())) { return false; } if (!ObjectUtilities.equal(this.getRangeDescription(), that.getRangeDescription())) { return false; } int count = getItemCount(); if (count != that.getItemCount()) { return false; } for (int i = 0; i < count; i++) { if (!getDataItem(i).equals(that.getDataItem(i))) { return false; } } return true; } /** * Returns a hash code value for the object. * * @return The hashcode */ @Override public int hashCode() { int result; result = (this.domain != null ? this.domain.hashCode() : 0); result = 29 * result + (this.range != null ? this.range.hashCode() : 0); result = 29 * result + this.data.hashCode(); result = 29 * result + this.minStartIndex; result = 29 * result + this.maxStartIndex; result = 29 * result + this.minMiddleIndex; result = 29 * result + this.maxMiddleIndex; result = 29 * result + this.minEndIndex; result = 29 * result + this.maxEndIndex; return result; } /** * Returns a clone of the collection. * <P> * Notes: * <ul> * <li>no need to clone the domain and range descriptions, since String * object is immutable;</li> * <li>we pass over to the more general method createCopy(start, end). * </li> * </ul> * * @return A clone of the time series. * * @throws CloneNotSupportedException if there is a cloning problem. */ @Override public Object clone() throws CloneNotSupportedException { Object clone = createCopy(0, getItemCount() - 1); return clone; } /** * Creates a new instance by copying a subset of the data in this * collection. * * @param start the index of the first item to copy. * @param end the index of the last item to copy. * * @return A copy of a subset of the items. * * @throws CloneNotSupportedException if there is a cloning problem. */ public TimePeriodValues createCopy(int start, int end) throws CloneNotSupportedException { TimePeriodValues copy = (TimePeriodValues) super.clone(); copy.data = new ArrayList<TimePeriodValue>(); if (this.data.size() > 0) { for (int index = start; index <= end; index++) { TimePeriodValue item = this.data.get(index); TimePeriodValue clone = (TimePeriodValue) item.clone(); try { copy.add(clone); } catch (SeriesException e) { throw new RuntimeException("Could not add cloned item", e); } } } return copy; } /** * Returns the index of the time period with the minimum start milliseconds. * * @return The index. */ public int getMinStartIndex() { return this.minStartIndex; } /** * Returns the index of the time period with the maximum start milliseconds. * * @return The index. */ public int getMaxStartIndex() { return this.maxStartIndex; } /** * Returns the index of the time period with the minimum middle * milliseconds. * * @return The index. */ public int getMinMiddleIndex() { return this.minMiddleIndex; } /** * Returns the index of the time period with the maximum middle * milliseconds. * * @return The index. */ public int getMaxMiddleIndex() { return this.maxMiddleIndex; } /** * Returns the index of the time period with the minimum end milliseconds. * * @return The index. */ public int getMinEndIndex() { return this.minEndIndex; } /** * Returns the index of the time period with the maximum end milliseconds. * * @return The index. */ public int getMaxEndIndex() { return this.maxEndIndex; } }
17,833
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Second.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Second.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.] * * ----------- * Second.java * ----------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 18-Dec-2001 : Changed order of parameters in constructor (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 14-Feb-2002 : Fixed bug in Second(Date) constructor, and changed start of * range to zero from one (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 13-Mar-2002 : Added parseSecond() method (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 05-Mar-2003 : Fixed bug in getLastMillisecond() picked up in JUnit * tests (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 02-Mar-2009 : Added new constructor with Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Represents a second in a particular day. This class is immutable, which is * a requirement for all {@link RegularTimePeriod} subclasses. */ public class Second extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = -6536564190712383466L; /** Useful constant for the first second in a minute. */ public static final int FIRST_SECOND_IN_MINUTE = 0; /** Useful constant for the last second in a minute. */ public static final int LAST_SECOND_IN_MINUTE = 59; /** The day. */ private Day day; /** The hour of the day. */ private byte hour; /** The minute. */ private byte minute; /** The second. */ private byte second; /** * The first millisecond. We don't store the last millisecond, because it * is always firstMillisecond + 999L. */ private long firstMillisecond; /** * Constructs a new Second, based on the system date/time. */ public Second() { this(new Date()); } /** * Constructs a new Second. * * @param second the second (0 to 24*60*60-1). * @param minute the minute (<code>null</code> not permitted). */ public Second(int second, Minute minute) { if (minute == null) { throw new IllegalArgumentException("Null 'minute' argument."); } this.day = minute.getDay(); this.hour = (byte) minute.getHourValue(); this.minute = (byte) minute.getMinute(); this.second = (byte) second; peg(Calendar.getInstance()); } /** * Creates a new second. * * @param second the second (0-59). * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Second(int second, int minute, int hour, int day, int month, int year) { this(second, new Minute(minute, hour, day, month, year)); } /** * Constructs a new instance from the specified date/time and the default * time zone.. * * @param time the time (<code>null</code> not permitted). * * @see #Second(Date, TimeZone) */ public Second(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a new second based on the supplied time and time zone. * * @param time the time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.13 */ public Second(Date time, TimeZone zone, Locale locale) { Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); this.second = (byte) calendar.get(Calendar.SECOND); this.minute = (byte) calendar.get(Calendar.MINUTE); this.hour = (byte) calendar.get(Calendar.HOUR_OF_DAY); this.day = new Day(time, zone, locale); peg(calendar); } /** * Returns the second within the minute. * * @return The second (0 - 59). */ public int getSecond() { return this.second; } /** * Returns the minute. * * @return The minute (never <code>null</code>). */ public Minute getMinute() { return new Minute(this.minute, new Hour(this.hour, this.day)); } /** * Returns the first millisecond of the second. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the second. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the second. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the second. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.firstMillisecond + 999L; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); } /** * Returns the second preceding this one. * * @return The second preceding this one. */ @Override public RegularTimePeriod previous() { Second result = null; if (this.second != FIRST_SECOND_IN_MINUTE) { result = new Second(this.second - 1, getMinute()); } else { Minute previous = (Minute) getMinute().previous(); if (previous != null) { result = new Second(LAST_SECOND_IN_MINUTE, previous); } } return result; } /** * Returns the second following this one. * * @return The second following this one. */ @Override public RegularTimePeriod next() { Second result = null; if (this.second != LAST_SECOND_IN_MINUTE) { result = new Second(this.second + 1, getMinute()); } else { Minute next = (Minute) getMinute().next(); if (next != null) { result = new Second(FIRST_SECOND_IN_MINUTE, next); } } return result; } /** * Returns a serial index number for the minute. * * @return The serial index number. */ @Override public long getSerialIndex() { long hourIndex = this.day.getSerialIndex() * 24L + this.hour; long minuteIndex = hourIndex * 60L + this.minute; return minuteIndex * 60L + this.second; } /** * Returns the first millisecond of the minute. * * @param calendar the calendar/timezone (<code>null</code> not permitted). * * @return The first millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { int year = this.day.getYear(); int month = this.day.getMonth() - 1; int day = this.day.getDayOfMonth(); calendar.clear(); calendar.set(year, month, day, this.hour, this.minute, this.second); calendar.set(Calendar.MILLISECOND, 0); //return calendar.getTimeInMillis(); // this won't work for JDK 1.3 return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the second. * * @param calendar the calendar/timezone (<code>null</code> not permitted). * * @return The last millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { return getFirstMillisecond(calendar) + 999L; } /** * Tests the equality of this object against an arbitrary Object. * <P> * This method will return true ONLY if the object is a Second object * representing the same second as this instance. * * @param obj the object to compare (<code>null</code> permitted). * * @return <code>true</code> if second and minute of this and the object * are the same. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Second)) { return false; } Second that = (Second) obj; if (this.second != that.second) { return false; } if (this.minute != that.minute) { return false; } if (this.hour != that.hour) { return false; } if (!this.day.equals(that.day)) { return false; } return true; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.second; result = 37 * result + this.minute; result = 37 * result + this.hour; result = 37 * result + this.day.hashCode(); return result; } /** * Returns an integer indicating the order of this Second object relative * to the specified * object: negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Second object // ------------------------------------------- if (o1 instanceof Second) { Second s = (Second) o1; if (this.firstMillisecond < s.firstMillisecond) { return -1; } else if (this.firstMillisecond > s.firstMillisecond) { return 1; } else { return 0; } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Creates a new instance by parsing a string. The string is assumed to * be in the format "YYYY-MM-DD HH:MM:SS", perhaps with leading or trailing * whitespace. * * @param s the string to parse. * * @return The second, or <code>null</code> if the string is not parseable. */ public static Second parseSecond(String s) { Second result = null; s = s.trim(); String daystr = s.substring(0, Math.min(10, s.length())); Day day = Day.parseDay(daystr); if (day != null) { String hmsstr = s.substring(Math.min(daystr.length() + 1, s.length()), s.length()); hmsstr = hmsstr.trim(); int l = hmsstr.length(); String hourstr = hmsstr.substring(0, Math.min(2, l)); String minstr = hmsstr.substring(Math.min(3, l), Math.min(5, l)); String secstr = hmsstr.substring(Math.min(6, l), Math.min(8, l)); int hour = Integer.parseInt(hourstr); if ((hour >= 0) && (hour <= 23)) { int minute = Integer.parseInt(minstr); if ((minute >= 0) && (minute <= 59)) { Minute m = new Minute(minute, new Hour(hour, day)); int second = Integer.parseInt(secstr); if ((second >= 0) && (second <= 59)) { result = new Second(second, m); } } } } return result; } }
14,559
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesDataItem.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimeSeriesDataItem.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.] * * ----------------------- * TimeSeriesDataItem.java * ----------------------- * (C) Copyright 2001-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 15-Nov-2001 : Updated Javadoc comments (DG); * 29-Nov-2001 : Added cloning (DG); * 24-Jun-2002 : Removed unnecessary import (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Renamed TimeSeriesDataPair --> TimeSeriesDataItem, moved to * com.jrefinery.data.time package, implemented Serializable (DG) * ------------- JFREECHART 1.0.x --------------------------------------------- * 09-Jun-2009 : Tidied up equals() (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.time; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; /** * Represents one data item in a time series. * <P> * The time period can be any of the following: * <ul> * <li>{@link Year}</li> * <li>{@link Quarter}</li> * <li>{@link Month}</li> * <li>{@link Week}</li> * <li>{@link Day}</li> * <li>{@link Hour}</li> * <li>{@link Minute}</li> * <li>{@link Second}</li> * <li>{@link Millisecond}</li> * <li>{@link FixedMillisecond}</li> * </ul> * * The time period is an immutable property of the data item. Data items will * often be sorted within a list, and allowing the time period to be changed * could destroy the sort order. * <P> * Implements the <code>Comparable</code> interface so that standard Java * sorting can be used to keep the data items in order. * */ public class TimeSeriesDataItem implements Cloneable, Comparable<TimeSeriesDataItem>, Serializable { /** For serialization. */ private static final long serialVersionUID = -2235346966016401302L; /** The time period. */ private RegularTimePeriod period; /** The value associated with the time period. */ private Number value; /** * Constructs a new data item that associates a value with a time period. * * @param period the time period (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public TimeSeriesDataItem(RegularTimePeriod period, Number value) { if (period == null) { throw new IllegalArgumentException("Null 'period' argument."); } this.period = period; this.value = value; } /** * Constructs a new data item that associates a value with a time period. * * @param period the time period (<code>null</code> not permitted). * @param value the value associated with the time period. */ public TimeSeriesDataItem(RegularTimePeriod period, double value) { this(period, new Double(value)); } /** * Returns the time period. * * @return The time period (never <code>null</code>). */ public RegularTimePeriod getPeriod() { return this.period; } /** * Returns the value. * * @return The value (<code>null</code> possible). * * @see #setValue(java.lang.Number) */ public Number getValue() { return this.value; } /** * Sets the value for this data item. * * @param value the value (<code>null</code> permitted). * * @see #getValue() */ public void setValue(Number value) { this.value = value; } /** * Tests this object for equality with an arbitrary object. * * @param obj the other object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof TimeSeriesDataItem)) { return false; } TimeSeriesDataItem that = (TimeSeriesDataItem) obj; if (!ObjectUtilities.equal(this.period, that.period)) { return false; } if (!ObjectUtilities.equal(this.value, that.value)) { return false; } return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; result = (this.period != null ? this.period.hashCode() : 0); result = 29 * result + (this.value != null ? this.value.hashCode() : 0); return result; } /** * Returns an integer indicating the order of this data pair object * relative to another object. * <P> * For the order we consider only the timing: * negative == before, zero == same, positive == after. * * @param o1 The object being compared to. * * @return An integer indicating the order of the data item object * relative to another object. */ @Override public int compareTo(TimeSeriesDataItem o1) { return getPeriod().compareTo(o1.getPeriod()); } /** * Clones the data item. Note: there is no need to clone the period or * value since they are immutable classes. * * @return A clone of the data item. */ @Override public Object clone() { Object clone = null; try { clone = super.clone(); } catch (CloneNotSupportedException e) { // won't get here... e.printStackTrace(); } return clone; } }
6,726
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Minute.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Minute.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.] * * ----------- * Minute.java * ----------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 18-Dec-2001 : Changed order of parameters in constructor (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 14-Feb-2002 : Fixed bug in Minute(Date) constructor, and changed the range * to start from zero instead of one (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 13-Mar-2002 : Added parseMinute() method (DG); * 19-Mar-2002 : Changed API, the minute is now defined in relation to an * Hour (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method, and new constructor for * convenience (DG); * 30-Sep-2004 : Replaced getTime().getTime() with getTimeInMillis() (DG); * 04-Nov-2004 : Reverted change of 30-Sep-2004, because it won't work for * JDK 1.3 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 11-Dec-2006 : Fix for previous() - bug 1611872 (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 02-Mar-2009 : Added new constructor that specifies Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Represents a minute. This class is immutable, which is a requirement for * all {@link RegularTimePeriod} subclasses. */ public class Minute extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = 2144572840034842871L; /** Useful constant for the first minute in a day. */ public static final int FIRST_MINUTE_IN_HOUR = 0; /** Useful constant for the last minute in a day. */ public static final int LAST_MINUTE_IN_HOUR = 59; /** The day. */ private Day day; /** The hour in which the minute falls. */ private byte hour; /** The minute. */ private byte minute; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Constructs a new Minute, based on the system date/time. */ public Minute() { this(new Date()); } /** * Constructs a new Minute. * * @param minute the minute (0 to 59). * @param hour the hour (<code>null</code> not permitted). */ public Minute(int minute, Hour hour) { if (hour == null) { throw new IllegalArgumentException("Null 'hour' argument."); } this.minute = (byte) minute; this.hour = (byte) hour.getHour(); this.day = hour.getDay(); peg(Calendar.getInstance()); } /** * Constructs a new instance, based on the supplied date/time and * the default time zone. * * @param time the time (<code>null</code> not permitted). * * @see #Minute(Date, TimeZone) */ public Minute(Date time) { // defer argument checking this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Constructs a new Minute, based on the supplied date/time and timezone. * * @param time the time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.13 */ public Minute(Date time, TimeZone zone, Locale locale) { if (time == null) { throw new IllegalArgumentException("Null 'time' argument."); } if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } if (locale == null) { throw new IllegalArgumentException("Null 'locale' argument."); } Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); int min = calendar.get(Calendar.MINUTE); this.minute = (byte) min; this.hour = (byte) calendar.get(Calendar.HOUR_OF_DAY); this.day = new Day(time, zone, locale); peg(calendar); } /** * Creates a new minute. * * @param minute the minute (0-59). * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Minute(int minute, int hour, int day, int month, int year) { this(minute, new Hour(hour, new Day(day, month, year))); } /** * Returns the day. * * @return The day. * * @since 1.0.3 */ public Day getDay() { return this.day; } /** * Returns the hour. * * @return The hour (never <code>null</code>). */ public Hour getHour() { return new Hour(this.hour, this.day); } /** * Returns the hour. * * @return The hour. * * @since 1.0.3 */ public int getHourValue() { return this.hour; } /** * Returns the minute. * * @return The minute. */ public int getMinute() { return this.minute; } /** * Returns the first millisecond of the minute. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the minute. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the minute. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the minute. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the minute preceding this one. * * @return The minute preceding this one. */ @Override public RegularTimePeriod previous() { Minute result; if (this.minute != FIRST_MINUTE_IN_HOUR) { result = new Minute(this.minute - 1, getHour()); } else { Hour h = (Hour) getHour().previous(); if (h != null) { result = new Minute(LAST_MINUTE_IN_HOUR, h); } else { result = null; } } return result; } /** * Returns the minute following this one. * * @return The minute following this one. */ @Override public RegularTimePeriod next() { Minute result; if (this.minute != LAST_MINUTE_IN_HOUR) { result = new Minute(this.minute + 1, getHour()); } else { // we are at the last minute in the hour... Hour nextHour = (Hour) getHour().next(); if (nextHour != null) { result = new Minute(FIRST_MINUTE_IN_HOUR, nextHour); } else { result = null; } } return result; } /** * Returns a serial index number for the minute. * * @return The serial index number. */ @Override public long getSerialIndex() { long hourIndex = this.day.getSerialIndex() * 24L + this.hour; return hourIndex * 60L + this.minute; } /** * Returns the first millisecond of the minute. * * @param calendar the calendar which defines the timezone * (<code>null</code> not permitted). * * @return The first millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { int year = this.day.getYear(); int month = this.day.getMonth() - 1; int day = this.day.getDayOfMonth(); calendar.clear(); calendar.set(year, month, day, this.hour, this.minute, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the minute. * * @param calendar the calendar / timezone (<code>null</code> not * permitted). * * @return The last millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { int year = this.day.getYear(); int month = this.day.getMonth() - 1; int day = this.day.getDayOfMonth(); calendar.clear(); calendar.set(year, month, day, this.hour, this.minute, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTimeInMillis(); } /** * Tests the equality of this object against an arbitrary Object. * <P> * This method will return true ONLY if the object is a Minute object * representing the same minute as this instance. * * @param obj the object to compare (<code>null</code> permitted). * * @return <code>true</code> if the minute and hour value of this and the * object are the same. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Minute)) { return false; } Minute that = (Minute) obj; if (this.minute != that.minute) { return false; } if (this.hour != that.hour) { return false; } return true; } /** * Returns a hash code for this object instance. The approach described * by Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.minute; result = 37 * result + this.hour; result = 37 * result + this.day.hashCode(); return result; } /** * Returns an integer indicating the order of this Minute object relative * to the specified object: * * negative == before, zero == same, positive == after. * * @param o1 object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Minute object // ------------------------------------------- if (o1 instanceof Minute) { Minute m = (Minute) o1; result = getHour().compareTo(m.getHour()); if (result == 0) { result = this.minute - m.getMinute(); } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Creates a Minute instance by parsing a string. The string is assumed to * be in the format "YYYY-MM-DD HH:MM", perhaps with leading or trailing * whitespace. * * @param s the minute string to parse. * * @return <code>null</code>, if the string is not parseable, the minute * otherwise. */ public static Minute parseMinute(String s) { Minute result = null; s = s.trim(); String daystr = s.substring(0, Math.min(10, s.length())); Day day = Day.parseDay(daystr); if (day != null) { String hmstr = s.substring( Math.min(daystr.length() + 1, s.length()), s.length() ); hmstr = hmstr.trim(); String hourstr = hmstr.substring(0, Math.min(2, hmstr.length())); int hour = Integer.parseInt(hourstr); if ((hour >= 0) && (hour <= 23)) { String minstr = hmstr.substring( Math.min(hourstr.length() + 1, hmstr.length()), hmstr.length() ); int minute = Integer.parseInt(minstr); if ((minute >= 0) && (minute <= 59)) { result = new Minute(minute, new Hour(hour, day)); } } } return result; } }
15,087
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DateRange.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/DateRange.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.] * * -------------- * DateRange.java * -------------- * (C) Copyright 2002-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Bill Kelemen; * * Changes * ------- * 22-Apr-2002 : Version 1 based on code by Bill Kelemen (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 23-Sep-2003 : Minor Javadoc update (DG); * 28-May-2008 : Fixed problem with immutability (DG); * 01-Sep-2008 : Added getLowerMillis() and getUpperMillis() (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.text.DateFormat; import java.util.Date; import org.jfree.data.Range; /** * A range specified in terms of two <code>java.util.Date</code> objects. * Instances of this class are immutable. */ public class DateRange extends Range implements Serializable { /** For serialization. */ private static final long serialVersionUID = -4705682568375418157L; /** The lower bound for the range. */ private long lowerDate; /** The upper bound for the range. */ private long upperDate; /** * Default constructor. */ public DateRange() { this(new Date(0), new Date(1)); } /** * Constructs a new range. * * @param lower the lower bound (<code>null</code> not permitted). * @param upper the upper bound (<code>null</code> not permitted). */ public DateRange(Date lower, Date upper) { super(lower.getTime(), upper.getTime()); this.lowerDate = lower.getTime(); this.upperDate = upper.getTime(); } /** * Constructs a new range using two values that will be interpreted as * "milliseconds since midnight GMT, 1-Jan-1970". * * @param lower the lower (oldest) date. * @param upper the upper (most recent) date. */ public DateRange(double lower, double upper) { super(lower, upper); this.lowerDate = (long) lower; this.upperDate = (long) upper; } /** * Constructs a new range that is based on another {@link Range}. The * other range does not have to be a {@link DateRange}. If it is not, the * upper and lower bounds are evaluated as milliseconds since midnight * GMT, 1-Jan-1970. * * @param other the other range (<code>null</code> not permitted). */ public DateRange(Range other) { this(other.getLowerBound(), other.getUpperBound()); } /** * Returns the lower (earlier) date for the range. * * @return The lower date for the range. * * @see #getLowerMillis() */ public Date getLowerDate() { return new Date(this.lowerDate); } /** * Returns the lower bound of the range in milliseconds. * * @return The lower bound. * * @see #getLowerDate() * * @since 1.0.11 */ public long getLowerMillis() { return this.lowerDate; } /** * Returns the upper (later) date for the range. * * @return The upper date for the range. * * @see #getUpperMillis() */ public Date getUpperDate() { return new Date(this.upperDate); } /** * Returns the upper bound of the range in milliseconds. * * @return The upper bound. * * @see #getUpperDate() * * @since 1.0.11 */ public long getUpperMillis() { return this.upperDate; } /** * Returns a string representing the date range (useful for debugging). * * @return A string representing the date range. */ @Override public String toString() { DateFormat df = DateFormat.getDateTimeInstance(); return "[" + df.format(getLowerDate()) + " --> " + df.format(getUpperDate()) + "]"; } }
5,072
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodValuesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimePeriodValuesCollection.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.] * * ------------------------------- * TimePeriodValuesCollection.java * ------------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 22-Apr-2003 : Version 1 (DG); * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 06-Oct-2004 : Updated for changes in DomainInfo interface (DG); * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 03-Oct-2006 : Deprecated get/setDomainIsPointsInTime() (DG); * 11-Jun-2007 : Fixed bug in getDomainBounds() method, and changed default * value for domainIsPointsInTime to false (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.List; import org.jfree.chart.util.ObjectUtilities; import org.jfree.data.DomainInfo; import org.jfree.data.Range; import org.jfree.data.xy.AbstractIntervalXYDataset; import org.jfree.data.xy.IntervalXYDataset; /** * A collection of {@link TimePeriodValues} objects. * <P> * This class implements the {@link org.jfree.data.xy.XYDataset} interface, as * well as the extended {@link IntervalXYDataset} interface. This makes it a * convenient dataset for use with the {@link org.jfree.chart.plot.XYPlot} * class. */ public class TimePeriodValuesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, DomainInfo, Serializable { /** For serialization. */ private static final long serialVersionUID = -3077934065236454199L; /** Storage for the time series. */ private List<TimePeriodValues> data; /** * The position within a time period to return as the x-value (START, * MIDDLE or END). */ private TimePeriodAnchor xPosition; /** * Constructs an empty dataset. */ public TimePeriodValuesCollection() { this(null); } /** * Constructs a dataset containing a single series. Additional series can * be added. * * @param series the series (<code>null</code> ignored). */ public TimePeriodValuesCollection(TimePeriodValues series) { this.data = new java.util.ArrayList<TimePeriodValues>(); this.xPosition = TimePeriodAnchor.MIDDLE; if (series != null) { this.data.add(series); series.addChangeListener(this); } } /** * Returns the position of the X value within each time period. * * @return The position (never <code>null</code>). * * @see #setXPosition(TimePeriodAnchor) */ public TimePeriodAnchor getXPosition() { return this.xPosition; } /** * Sets the position of the x axis within each time period. * * @param position the position (<code>null</code> not permitted). * * @see #getXPosition() */ public void setXPosition(TimePeriodAnchor position) { if (position == null) { throw new IllegalArgumentException("Null 'position' argument."); } this.xPosition = position; } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a series. * * @param series the index of the series (zero-based). * * @return The series. */ public TimePeriodValues getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Index 'series' out of range."); } return this.data.get(series); } /** * Returns the key for a series. * * @param series the index of the series (zero-based). * * @return The key for a series. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Adds a series to the collection. A * {@link org.jfree.data.general.DatasetChangeEvent} is sent to all * registered listeners. * * @param series the time series. */ public void addSeries(TimePeriodValues series) { if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Removes the specified series from the collection. * * @param series the series to remove (<code>null</code> not permitted). */ public void removeSeries(TimePeriodValues series) { if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } this.data.remove(series); series.removeChangeListener(this); fireDatasetChanged(); } /** * Removes a series from the collection. * * @param index the series index (zero-based). */ public void removeSeries(int index) { TimePeriodValues series = getSeries(index); if (series != null) { removeSeries(series); } } /** * Returns the number of items in the specified series. * <P> * This method is provided for convenience. * * @param series the index of the series of interest (zero-based). * * @return The number of items in the specified series. */ @Override public int getItemCount(int series) { return getSeries(series).getItemCount(); } /** * Returns the x-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The x-value for the specified series and item. */ @Override public Number getX(int series, int item) { TimePeriodValues ts = this.data.get(series); TimePeriodValue dp = ts.getDataItem(item); TimePeriod period = dp.getPeriod(); return getX(period); } /** * Returns the x-value for a time period. * * @param period the time period. * * @return The x-value. */ private long getX(TimePeriod period) { if (this.xPosition == TimePeriodAnchor.START) { return period.getStart().getTime(); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { return period.getStart().getTime() / 2 + period.getEnd().getTime() / 2; } else if (this.xPosition == TimePeriodAnchor.END) { return period.getEnd().getTime(); } else { throw new IllegalStateException("TimePeriodAnchor unknown."); } } /** * Returns the starting X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The starting X value for the specified series and item. */ @Override public Number getStartX(int series, int item) { TimePeriodValues ts = this.data.get(series); TimePeriodValue dp = ts.getDataItem(item); return dp.getPeriod().getStart().getTime(); } /** * Returns the ending X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The ending X value for the specified series and item. */ @Override public Number getEndX(int series, int item) { TimePeriodValues ts = this.data.get(series); TimePeriodValue dp = ts.getDataItem(item); return dp.getPeriod().getEnd().getTime(); } /** * Returns the y-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The y-value for the specified series and item. */ @Override public Number getY(int series, int item) { TimePeriodValues ts = this.data.get(series); TimePeriodValue dp = ts.getDataItem(item); return dp.getValue(); } /** * Returns the starting Y value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The starting Y value for the specified series and item. */ @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 (zero-based index). * @param item the item (zero-based index). * * @return The ending Y value for the specified series and item. */ @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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getLowerBound(); } return result; } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getUpperBound(); } return result; } /** * 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) { boolean interval = includeInterval; Range result = null; Range temp = null; for (TimePeriodValues series : this.data) { int count = series.getItemCount(); if (count > 0) { TimePeriod start = series.getTimePeriod( series.getMinStartIndex()); TimePeriod end = series.getTimePeriod(series.getMaxEndIndex()); if (!interval) { if (this.xPosition == TimePeriodAnchor.START) { TimePeriod maxStart = series.getTimePeriod( series.getMaxStartIndex()); temp = new Range(start.getStart().getTime(), maxStart.getStart().getTime()); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { TimePeriod minMiddle = series.getTimePeriod( series.getMinMiddleIndex()); long s1 = minMiddle.getStart().getTime(); long e1 = minMiddle.getEnd().getTime(); TimePeriod maxMiddle = series.getTimePeriod( series.getMaxMiddleIndex()); long s2 = maxMiddle.getStart().getTime(); long e2 = maxMiddle.getEnd().getTime(); temp = new Range(s1 + (e1 - s1) / 2, s2 + (e2 - s2) / 2); } else if (this.xPosition == TimePeriodAnchor.END) { TimePeriod minEnd = series.getTimePeriod( series.getMinEndIndex()); temp = new Range(minEnd.getEnd().getTime(), end.getEnd().getTime()); } } else { temp = new Range(start.getStart().getTime(), end.getEnd().getTime()); } result = Range.combine(result, temp); } } return result; } /** * 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 TimePeriodValuesCollection)) { return false; } TimePeriodValuesCollection that = (TimePeriodValuesCollection) obj; if (this.xPosition != that.xPosition) { return false; } if (!ObjectUtilities.equal(this.data, that.data)) { return false; } return true; } }
14,659
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Month.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Month.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.] * * ---------- * Month.java * ---------- * (C) Copyright 2001-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Chris Boek; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 14-Nov-2001 : Added method to get year as primitive (DG); * Override for toString() method (DG); * 18-Dec-2001 : Changed order of parameters in constructor (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 29-Jan-2002 : Worked on the parseMonth() method (DG); * 14-Feb-2002 : Fixed bugs in the Month constructors (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 19-Mar-2002 : Changed API for TimePeriod classes (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * 01-Nov-2005 : Fixed bug 1345383 (argument check in constructor) (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 04-Apr-2007 : Fixed bug in Month(Date, TimeZone) constructor (CB); * 01-Sep-2008 : Added clarification for previous() and next() methods (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE, and updated parsing to handle * extended range in Year (DG); * 25-Nov-2008 : Added new constructor with Locale (DG); * 04-Feb-2009 : Fix for new constructor with Locale - bug 2564636 (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.jfree.chart.date.SerialDate; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Represents a single month. This class is immutable, which is a requirement * for all {@link RegularTimePeriod} subclasses. */ public class Month extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = -5090216912548722570L; /** The month (1-12). */ private int month; /** The year in which the month falls. */ private int year; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Constructs a new Month, based on the current system time. */ public Month() { this(new Date()); } /** * Constructs a new month instance. * * @param month the month (in the range 1 to 12). * @param year the year. */ public Month(int month, int year) { if ((month < 1) || (month > 12)) { throw new IllegalArgumentException("Month outside valid range."); } this.month = month; this.year = year; peg(Calendar.getInstance()); } /** * Constructs a new month instance. * * @param month the month (in the range 1 to 12). * @param year the year. */ public Month(int month, Year year) { if ((month < 1) || (month > 12)) { throw new IllegalArgumentException("Month outside valid range."); } this.month = month; this.year = year.getYear(); peg(Calendar.getInstance()); } /** * Constructs a new <code>Month</code> instance, based on a date/time and * the default time zone. * * @param time the date/time (<code>null</code> not permitted). * * @see #Month(Date, TimeZone) */ public Month(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a new <code>Month</code> instance, based on the specified time, * zone and locale. * * @param time the current time. * @param zone the time zone. * @param locale the locale. * * @since 1.0.12 */ public Month(Date time, TimeZone zone, Locale locale) { Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); this.month = calendar.get(Calendar.MONTH) + 1; this.year = calendar.get(Calendar.YEAR); peg(calendar); } /** * Returns the year in which the month falls. * * @return The year in which the month falls (as a Year object). */ public Year getYear() { return new Year(this.year); } /** * Returns the year in which the month falls. * * @return The year in which the month falls (as an int). */ public int getYearValue() { return this.year; } /** * Returns the month. Note that 1=JAN, 2=FEB, ... * * @return The month. */ public int getMonth() { return this.month; } /** * Returns the first millisecond of the month. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the month. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the month. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the month. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the month preceding this one. Note that the returned * {@link Month} is "pegged" using the default time-zone, irrespective of * the time-zone used to peg of the current month (which is not recorded * anywhere). See the {@link #peg(Calendar)} method. * * @return The month preceding this one. */ @Override public RegularTimePeriod previous() { Month result; if (this.month != MonthConstants.JANUARY) { result = new Month(this.month - 1, this.year); } else { if (this.year > 1900) { result = new Month(MonthConstants.DECEMBER, this.year - 1); } else { result = null; } } return result; } /** * Returns the month following this one. Note that the returned * {@link Month} is "pegged" using the default time-zone, irrespective of * the time-zone used to peg of the current month (which is not recorded * anywhere). See the {@link #peg(Calendar)} method. * * @return The month following this one. */ @Override public RegularTimePeriod next() { Month result; if (this.month != MonthConstants.DECEMBER) { result = new Month(this.month + 1, this.year); } else { if (this.year < 9999) { result = new Month(MonthConstants.JANUARY, this.year + 1); } else { result = null; } } return result; } /** * Returns a serial index number for the month. * * @return The serial index number. */ @Override public long getSerialIndex() { return this.year * 12L + this.month; } /** * Returns a string representing the month (e.g. "January 2002"). * <P> * To do: look at internationalisation. * * @return A string representing the month. */ @Override public String toString() { return SerialDate.monthCodeToString(this.month) + " " + this.year; } /** * Tests the equality of this Month object to an arbitrary object. * Returns true if the target is a Month instance representing the same * month as this object. In all other cases, returns false. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> if month and year of this and object are the * same. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Month)) { return false; } Month that = (Month) obj; if (this.month != that.month) { return false; } if (this.year != that.year) { return false; } return true; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.month; result = 37 * result + this.year; return result; } /** * Returns an integer indicating the order of this Month object relative to * the specified * object: negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Month object // -------------------------------------------- if (o1 instanceof Month) { Month m = (Month) o1; result = this.year - m.getYearValue(); if (result == 0) { result = this.month - m.getMonth(); } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Returns the first millisecond of the month, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the month. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { calendar.set(this.year, this.month - 1, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the month, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the month. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { int eom = SerialDate.lastDayOfMonth(this.month, this.year); calendar.set(this.year, this.month - 1, eom, 23, 59, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTimeInMillis(); } /** * Parses the string argument as a month. This method is required to * accept the format "YYYY-MM". It will also accept "MM-YYYY". Anything * else, at the moment, is a bonus. * * @param s the string to parse (<code>null</code> permitted). * * @return <code>null</code> if the string is not parseable, the month * otherwise. */ public static Month parseMonth(String s) { Month result = null; if (s == null) { return result; } // trim whitespace from either end of the string s = s.trim(); int i = Month.findSeparator(s); String s1, s2; boolean yearIsFirst; // if there is no separator, we assume the first four characters // are YYYY if (i == -1) { yearIsFirst = true; s1 = s.substring(0, 5); s2 = s.substring(5); } else { s1 = s.substring(0, i).trim(); s2 = s.substring(i + 1, s.length()).trim(); // now it is trickier to determine if the month or year is first Year y1 = Month.evaluateAsYear(s1); if (y1 == null) { yearIsFirst = false; } else { Year y2 = Month.evaluateAsYear(s2); if (y2 == null) { yearIsFirst = true; } else { yearIsFirst = (s1.length() > s2.length()); } } } Year year; int month; if (yearIsFirst) { year = Month.evaluateAsYear(s1); month = SerialDate.stringToMonthCode(s2); } else { year = Month.evaluateAsYear(s2); month = SerialDate.stringToMonthCode(s1); } if (month == -1) { throw new TimePeriodFormatException("Can't evaluate the month."); } if (year == null) { throw new TimePeriodFormatException("Can't evaluate the year."); } result = new Month(month, year); return result; } /** * Finds the first occurrence of '-', or if that character is not found, * the first occurrence of ',', or the first occurrence of ' ' or '.' * * @param s the string to parse. * * @return The position of the separator character, or <code>-1</code> if * none of the characters were found. */ private static int findSeparator(String s) { int result = s.indexOf('-'); if (result == -1) { result = s.indexOf(','); } if (result == -1) { result = s.indexOf(' '); } if (result == -1) { result = s.indexOf('.'); } return result; } /** * Creates a year from a string, or returns <code>null</code> (format * exceptions suppressed). * * @param s the string to parse. * * @return <code>null</code> if the string is not parseable, the year * otherwise. */ private static Year evaluateAsYear(String s) { Year result = null; try { result = Year.parseYear(s); } catch (TimePeriodFormatException e) { // suppress } return result; } }
16,778
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MovingAverage.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/MovingAverage.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.] * * ------------------ * MovingAverage.java * ------------------ * (C) Copyright 2003-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Benoit Xhenseval; * * Changes * ------- * 28-Jan-2003 : Version 1 (DG); * 10-Mar-2003 : Added createPointMovingAverage() method contributed by Benoit * Xhenseval (DG); * 01-Aug-2003 : Added new method for TimeSeriesCollection, and fixed bug in * XYDataset method (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * 09-Jun-2009 : Tidied up some calls to TimeSeries (DG); * */ package org.jfree.data.time; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; /** * A utility class for calculating moving averages of time series data. */ public class MovingAverage { /** * Creates a new {@link TimeSeriesCollection} containing a moving average * series for each series in the source collection. * * @param source the source collection. * @param suffix the suffix added to each source series name to create the * corresponding moving average series name. * @param periodCount the number of periods in the moving average * calculation. * @param skip the number of initial periods to skip. * * @return A collection of moving average time series. */ public static TimeSeriesCollection createMovingAverage( TimeSeriesCollection source, String suffix, int periodCount, int skip) { if (source == null) { throw new IllegalArgumentException("Null 'source' argument."); } if (periodCount < 1) { throw new IllegalArgumentException("periodCount must be greater " + "than or equal to 1."); } TimeSeriesCollection result = new TimeSeriesCollection(); for (int i = 0; i < source.getSeriesCount(); i++) { TimeSeries sourceSeries = source.getSeries(i); TimeSeries maSeries = createMovingAverage(sourceSeries, sourceSeries.getKey() + suffix, periodCount, skip); result.addSeries(maSeries); } return result; } /** * Creates a new {@link TimeSeries} containing moving average values for * the given series. If the series is empty (contains zero items), the * result is an empty series. * * @param source the source series. * @param name the name of the new series. * @param periodCount the number of periods used in the average * calculation. * @param skip the number of initial periods to skip. * * @return The moving average series. */ public static TimeSeries createMovingAverage(TimeSeries source, String name, int periodCount, int skip) { if (source == null) { throw new IllegalArgumentException("Null source."); } if (periodCount < 1) { throw new IllegalArgumentException("periodCount must be greater " + "than or equal to 1."); } TimeSeries result = new TimeSeries(name); if (source.getItemCount() > 0) { // if the initial averaging period is to be excluded, then // calculate the index of the // first data item to have an average calculated... long firstSerial = source.getTimePeriod(0).getSerialIndex() + skip; for (int i = source.getItemCount() - 1; i >= 0; i--) { // get the current data item... RegularTimePeriod period = source.getTimePeriod(i); long serial = period.getSerialIndex(); if (serial >= firstSerial) { // work out the average for the earlier values... int n = 0; double sum = 0.0; long serialLimit = period.getSerialIndex() - periodCount; int offset = 0; boolean finished = false; while ((offset < periodCount) && (!finished)) { if ((i - offset) >= 0) { TimeSeriesDataItem item = source.getRawDataItem( i - offset); RegularTimePeriod p = item.getPeriod(); Number v = item.getValue(); long currentIndex = p.getSerialIndex(); if (currentIndex > serialLimit) { if (v != null) { sum = sum + v.doubleValue(); n = n + 1; } } else { finished = true; } } offset = offset + 1; } if (n > 0) { result.add(period, sum / n); } else { result.add(period, null); } } } } return result; } /** * Creates a new {@link TimeSeries} containing moving average values for * the given series, calculated by number of points (irrespective of the * 'age' of those points). If the series is empty (contains zero items), * the result is an empty series. * <p> * Developed by Benoit Xhenseval (www.ObjectLab.co.uk). * * @param source the source series. * @param name the name of the new series. * @param pointCount the number of POINTS used in the average calculation * (not periods!) * * @return The moving average series. */ public static TimeSeries createPointMovingAverage(TimeSeries source, String name, int pointCount) { if (source == null) { throw new IllegalArgumentException("Null 'source'."); } if (pointCount < 2) { throw new IllegalArgumentException("periodCount must be greater " + "than or equal to 2."); } TimeSeries result = new TimeSeries(name); double rollingSumForPeriod = 0.0; for (int i = 0; i < source.getItemCount(); i++) { // get the current data item... TimeSeriesDataItem current = source.getRawDataItem(i); RegularTimePeriod period = current.getPeriod(); // FIXME: what if value is null on next line? rollingSumForPeriod += current.getValue().doubleValue(); if (i > pointCount - 1) { // remove the point i-periodCount out of the rolling sum. TimeSeriesDataItem startOfMovingAvg = source.getRawDataItem( i - pointCount); rollingSumForPeriod -= startOfMovingAvg.getValue() .doubleValue(); result.add(period, rollingSumForPeriod / pointCount); } else if (i == pointCount - 1) { result.add(period, rollingSumForPeriod / pointCount); } } return result; } /** * Creates a new {@link XYDataset} containing the moving averages of each * series in the <code>source</code> dataset. * * @param source the source dataset. * @param suffix the string to append to source series names to create * target series names. * @param period the averaging period. * @param skip the length of the initial skip period. * * @return The dataset. */ public static XYDataset createMovingAverage(XYDataset source, String suffix, long period, long skip) { return createMovingAverage(source, suffix, (double) period, (double) skip); } /** * Creates a new {@link XYDataset} containing the moving averages of each * series in the <code>source</code> dataset. * * @param source the source dataset. * @param suffix the string to append to source series names to create * target series names. * @param period the averaging period. * @param skip the length of the initial skip period. * * @return The dataset. */ public static XYDataset createMovingAverage(XYDataset source, String suffix, double period, double skip) { if (source == null) { throw new IllegalArgumentException("Null source (XYDataset)."); } XYSeriesCollection result = new XYSeriesCollection(); for (int i = 0; i < source.getSeriesCount(); i++) { XYSeries s = createMovingAverage(source, i, source.getSeriesKey(i) + suffix, period, skip); result.addSeries(s); } return result; } /** * Creates a new {@link XYSeries} containing the moving averages of one * series in the <code>source</code> dataset. * * @param source the source dataset. * @param series the series index (zero based). * @param name the name for the new series. * @param period the averaging period. * @param skip the length of the initial skip period. * * @return The dataset. */ public static XYSeries createMovingAverage(XYDataset source, int series, String name, double period, double skip) { if (source == null) { throw new IllegalArgumentException("Null source (XYDataset)."); } if (period < Double.MIN_VALUE) { throw new IllegalArgumentException("period must be positive."); } if (skip < 0.0) { throw new IllegalArgumentException("skip must be >= 0.0."); } XYSeries result = new XYSeries(name); if (source.getItemCount(series) > 0) { // if the initial averaging period is to be excluded, then // calculate the lowest x-value to have an average calculated... double first = source.getXValue(series, 0) + skip; for (int i = source.getItemCount(series) - 1; i >= 0; i--) { // get the current data item... double x = source.getXValue(series, i); if (x >= first) { // work out the average for the earlier values... int n = 0; double sum = 0.0; double limit = x - period; int offset = 0; boolean finished = false; while (!finished) { if ((i - offset) >= 0) { double xx = source.getXValue(series, i - offset); Number yy = source.getY(series, i - offset); if (xx > limit) { if (yy != null) { sum = sum + yy.doubleValue(); n = n + 1; } } else { finished = true; } } else { finished = true; } offset = offset + 1; } if (n > 0) { result.add(x, sum / n); } else { result.add(x, null); } } } } return result; } }
13,293
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
RegularTimePeriod.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/RegularTimePeriod.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.] * * ---------------------- * RegularTimePeriod.java * ---------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 29-May-2002 : Implemented MonthConstants interface, so that these constants * are conveniently available (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 10-Jan-2003 : Renamed TimePeriod --> RegularTimePeriod (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package (DG); * 29-Apr-2004 : Changed getMiddleMillisecond() methods to fix bug 943985 (DG); * 25-Nov-2004 : Added utility methods (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Oct-2006 : Deprecated the WORKING_CALENDAR field and several methods, * added new peg() method (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 23-Feb-2014 : Added getMillisecond() method (DG); * */ package org.jfree.data.time; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * An abstract class representing a unit of time. Convenient methods are * provided for calculating the next and previous time periods. Conversion * methods are defined that return the first and last milliseconds of the time * period. The results from these methods are timezone dependent. * <P> * This class is immutable, and all subclasses should be immutable also. */ public abstract class RegularTimePeriod implements TimePeriod, Comparable<TimePeriod> { /** * Creates a time period that includes the specified millisecond, assuming * the given time zone. * * @param c the time period class. * @param millisecond the time. * @param zone the time zone. * @param locale the locale. * * @return The time period. */ public static RegularTimePeriod createInstance(Class c, Date millisecond, TimeZone zone, Locale locale) { RegularTimePeriod result = null; try { Constructor constructor = c.getDeclaredConstructor( new Class[] {Date.class, TimeZone.class, Locale.class}); result = (RegularTimePeriod) constructor.newInstance( millisecond, zone, locale); } catch (NoSuchMethodException e) { // do nothing, so null is returned } catch (IllegalAccessException e) { // do nothing, so null is returned } catch (InvocationTargetException e) { // do nothing, so null is returned } catch (InstantiationException e) { // do nothing, so null is returned } return result; } /** * Returns a subclass of {@link RegularTimePeriod} that is smaller than * the specified class. * * @param c a subclass of {@link RegularTimePeriod}. * * @return A class. */ public static Class downsize(Class c) { if (c.equals(Year.class)) { return Quarter.class; } else if (c.equals(Quarter.class)) { return Month.class; } else if (c.equals(Month.class)) { return Day.class; } else if (c.equals(Day.class)) { return Hour.class; } else if (c.equals(Hour.class)) { return Minute.class; } else if (c.equals(Minute.class)) { return Second.class; } else if (c.equals(Second.class)) { return Millisecond.class; } else { return Millisecond.class; } } /** * Returns the time period preceding this one, or <code>null</code> if some * lower limit has been reached. * * @return The previous time period (possibly <code>null</code>). */ public abstract RegularTimePeriod previous(); /** * Returns the time period following this one, or <code>null</code> if some * limit has been reached. * * @return The next time period (possibly <code>null</code>). */ public abstract RegularTimePeriod next(); /** * Returns a serial index number for the time unit. * * @return The serial index number. */ public abstract long getSerialIndex(); ////////////////////////////////////////////////////////////////////////// /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ public abstract void peg(Calendar calendar); /** * Returns the date/time that marks the start of the time period. This * method returns a new <code>Date</code> instance every time it is called. * * @return The start date/time. * * @see #getFirstMillisecond() */ @Override public Date getStart() { return new Date(getFirstMillisecond()); } /** * Returns the date/time that marks the end of the time period. This * method returns a new <code>Date</code> instance every time it is called. * * @return The end date/time. * * @see #getLastMillisecond() */ @Override public Date getEnd() { return new Date(getLastMillisecond()); } /** * Returns the first millisecond of the time period. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the time period. * * @see #getLastMillisecond() */ public abstract long getFirstMillisecond(); /** * Returns the first millisecond of the time period, evaluated using the * supplied calendar (which incorporates a timezone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the time period. * * @throws NullPointerException if <code>calendar,/code> is * </code>null</code>. * * @see #getLastMillisecond(Calendar) */ public abstract long getFirstMillisecond(Calendar calendar); /** * Returns the last millisecond of the time period. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the time period. * * @see #getFirstMillisecond() */ public abstract long getLastMillisecond(); /** * Returns the last millisecond of the time period, evaluated using the * supplied calendar (which incorporates a timezone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the time period. * * @see #getFirstMillisecond(Calendar) */ public abstract long getLastMillisecond(Calendar calendar); /** * Returns the millisecond closest to the middle of the time period. * * @return The middle millisecond. */ public long getMiddleMillisecond() { long m1 = getFirstMillisecond(); long m2 = getLastMillisecond(); return m1 + (m2 - m1) / 2; } /** * Returns the millisecond closest to the middle of the time period, * evaluated using the supplied calendar (which incorporates a timezone). * * @param calendar the calendar. * * @return The middle millisecond. */ public long getMiddleMillisecond(Calendar calendar) { long m1 = getFirstMillisecond(calendar); long m2 = getLastMillisecond(calendar); return m1 + (m2 - m1) / 2; } /** * Returns the millisecond (relative to the epoch) corresponding to the * specified <code>anchor</code> using the supplied <code>calendar</code> * (which incorporates a time zone). * * @param anchor the anchor (<code>null</code> not permitted). * @param calendar the calendar (<code>null</code> not permitted). * * @return Milliseconds since the epoch. * * @since 1.0.18 */ public long getMillisecond(TimePeriodAnchor anchor, Calendar calendar) { if (anchor.equals(TimePeriodAnchor.START)) { return getFirstMillisecond(calendar); } else if (anchor.equals(TimePeriodAnchor.MIDDLE)) { return getMiddleMillisecond(calendar); } else if (anchor.equals(TimePeriodAnchor.END)) { return getLastMillisecond(calendar); } else { throw new IllegalStateException("Unrecognised anchor: " + anchor); } } /** * Returns a string representation of the time period. * * @return The string. */ @Override public String toString() { return String.valueOf(getStart()); } }
10,688
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimeSeries.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.] * * --------------- * TimeSeries.java * --------------- * (C) Copyright 2001-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Bryan Scott; * Nick Guenther; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 14-Nov-2001 : Added listener mechanism (DG); * 15-Nov-2001 : Updated argument checking and exceptions in add() method (DG); * 29-Nov-2001 : Added properties to describe the domain and range (DG); * 07-Dec-2001 : Renamed TimeSeries --> BasicTimeSeries (DG); * 01-Mar-2002 : Updated import statements (DG); * 28-Mar-2002 : Added a method add(TimePeriod, double) (DG); * 27-Aug-2002 : Changed return type of delete method to void (DG); * 04-Oct-2002 : Added itemCount and historyCount attributes, fixed errors * reported by Checkstyle (DG); * 29-Oct-2002 : Added series change notification to addOrUpdate() method (DG); * 28-Jan-2003 : Changed name back to TimeSeries (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package and implemented * Serializable (DG); * 01-May-2003 : Updated equals() method (see bug report 727575) (DG); * 14-Aug-2003 : Added ageHistoryCountItems method (copied existing code for * contents) made a method and added to addOrUpdate. Made a * public method to enable ageing against a specified time * (eg now) as opposed to lastest time in series (BS); * 15-Oct-2003 : Added fix for setItemCount method - see bug report 804425. * Modified exception message in add() method to be more * informative (DG); * 13-Apr-2004 : Added clear() method (DG); * 21-May-2004 : Added an extra addOrUpdate() method (DG); * 15-Jun-2004 : Fixed NullPointerException in equals() method (DG); * 29-Nov-2004 : Fixed bug 1075255 (DG); * 17-Nov-2005 : Renamed historyCount --> maximumItemAge (DG); * 28-Nov-2005 : Changed maximumItemAge from int to long (DG); * 01-Dec-2005 : New add methods accept notify flag (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 24-May-2006 : Improved error handling in createCopy() methods (DG); * 01-Sep-2006 : Fixed bugs in removeAgedItems() methods - see bug report * 1550045 (DG); * 22-Mar-2007 : Simplified getDataItem(RegularTimePeriod) - see patch 1685500 * by Nick Guenther (DG); * 31-Oct-2007 : Implemented faster hashCode() (DG); * 21-Nov-2007 : Fixed clone() method (bug 1832432) (DG); * 10-Jan-2008 : Fixed createCopy(RegularTimePeriod, RegularTimePeriod) (bug * 1864222) (DG); * 13-Jan-2009 : Fixed constructors so that timePeriodClass doesn't need to * be specified in advance (DG); * 26-May-2009 : Added cache for minY and maxY values (DG); * 09-Jun-2009 : Ensure that TimeSeriesDataItem objects used in underlying * storage are cloned to keep series isolated from external * changes (DG); * 10-Jun-2009 : Added addOrUpdate(TimeSeriesDataItem) method (DG); * 31-Aug-2009 : Clear minY and maxY cache values in createCopy (DG); * 03-Dec-2011 : Fixed bug 3446965 which affects the y-range calculation for * the series (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.TimeZone; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.data.Range; import org.jfree.data.general.Series; import org.jfree.data.general.SeriesException; /** * Represents a sequence of zero or more data items in the form (period, value) * where 'period' is some instance of a subclass of {@link RegularTimePeriod}. * The time series will ensure that (a) all data items have the same type of * period (for example, {@link Day}) and (b) that each period appears at * most one time in the series. */ public class TimeSeries extends Series implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -5032960206869675528L; /** Default value for the domain description. */ protected static final String DEFAULT_DOMAIN_DESCRIPTION = "Time"; /** Default value for the range description. */ protected static final String DEFAULT_RANGE_DESCRIPTION = "Value"; /** A description of the domain. */ private String domain; /** A description of the range. */ private String range; /** The type of period for the data. */ protected Class<? extends TimePeriod> timePeriodClass; /** The list of data items in the series. */ protected List<TimeSeriesDataItem> data; /** The maximum number of items for the series. */ private int maximumItemCount; /** * The maximum age of items for the series, specified as a number of * time periods. */ private long maximumItemAge; /** * The minimum y-value in the series. * * @since 1.0.14 */ private double minY; /** * The maximum y-value in the series. * * @since 1.0.14 */ private double maxY; /** * Creates a new (empty) time series. By default, a daily time series is * created. Use one of the other constructors if you require a different * time period. * * @param name the series name (<code>null</code> not permitted). */ public TimeSeries(Comparable name) { this(name, DEFAULT_DOMAIN_DESCRIPTION, DEFAULT_RANGE_DESCRIPTION); } /** * Creates a new time series that contains no data. * <P> * Descriptions can be specified for the domain and range. One situation * where this is helpful is when generating a chart for the time series - * axis labels can be taken from the domain and range description. * * @param name the name of the series (<code>null</code> not permitted). * @param domain the domain description (<code>null</code> permitted). * @param range the range description (<code>null</code> permitted). * * @since 1.0.13 */ public TimeSeries(Comparable name, String domain, String range) { super(name); this.domain = domain; this.range = range; this.timePeriodClass = null; this.data = new java.util.ArrayList<TimeSeriesDataItem>(); this.maximumItemCount = Integer.MAX_VALUE; this.maximumItemAge = Long.MAX_VALUE; this.minY = Double.NaN; this.maxY = Double.NaN; } /** * Returns the domain description. * * @return The domain description (possibly <code>null</code>). * * @see #setDomainDescription(String) */ public String getDomainDescription() { return this.domain; } /** * Sets the domain description and sends a <code>PropertyChangeEvent</code> * (with the property name <code>Domain</code>) to all registered * property change listeners. * * @param description the description (<code>null</code> permitted). * * @see #getDomainDescription() */ public void setDomainDescription(String description) { String old = this.domain; this.domain = description; firePropertyChange("Domain", old, description); } /** * Returns the range description. * * @return The range description (possibly <code>null</code>). * * @see #setRangeDescription(String) */ public String getRangeDescription() { return this.range; } /** * Sets the range description and sends a <code>PropertyChangeEvent</code> * (with the property name <code>Range</code>) to all registered listeners. * * @param description the description (<code>null</code> permitted). * * @see #getRangeDescription() */ public void setRangeDescription(String description) { String old = this.range; this.range = description; firePropertyChange("Range", old, description); } /** * Returns the number of items in the series. * * @return The item count. */ @Override public int getItemCount() { return this.data.size(); } /** * Returns the list of data items for the series (the list contains * {@link TimeSeriesDataItem} objects and is unmodifiable). * * @return The list of data items. */ public List<TimeSeriesDataItem> getItems() { // FIXME: perhaps we should clone the data list 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. * * @param maximum the maximum (requires >= 0). * * @see #getMaximumItemCount() */ public void setMaximumItemCount(int maximum) { if (maximum < 0) { throw new IllegalArgumentException("Negative 'maximum' argument."); } this.maximumItemCount = maximum; int count = this.data.size(); if (count > maximum) { delete(0, count - maximum - 1); } } /** * Returns the maximum item age (in time periods) for the series. * * @return The maximum item age. * * @see #setMaximumItemAge(long) */ public long getMaximumItemAge() { return this.maximumItemAge; } /** * Sets the number of time units in the 'history' for the series. This * provides one mechanism for automatically dropping old data from the * time series. For example, if a series contains daily data, you might set * the history count to 30. Then, when you add a new data item, all data * items more than 30 days older than the latest value are automatically * dropped from the series. * * @param periods the number of time periods. * * @see #getMaximumItemAge() */ public void setMaximumItemAge(long periods) { if (periods < 0) { throw new IllegalArgumentException("Negative 'periods' argument."); } this.maximumItemAge = periods; removeAgedItems(true); // remove old items and notify if necessary } /** * Returns the range of y-values in the time series. Any <code>null</code> * data values in the series will be ignored (except for the special case * where all data values are <code>null</code>, in which case the return * value is <code>Range(Double.NaN, Double.NaN)</code>). If the time * series contains no items, this method will return <code>null</code>. * * @return The range of y-values in the time series (possibly * <code>null</code>). * * @since 1.0.18 */ public Range findValueRange() { if (this.data.isEmpty()) { return null; } return new Range(this.minY, this.maxY); } /** * Returns the range of y-values in the time series that fall within * the specified range of x-values. This is equivalent to * <code>findValueRange(xRange, TimePeriodAnchor.MIDDLE, timeZone)</code>. * * @param xRange the subrange of x-values (<code>null</code> not * permitted). * @param timeZone the time zone used to convert x-values to time periods * (<code>null</code> not permitted). * * @return The range. * * @since 1.0.18 */ public Range findValueRange(Range xRange, TimeZone timeZone) { return findValueRange(xRange, TimePeriodAnchor.MIDDLE, timeZone); } /** * Finds the range of y-values that fall within the specified range of * x-values (where the x-values are interpreted as milliseconds since the * epoch and converted to time periods using the specified timezone). * * @param xRange the subset of x-values to use (<coded>null</code> not * permitted). * @param xAnchor the anchor point for the x-values (<code>null</code> * not permitted). * @param zone the time zone (<code>null</code> not permitted). * * @return The range of y-values. * * @since 1.0.18 */ public Range findValueRange(Range xRange, TimePeriodAnchor xAnchor, TimeZone zone) { ParamChecks.nullNotPermitted(xRange, "xRange"); ParamChecks.nullNotPermitted(xAnchor, "xAnchor"); ParamChecks.nullNotPermitted(zone, "zone"); if (this.data.isEmpty()) { return null; } Calendar calendar = Calendar.getInstance(zone); // since the items are ordered, we could be more clever here and avoid // iterating over all the data double lowY = Double.POSITIVE_INFINITY; double highY = Double.NEGATIVE_INFINITY; for (TimeSeriesDataItem item : this.data) { long millis = item.getPeriod().getMillisecond(xAnchor, calendar); if (xRange.contains(millis)) { Number n = item.getValue(); if (n != null) { double v = n.doubleValue(); lowY = Math.min(lowY, v); highY = Math.max(highY, v); } } } if (Double.isInfinite(lowY) && Double.isInfinite(highY)) { if (lowY < highY) { return new Range(lowY, highY); } else { return new Range(Double.NaN, Double.NaN); } } return new Range(lowY, highY); } /** * Returns the smallest y-value in the series, ignoring any * <code>null</code> and <code>Double.NaN</code> values. This method * returns <code>Double.NaN</code> if there is no smallest y-value (for * example, when the series is empty). * * @return The smallest y-value. * * @see #getMaxY() * * @since 1.0.14 */ public double getMinY() { return this.minY; } /** * Returns the largest y-value in the series, ignoring any * <code>null</code> and <code>Double.NaN</code> values. This method * returns <code>Double.NaN</code> if there is no largest y-value * (for example, when the series is empty). * * @return The largest y-value. * * @see #getMinY() * * @since 1.0.14 */ public double getMaxY() { return this.maxY; } /** * Returns the time period class for this series. * <p> * Only one time period class can be used within a single series (enforced). * If you add a data item with a {@link Year} for the time period, then all * subsequent data items must also have a {@link Year} for the time period. * * @return The time period class (may be <code>null</code> but only for * an empty series). */ public Class getTimePeriodClass() { return this.timePeriodClass; } /** * Returns a data item from the dataset. Note that the returned object * is a clone of the item in the series, so modifying it will have no * effect on the data series. * * @param index the item index. * * @return The data item. */ public TimeSeriesDataItem getDataItem(int index) { TimeSeriesDataItem item = this.data.get(index); return (TimeSeriesDataItem) item.clone(); } /** * Returns the data item for a specific period. Note that the returned * object is a clone of the item in the series, so modifying it will have * no effect on the data series. * * @param period the period of interest (<code>null</code> not allowed). * * @return The data item matching the specified period (or * <code>null</code> if there is no match). * * @see #getDataItem(int) */ public TimeSeriesDataItem getDataItem(RegularTimePeriod period) { int index = getIndex(period); if (index >= 0) { return getDataItem(index); } return null; } /** * Returns a data item for the series. This method returns the object * that is used for the underlying storage - you should not modify the * contents of the returned value unless you know what you are doing. * * @param index the item index (zero-based). * * @return The data item. * * @see #getDataItem(int) * * @since 1.0.14 */ TimeSeriesDataItem getRawDataItem(int index) { return this.data.get(index); } /** * Returns a data item for the series. This method returns the object * that is used for the underlying storage - you should not modify the * contents of the returned value unless you know what you are doing. * * @param period the item index (zero-based). * * @return The data item. * * @see #getDataItem(RegularTimePeriod) * * @since 1.0.14 */ TimeSeriesDataItem getRawDataItem(RegularTimePeriod period) { int index = getIndex(period); if (index >= 0) { return this.data.get(index); } return null; } /** * Returns the time period at the specified index. * * @param index the index of the data item. * * @return The time period. */ public RegularTimePeriod getTimePeriod(int index) { return getRawDataItem(index).getPeriod(); } /** * Returns a time period that would be the next in sequence on the end of * the time series. * * @return The next time period. */ public RegularTimePeriod getNextTimePeriod() { RegularTimePeriod last = getTimePeriod(getItemCount() - 1); return last.next(); } /** * Returns a collection of all the time periods in the time series. * * @return A collection of all the time periods. */ public Collection<RegularTimePeriod> getTimePeriods() { Collection<RegularTimePeriod> result = new java.util.ArrayList<RegularTimePeriod>(); for (int i = 0; i < getItemCount(); i++) { result.add(getTimePeriod(i)); } return result; } /** * Returns a collection of time periods in the specified series, but not in * this series, and therefore unique to the specified series. * * @param series the series to check against this one. * * @return The unique time periods. */ public Collection<RegularTimePeriod> getTimePeriodsUniqueToOtherSeries(TimeSeries series) { Collection<RegularTimePeriod> result = new java.util.ArrayList<RegularTimePeriod>(); for (int i = 0; i < series.getItemCount(); i++) { RegularTimePeriod period = series.getTimePeriod(i); int index = getIndex(period); if (index < 0) { result.add(period); } } return result; } /** * Returns the index for the item (if any) that corresponds to a time * period. * * @param period the time period (<code>null</code> not permitted). * * @return The index. */ public int getIndex(RegularTimePeriod period) { ParamChecks.nullNotPermitted(period, "period"); TimeSeriesDataItem dummy = new TimeSeriesDataItem( period, Integer.MIN_VALUE); return Collections.binarySearch(this.data, dummy); } /** * Returns the value at the specified index. * * @param index index of a value. * * @return The value (possibly <code>null</code>). */ public Number getValue(int index) { return getRawDataItem(index).getValue(); } /** * Returns the value for a time period. If there is no data item with the * specified period, this method will return <code>null</code>. * * @param period time period (<code>null</code> not permitted). * * @return The value (possibly <code>null</code>). */ public Number getValue(RegularTimePeriod period) { int index = getIndex(period); if (index >= 0) { return getValue(index); } return null; } /** * Adds a data item to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. * * @param item the (timeperiod, value) pair (<code>null</code> not * permitted). */ public void add(TimeSeriesDataItem item) { add(item, true); } /** * Adds a data item to the series and sends a {@link SeriesChangeEvent} to * all registered listeners. * * @param item the (timeperiod, value) pair (<code>null</code> not * permitted). * @param notify notify listeners? */ public void add(TimeSeriesDataItem item, boolean notify) { ParamChecks.nullNotPermitted(item, "item"); item = (TimeSeriesDataItem) item.clone(); Class<? extends TimePeriod> c = item.getPeriod().getClass(); if (this.timePeriodClass == null) { this.timePeriodClass = c; } else if (!this.timePeriodClass.equals(c)) { StringBuilder b = new StringBuilder(); b.append("You are trying to add data where the time period class "); b.append("is "); b.append(item.getPeriod().getClass().getName()); b.append(", but the TimeSeries is expecting an instance of "); b.append(this.timePeriodClass.getName()); b.append("."); throw new SeriesException(b.toString()); } // make the change (if it's not a duplicate time period)... boolean added; int count = getItemCount(); if (count == 0) { this.data.add(item); added = true; } else { RegularTimePeriod last = getTimePeriod(getItemCount() - 1); if (item.getPeriod().compareTo(last) > 0) { this.data.add(item); added = true; } else { int index = Collections.binarySearch(this.data, item); if (index < 0) { this.data.add(-index - 1, item); added = true; } else { StringBuilder b = new StringBuilder(); b.append("You are attempting to add an observation for "); b.append("the time period "); b.append(item.getPeriod().toString()); b.append(" but the series already contains an observation"); b.append(" for that time period. Duplicates are not "); b.append("permitted. Try using the addOrUpdate() method."); throw new SeriesException(b.toString()); } } } if (added) { updateBoundsForAddedItem(item); // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { TimeSeriesDataItem d = this.data.remove(0); updateBoundsForRemovedItem(d); } removeAgedItems(false); // remove old items if necessary, but // don't notify anyone, because that // happens next anyway... if (notify) { fireSeriesChanged(); } } } /** * Adds a new data item to the series and sends a {@link SeriesChangeEvent} * to all registered listeners. * * @param period the time period (<code>null</code> not permitted). * @param value the value. */ public void add(RegularTimePeriod period, double value) { // defer argument checking... add(period, value, true); } /** * Adds a new data item to the series and sends a {@link SeriesChangeEvent} * to all registered listeners. * * @param period the time period (<code>null</code> not permitted). * @param value the value. * @param notify notify listeners? */ public void add(RegularTimePeriod period, double value, boolean notify) { // defer argument checking... TimeSeriesDataItem item = new TimeSeriesDataItem(period, value); add(item, notify); } /** * Adds a new data item to the series and sends * a {@link org.jfree.data.general.SeriesChangeEvent} to all registered * listeners. * * @param period the time period (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public void add(RegularTimePeriod period, Number value) { // defer argument checking... add(period, value, true); } /** * Adds a new data item to the series and sends a {@link SeriesChangeEvent} * to all registered listeners. * * @param period the time period (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * @param notify notify listeners? */ public void add(RegularTimePeriod period, Number value, boolean notify) { // defer argument checking... TimeSeriesDataItem item = new TimeSeriesDataItem(period, value); add(item, notify); } /** * Updates (changes) the value for a time period. Throws a * {@link SeriesException} if the period does not exist. * * @param period the period (<code>null</code> not permitted). * @param value the value. * * @since 1.0.14 */ public void update(RegularTimePeriod period, double value) { update(period, new Double(value)); } /** * Updates (changes) the value for a time period. Throws a * {@link SeriesException} if the period does not exist. * * @param period the period (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). */ public void update(RegularTimePeriod period, Number value) { TimeSeriesDataItem temp = new TimeSeriesDataItem(period, value); int index = Collections.binarySearch(this.data, temp); if (index < 0) { throw new SeriesException("There is no existing value for the " + "specified 'period'."); } update(index, value); } /** * Updates (changes) the value of a data item. * * @param index the index of the data item. * @param value the new value (<code>null</code> permitted). */ public void update(int index, Number value) { TimeSeriesDataItem item = this.data.get(index); boolean iterate = false; Number oldYN = item.getValue(); if (oldYN != null) { double oldY = oldYN.doubleValue(); if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } } item.setValue(value); if (iterate) { updateMinMaxYByIteration(); } else if (value != null) { double yy = value.doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } fireSeriesChanged(); } /** * Adds or updates data from one series to another. Returns another series * containing the values that were overwritten. * * @param series the series to merge with this. * * @return A series containing the values that were overwritten. */ public TimeSeries addAndOrUpdate(TimeSeries series) { TimeSeries overwritten = new TimeSeries("Overwritten values from: " + getKey()); for (int i = 0; i < series.getItemCount(); i++) { TimeSeriesDataItem item = series.getRawDataItem(i); TimeSeriesDataItem oldItem = addOrUpdate(item.getPeriod(), item.getValue()); if (oldItem != null) { overwritten.add(oldItem); } } return overwritten; } /** * Adds or updates an item in the times series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param period the time period to add/update (<code>null</code> not * permitted). * @param value the new value. * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten. */ public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, double value) { return addOrUpdate(period, new Double(value)); } /** * Adds or updates an item in the times series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param period the time period to add/update (<code>null</code> not * permitted). * @param value the new value (<code>null</code> permitted). * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten. */ public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value) { return addOrUpdate(new TimeSeriesDataItem(period, value)); } /** * Adds or updates an item in the times 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 TimeSeriesDataItem addOrUpdate(TimeSeriesDataItem item) { ParamChecks.nullNotPermitted(item, "item"); Class<? extends TimePeriod> periodClass = item.getPeriod().getClass(); if (this.timePeriodClass == null) { this.timePeriodClass = periodClass; } else if (!this.timePeriodClass.equals(periodClass)) { String msg = "You are trying to add data where the time " + "period class is " + periodClass.getName() + ", but the TimeSeries is expecting an instance of " + this.timePeriodClass.getName() + "."; throw new SeriesException(msg); } TimeSeriesDataItem overwritten = null; int index = Collections.binarySearch(this.data, item); if (index >= 0) { TimeSeriesDataItem existing = this.data.get(index); overwritten = (TimeSeriesDataItem) existing.clone(); // figure out if we need to iterate through all the y-values // to find the revised minY / maxY boolean iterate = false; Number oldYN = existing.getValue(); double oldY = oldYN != null ? oldYN.doubleValue() : Double.NaN; if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } existing.setValue(item.getValue()); if (iterate) { updateMinMaxYByIteration(); } else if (item.getValue() != null) { double yy = item.getValue().doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } } else { item = (TimeSeriesDataItem) item.clone(); this.data.add(-index - 1, item); updateBoundsForAddedItem(item); // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { TimeSeriesDataItem d = this.data.remove(0); updateBoundsForRemovedItem(d); } } removeAgedItems(false); // remove old items if necessary, but // don't notify anyone, because that // happens next anyway... fireSeriesChanged(); return overwritten; } /** * Age items in the series. Ensure that the timespan from the youngest to * the oldest record in the series does not exceed maximumItemAge time * periods. Oldest items will be removed if required. * * @param notify controls whether or not a {@link SeriesChangeEvent} is * sent to registered listeners IF any items are removed. */ public void removeAgedItems(boolean notify) { // check if there are any values earlier than specified by the history // count... if (getItemCount() > 1) { long latest = getTimePeriod(getItemCount() - 1).getSerialIndex(); boolean removed = false; while ((latest - getTimePeriod(0).getSerialIndex()) > this.maximumItemAge) { this.data.remove(0); removed = true; } if (removed) { updateMinMaxYByIteration(); if (notify) { fireSeriesChanged(); } } } } /** * Age items in the series. Ensure that the timespan from the supplied * time to the oldest record in the series does not exceed history count. * oldest items will be removed if required. * * @param latest the time to be compared against when aging data * (specified in milliseconds). * @param notify controls whether or not a {@link SeriesChangeEvent} is * sent to registered listeners IF any items are removed. */ public void removeAgedItems(long latest, boolean notify) { if (this.data.isEmpty()) { return; // nothing to do } // find the serial index of the period specified by 'latest' RegularTimePeriod newest = RegularTimePeriod.createInstance( this.timePeriodClass, new Date(latest), TimeZone.getDefault(), Locale.getDefault()); long index = newest.getSerialIndex(); // check if there are any values earlier than specified by the history // count... boolean removed = false; while (getItemCount() > 0 && (index - getTimePeriod(0).getSerialIndex()) > this.maximumItemAge) { this.data.remove(0); removed = true; } if (removed) { updateMinMaxYByIteration(); if (notify) { fireSeriesChanged(); } } } /** * 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.timePeriodClass = null; this.minY = Double.NaN; this.maxY = Double.NaN; fireSeriesChanged(); } } /** * Deletes the data item for the given time period and sends a * {@link SeriesChangeEvent} to all registered listeners. If there is no * item with the specified time period, this method does nothing. * * @param period the period of the item to delete (<code>null</code> not * permitted). */ public void delete(RegularTimePeriod period) { int index = getIndex(period); if (index >= 0) { TimeSeriesDataItem item = this.data.remove( index); updateBoundsForRemovedItem(item); if (this.data.isEmpty()) { this.timePeriodClass = null; } fireSeriesChanged(); } } /** * Deletes data from start until end index (end inclusive). * * @param start the index of the first period to delete. * @param end the index of the last period to delete. */ public void delete(int start, int end) { delete(start, end, true); } /** * Deletes data from start until end index (end inclusive). * * @param start the index of the first period to delete. * @param end the index of the last period to delete. * @param notify notify listeners? * * @since 1.0.14 */ public void delete(int start, int end, boolean notify) { if (end < start) { throw new IllegalArgumentException("Requires start <= end."); } for (int i = 0; i <= (end - start); i++) { this.data.remove(start); } updateMinMaxYByIteration(); if (this.data.isEmpty()) { this.timePeriodClass = null; } if (notify) { fireSeriesChanged(); } } /** * Returns a clone of the time series. * <P> * Notes: * <ul> * <li>no need to clone the domain and range descriptions, since String * object is immutable;</li> * <li>we pass over to the more general method clone(start, end).</li> * </ul> * * @return A clone of the time series. * * @throws CloneNotSupportedException not thrown by this class, but * subclasses may differ. */ @Override public Object clone() throws CloneNotSupportedException { TimeSeries clone = (TimeSeries) super.clone(); clone.data = ObjectUtilities.deepClone(this.data); return clone; } /** * Creates a new timeseries by copying a subset of the data in this time * series. * * @param start the index of the first time period to copy. * @param end the index of the last time period to copy. * * @return A series containing a copy of this times series from start until * end. * * @throws CloneNotSupportedException if there is a cloning problem. */ public TimeSeries createCopy(int start, int end) throws CloneNotSupportedException { if (start < 0) { throw new IllegalArgumentException("Requires start >= 0."); } if (end < start) { throw new IllegalArgumentException("Requires start <= end."); } TimeSeries copy = (TimeSeries) super.clone(); copy.minY = Double.NaN; copy.maxY = Double.NaN; copy.data = new java.util.ArrayList<TimeSeriesDataItem>(); if (this.data.size() > 0) { for (int index = start; index <= end; index++) { TimeSeriesDataItem item = this.data.get(index); TimeSeriesDataItem clone = (TimeSeriesDataItem) item.clone(); try { copy.add(clone); } catch (SeriesException e) { throw new RuntimeException("Could not add cloned item to series", e); } } } return copy; } /** * Creates a new timeseries by copying a subset of the data in this time * series. * * @param start the first time period to copy (<code>null</code> not * permitted). * @param end the last time period to copy (<code>null</code> not * permitted). * * @return A time series containing a copy of this time series from start * until end. * * @throws CloneNotSupportedException if there is a cloning problem. */ public TimeSeries createCopy(RegularTimePeriod start, RegularTimePeriod end) throws CloneNotSupportedException { ParamChecks.nullNotPermitted(start, "start"); ParamChecks.nullNotPermitted(end, "end"); if (start.compareTo(end) > 0) { throw new IllegalArgumentException( "Requires start on or before end."); } boolean emptyRange = false; int startIndex = getIndex(start); if (startIndex < 0) { startIndex = -(startIndex + 1); if (startIndex == this.data.size()) { emptyRange = true; // start is after last data item } } int endIndex = getIndex(end); if (endIndex < 0) { // end period is not in original series endIndex = -(endIndex + 1); // this is first item AFTER end period endIndex = endIndex - 1; // so this is last item BEFORE end } if ((endIndex < 0) || (endIndex < startIndex)) { emptyRange = true; } if (emptyRange) { TimeSeries copy = (TimeSeries) super.clone(); copy.data = new java.util.ArrayList<TimeSeriesDataItem>(); return copy; } return createCopy(startIndex, endIndex); } /** * Tests the series 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 == this) { return true; } if (!(obj instanceof TimeSeries)) { return false; } TimeSeries that = (TimeSeries) obj; if (!ObjectUtilities.equal(getDomainDescription(), that.getDomainDescription())) { return false; } if (!ObjectUtilities.equal(getRangeDescription(), that.getRangeDescription())) { return false; } if (!ObjectUtilities.equal(this.timePeriodClass, that.timePeriodClass)) { return false; } if (getMaximumItemAge() != that.getMaximumItemAge()) { return false; } if (getMaximumItemCount() != that.getMaximumItemCount()) { return false; } int count = getItemCount(); if (count != that.getItemCount()) { return false; } if (!ObjectUtilities.equal(this.data, that.data)) { return false; } return super.equals(obj); } /** * Returns a hash code value for the object. * * @return The hashcode */ @Override public int hashCode() { int result = super.hashCode(); result = 29 * result + (this.domain != null ? this.domain.hashCode() : 0); result = 29 * result + (this.range != null ? this.range.hashCode() : 0); result = 29 * result + (this.timePeriodClass != null ? this.timePeriodClass.hashCode() : 0); // 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) { TimeSeriesDataItem item = getRawDataItem(0); result = 29 * result + item.hashCode(); } if (count > 1) { TimeSeriesDataItem item = getRawDataItem(count - 1); result = 29 * result + item.hashCode(); } if (count > 2) { TimeSeriesDataItem item = getRawDataItem(count / 2); result = 29 * result + item.hashCode(); } result = 29 * result + this.maximumItemCount; result = 29 * result + (int) this.maximumItemAge; return result; } /** * Updates the cached values for the minimum and maximum data values. * * @param item the item added (<code>null</code> not permitted). * * @since 1.0.14 */ private void updateBoundsForAddedItem(TimeSeriesDataItem item) { Number yN = item.getValue(); if (item.getValue() != null) { double y = yN.doubleValue(); 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.14 */ private void updateBoundsForRemovedItem(TimeSeriesDataItem item) { Number yN = item.getValue(); if (yN != null) { double y = yN.doubleValue(); if (!Double.isNaN(y)) { if (y <= this.minY || y >= this.maxY) { updateMinMaxYByIteration(); } } } } /** * Finds the bounds of the x and y values for the series, by iterating * through all the data items. * * @since 1.0.14 */ private void updateMinMaxYByIteration() { this.minY = Double.NaN; this.maxY = Double.NaN; for (TimeSeriesDataItem aData : this.data) { TimeSeriesDataItem item = aData; updateBoundsForAddedItem(item); } } /** * 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; } else { return Math.max(a, b); } } }
47,898
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Quarter.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Quarter.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.] * * ------------ * Quarter.java * ------------ * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 18-Dec-2001 : Changed order of parameters in constructor (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 29-Jan-2002 : Added a new method parseQuarter(String) (DG); * 14-Feb-2002 : Fixed bug in Quarter(Date) constructor (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 19-Mar-2002 : Changed API for TimePeriod classes (DG); * 24-Jun-2002 : Removed main method (just test code) (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * 10-Dec-2005 : Fixed argument checking bug (1377239) in constructor (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 25-Nov-2008 : Added new constructor with Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; import org.jfree.chart.date.MonthConstants; import org.jfree.chart.date.SerialDate; /** * Defines a quarter (in a given year). The range supported is Q1 1900 to * Q4 9999. This class is immutable, which is a requirement for all * {@link RegularTimePeriod} subclasses. */ public class Quarter extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = 3810061714380888671L; /** Constant for quarter 1. */ public static final int FIRST_QUARTER = 1; /** Constant for quarter 4. */ public static final int LAST_QUARTER = 4; /** The first month in each quarter. */ public static final int[] FIRST_MONTH_IN_QUARTER = { 0, MonthConstants.JANUARY, MonthConstants.APRIL, MonthConstants.JULY, MonthConstants.OCTOBER }; /** The last month in each quarter. */ public static final int[] LAST_MONTH_IN_QUARTER = { 0, MonthConstants.MARCH, MonthConstants.JUNE, MonthConstants.SEPTEMBER, MonthConstants.DECEMBER }; /** The year in which the quarter falls. */ private short year; /** The quarter (1-4). */ private byte quarter; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Constructs a new Quarter, based on the current system date/time. */ public Quarter() { this(new Date()); } /** * Constructs a new quarter. * * @param year the year (1900 to 9999). * @param quarter the quarter (1 to 4). */ public Quarter(int quarter, int year) { if ((quarter < FIRST_QUARTER) || (quarter > LAST_QUARTER)) { throw new IllegalArgumentException("Quarter outside valid range."); } this.year = (short) year; this.quarter = (byte) quarter; peg(Calendar.getInstance()); } /** * Constructs a new quarter. * * @param quarter the quarter (1 to 4). * @param year the year (1900 to 9999). */ public Quarter(int quarter, Year year) { if ((quarter < FIRST_QUARTER) || (quarter > LAST_QUARTER)) { throw new IllegalArgumentException("Quarter outside valid range."); } this.year = (short) year.getYear(); this.quarter = (byte) quarter; peg(Calendar.getInstance()); } /** * Constructs a new instance, based on a date/time and the default time * zone. * * @param time the date/time (<code>null</code> not permitted). * * @see #Quarter(Date, TimeZone) */ public Quarter(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a new <code>Quarter</code> instance, using the specified * zone and locale. * * @param time the current time. * @param zone the time zone. * @param locale the locale. * * @since 1.0.12 */ public Quarter(Date time, TimeZone zone, Locale locale) { Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); int month = calendar.get(Calendar.MONTH) + 1; this.quarter = (byte) SerialDate.monthCodeToQuarter(month); this.year = (short) calendar.get(Calendar.YEAR); peg(calendar); } /** * Returns the quarter. * * @return The quarter. */ public int getQuarter() { return this.quarter; } /** * Returns the year. * * @return The year. */ public Year getYear() { return new Year(this.year); } /** * Returns the year. * * @return The year. * * @since 1.0.3 */ public int getYearValue() { return this.year; } /** * Returns the first millisecond of the quarter. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the quarter. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the quarter. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the quarter. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the quarter preceding this one. * * @return The quarter preceding this one (or <code>null</code> if this is * Q1 1900). */ @Override public RegularTimePeriod previous() { Quarter result; if (this.quarter > FIRST_QUARTER) { result = new Quarter(this.quarter - 1, this.year); } else { if (this.year > 1900) { result = new Quarter(LAST_QUARTER, this.year - 1); } else { result = null; } } return result; } /** * Returns the quarter following this one. * * @return The quarter following this one (or null if this is Q4 9999). */ @Override public RegularTimePeriod next() { Quarter result; if (this.quarter < LAST_QUARTER) { result = new Quarter(this.quarter + 1, this.year); } else { if (this.year < 9999) { result = new Quarter(FIRST_QUARTER, this.year + 1); } else { result = null; } } return result; } /** * Returns a serial index number for the quarter. * * @return The serial index number. */ @Override public long getSerialIndex() { return this.year * 4L + this.quarter; } /** * Tests the equality of this Quarter object to an arbitrary object. * Returns <code>true</code> if the target is a Quarter instance * representing the same quarter as this object. In all other cases, * returns <code>false</code>. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> if quarter and year of this and the object are * the same. */ @Override public boolean equals(Object obj) { if (obj != null) { if (obj instanceof Quarter) { Quarter target = (Quarter) obj; return (this.quarter == target.getQuarter() && (this.year == target.getYearValue())); } return false; } return false; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.quarter; result = 37 * result + this.year; return result; } /** * Returns an integer indicating the order of this Quarter object relative * to the specified object: * * negative == before, zero == same, positive == after. * * @param o1 the object to compare * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Quarter object // -------------------------------------------- if (o1 instanceof Quarter) { Quarter q = (Quarter) o1; result = this.year - q.getYearValue(); if (result == 0) { result = this.quarter - q.getQuarter(); } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Returns a string representing the quarter (e.g. "Q1/2002"). * * @return A string representing the quarter. */ @Override public String toString() { return "Q" + this.quarter + "/" + this.year; } /** * Returns the first millisecond in the Quarter, evaluated using the * supplied calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond in the Quarter. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { int month = Quarter.FIRST_MONTH_IN_QUARTER[this.quarter]; calendar.set(this.year, month - 1, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the Quarter, evaluated using the * supplied calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the Quarter. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { int month = Quarter.LAST_MONTH_IN_QUARTER[this.quarter]; int eom = SerialDate.lastDayOfMonth(month, this.year); calendar.set(this.year, month - 1, eom, 23, 59, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTimeInMillis(); } /** * Parses the string argument as a quarter. * <P> * This method should accept the following formats: "YYYY-QN" and "QN-YYYY", * where the "-" can be a space, a forward-slash (/), comma or a dash (-). * @param s A string representing the quarter. * * @return The quarter. */ public static Quarter parseQuarter(String s) { // find the Q and the integer following it (remove both from the // string)... int i = s.indexOf("Q"); if (i == -1) { throw new TimePeriodFormatException("Missing Q."); } if (i == s.length() - 1) { throw new TimePeriodFormatException("Q found at end of string."); } String qstr = s.substring(i + 1, i + 2); int quarter = Integer.parseInt(qstr); String remaining = s.substring(0, i) + s.substring(i + 2, s.length()); // replace any / , or - with a space remaining = remaining.replace('/', ' '); remaining = remaining.replace(',', ' '); remaining = remaining.replace('-', ' '); // parse the string... Year year = Year.parseYear(remaining.trim()); Quarter result = new Quarter(quarter, year); return result; } }
14,734
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SimpleTimePeriod.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/SimpleTimePeriod.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.] * * --------------------- * SimpleTimePeriod.java * --------------------- * (C) Copyright 2002-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 07-Oct-2002 : Added Javadocs (DG); * 10-Jan-2003 : Renamed TimeAllocation --> SimpleTimePeriod (DG); * 13-Mar-2003 : Added equals() method, and Serializable interface (DG); * 21-Oct-2003 : Added hashCode() method (DG); * 27-Jan-2005 : Implemented Comparable, to enable this class to be used * in the TimeTableXYDataset class (DG); * 02-Jun-2008 : Fixed problem with fields being mutable (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Date; /** * An arbitrary period of time, measured to millisecond precision using * <code>java.util.Date</code>. * <p> * This class is intentionally immutable (that is, once constructed, you cannot * alter the start and end attributes). */ public class SimpleTimePeriod implements TimePeriod, Comparable<TimePeriod>, Serializable { /** For serialization. */ private static final long serialVersionUID = 8684672361131829554L; /** The start date/time. */ private long start; /** The end date/time. */ private long end; /** * Creates a new time allocation. * * @param start the start date/time in milliseconds. * @param end the end date/time in milliseconds. */ public SimpleTimePeriod(long start, long end) { if (start > end) { throw new IllegalArgumentException("Requires start <= end."); } this.start = start; this.end = end; } /** * Creates a new time allocation. * * @param start the start date/time (<code>null</code> not permitted). * @param end the end date/time (<code>null</code> not permitted). */ public SimpleTimePeriod(Date start, Date end) { this(start.getTime(), end.getTime()); } /** * Returns the start date/time. * * @return The start date/time (never <code>null</code>). */ @Override public Date getStart() { return new Date(this.start); } /** * Returns the start date/time in milliseconds. * * @return The start. * * @since 1.0.10. */ public long getStartMillis() { return this.start; } /** * Returns the end date/time. * * @return The end date/time (never <code>null</code>). */ @Override public Date getEnd() { return new Date(this.end); } /** * Returns the end date/time in milliseconds. * * @return The end. * * @since 1.0.10. */ public long getEndMillis() { return this.end; } /** * Tests this time period instance for equality with an arbitrary object. * The object is considered equal if it is an instance of {@link TimePeriod} * and it has the same start and end dates. * * @param obj the other object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof TimePeriod)) { return false; } TimePeriod that = (TimePeriod) obj; if (!this.getStart().equals(that.getStart())) { return false; } if (!this.getEnd().equals(that.getEnd())) { return false; } return true; } /** * Returns an integer that indicates the relative ordering of two * time periods. * * @param that the object (<code>null</code> not permitted). * * @return An integer. * * @throws ClassCastException if <code>obj</code> is not an instance of * {@link TimePeriod}. */ @Override public int compareTo(TimePeriod that) { long t0 = getStart().getTime(); long t1 = getEnd().getTime(); long m0 = t0 + (t1 - t0) / 2L; long t2 = that.getStart().getTime(); long t3 = that.getEnd().getTime(); long m1 = t2 + (t3 - t2) / 2L; if (m0 < m1) { return -1; } else if (m0 > m1) { return 1; } else { if (t0 < t2) { return -1; } else if (t0 > t2) { return 1; } else { if (t1 < t3) { return -1; } else if (t1 > t3) { return 1; } else { return 0; } } } } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here - see: * <p> * <code>http://developer.java.sun.com/ * developer/Books/effectivejava/Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + (int) this.start; result = 37 * result + (int) this.end; return result; } }
6,538
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesTableModel.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimeSeriesTableModel.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.] * * ------------------------- * TimeSeriesTableModel.java * ------------------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 14-Nov-2001 : Version 1 (DG); * 05-Apr-2002 : Removed redundant first column (DG); * 24-Jun-2002 : Removed unnecessary local variable (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */ package org.jfree.data.time; import javax.swing.table.AbstractTableModel; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesChangeListener; /** * Wrapper around a time series to convert it to a table model for use in * a <code>JTable</code>. */ public class TimeSeriesTableModel extends AbstractTableModel implements SeriesChangeListener { /** The series. */ private TimeSeries series; /** A flag that controls whether the series is editable. */ private boolean editable; /** The new time period. */ private RegularTimePeriod newTimePeriod; /** The new value. */ private Number newValue; /** * Default constructor. */ public TimeSeriesTableModel() { this(new TimeSeries("Untitled")); } /** * Constructs a table model for a time series. * * @param series the time series. */ public TimeSeriesTableModel(TimeSeries series) { this(series, false); } /** * Creates a table model based on a time series. * * @param series the time series. * @param editable if <ocde>true</code>, the table is editable. */ public TimeSeriesTableModel(TimeSeries series, boolean editable) { this.series = series; this.series.addChangeListener(this); this.editable = editable; } /** * Returns the number of columns in the table model. For this particular * model, the column count is fixed at 2. * * @return The column count. */ @Override public int getColumnCount() { return 2; } /** * Returns the column class in the table model. * * @param column The column index. * * @return The column class in the table model. */ @Override public Class getColumnClass(int column) { if (column == 0) { return String.class; } else { if (column == 1) { return Double.class; } else { return null; } } } /** * Returns the name of a column * * @param column the column index. * * @return The name of a column. */ @Override public String getColumnName(int column) { if (column == 0) { return "Period:"; } else { if (column == 1) { return "Value:"; } else { return null; } } } /** * Returns the number of rows in the table model. * * @return The row count. */ @Override public int getRowCount() { return this.series.getItemCount(); } /** * Returns the data value for a cell in the table model. * * @param row the row number. * @param column the column number. * * @return The data value for a cell in the table model. */ @Override public Object getValueAt(int row, int column) { if (row < this.series.getItemCount()) { if (column == 0) { return this.series.getTimePeriod(row); } else { if (column == 1) { return this.series.getValue(row); } else { return null; } } } else { if (column == 0) { return this.newTimePeriod; } else { if (column == 1) { return this.newValue; } else { return null; } } } } /** * Returns a flag indicating whether or not the specified cell is editable. * * @param row the row number. * @param column the column number. * * @return <code>true</code> if the specified cell is editable. */ @Override public boolean isCellEditable(int row, int column) { if (this.editable) { if ((column == 0) || (column == 1)) { return true; } else { return false; } } else { return false; } } /** * Updates the time series. * * @param value the new value. * @param row the row. * @param column the column. */ @Override public void setValueAt(Object value, int row, int column) { if (row < this.series.getItemCount()) { // update the time series appropriately if (column == 1) { try { Double v = Double.valueOf(value.toString()); this.series.update(row, v); } catch (NumberFormatException nfe) { System.err.println("Number format exception"); } } } else { if (column == 0) { // this.series.getClass().valueOf(value.toString()); this.newTimePeriod = null; } else if (column == 1) { this.newValue = Double.valueOf(value.toString()); } } } /** * Receives notification that the time series has been changed. Responds * by firing a table data change event. * * @param event the event. */ @Override public void seriesChanged(SeriesChangeEvent event) { fireTableDataChanged(); } }
7,320
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimeSeriesCollection.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.] * * ------------------------- * TimeSeriesCollection.java * ------------------------- * (C) Copyright 2001-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 18-Oct-2001 : Added implementation of IntervalXYDataSource so that bar plots * (using numerical axes) can be plotted from time series * data (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 15-Nov-2001 : Added getSeries() method. Changed name from TimeSeriesDataset * to TimeSeriesCollection (DG); * 07-Dec-2001 : TimeSeries --> BasicTimeSeries (DG); * 01-Mar-2002 : Added a time zone offset attribute, to enable fast calculation * of the time period start and end values (DG); * 29-Mar-2002 : The collection now registers itself with all the time series * objects as a SeriesChangeListener. Removed redundant * calculateZoneOffset method (DG); * 06-Jun-2002 : Added a setting to control whether the x-value supplied in the * getXValue() method comes from the START, MIDDLE, or END of the * time period. This is a workaround for JFreeChart, where the * current date axis always labels the start of a time * period (DG); * 24-Jun-2002 : Removed unnecessary import (DG); * 24-Aug-2002 : Implemented DomainInfo interface, and added the * DomainIsPointsInTime flag (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 16-Oct-2002 : Added remove methods (DG); * 10-Jan-2003 : Changed method names in RegularTimePeriod class (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package and implemented * Serializable (DG); * 04-Sep-2003 : Added getSeries(String) method (DG); * 15-Sep-2003 : Added a removeAllSeries() method to match * XYSeriesCollection (DG); * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 06-Oct-2004 : Updated for changed in DomainInfo interface (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * 28-Mar-2005 : Fixed bug in getSeries(int) method (1170825) (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 13-Dec-2005 : Deprecated the 'domainIsPointsInTime' flag as it is * redundant. Fixes bug 1243050 (DG); * 04-May-2007 : Override getDomainOrder() to indicate that items are sorted * by x-value (ascending) (DG); * 08-May-2007 : Added indexOf(TimeSeries) method (DG); * 18-Jan-2008 : Changed getSeries(String) to getSeries(Comparable) (DG); * 19-May-2009 : Implemented XYDomainInfo (DG); * 26-May-2009 : Implemented XYRangeInfo (DG); * 09-Jun-2009 : Apply some short-cuts to series value lookups (DG); * 26-Jun-2009 : Fixed clone() (DG); * 08-Jan-2012 : Fixed getRangeBounds() method (bug 3445507) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * 02-Jul-2013 : Use ParamChecks (DG); * 23-Feb-2014 : Improve implementation of getRangeBounds() (DG); * */ package org.jfree.data.time; import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.List; import java.util.TimeZone; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.data.DomainInfo; import org.jfree.data.DomainOrder; import org.jfree.data.Range; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.Series; import org.jfree.data.xy.AbstractIntervalXYDataset; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYDomainInfo; import org.jfree.data.xy.XYRangeInfo; /** * A collection of time series objects. This class implements the * {@link XYDataset} interface, as well as the extended * {@link IntervalXYDataset} interface. This makes it a convenient dataset for * use with the {@link org.jfree.chart.plot.XYPlot} class. */ public class TimeSeriesCollection extends AbstractIntervalXYDataset implements XYDataset, IntervalXYDataset, DomainInfo, XYDomainInfo, XYRangeInfo, VetoableChangeListener, Serializable { /** For serialization. */ private static final long serialVersionUID = 834149929022371137L; /** Storage for the time series. */ private List<TimeSeries> data; /** A working calendar (to recycle) */ private Calendar workingCalendar; /** * The point within each time period that is used for the X value when this * collection is used as an {@link org.jfree.data.xy.XYDataset}. This can * be the start, middle or end of the time period. */ private TimePeriodAnchor xPosition; /** * Constructs an empty dataset, tied to the default timezone. */ public TimeSeriesCollection() { this(null, TimeZone.getDefault()); } /** * Constructs an empty dataset, tied to a specific timezone. * * @param zone the timezone (<code>null</code> permitted, will use * <code>TimeZone.getDefault()</code> in that case). */ public TimeSeriesCollection(TimeZone zone) { // FIXME: need a locale as well as a timezone this(null, zone); } /** * Constructs a dataset containing a single series (more can be added), * tied to the default timezone. * * @param series the series (<code>null</code> permitted). */ public TimeSeriesCollection(TimeSeries series) { this(series, TimeZone.getDefault()); } /** * Constructs a dataset containing a single series (more can be added), * tied to a specific timezone. * * @param series a series to add to the collection (<code>null</code> * permitted). * @param zone the timezone (<code>null</code> permitted, will use * <code>TimeZone.getDefault()</code> in that case). */ public TimeSeriesCollection(TimeSeries series, TimeZone zone) { // FIXME: need a locale as well as a timezone if (zone == null) { zone = TimeZone.getDefault(); } this.workingCalendar = Calendar.getInstance(zone); this.data = new ArrayList<TimeSeries>(); if (series != null) { this.data.add(series); series.addChangeListener(this); } this.xPosition = TimePeriodAnchor.START; } /** * Returns the order of the domain values in this dataset. * * @return {@link DomainOrder#ASCENDING} */ @Override public DomainOrder getDomainOrder() { return DomainOrder.ASCENDING; } /** * Returns the position within each time period that is used for the X * value when the collection is used as an * {@link org.jfree.data.xy.XYDataset}. The default value is * <code>TimePeriodAnchor.START</code>. * * @return The anchor position (never <code>null</code>). */ public TimePeriodAnchor getXPosition() { return this.xPosition; } /** * Sets the position within each time period that is used for the X values * when the collection is used as an {@link XYDataset}, then sends a * {@link DatasetChangeEvent} is sent to all registered listeners. * * @param anchor the anchor position (<code>null</code> not permitted). */ public void setXPosition(TimePeriodAnchor anchor) { ParamChecks.nullNotPermitted(anchor, "anchor"); this.xPosition = anchor; notifyListeners(new DatasetChangeEvent(this, this)); } /** * Returns a list of all the series in the collection. * * @return The list (which is unmodifiable). */ public List<TimeSeries> getSeries() { return Collections.unmodifiableList(this.data); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns the index of the specified series, or -1 if that series is not * present in the dataset. * * @param series the series (<code>null</code> not permitted). * * @return The series index. * * @since 1.0.6 */ public int indexOf(TimeSeries series) { ParamChecks.nullNotPermitted(series, "series"); return this.data.indexOf(series); } /** * Returns a series. * * @param series the index of the series (zero-based). * * @return The series. */ public TimeSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException( "The 'series' argument is out of bounds (" + series + ")."); } return this.data.get(series); } /** * Returns the series with the specified key, or <code>null</code> if * there is no such series. * * @param key the series key (<code>null</code> permitted). * * @return The series with the given key. */ public TimeSeries getSeries(Comparable key) { TimeSeries result = null; for (TimeSeries series : this.data) { Comparable k = series.getKey(); if (k != null && k.equals(key)) { result = series; } } return result; } /** * Returns the key for a series. * * @param series the index of the series (zero-based). * * @return The key for a series. */ @Override public Comparable getSeriesKey(int series) { // check arguments...delegated // fetch the series name... return getSeries(series).getKey(); } /** * Returns the index of the series with the specified key, or -1 if no * series has that key. * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.17 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { TimeSeries series = (TimeSeries) this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} to * all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(TimeSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); series.addVetoableChangeListener(this); fireDatasetChanged(); } /** * Removes the specified series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void removeSeries(TimeSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.remove(series); series.removeChangeListener(this); series.removeVetoableChangeListener(this); fireDatasetChanged(); } /** * Removes a series from the collection. * * @param index the series index (zero-based). */ public void removeSeries(int index) { TimeSeries series = getSeries(index); if (series != null) { removeSeries(series); } } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. */ public void removeAllSeries() { // deregister the collection as a change listener to each series in the // collection for (TimeSeries series : this.data) { series.removeChangeListener(this); series.removeVetoableChangeListener(this); } // remove all the series from the collection and notify listeners. this.data.clear(); fireDatasetChanged(); } /** * Returns the number of items in the specified series. This method is * provided for convenience. * * @param series the series index (zero-based). * * @return The item count. */ @Override public int getItemCount(int series) { return getSeries(series).getItemCount(); } /** * Returns the x-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 x-value. */ @Override public double getXValue(int series, int item) { TimeSeries s = this.data.get(series); RegularTimePeriod period = s.getTimePeriod(item); return getX(period); } /** * Returns the x-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ @Override public Number getX(int series, int item) { TimeSeries ts = this.data.get(series); RegularTimePeriod period = ts.getTimePeriod(item); return getX(period); } /** * Returns the x-value for a time period. * * @param period the time period (<code>null</code> not permitted). * * @return The x-value. */ protected synchronized long getX(RegularTimePeriod period) { long result = 0L; if (this.xPosition == TimePeriodAnchor.START) { result = period.getFirstMillisecond(this.workingCalendar); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { result = period.getMiddleMillisecond(this.workingCalendar); } else if (this.xPosition == TimePeriodAnchor.END) { result = period.getLastMillisecond(this.workingCalendar); } return result; } /** * Returns the starting X value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value. */ @Override public synchronized Number getStartX(int series, int item) { TimeSeries ts = this.data.get(series); return ts.getTimePeriod(item).getFirstMillisecond( this.workingCalendar); } /** * Returns the ending X value for the specified series and item. * * @param series The series (zero-based index). * @param item The item (zero-based index). * * @return The value. */ @Override public synchronized Number getEndX(int series, int item) { TimeSeries ts = this.data.get(series); return ts.getTimePeriod(item).getLastMillisecond( this.workingCalendar); } /** * Returns the y-value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value (possibly <code>null</code>). */ @Override public Number getY(int series, int item) { TimeSeries ts = this.data.get(series); return ts.getValue(item); } /** * Returns the starting Y value for the specified series and item. * * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The value (possibly <code>null</code>). */ @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 te series (zero-based index). * @param item the item (zero-based index). * * @return The value (possibly <code>null</code>). */ @Override public Number getEndY(int series, int item) { return getY(series, item); } /** * Returns the indices of the two data items surrounding a particular * millisecond value. * * @param series the series index. * @param milliseconds the time. * * @return An array containing the (two) indices of the items surrounding * the time. */ public int[] getSurroundingItems(int series, long milliseconds) { int[] result = new int[] {-1, -1}; TimeSeries timeSeries = getSeries(series); for (int i = 0; i < timeSeries.getItemCount(); i++) { Number x = getX(series, i); long m = x.longValue(); if (m <= milliseconds) { result[0] = i; } if (m >= milliseconds) { result[1] = i; break; } } return result; } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getLowerBound(); } return result; } /** * 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) { double result = Double.NaN; Range r = getDomainBounds(includeInterval); if (r != null) { result = r.getUpperBound(); } return result; } /** * 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) { Range result = null; for (TimeSeries series : this.data) { int count = series.getItemCount(); if (count > 0) { RegularTimePeriod start = series.getTimePeriod(0); RegularTimePeriod end = series.getTimePeriod(count - 1); Range temp; if (!includeInterval) { temp = new Range(getX(start), getX(end)); } else { temp = new Range( start.getFirstMillisecond(this.workingCalendar), end.getLastMillisecond(this.workingCalendar)); } result = Range.combine(result, temp); } } return result; } /** * Returns the bounds of the domain values for the specified series. * * @param visibleSeriesKeys a list of keys for the visible series. * @param includeInterval include the x-interval? * * @return A range. * * @since 1.0.13 */ @Override public Range getDomainBounds(List<Comparable> visibleSeriesKeys, boolean includeInterval) { Range result = null; for (Comparable seriesKey : visibleSeriesKeys) { TimeSeries series = getSeries(seriesKey); int count = series.getItemCount(); if (count > 0) { RegularTimePeriod start = series.getTimePeriod(0); RegularTimePeriod end = series.getTimePeriod(count - 1); Range temp; if (!includeInterval) { temp = new Range(getX(start), getX(end)); } else { temp = new Range( start.getFirstMillisecond(this.workingCalendar), end.getLastMillisecond(this.workingCalendar)); } result = Range.combine(result, temp); } } return result; } /** * Returns the bounds for the y-values in the dataset. * * @param includeInterval ignored for this dataset. * * @return The range of value in the dataset (possibly <code>null</code>). * * @since 1.0.15 */ public Range getRangeBounds(boolean includeInterval) { Range result = null; for (TimeSeries series : this.data) { result = Range.combineIgnoringNaN(result, series.findValueRange()); } return result; } /** * Returns the bounds for the y-values in the dataset. * * @param visibleSeriesKeys the visible series keys. * @param xRange the x-range (<code>null</code> not permitted). * @param includeInterval ignored. * * @return The bounds. * * @since 1.0.14 */ @Override public Range getRangeBounds(List<Comparable> visibleSeriesKeys, Range xRange, boolean includeInterval) { Range result = null; for (Comparable seriesKey : visibleSeriesKeys) { TimeSeries series = getSeries(seriesKey); Range r = series.findValueRange(xRange, this.xPosition, this.workingCalendar.getTimeZone()); result = Range.combineIgnoringNaN(result, r); } return result; } /** * Receives notification that the key for one of the series in the * collection has changed, and vetos it if the key is already present in * the collection. * * @param e the event. * * @since 1.0.17 */ @Override public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException { // if it is not the series name, then we have no interest if (!"Key".equals(e.getPropertyName())) { return; } // to be defensive, let's check that the source series does in fact // belong to this collection Series s = (Series) e.getSource(); if (getSeriesIndex(s.getKey()) == -1) { throw new IllegalStateException("Receiving events from a series " + "that does not belong to this collection."); } // check if the new series name already exists for another series Comparable key = (Comparable) e.getNewValue(); if (getSeriesIndex(key) >= 0) { throw new PropertyVetoException("Duplicate key2", e); } } /** * Tests this time series collection for equality with another object. * * @param obj the other object. * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof TimeSeriesCollection)) { return false; } TimeSeriesCollection that = (TimeSeriesCollection) obj; if (this.xPosition != that.xPosition) { return false; } if (!ObjectUtilities.equal(this.data, that.data)) { return false; } return true; } /** * Returns a hash code value for the object. * * @return The hashcode */ @Override public int hashCode() { int result; result = this.data.hashCode(); result = 29 * result + (this.workingCalendar != null ? this.workingCalendar.hashCode() : 0); result = 29 * result + (this.xPosition != null ? this.xPosition.hashCode() : 0); return result; } /** * Returns a clone of this time series collection. * * @return A clone. * * @throws java.lang.CloneNotSupportedException */ @Override public Object clone() throws CloneNotSupportedException { TimeSeriesCollection clone = (TimeSeriesCollection) super.clone(); clone.data = ObjectUtilities.deepClone(this.data); clone.workingCalendar = (Calendar) this.workingCalendar.clone(); return clone; } }
26,036
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodAnchor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/TimePeriodAnchor.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.] * * --------------------- * TimePeriodAnchor.java * --------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 30-Jul-2003 : Version 1 (DG); * 01-Mar-2004 : Added readResolve() method (DG); * */ package org.jfree.data.time; /** * Used to indicate one of three positions in a time period: * <code>START</code>, <code>MIDDLE</code> and <code>END</code>. */ public enum TimePeriodAnchor { /** Start of period. */ START("TimePeriodAnchor.START"), /** Middle of period. */ MIDDLE("TimePeriodAnchor.MIDDLE"), /** End of period. */ END("TimePeriodAnchor.END"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private TimePeriodAnchor(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,340
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Year.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Year.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.] * * --------- * Year.java * --------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 14-Nov-2001 : Override for toString() method (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 29-Jan-2002 : Worked on parseYear() method (DG); * 14-Feb-2002 : Fixed bug in Year(Date) constructor (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 19-Mar-2002 : Changed API for TimePeriod classes (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 05-Mar-2003 : Fixed bug in getFirstMillisecond() picked up in JUnit * tests (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 16-Sep-2008 : Extended range of valid years, and deprecated * DEFAULT_TIME_ZONE (DG); * 25-Nov-2008 : Added new constructor with Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Represents a year in the range -9999 to 9999. This class is immutable, * which is a requirement for all {@link RegularTimePeriod} subclasses. */ public class Year extends RegularTimePeriod implements Serializable { /** * The minimum year value. * * @since 1.0.11 */ public static final int MINIMUM_YEAR = -9999; /** * The maximum year value. * * @since 1.0.11 */ public static final int MAXIMUM_YEAR = 9999; /** For serialization. */ private static final long serialVersionUID = -7659990929736074836L; /** The year. */ private short year; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Creates a new <code>Year</code>, based on the current system date/time. */ public Year() { this(new Date()); } /** * Creates a time period representing a single year. * * @param year the year. */ public Year(int year) { if ((year < Year.MINIMUM_YEAR) || (year > Year.MAXIMUM_YEAR)) { throw new IllegalArgumentException( "Year constructor: year (" + year + ") outside valid range."); } this.year = (short) year; peg(Calendar.getInstance()); } /** * Creates a new <code>Year</code>, based on a particular instant in time, * using the default time zone. * * @param time the time (<code>null</code> not permitted). * * @see #Year(Date, TimeZone) */ public Year(Date time) { this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a new <code>Year</code> instance, for the specified time zone * and locale. * * @param time the current time (<code>null</code> not permitted). * @param zone the time zone. * @param locale the locale. * * @since 1.0.12 */ public Year(Date time, TimeZone zone, Locale locale) { Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); this.year = (short) calendar.get(Calendar.YEAR); peg(calendar); } /** * Returns the year. * * @return The year. */ public int getYear() { return this.year; } /** * Returns the first millisecond of the year. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the year. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the year. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the year. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the year preceding this one. * * @return The year preceding this one (or <code>null</code> if the * current year is -9999). */ @Override public RegularTimePeriod previous() { if (this.year > Year.MINIMUM_YEAR) { return new Year(this.year - 1); } return null; } /** * Returns the year following this one. * * @return The year following this one (or <code>null</code> if the current * year is 9999). */ @Override public RegularTimePeriod next() { if (this.year < Year.MAXIMUM_YEAR) { return new Year(this.year + 1); } else { return null; } } /** * Returns a serial index number for the year. * <P> * The implementation simply returns the year number (e.g. 2002). * * @return The serial index number. */ @Override public long getSerialIndex() { return this.year; } /** * Returns the first millisecond of the year, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the year. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { calendar.set(this.year, Calendar.JANUARY, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the year, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the year. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { calendar.set(this.year, Calendar.DECEMBER, 31, 23, 59, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTimeInMillis(); } /** * Tests the equality of this <code>Year</code> object to an arbitrary * object. Returns <code>true</code> if the target is a <code>Year</code> * instance representing the same year as this object. In all other cases, * returns <code>false</code>. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> if the year of this and the object are the * same. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Year)) { return false; } Year that = (Year) obj; return (this.year == that.year); } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; int c = this.year; result = 37 * result + c; return result; } /** * Returns an integer indicating the order of this <code>Year</code> object * relative to the specified object: * * negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Year object // ----------------------------------------- if (o1 instanceof Year) { Year y = (Year) o1; result = this.year - y.getYear(); } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Returns a string representing the year.. * * @return A string representing the year. */ @Override public String toString() { return Integer.toString(this.year); } /** * Parses the string argument as a year. * <P> * The string format is YYYY. * * @param s a string representing the year. * * @return <code>null</code> if the string is not parseable, the year * otherwise. */ public static Year parseYear(String s) { // parse the string... int y; try { y = Integer.parseInt(s.trim()); } catch (NumberFormatException e) { throw new TimePeriodFormatException("Cannot parse string."); } // create the year... try { return new Year(y); } catch (IllegalArgumentException e) { throw new TimePeriodFormatException("Year outside valid range."); } } }
11,930
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Week.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Week.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.] * * --------- * Week.java * --------- * (C) Copyright 2001-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Aimin Han; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 18-Dec-2001 : Changed order of parameters in constructor (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 29-Jan-2002 : Worked on the parseWeek() method (DG); * 13-Feb-2002 : Fixed bug in Week(Date) constructor (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 05-Apr-2002 : Reinstated this class to the JCommon library (DG); * 24-Jun-2002 : Removed unnecessary main method (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 06-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 18-Oct-2002 : Changed to observe 52 or 53 weeks per year, consistent with * GregorianCalendar. Thanks to Aimin Han for the code (DG); * 02-Jan-2003 : Removed debug code (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method (DG); * 24-May-2004 : Modified getFirstMillisecond() and getLastMillisecond() to * take account of firstDayOfWeek setting in Java's Calendar * class (DG); * 30-Sep-2004 : Replaced getTime().getTime() with getTimeInMillis() (DG); * 04-Nov-2004 : Reverted change of 30-Sep-2004, because it won't work for * JDK 1.3 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Mar-2006 : Fix for bug 1448828, incorrect calculation of week and year * for the first few days of some years (DG); * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 09-Jan-2007 : Fixed bug in next() (DG); * 28-Aug-2007 : Added new constructor to avoid problem in creating new * instances (DG); * 19-Dec-2007 : Fixed bug in deprecated constructor (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * A calendar week. All years are considered to have 53 weeks, numbered from 1 * to 53, although in many cases the 53rd week is empty. Most of the time, the * 1st week of the year *begins* in the previous calendar year, but it always * finishes in the current year (this behaviour matches the workings of the * <code>GregorianCalendar</code> class). * <P> * This class is immutable, which is a requirement for all * {@link RegularTimePeriod} subclasses. */ public class Week extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = 1856387786939865061L; /** Constant for the first week in the year. */ public static final int FIRST_WEEK_IN_YEAR = 1; /** Constant for the last week in the year. */ public static final int LAST_WEEK_IN_YEAR = 53; /** The year in which the week falls. */ private short year; /** The week (1-53). */ private byte week; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Creates a new time period for the week in which the current system * date/time falls. */ public Week() { this(new Date()); } /** * Creates a time period representing the week in the specified year. * * @param week the week (1 to 53). * @param year the year (1900 to 9999). */ public Week(int week, int year) { if ((week < FIRST_WEEK_IN_YEAR) && (week > LAST_WEEK_IN_YEAR)) { throw new IllegalArgumentException( "The 'week' argument must be in the range 1 - 53."); } this.week = (byte) week; this.year = (short) year; peg(Calendar.getInstance()); } /** * Creates a time period representing the week in the specified year. * * @param week the week (1 to 53). * @param year the year (1900 to 9999). */ public Week(int week, Year year) { if ((week < FIRST_WEEK_IN_YEAR) && (week > LAST_WEEK_IN_YEAR)) { throw new IllegalArgumentException( "The 'week' argument must be in the range 1 - 53."); } this.week = (byte) week; this.year = (short) year.getYear(); peg(Calendar.getInstance()); } /** * Creates a time period for the week in which the specified date/time * falls, using the default time zone and locale (the locale can affect the * day-of-the-week that marks the beginning of the week, as well as the * minimal number of days in the first week of the year). * * @param time the time (<code>null</code> not permitted). * * @see #Week(Date, TimeZone, Locale) */ public Week(Date time) { // defer argument checking... this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Creates a time period for the week in which the specified date/time * falls, calculated relative to the specified time zone. * * @param time the date/time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.7 */ public Week(Date time, TimeZone zone, Locale locale) { if (time == null) { throw new IllegalArgumentException("Null 'time' argument."); } if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } if (locale == null) { throw new IllegalArgumentException("Null 'locale' argument."); } Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); // sometimes the last few days of the year are considered to fall in // the *first* week of the following year. Refer to the Javadocs for // GregorianCalendar. int tempWeek = calendar.get(Calendar.WEEK_OF_YEAR); if (tempWeek == 1 && calendar.get(Calendar.MONTH) == Calendar.DECEMBER) { this.week = 1; this.year = (short) (calendar.get(Calendar.YEAR) + 1); } else { this.week = (byte) Math.min(tempWeek, LAST_WEEK_IN_YEAR); int yyyy = calendar.get(Calendar.YEAR); // alternatively, sometimes the first few days of the year are // considered to fall in the *last* week of the previous year... if (calendar.get(Calendar.MONTH) == Calendar.JANUARY && this.week >= 52) { yyyy--; } this.year = (short) yyyy; } peg(calendar); } /** * Returns the year in which the week falls. * * @return The year (never <code>null</code>). */ public Year getYear() { return new Year(this.year); } /** * Returns the year in which the week falls, as an integer value. * * @return The year. */ public int getYearValue() { return this.year; } /** * Returns the week. * * @return The week. */ public int getWeek() { return this.week; } /** * Returns the first millisecond of the week. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the week. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the week. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the week. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the week preceding this one. This method will return * <code>null</code> for some lower limit on the range of weeks (currently * week 1, 1900). For week 1 of any year, the previous week is always week * 53, but week 53 may not contain any days (you should check for this). * * @return The preceding week (possibly <code>null</code>). */ @Override public RegularTimePeriod previous() { Week result; if (this.week != FIRST_WEEK_IN_YEAR) { result = new Week(this.week - 1, this.year); } else { // we need to work out if the previous year has 52 or 53 weeks... if (this.year > 1900) { int yy = this.year - 1; Calendar prevYearCalendar = Calendar.getInstance(); prevYearCalendar.set(yy, Calendar.DECEMBER, 31); result = new Week(prevYearCalendar.getActualMaximum( Calendar.WEEK_OF_YEAR), yy); } else { result = null; } } return result; } /** * Returns the week following this one. This method will return * <code>null</code> for some upper limit on the range of weeks (currently * week 53, 9999). For week 52 of any year, the following week is always * week 53, but week 53 may not contain any days (you should check for * this). * * @return The following week (possibly <code>null</code>). */ @Override public RegularTimePeriod next() { Week result; if (this.week < 52) { result = new Week(this.week + 1, this.year); } else { Calendar calendar = Calendar.getInstance(); calendar.set(this.year, Calendar.DECEMBER, 31); int actualMaxWeek = calendar.getActualMaximum(Calendar.WEEK_OF_YEAR); if (this.week < actualMaxWeek) { result = new Week(this.week + 1, this.year); } else { if (this.year < 9999) { result = new Week(FIRST_WEEK_IN_YEAR, this.year + 1); } else { result = null; } } } return result; } /** * Returns a serial index number for the week. * * @return The serial index number. */ @Override public long getSerialIndex() { return this.year * 53L + this.week; } /** * Returns the first millisecond of the week, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The first millisecond of the week. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { Calendar c = (Calendar) calendar.clone(); c.clear(); c.set(Calendar.YEAR, this.year); c.set(Calendar.WEEK_OF_YEAR, this.week); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis(); } /** * Returns the last millisecond of the week, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the week. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { Calendar c = (Calendar) calendar.clone(); c.clear(); c.set(Calendar.YEAR, this.year); c.set(Calendar.WEEK_OF_YEAR, this.week + 1); c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTimeInMillis() - 1; } /** * Returns a string representing the week (e.g. "Week 9, 2002"). * * TODO: look at internationalisation. * * @return A string representing the week. */ @Override public String toString() { return "Week " + this.week + ", " + this.year; } /** * Tests the equality of this Week object to an arbitrary object. Returns * true if the target is a Week instance representing the same week as this * object. In all other cases, returns false. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> if week and year of this and object are the * same. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Week)) { return false; } Week that = (Week) obj; if (this.week != that.week) { return false; } if (this.year != that.year) { return false; } return true; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.week; result = 37 * result + this.year; return result; } /** * Returns an integer indicating the order of this Week object relative to * the specified object: * * negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Week object // -------------------------------------------- if (o1 instanceof Week) { Week w = (Week) o1; result = this.year - w.getYear().getYear(); if (result == 0) { result = this.week - w.getWeek(); } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Parses the string argument as a week. * <P> * This method is required to accept the format "YYYY-Wnn". It will also * accept "Wnn-YYYY". Anything else, at the moment, is a bonus. * * @param s string to parse. * * @return <code>null</code> if the string is not parseable, the week * otherwise. */ public static Week parseWeek(String s) { Week result = null; if (s != null) { // trim whitespace from either end of the string s = s.trim(); int i = Week.findSeparator(s); if (i != -1) { String s1 = s.substring(0, i).trim(); String s2 = s.substring(i + 1, s.length()).trim(); Year y = Week.evaluateAsYear(s1); int w; if (y != null) { w = Week.stringToWeek(s2); if (w == -1) { throw new TimePeriodFormatException( "Can't evaluate the week."); } result = new Week(w, y); } else { y = Week.evaluateAsYear(s2); if (y != null) { w = Week.stringToWeek(s1); if (w == -1) { throw new TimePeriodFormatException( "Can't evaluate the week."); } result = new Week(w, y); } else { throw new TimePeriodFormatException( "Can't evaluate the year."); } } } else { throw new TimePeriodFormatException( "Could not find separator."); } } return result; } /** * Finds the first occurrence of ' ', '-', ',' or '.' * * @param s the string to parse. * * @return <code>-1</code> if none of the characters was found, the * index of the first occurrence otherwise. */ private static int findSeparator(String s) { int result = s.indexOf('-'); if (result == -1) { result = s.indexOf(','); } if (result == -1) { result = s.indexOf(' '); } if (result == -1) { result = s.indexOf('.'); } return result; } /** * Creates a year from a string, or returns null (format exceptions * suppressed). * * @param s string to parse. * * @return <code>null</code> if the string is not parseable, the year * otherwise. */ private static Year evaluateAsYear(String s) { Year result = null; try { result = Year.parseYear(s); } catch (TimePeriodFormatException e) { // suppress } return result; } /** * Converts a string to a week. * * @param s the string to parse. * @return <code>-1</code> if the string does not contain a week number, * the number of the week otherwise. */ private static int stringToWeek(String s) { int result = -1; s = s.replace('W', ' '); s = s.trim(); try { result = Integer.parseInt(s); if ((result < 1) || (result > LAST_WEEK_IN_YEAR)) { result = -1; } } catch (NumberFormatException e) { // suppress } return result; } }
20,792
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DynamicTimeSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/DynamicTimeSeriesCollection.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.] * * -------------------------------- * DynamicTimeSeriesCollection.java * -------------------------------- * (C) Copyright 2002-2008, by I. H. Thomae and Contributors. * * Original Author: I. H. Thomae ([email protected]); * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 22-Nov-2002 : Initial version completed * Jan 2003 : Optimized advanceTime(), added implemnt'n of RangeInfo intfc * (using cached values for min, max, and range); also added * getOldestIndex() and getNewestIndex() ftns so client classes * can use this class as the master "index authority". * 22-Jan-2003 : Made this class stand on its own, rather than extending * class FastTimeSeriesCollection * 31-Jan-2003 : Changed TimePeriod --> RegularTimePeriod (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package (DG); * 29-Apr-2003 : Added small change to appendData method, from Irv Thomae (DG); * 19-Sep-2003 : Added new appendData method, from Irv Thomae (DG); * 05-May-2004 : Now extends AbstractIntervalXYDataset. This also required a * change to the return type of the getY() method - I'm slightly * unsure of the implications of this, so it might require some * further amendment (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 11-Jan-2004 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */ package org.jfree.data.time; import java.util.Calendar; import java.util.TimeZone; import org.jfree.data.DomainInfo; import org.jfree.data.Range; import org.jfree.data.RangeInfo; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.xy.AbstractIntervalXYDataset; import org.jfree.data.xy.IntervalXYDataset; /** * A dynamic dataset. * <p> * Like FastTimeSeriesCollection, this class is a functional replacement * for JFreeChart's TimeSeriesCollection _and_ TimeSeries classes. * FastTimeSeriesCollection is appropriate for a fixed time range; for * real-time applications this subclass adds the ability to append new * data and discard the oldest. * In this class, the arrays used in FastTimeSeriesCollection become FIFO's. * NOTE:As presented here, all data is assumed >= 0, an assumption which is * embodied only in methods associated with interface RangeInfo. */ public class DynamicTimeSeriesCollection extends AbstractIntervalXYDataset implements IntervalXYDataset, DomainInfo, RangeInfo { /** * Useful constant for controlling the x-value returned for a time * period. */ public static final int START = 0; /** * Useful constant for controlling the x-value returned for a time period. */ public static final int MIDDLE = 1; /** * Useful constant for controlling the x-value returned for a time period. */ public static final int END = 2; /** The maximum number of items for each series (can be overridden). */ private int maximumItemCount = 2000; // an arbitrary safe default value /** The history count. */ protected int historyCount; /** Storage for the series keys. */ private Comparable[] seriesKeys; /** The time period class - barely used, and could be removed (DG). */ private Class timePeriodClass = Minute.class; // default value; /** Storage for the x-values. */ protected RegularTimePeriod[] pointsInTime; /** The number of series. */ private int seriesCount; /** * A wrapper for a fixed array of float values. */ protected class ValueSequence { /** Storage for the float values. */ float[] dataPoints; /** * Default constructor: */ public ValueSequence() { this(DynamicTimeSeriesCollection.this.maximumItemCount); } /** * Creates a sequence with the specified length. * * @param length the length. */ public ValueSequence(int length) { this.dataPoints = new float[length]; for (int i = 0; i < length; i++) { this.dataPoints[i] = 0.0f; } } /** * Enters data into the storage array. * * @param index the index. * @param value the value. */ public void enterData(int index, float value) { this.dataPoints[index] = value; } /** * Returns a value from the storage array. * * @param index the index. * * @return The value. */ public float getData(int index) { return this.dataPoints[index]; } } /** An array for storing the objects that represent each series. */ protected ValueSequence[] valueHistory; /** A working calendar (to recycle) */ protected Calendar workingCalendar; /** * The position within a time period to return as the x-value (START, * MIDDLE or END). */ private int position; /** * A flag that indicates that the domain is 'points in time'. If this flag * is true, only the x-value is used to determine the range of values in * the domain, the start and end x-values are ignored. */ private boolean domainIsPointsInTime; /** index for mapping: points to the oldest valid time & data. */ private int oldestAt; // as a class variable, initializes == 0 /** Index of the newest data item. */ private int newestAt; // cached values used for interface DomainInfo: /** the # of msec by which time advances. */ private long deltaTime; /** Cached domain start (for use by DomainInfo). */ private Long domainStart; /** Cached domain end (for use by DomainInfo). */ private Long domainEnd; /** Cached domain range (for use by DomainInfo). */ private Range domainRange; // Cached values used for interface RangeInfo: (note minValue pinned at 0) // A single set of extrema covers the entire SeriesCollection /** The minimum value. */ private Float minValue = 0.0f; /** The maximum value. */ private Float maxValue = null; /** The value range. */ private Range valueRange; // autoinit's to null. /** * Constructs a dataset with capacity for N series, tied to default * timezone. * * @param nSeries the number of series to be accommodated. * @param nMoments the number of TimePeriods to be spanned. */ public DynamicTimeSeriesCollection(int nSeries, int nMoments) { this(nSeries, nMoments, new Millisecond(), TimeZone.getDefault()); this.newestAt = nMoments - 1; } /** * Constructs an empty dataset, tied to a specific timezone. * * @param nSeries the number of series to be accommodated * @param nMoments the number of TimePeriods to be spanned * @param zone the timezone. */ public DynamicTimeSeriesCollection(int nSeries, int nMoments, TimeZone zone) { this(nSeries, nMoments, new Millisecond(), zone); this.newestAt = nMoments - 1; } /** * Creates a new dataset. * * @param nSeries the number of series. * @param nMoments the number of items per series. * @param timeSample a time period sample. */ public DynamicTimeSeriesCollection(int nSeries, int nMoments, RegularTimePeriod timeSample) { this(nSeries, nMoments, timeSample, TimeZone.getDefault()); } /** * Creates a new dataset. * * @param nSeries the number of series. * @param nMoments the number of items per series. * @param timeSample a time period sample. * @param zone the time zone. */ public DynamicTimeSeriesCollection(int nSeries, int nMoments, RegularTimePeriod timeSample, TimeZone zone) { // the first initialization must precede creation of the ValueSet array: this.maximumItemCount = nMoments; // establishes length of each array this.historyCount = nMoments; this.seriesKeys = new Comparable[nSeries]; // initialize the members of "seriesNames" array so they won't be null: for (int i = 0; i < nSeries; i++) { this.seriesKeys[i] = ""; } this.newestAt = nMoments - 1; this.valueHistory = new ValueSequence[nSeries]; this.timePeriodClass = timeSample.getClass(); /// Expand the following for all defined TimePeriods: if (this.timePeriodClass == Second.class) { this.pointsInTime = new Second[nMoments]; } else if (this.timePeriodClass == Minute.class) { this.pointsInTime = new Minute[nMoments]; } else if (this.timePeriodClass == Hour.class) { this.pointsInTime = new Hour[nMoments]; } /// .. etc.... this.workingCalendar = Calendar.getInstance(zone); this.position = START; this.domainIsPointsInTime = true; } /** * Fill the pointsInTime with times using TimePeriod.next(): * Will silently return if the time array was already populated. * * Also computes the data cached for later use by * methods implementing the DomainInfo interface: * * @param start the start. * * @return ??. */ public synchronized long setTimeBase(RegularTimePeriod start) { if (this.pointsInTime[0] == null) { this.pointsInTime[0] = start; for (int i = 1; i < this.historyCount; i++) { this.pointsInTime[i] = this.pointsInTime[i - 1].next(); } } long oldestL = this.pointsInTime[0].getFirstMillisecond( this.workingCalendar ); long nextL = this.pointsInTime[1].getFirstMillisecond( this.workingCalendar ); this.deltaTime = nextL - oldestL; this.oldestAt = 0; this.newestAt = this.historyCount - 1; findDomainLimits(); return this.deltaTime; } /** * Finds the domain limits. Note: this doesn't need to be synchronized * because it's called from within another method that already is. */ protected void findDomainLimits() { long startL = getOldestTime().getFirstMillisecond(this.workingCalendar); long endL; if (this.domainIsPointsInTime) { endL = getNewestTime().getFirstMillisecond(this.workingCalendar); } else { endL = getNewestTime().getLastMillisecond(this.workingCalendar); } this.domainStart = startL; this.domainEnd = endL; this.domainRange = new Range(startL, endL); } /** * Returns the x position type (START, MIDDLE or END). * * @return The x position type. */ public int getPosition() { return this.position; } /** * Sets the x position type (START, MIDDLE or END). * * @param position The x position type. */ public void setPosition(int position) { this.position = position; } /** * Adds a series to the dataset. Only the y-values are supplied, the * x-values are specified elsewhere. * * @param values the y-values. * @param seriesNumber the series index (zero-based). * @param seriesKey the series key. * * Use this as-is during setup only, or add the synchronized keyword around * the copy loop. */ public void addSeries(float[] values, int seriesNumber, Comparable seriesKey) { invalidateRangeInfo(); int i; if (values == null) { throw new IllegalArgumentException("TimeSeriesDataset.addSeries(): " + "cannot add null array of values."); } if (seriesNumber >= this.valueHistory.length) { throw new IllegalArgumentException("TimeSeriesDataset.addSeries(): " + "cannot add more series than specified in c'tor"); } if (this.valueHistory[seriesNumber] == null) { this.valueHistory[seriesNumber] = new ValueSequence(this.historyCount); this.seriesCount++; } // But if that series array already exists, just overwrite its contents // Avoid IndexOutOfBoundsException: int srcLength = values.length; int copyLength = this.historyCount; boolean fillNeeded = false; if (srcLength < this.historyCount) { fillNeeded = true; copyLength = srcLength; } //{ for (i = 0; i < copyLength; i++) { // deep copy from values[], caller // can safely discard that array this.valueHistory[seriesNumber].enterData(i, values[i]); } if (fillNeeded) { for (i = copyLength; i < this.historyCount; i++) { this.valueHistory[seriesNumber].enterData(i, 0.0f); } } //} if (seriesKey != null) { this.seriesKeys[seriesNumber] = seriesKey; } fireSeriesChanged(); } /** * Sets the name of a series. If planning to add values individually. * * @param seriesNumber the series. * @param key the new key. */ public void setSeriesKey(int seriesNumber, Comparable key) { this.seriesKeys[seriesNumber] = key; } /** * Adds a value to a series. * * @param seriesNumber the series index. * @param index ??. * @param value the value. */ public void addValue(int seriesNumber, int index, float value) { invalidateRangeInfo(); if (seriesNumber >= this.valueHistory.length) { throw new IllegalArgumentException( "TimeSeriesDataset.addValue(): series #" + seriesNumber + "unspecified in c'tor" ); } if (this.valueHistory[seriesNumber] == null) { this.valueHistory[seriesNumber] = new ValueSequence(this.historyCount); this.seriesCount++; } // But if that series array already exists, just overwrite its contents //synchronized(this) //{ this.valueHistory[seriesNumber].enterData(index, value); //} fireSeriesChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.seriesCount; } /** * Returns the number of items in a series. * <p> * For this implementation, all series have the same number of items. * * @param series the series index (zero-based). * * @return The item count. */ @Override public int getItemCount(int series) { // all arrays equal length, // so ignore argument: return this.historyCount; } // Methods for managing the FIFO's: /** * Re-map an index, for use in retrieving data. * * @param toFetch the index. * * @return The translated index. */ protected int translateGet(int toFetch) { if (this.oldestAt == 0) { return toFetch; // no translation needed } // else [implicit here] int newIndex = toFetch + this.oldestAt; if (newIndex >= this.historyCount) { newIndex -= this.historyCount; } return newIndex; } /** * Returns the actual index to a time offset by "delta" from newestAt. * * @param delta the delta. * * @return The offset. */ public int offsetFromNewest(int delta) { return wrapOffset(this.newestAt + delta); } /** * ?? * * @param delta ?? * * @return The offset. */ public int offsetFromOldest(int delta) { return wrapOffset(this.oldestAt + delta); } /** * ?? * * @param protoIndex the index. * * @return The offset. */ protected int wrapOffset(int protoIndex) { int tmp = protoIndex; if (tmp >= this.historyCount) { tmp -= this.historyCount; } else if (tmp < 0) { tmp += this.historyCount; } return tmp; } /** * Adjust the array offset as needed when a new time-period is added: * Increments the indices "oldestAt" and "newestAt", mod(array length), * zeroes the series values at newestAt, returns the new TimePeriod. * * @return The new time period. */ public synchronized RegularTimePeriod advanceTime() { RegularTimePeriod nextInstant = this.pointsInTime[this.newestAt].next(); this.newestAt = this.oldestAt; // newestAt takes value previously held // by oldestAT /*** * The next 10 lines or so should be expanded if data can be negative ***/ // if the oldest data contained a maximum Y-value, invalidate the stored // Y-max and Y-range data: boolean extremaChanged = false; float oldMax = 0.0f; if (this.maxValue != null) { oldMax = this.maxValue; } for (int s = 0; s < getSeriesCount(); s++) { if (this.valueHistory[s].getData(this.oldestAt) == oldMax) { extremaChanged = true; } if (extremaChanged) { break; } } /*** If data can be < 0, add code here to check the minimum **/ if (extremaChanged) { invalidateRangeInfo(); } // wipe the next (about to be used) set of data slots float wiper = (float) 0.0; for (int s = 0; s < getSeriesCount(); s++) { this.valueHistory[s].enterData(this.newestAt, wiper); } // Update the array of TimePeriods: this.pointsInTime[this.newestAt] = nextInstant; // Now advance "oldestAt", wrapping at end of the array this.oldestAt++; if (this.oldestAt >= this.historyCount) { this.oldestAt = 0; } // Update the domain limits: long startL = this.domainStart; //(time is kept in msec) this.domainStart = startL + this.deltaTime; long endL = this.domainEnd; this.domainEnd = endL + this.deltaTime; this.domainRange = new Range(startL, endL); fireSeriesChanged(); return nextInstant; } // If data can be < 0, the next 2 methods should be modified /** * Invalidates the range info. */ public void invalidateRangeInfo() { this.maxValue = null; this.valueRange = null; } /** * Returns the maximum value. * * @return The maximum value. */ protected double findMaxValue() { double max = 0.0f; for (int s = 0; s < getSeriesCount(); s++) { for (int i = 0; i < this.historyCount; i++) { double tmp = getYValue(s, i); if (tmp > max) { max = tmp; } } } return max; } /** End, positive-data-only code **/ /** * Returns the index of the oldest data item. * * @return The index. */ public int getOldestIndex() { return this.oldestAt; } /** * Returns the index of the newest data item. * * @return The index. */ public int getNewestIndex() { return this.newestAt; } // appendData() writes new data at the index position given by newestAt/ // When adding new data dynamically, use advanceTime(), followed by this: /** * Appends new data. * * @param newData the data. */ public void appendData(float[] newData) { int nDataPoints = newData.length; if (nDataPoints > this.valueHistory.length) { throw new IllegalArgumentException( "More data than series to put them in" ); } int s; // index to select the "series" for (s = 0; s < nDataPoints; s++) { // check whether the "valueHistory" array member exists; if not, // create them: if (this.valueHistory[s] == null) { this.valueHistory[s] = new ValueSequence(this.historyCount); } this.valueHistory[s].enterData(this.newestAt, newData[s]); } fireSeriesChanged(); } /** * Appends data at specified index, for loading up with data from file(s). * * @param newData the data * @param insertionIndex the index value at which to put it * @param refresh value of n in "refresh the display on every nth call" * (ignored if <= 0 ) */ public void appendData(float[] newData, int insertionIndex, int refresh) { int nDataPoints = newData.length; if (nDataPoints > this.valueHistory.length) { throw new IllegalArgumentException( "More data than series to put them " + "in" ); } for (int s = 0; s < nDataPoints; s++) { if (this.valueHistory[s] == null) { this.valueHistory[s] = new ValueSequence(this.historyCount); } this.valueHistory[s].enterData(insertionIndex, newData[s]); } if (refresh > 0) { insertionIndex++; if (insertionIndex % refresh == 0) { fireSeriesChanged(); } } } /** * Returns the newest time. * * @return The newest time. */ public RegularTimePeriod getNewestTime() { return this.pointsInTime[this.newestAt]; } /** * Returns the oldest time. * * @return The oldest time. */ public RegularTimePeriod getOldestTime() { return this.pointsInTime[this.oldestAt]; } /** * Returns the x-value. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ // getXxx() ftns can ignore the "series" argument: // Don't synchronize this!! Instead, synchronize the loop that calls it. @Override public Number getX(int series, int item) { RegularTimePeriod tp = this.pointsInTime[translateGet(item)]; return getX(tp); } /** * Returns the y-value. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public double getYValue(int series, int item) { // Don't synchronize this!! // Instead, synchronize the loop that calls it. ValueSequence values = this.valueHistory[series]; return values.getData(translateGet(item)); } /** * Returns the y-value. * * @param series the series index (zero-based). * @param item the item index (zero-based). * * @return The value. */ @Override public Number getY(int series, int item) { return new Float(getYValue(series, item)); } /** * Returns the start x-value. * * @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) { RegularTimePeriod tp = this.pointsInTime[translateGet(item)]; return tp.getFirstMillisecond(this.workingCalendar); } /** * Returns the end x-value. * * @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) { RegularTimePeriod tp = this.pointsInTime[translateGet(item)]; return tp.getLastMillisecond(this.workingCalendar); } /** * Returns the start y-value. * * @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 getY(series, item); } /** * Returns the end y-value. * * @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 getY(series, item); } /* // "Extras" found useful when analyzing/verifying class behavior: public Number getUntranslatedXValue(int series, int item) { return super.getXValue(series, item); } public float getUntranslatedY(int series, int item) { return super.getY(series, item); } */ /** * Returns the key for a series. * * @param series the series index (zero-based). * * @return The key. */ @Override public Comparable getSeriesKey(int series) { return this.seriesKeys[series]; } /** * Sends a {@link SeriesChangeEvent} to all registered listeners. */ protected void fireSeriesChanged() { seriesChanged(new SeriesChangeEvent(this)); } // The next 3 functions override the base-class implementation of // the DomainInfo interface. Using saved limits (updated by // each updateTime() call), improves performance. // /** * 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.domainStart.doubleValue(); // a Long kept updated by advanceTime() } /** * 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.domainEnd.doubleValue(); // a Long kept updated by advanceTime() } /** * 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 (this.domainRange == null) { findDomainLimits(); } return this.domainRange; } /** * Returns the x-value for a time period. * * @param period the period. * * @return The x-value. */ private long getX(RegularTimePeriod period) { switch (this.position) { case (START) : return period.getFirstMillisecond(this.workingCalendar); case (MIDDLE) : return period.getMiddleMillisecond(this.workingCalendar); case (END) : return period.getLastMillisecond(this.workingCalendar); default: return period.getMiddleMillisecond(this.workingCalendar); } } // The next 3 functions implement the RangeInfo interface. // Using saved limits (updated by each updateTime() call) significantly // improves performance. WARNING: this code makes the simplifying // assumption that data is never negative. Expand as needed for the // general case. /** * Returns the minimum range value. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The minimum range value. */ @Override public double getRangeLowerBound(boolean includeInterval) { double result = Double.NaN; if (this.minValue != null) { result = this.minValue.doubleValue(); } return result; } /** * Returns the maximum range value. * * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The maximum range value. */ @Override public double getRangeUpperBound(boolean includeInterval) { double result = Double.NaN; if (this.maxValue != null) { result = this.maxValue.doubleValue(); } return result; } /** * Returns the value 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) { if (this.valueRange == null) { double max = getRangeUpperBound(includeInterval); this.valueRange = new Range(0.0, max); } return this.valueRange; } }
31,170
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Hour.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/Hour.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.] * * --------- * Hour.java * --------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Oct-2001 : Version 1 (DG); * 18-Dec-2001 : Changed order of parameters in constructor (DG); * 19-Dec-2001 : Added a new constructor as suggested by Paul English (DG); * 14-Feb-2002 : Fixed bug in Hour(Date) constructor (DG); * 26-Feb-2002 : Changed getStart(), getMiddle() and getEnd() methods to * evaluate with reference to a particular time zone (DG); * 15-Mar-2002 : Changed API (DG); * 16-Apr-2002 : Fixed small time zone bug in constructor (DG); * 10-Sep-2002 : Added getSerialIndex() method (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 10-Jan-2003 : Changed base class and method names (DG); * 13-Mar-2003 : Moved to com.jrefinery.data.time package, and implemented * Serializable (DG); * 21-Oct-2003 : Added hashCode() method, and new constructor for * convenience (DG); * 30-Sep-2004 : Replaced getTime().getTime() with getTimeInMillis() (DG); * 04-Nov-2004 : Reverted change of 30-Sep-2004, because it won't work for * JDK 1.3 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 04-Apr-2007 : In Hour(Date, TimeZone), peg milliseconds using specified * time zone (DG); * 16-Sep-2008 : Deprecated DEFAULT_TIME_ZONE (DG); * 02-Mar-2009 : Added new constructor with Locale (DG); * */ package org.jfree.data.time; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Represents an hour in a specific day. This class is immutable, which is a * requirement for all {@link RegularTimePeriod} subclasses. */ public class Hour extends RegularTimePeriod implements Serializable { /** For serialization. */ private static final long serialVersionUID = -835471579831937652L; /** Useful constant for the first hour in the day. */ public static final int FIRST_HOUR_IN_DAY = 0; /** Useful constant for the last hour in the day. */ public static final int LAST_HOUR_IN_DAY = 23; /** The day. */ private Day day; /** The hour. */ private byte hour; /** The first millisecond. */ private long firstMillisecond; /** The last millisecond. */ private long lastMillisecond; /** * Constructs a new Hour, based on the system date/time. */ public Hour() { this(new Date()); } /** * Constructs a new Hour. * * @param hour the hour (in the range 0 to 23). * @param day the day (<code>null</code> not permitted). */ public Hour(int hour, Day day) { if (day == null) { throw new IllegalArgumentException("Null 'day' argument."); } this.hour = (byte) hour; this.day = day; peg(Calendar.getInstance()); } /** * Creates a new hour. * * @param hour the hour (0-23). * @param day the day (1-31). * @param month the month (1-12). * @param year the year (1900-9999). */ public Hour(int hour, int day, int month, int year) { this(hour, new Day(day, month, year)); } /** * Constructs a new instance, based on the supplied date/time and * the default time zone. * * @param time the date-time (<code>null</code> not permitted). * * @see #Hour(Date, TimeZone) */ public Hour(Date time) { // defer argument checking... this(time, TimeZone.getDefault(), Locale.getDefault()); } /** * Constructs a new instance, based on the supplied date/time evaluated * in the specified time zone. * * @param time the date-time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). * @param locale the locale (<code>null</code> not permitted). * * @since 1.0.13 */ public Hour(Date time, TimeZone zone, Locale locale) { if (time == null) { throw new IllegalArgumentException("Null 'time' argument."); } if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } if (locale == null) { throw new IllegalArgumentException("Null 'locale' argument."); } Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); this.hour = (byte) calendar.get(Calendar.HOUR_OF_DAY); this.day = new Day(time, zone, locale); peg(calendar); } /** * Returns the hour. * * @return The hour (0 <= hour <= 23). */ public int getHour() { return this.hour; } /** * Returns the day in which this hour falls. * * @return The day. */ public Day getDay() { return this.day; } /** * Returns the year in which this hour falls. * * @return The year. */ public int getYear() { return this.day.getYear(); } /** * Returns the month in which this hour falls. * * @return The month. */ public int getMonth() { return this.day.getMonth(); } /** * Returns the day-of-the-month in which this hour falls. * * @return The day-of-the-month. */ public int getDayOfMonth() { return this.day.getDayOfMonth(); } /** * Returns the first millisecond of the hour. This will be determined * relative to the time zone specified in the constructor, or in the * calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The first millisecond of the hour. * * @see #getLastMillisecond() */ @Override public long getFirstMillisecond() { return this.firstMillisecond; } /** * Returns the last millisecond of the hour. This will be * determined relative to the time zone specified in the constructor, or * in the calendar instance passed in the most recent call to the * {@link #peg(Calendar)} method. * * @return The last millisecond of the hour. * * @see #getFirstMillisecond() */ @Override public long getLastMillisecond() { return this.lastMillisecond; } /** * Recalculates the start date/time and end date/time for this time period * relative to the supplied calendar (which incorporates a time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @since 1.0.3 */ @Override public void peg(Calendar calendar) { this.firstMillisecond = getFirstMillisecond(calendar); this.lastMillisecond = getLastMillisecond(calendar); } /** * Returns the hour preceding this one. * * @return The hour preceding this one. */ @Override public RegularTimePeriod previous() { Hour result; if (this.hour != FIRST_HOUR_IN_DAY) { result = new Hour(this.hour - 1, this.day); } else { // we are at the first hour in the day... Day prevDay = (Day) this.day.previous(); if (prevDay != null) { result = new Hour(LAST_HOUR_IN_DAY, prevDay); } else { result = null; } } return result; } /** * Returns the hour following this one. * * @return The hour following this one. */ @Override public RegularTimePeriod next() { Hour result; if (this.hour != LAST_HOUR_IN_DAY) { result = new Hour(this.hour + 1, this.day); } else { // we are at the last hour in the day... Day nextDay = (Day) this.day.next(); if (nextDay != null) { result = new Hour(FIRST_HOUR_IN_DAY, nextDay); } else { result = null; } } return result; } /** * Returns a serial index number for the hour. * * @return The serial index number. */ @Override public long getSerialIndex() { return this.day.getSerialIndex() * 24L + this.hour; } /** * Returns the first millisecond of the hour. * * @param calendar the calendar/timezone (<code>null</code> not permitted). * * @return The first millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getFirstMillisecond(Calendar calendar) { int year = this.day.getYear(); int month = this.day.getMonth() - 1; int dom = this.day.getDayOfMonth(); calendar.set(year, month, dom, this.hour, 0, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTimeInMillis(); } /** * Returns the last millisecond of the hour. * * @param calendar the calendar/timezone (<code>null</code> not permitted). * * @return The last millisecond. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ @Override public long getLastMillisecond(Calendar calendar) { int year = this.day.getYear(); int month = this.day.getMonth() - 1; int dom = this.day.getDayOfMonth(); calendar.set(year, month, dom, this.hour, 59, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTimeInMillis(); } /** * Tests the equality of this object against an arbitrary Object. * <P> * This method will return true ONLY if the object is an Hour object * representing the same hour as this instance. * * @param obj the object to compare (<code>null</code> permitted). * * @return <code>true</code> if the hour and day value of the object * is the same as this. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Hour)) { return false; } Hour that = (Hour) obj; if (this.hour != that.hour) { return false; } if (!this.day.equals(that.day)) { return false; } return true; } /** * Returns a string representation of this instance, for debugging * purposes. * * @return A string. */ @Override public String toString() { return "[" + this.hour + "," + getDayOfMonth() + "/" + getMonth() + "/" + getYear() + "]"; } /** * Returns a hash code for this object instance. The approach described by * Joshua Bloch in "Effective Java" has been used here: * <p> * <code>http://developer.java.sun.com/developer/Books/effectivejava * /Chapter3.pdf</code> * * @return A hash code. */ @Override public int hashCode() { int result = 17; result = 37 * result + this.hour; result = 37 * result + this.day.hashCode(); return result; } /** * Returns an integer indicating the order of this Hour object relative to * the specified object: * * negative == before, zero == same, positive == after. * * @param o1 the object to compare. * * @return negative == before, zero == same, positive == after. */ @Override public int compareTo(TimePeriod o1) { int result; // CASE 1 : Comparing to another Hour object // ----------------------------------------- if (o1 instanceof Hour) { Hour h = (Hour) o1; result = getDay().compareTo(h.getDay()); if (result == 0) { result = this.hour - h.getHour(); } } // CASE 2 : Comparing to another TimePeriod object // ----------------------------------------------- else { // more difficult case - evaluate later... result = 0; } return result; } /** * Creates an Hour instance by parsing a string. The string is assumed to * be in the format "YYYY-MM-DD HH", perhaps with leading or trailing * whitespace. * * @param s the hour string to parse. * * @return <code>null</code> if the string is not parseable, the hour * otherwise. */ public static Hour parseHour(String s) { Hour result = null; s = s.trim(); String daystr = s.substring(0, Math.min(10, s.length())); Day day = Day.parseDay(daystr); if (day != null) { String hourstr = s.substring( Math.min(daystr.length() + 1, s.length()), s.length() ); hourstr = hourstr.trim(); int hour = Integer.parseInt(hourstr); // if the hour is 0 - 23 then create an hour if ((hour >= FIRST_HOUR_IN_DAY) && (hour <= LAST_HOUR_IN_DAY)) { result = new Hour(hour, day); } } return result; } }
14,680
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/time/ohlc/package-info.java
/** * Classes for representing financial data in open-high-low-close form. */ package org.jfree.data.time.ohlc;
114
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCSeriesCollection.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/ohlc/OHLCSeriesCollection.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.] * * ------------------------- * OHLCSeriesCollection.java * ------------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1 (DG); * 10-Jul-2008 : Added accessor methods for xPosition attribute (DG); * 23-May-2009 : Added hashCode() implementation (DG); * 26-Jun-2009 : Added removeSeries() methods (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.time.ohlc; import java.io.Serializable; import java.util.List; import org.jfree.chart.HashUtilities; import org.jfree.chart.util.ObjectUtilities; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.time.RegularTimePeriod; import org.jfree.data.time.TimePeriodAnchor; import org.jfree.data.xy.AbstractXYDataset; import org.jfree.data.xy.OHLCDataset; import org.jfree.data.xy.XYDataset; /** * A collection of {@link OHLCSeries} objects. * * @since 1.0.4 * * @see OHLCSeries */ public class OHLCSeriesCollection extends AbstractXYDataset implements OHLCDataset, Serializable { /** Storage for the data series. */ private List<OHLCSeries> data; private TimePeriodAnchor xPosition = TimePeriodAnchor.MIDDLE; /** * Creates a new instance of <code>OHLCSeriesCollection</code>. */ public OHLCSeriesCollection() { this.data = new java.util.ArrayList<OHLCSeries>(); } /** * Returns the position within each time period that is used for the X * value when the collection is used as an {@link XYDataset}. * * @return The anchor position (never <code>null</code>). * * @since 1.0.11 */ public TimePeriodAnchor getXPosition() { return this.xPosition; } /** * Sets the position within each time period that is used for the X values * when the collection is used as an {@link XYDataset}, then sends a * {@link DatasetChangeEvent} is sent to all registered listeners. * * @param anchor the anchor position (<code>null</code> not permitted). * * @since 1.0.11 */ public void setXPosition(TimePeriodAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.xPosition = anchor; notifyListeners(new DatasetChangeEvent(this, this)); } /** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series (<code>null</code> not permitted). */ public void addSeries(OHLCSeries series) { if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } this.data.add(series); series.addChangeListener(this); fireDatasetChanged(); } /** * Returns the number of series in the collection. * * @return The series count. */ @Override public int getSeriesCount() { return this.data.size(); } /** * Returns a series from the collection. * * @param series the series index (zero-based). * * @return The series. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ public OHLCSeries getSeries(int series) { if ((series < 0) || (series >= getSeriesCount())) { throw new IllegalArgumentException("Series index out of bounds"); } return this.data.get(series); } /** * 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 a series. * * @throws IllegalArgumentException if <code>series</code> is not in the * specified range. */ @Override public Comparable getSeriesKey(int series) { // defer argument checking return getSeries(series).getKey(); } /** * Returns the number of items in the specified series. * * @param series the series (zero-based index). * * @return The item count. * * @throws IllegalArgumentException if <code>series</code> is not in the * range <code>0</code> to <code>getSeriesCount() - 1</code>. */ @Override public int getItemCount(int series) { // defer argument checking return getSeries(series).getItemCount(); } /** * Returns the x-value for a time period. * * @param period the time period (<code>null</code> not permitted). * * @return The x-value. */ protected synchronized long getX(RegularTimePeriod period) { long result = 0L; if (this.xPosition == TimePeriodAnchor.START) { result = period.getFirstMillisecond(); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { result = period.getMiddleMillisecond(); } else if (this.xPosition == TimePeriodAnchor.END) { result = period.getLastMillisecond(); } return result; } /** * Returns the x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @Override public double getXValue(int series, int item) { OHLCSeries s = this.data.get(series); OHLCItem di = (OHLCItem) s.getDataItem(item); RegularTimePeriod period = di.getPeriod(); return getX(period); } /** * Returns the x-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The x-value. */ @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. * @param item the item index. * * @return The y-value. */ @Override public Number getY(int series, int item) { OHLCSeries s = this.data.get(series); OHLCItem di = (OHLCItem) s.getDataItem(item); return di.getYValue(); } /** * Returns the open-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The open-value. */ @Override public double getOpenValue(int series, int item) { OHLCSeries s = this.data.get(series); OHLCItem di = (OHLCItem) s.getDataItem(item); return di.getOpenValue(); } /** * Returns the open-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The open-value. */ @Override public Number getOpen(int series, int item) { return getOpenValue(series, item); } /** * Returns the close-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The close-value. */ @Override public double getCloseValue(int series, int item) { OHLCSeries s = this.data.get(series); OHLCItem di = (OHLCItem) s.getDataItem(item); return di.getCloseValue(); } /** * Returns the close-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The close-value. */ @Override public Number getClose(int series, int item) { return getCloseValue(series, item); } /** * Returns the high-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The high-value. */ @Override public double getHighValue(int series, int item) { OHLCSeries s = this.data.get(series); OHLCItem di = (OHLCItem) s.getDataItem(item); return di.getHighValue(); } /** * Returns the high-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The high-value. */ @Override public Number getHigh(int series, int item) { return getHighValue(series, item); } /** * Returns the low-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The low-value. */ @Override public double getLowValue(int series, int item) { OHLCSeries s = this.data.get(series); OHLCItem di = (OHLCItem) s.getDataItem(item); return di.getLowValue(); } /** * Returns the low-value for an item within a series. * * @param series the series index. * @param item the item index. * * @return The low-value. */ @Override public Number getLow(int series, int item) { return getLowValue(series, item); } /** * Returns <code>null</code> always, because this dataset doesn't record * any volume data. * * @param series the series index (ignored). * @param item the item index (ignored). * * @return <code>null</code>. */ @Override public Number getVolume(int series, int item) { return null; } /** * Returns <code>Double.NaN</code> always, because this dataset doesn't * record any volume data. * * @param series the series index (ignored). * @param item the item index (ignored). * * @return <code>Double.NaN</code>. */ @Override public double getVolumeValue(int series, int item) { return Double.NaN; } /** * Removes the series with the specified index and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param index the series index. * * @since 1.0.14 */ public void removeSeries(int index) { OHLCSeries series = getSeries(index); if (series != null) { removeSeries(series); } } /** * Removes the specified series from the dataset and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @return <code>true</code> if the series was removed, and * <code>false</code> otherwise. * * @since 1.0.14 */ public boolean removeSeries(OHLCSeries series) { if (series == null) { throw new IllegalArgumentException("Null 'series' argument."); } boolean removed = this.data.remove(series); if (removed) { series.removeChangeListener(this); fireDatasetChanged(); } return removed; } /** * Removes all the series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.14 */ public void removeAllSeries() { if (this.data.size() == 0) { return; // nothing to do } // deregister the collection as a change listener to each series in the // collection for (OHLCSeries series : this.data) { series.removeChangeListener(this); } // remove all the series from the collection and notify listeners. this.data.clear(); fireDatasetChanged(); } /** * 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 OHLCSeriesCollection)) { return false; } OHLCSeriesCollection that = (OHLCSeriesCollection) obj; if (!this.xPosition.equals(that.xPosition)) { return false; } return ObjectUtilities.equal(this.data, that.data); } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 137; result = HashUtilities.hashCode(result, this.xPosition); for (OHLCSeries aData : this.data) { result = HashUtilities.hashCode(result, aData); } return result; } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem. */ @Override public Object clone() throws CloneNotSupportedException { OHLCSeriesCollection clone = (OHLCSeriesCollection) super.clone(); clone.data = ObjectUtilities.deepClone(this.data); return clone; } }
14,415
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCSeries.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/ohlc/OHLCSeries.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.] * * --------------- * OHLCSeries.java * --------------- * (C) Copyright 2006-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1 (DG); * 17-Jun-2009 : Added remove(int) method (DG); * */ package org.jfree.data.time.ohlc; import org.jfree.chart.util.ParamChecks; import org.jfree.data.ComparableObjectItem; import org.jfree.data.ComparableObjectSeries; import org.jfree.data.time.RegularTimePeriod; /** * A list of ({@link RegularTimePeriod}, open, high, low, close) data items. * * @since 1.0.4 * * @see OHLCSeriesCollection */ public class OHLCSeries extends ComparableObjectSeries { /** * Creates a new empty series. By default, items added to the series will * be sorted into ascending order by period, and duplicate periods will * not be allowed. * * @param key the series key (<code>null</code> not permitted). */ public OHLCSeries(Comparable key) { super(key, true, false); } /** * Returns the time period for the specified item. * * @param index the item index. * * @return The time period. */ public RegularTimePeriod getPeriod(int index) { OHLCItem item = (OHLCItem) getDataItem(index); return item.getPeriod(); } /** * 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); } /** * Adds a data item to the series. * * @param period the period. * @param open the open-value. * @param high the high-value. * @param low the low-value. * @param close the close-value. */ public void add(RegularTimePeriod period, double open, double high, double low, double close) { if (getItemCount() > 0) { OHLCItem item0 = (OHLCItem) this.getDataItem(0); if (!period.getClass().equals(item0.getPeriod().getClass())) { throw new IllegalArgumentException( "Can't mix RegularTimePeriod class types."); } } super.add(new OHLCItem(period, open, high, low, close), true); } /** * Adds a data item to the series. The values from the item passed to * this method will be copied into a new object. * * @param item the item (<code>null</code> not permitted). * * @since 1.0.17 */ public void add(OHLCItem item) { ParamChecks.nullNotPermitted(item, "item"); add(item.getPeriod(), item.getOpenValue(), item.getHighValue(), item.getLowValue(), item.getCloseValue()); } /** * Removes the item with the specified index. * * @param index the item index. * * @since 1.0.14 */ @Override public ComparableObjectItem remove(int index) { return super.remove(index); } }
4,336
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLC.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/data/time/ohlc/OHLC.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.] * * --------- * OHLC.java * --------- * (C) Copyright 2006, 2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1 (DG); * 23-May-2009 : Implemented hashCode() (DG); * */ package org.jfree.data.time.ohlc; import java.io.Serializable; import org.jfree.chart.HashUtilities; /** * A high low data record (immutable). This class is used internally by the * {@link OHLCItem} class. * * @since 1.0.4 */ public class OHLC implements Serializable { /** The open value. */ private double open; /** The close value. */ private double close; /** The high value. */ private double high; /** The low value. */ private double low; /** * Creates a new instance of <code>OHLC</code>. * * @param open the open value. * @param close the close value. * @param high the high value. * @param low the low value. */ public OHLC(double open, double high, double low, double close) { this.open = open; this.close = close; this.high = high; this.low = low; } /** * Returns the open value. * * @return The open value. */ public double getOpen() { return this.open; } /** * Returns the close value. * * @return The close value. */ public double getClose() { return this.close; } /** * Returns the high value. * * @return The high value. */ public double getHigh() { return this.high; } /** * Returns the low value. * * @return The low value. */ public double getLow() { return this.low; } /** * 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 OHLC)) { return false; } OHLC that = (OHLC) obj; if (this.open != that.open) { return false; } if (this.close != that.close) { return false; } if (this.high != that.high) { return false; } if (this.low != that.low) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = HashUtilities.hashCode(result, this.open); result = HashUtilities.hashCode(result, this.high); result = HashUtilities.hashCode(result, this.low); result = HashUtilities.hashCode(result, this.close); return result; } }
4,173
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z