⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segmentedtimelinetests.java

📁 用于制作报表的中间件控件,纯java编写,还附带有数据库操作的源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2007, 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.   * * [Java is a trademark or registered trademark of Sun Microsystems, Inc.  * in the United States and other countries.] * * ---------------------------- * SegmentedTimelineTests.java * ---------------------------- * (C) Copyright 2003-2007, by Bill Kelemen and Contributors. * * Original Author:  Bill Kelemen; * Contributor(s):   David Gilbert (for Object Refinery Limited); * * Changes * ------- * 24-May-2003 : Version 1 (BK); * 07-Jan-2005 : Added test for hashCode() method (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * */package org.jfree.chart.axis.junit;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.ObjectInput;import java.io.ObjectInputStream;import java.io.ObjectOutput;import java.io.ObjectOutputStream;import java.text.Format;import java.text.NumberFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.Iterator;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import org.jfree.chart.axis.SegmentedTimeline;/** * JUnit Tests for the {@link SegmentedTimeline} class. */public class SegmentedTimelineTests extends TestCase {    /** These constants control test cycles in the validateXXXX methods. */    private static final int TEST_CYCLE_START = 0;    /** These constants control test cycles in the validateXXXX methods. */    private static final int TEST_CYCLE_END   = 1000;    /** These constants control test cycles in the validateXXXX methods. */    private static final int TEST_CYCLE_INC   = 55;    /** Number of ms in five years */    private static final long FIVE_YEARS = 5 * 365             * SegmentedTimeline.DAY_SEGMENT_SIZE;    /** Number format object for ms tests. */    private static final NumberFormat NUMBER_FORMAT             = NumberFormat.getNumberInstance();    /** Date format object for Monday through Friday tests. */    private static final SimpleDateFormat DATE_FORMAT;    /** Date format object 9:00 AM to 4:00 PM tests. */    private static final SimpleDateFormat DATE_TIME_FORMAT;    /** Some ms exceptions for ms testing. */    private static final String[] MS_EXCEPTIONS = {"0", "2", "4", "10", "15",         "16", "17", "18", "19", "20", "21", "22", "23", "24", "47", "58",         "100", "101"};     /** Some ms4 exceptions for ms testing. */     private static final String[] MS2_BASE_TIMELINE_EXCEPTIONS = {"0", "8",          "16", "24", "32", "40", "48", "56", "64", "72", "80", "88", "96",          "104", "112", "120", "128", "136"};    /** US non-trading dates in 2000 through 2002 to test exceptions. */    private static final String[] US_HOLIDAYS = {"2000-01-17", "2000-02-21",         "2000-04-21", "2000-05-29", "2000-07-04", "2000-09-04", "2000-11-23",         "2000-12-25", "2001-01-01", "2001-01-15", "2001-02-19", "2001-04-13",         "2001-05-28", "2001-07-04", "2001-09-03", "2001-09-11", "2001-09-12",         "2001-09-13", "2001-09-14", "2001-11-22", "2001-12-25", "2002-01-01",         "2002-01-21", "2002-02-18", "2002-03-29", "2002-05-27", "2002-07-04",         "2002-09-02", "2002-11-28", "2002-12-25"};     /** Some test exceptions for the fifteen min timeline. */     private static final String[] FIFTEEN_MIN_EXCEPTIONS = {         "2000-01-10 09:00:00", "2000-01-10 09:15:00", "2000-01-10 09:30:00",         "2000-01-10 09:45:00", "2000-01-10 10:00:00", "2000-01-10 10:15:00",         "2000-02-15 09:00:00", "2000-02-15 09:15:00", "2000-02-15 09:30:00",         "2000-02-15 09:45:00", "2000-02-15 10:00:00", "2000-02-15 10:15:00",         "2000-02-16 11:00:00", "2000-02-16 11:15:00", "2000-02-16 11:30:00",         "2000-02-16 11:45:00", "2000-02-16 12:00:00", "2000-02-16 12:15:00",         "2000-02-16 12:30:00", "2000-02-16 12:45:00", "2000-02-16 01:00:00",         "2000-02-16 01:15:00", "2000-02-16 01:30:00", "2000-02-16 01:45:00",         "2000-05-17 11:45:00", "2000-05-17 12:00:00", "2000-05-17 12:15:00",         "2000-05-17 12:30:00", "2000-05-17 12:45:00", "2000-05-17 01:00:00",         "2000-05-17 01:15:00", "2000-05-17 01:30:00", "2000-05-17 01:45:00",         "2000-05-17 02:00:00", "2000-05-17 02:15:00", "2000-05-17 02:30:00",         "2000-05-17 02:45:00", "2000-05-17 03:00:00", "2000-05-17 03:15:00",         "2000-05-17 03:30:00", "2000-05-17 03:45:00", "2000-05-17 04:00:00"};    /** Our 1-ms test timeline using 5 included and 2 excluded segments. */    private SegmentedTimeline msTimeline;    /**      * Our 1-ms test timeline (with baseTimeline) using 2 included and 2      * excluded segments.      */    private SegmentedTimeline ms2Timeline;    /**      * Our 4-ms test base timeline for ms2Timeline using 1 included and 1      * excluded segments      */    private SegmentedTimeline ms2BaseTimeline;    /** Our test Monday through Friday test timeline. */    private SegmentedTimeline mondayFridayTimeline;    /** Our 9:00 AM to 4:00 PM fifteen minute timeline. */    private SegmentedTimeline fifteenMinTimeline;    /** ms from 1970-01-01 to first monday after 2001-01-01. */    private Calendar monday;    /** ms from 1970-01-01 to 9 am first monday after 2001-01-01. */    private Calendar monday9am;    /** Static initialization block. */    static {        DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");        DATE_FORMAT.setTimeZone(SegmentedTimeline.NO_DST_TIME_ZONE);        DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        DATE_TIME_FORMAT.setTimeZone(SegmentedTimeline.NO_DST_TIME_ZONE);    }    /**     * Returns the tests as a test suite.     *     * @return The test suite.     */    public static Test suite() {        return new TestSuite(SegmentedTimelineTests.class);    }    /**     * Constructs a new set of tests.     *     * @param name  the name of the tests.     */    public SegmentedTimelineTests(String name) {        super(name);    }    /**     * Sets up the fixture, for example, open a network connection.     * This method is called before a test is executed.     *      * @throws Exception if there is a problem.     */    protected void setUp() throws Exception {        // setup our test timelines        //        // Legend for comments below:        // <spaces> = Segments included in the final timeline        // EE       = Excluded segments via timeline rules        // xx       = Exception segments inherited from base timeline exclusions        // 1-ms test timeline using 5 included and 2 excluded segments.        //        // timeline start time = 0        //   |        //   v        //   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 ..        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+..        // |  |  |  |  |  |EE|EE|  |  |  |  |  |EE|EE|  |  |  |  |  |  |EE|EE|    <-- msTimeline        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+..        //  \_________  ________/            \_/        //            \/                      |        //       segment group         segment size = 1 ms        //        this.msTimeline = new SegmentedTimeline(1, 5, 2);        this.msTimeline.setStartTime(0);        // 4-ms test base timeline for ms2Timeline using 1 included and 1        // excluded segments        //        // timeline start time = 0        //   |        //   v        //   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 ...        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        // |  |  |  |  |EE|EE|EE|EE|  |  |  |  |EE|EE|EE|EE|  |  |  |  |    <-- ms2BaseTimeline        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        //  \__________  _________/            \____  _____/        //             \/                           \/        //        segment group              segment size = 4 ms        //        this.ms2BaseTimeline = new SegmentedTimeline(4, 1, 1);        this.ms2BaseTimeline.setStartTime(0);        // 1-ms test timeline (with a baseTimeline) using 2 included and 2         // excluded segments centered inside each base segment        //        // The ms2Timeline without a base would look like this:        //        //    timeline start time = 1        //      |        //      v        //   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 ...        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        // |EE|  |  |EE|EE|  |  |EE|EE|  |  |EE|EE|  |  |EE|EE|  |  |EE|    <-- ms2Timeline        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        //    \____  _____/            \_/        //         \/                   |        //    segment group      segment size = 1 ms        //        // With the base timeline some originally included segments are now         // removed (see "xx" below):        //        //   0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 ...        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        // |EE|  |  |EE|EE|xx|xx|EE|EE|  |  |EE|EE|xx|xx|EE|EE|  |  |EE|    <-- ms2Timeline        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        // |  |  |  |  |EE|EE|EE|EE|  |  |  |  |EE|EE|EE|EE|  |  |  |  |    <-- ms2BaseTimeline        // +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...        //        this.ms2Timeline = new SegmentedTimeline(1, 2, 2);        this.ms2Timeline.setStartTime(1);        this.ms2Timeline.setBaseTimeline(this.ms2BaseTimeline);        // test monday though friday timeline        this.mondayFridayTimeline                 = SegmentedTimeline.newMondayThroughFridayTimeline();        // test 9am-4pm Monday through Friday timeline        this.fifteenMinTimeline                 = SegmentedTimeline.newFifteenMinuteTimeline();        // find first Monday after 2001-01-01        Calendar cal = new GregorianCalendar(                SegmentedTimeline.NO_DST_TIME_ZONE);        cal.set(2001, 0, 1, 0, 0, 0);        cal.set(Calendar.MILLISECOND, 0);        while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {            cal.add(Calendar.DATE, 1);        }        this.monday = (Calendar) cal.clone();        // calculate 9am on the first Monday after 2001-01-01        cal.add(Calendar.HOUR, 9);        this.monday9am = (Calendar) cal.clone();    }    /**     * Tears down the fixture, for example, close a network connection.     * This method is called after a test is executed.     *      * @throws Exception if there is a problem.     */    protected void tearDown() throws Exception {        // does nothing

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -