Source Code Cross Referenced for SimpleTimePeriod.java in  » Chart » jfreechart » org » jfree » data » time » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » jfreechart » org.jfree.data.time 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006:         *
007:         * Project Info:  http://www.jfree.org/jfreechart/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         *
027:         * ---------------------
028:         * SimpleTimePeriod.java
029:         * ---------------------
030:         * (C) Copyright 2002-2005, by Object Refinery Limited and Contributors.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   -;
034:         *
035:         * $Id: SimpleTimePeriod.java,v 1.5.2.1 2005/10/25 21:35:24 mungady Exp $
036:         *
037:         * Changes
038:         * -------
039:         * 07-Oct-2002 : Added Javadocs (DG);
040:         * 10-Jan-2003 : Renamed TimeAllocation --> SimpleTimePeriod (DG);
041:         * 13-Mar-2003 : Added equals() method, and Serializable interface (DG);
042:         * 21-Oct-2003 : Added hashCode() method (DG);
043:         * 27-Jan-2005 : Implemented Comparable, to enable this class to be used
044:         *               in the TimeTableXYDataset class (DG);
045:         *
046:         */
047:
048:        package org.jfree.data.time;
049:
050:        import java.io.Serializable;
051:        import java.util.Date;
052:
053:        /**
054:         * An arbitrary period of time, measured to millisecond precision using 
055:         * <code>java.util.Date</code>.
056:         * <p>
057:         * This class is intentionally immutable (that is, once constructed, you cannot 
058:         * alter the start and end attributes).
059:         */
060:        public class SimpleTimePeriod implements  TimePeriod, Comparable,
061:                Serializable {
062:
063:            /** For serialization. */
064:            private static final long serialVersionUID = 8684672361131829554L;
065:
066:            /** The start date/time. */
067:            private Date start;
068:
069:            /** The end date/time. */
070:            private Date end;
071:
072:            /**
073:             * Creates a new time allocation.
074:             *
075:             * @param start  the start date/time in milliseconds.
076:             * @param end  the end date/time in milliseconds.
077:             */
078:            public SimpleTimePeriod(long start, long end) {
079:                this (new Date(start), new Date(end));
080:            }
081:
082:            /**
083:             * Creates a new time allocation.
084:             *
085:             * @param start  the start date/time (<code>null</code> not permitted).
086:             * @param end  the end date/time (<code>null</code> not permitted).
087:             */
088:            public SimpleTimePeriod(Date start, Date end) {
089:                if (start.getTime() > end.getTime()) {
090:                    throw new IllegalArgumentException("Requires end >= start.");
091:                }
092:                this .start = start;
093:                this .end = end;
094:            }
095:
096:            /**
097:             * Returns the start date/time.
098:             *
099:             * @return The start date/time (never <code>null</code>).
100:             */
101:            public Date getStart() {
102:                return this .start;
103:            }
104:
105:            /**
106:             * Returns the end date/time.
107:             *
108:             * @return The end date/time (never <code>null</code>).
109:             */
110:            public Date getEnd() {
111:                return this .end;
112:            }
113:
114:            /**
115:             * Tests this time period instance for equality with an arbitrary object.  
116:             * The object is considered equal if it is an instance of {@link TimePeriod}
117:             * and it has the same start and end dates.
118:             *
119:             * @param obj  the other object (<code>null</code> permitted).
120:             *
121:             * @return A boolean.
122:             */
123:            public boolean equals(Object obj) {
124:                if (obj == this ) {
125:                    return true;
126:                }
127:                if (!(obj instanceof  TimePeriod)) {
128:                    return false;
129:                }
130:                TimePeriod that = (TimePeriod) obj;
131:                if (!this .start.equals(that.getStart())) {
132:                    return false;
133:                }
134:                if (!this .end.equals(that.getEnd())) {
135:                    return false;
136:                }
137:                return true;
138:            }
139:
140:            /**
141:             * Returns an integer that indicates the relative ordering of two
142:             * time periods.
143:             * 
144:             * @param obj  the object (<code>null</code> not permitted).
145:             * 
146:             * @return An integer.
147:             * 
148:             * @throws ClassCastException if <code>obj</code> is not an instance of
149:             *                            {@link TimePeriod}.
150:             */
151:            public int compareTo(Object obj) {
152:                TimePeriod that = (TimePeriod) obj;
153:                long t0 = getStart().getTime();
154:                long t1 = getEnd().getTime();
155:                long m0 = t0 + (t1 - t0) / 2L;
156:                long t2 = that.getStart().getTime();
157:                long t3 = that.getEnd().getTime();
158:                long m1 = t2 + (t3 - t2) / 2L;
159:                if (m0 < m1) {
160:                    return -1;
161:                } else if (m0 > m1) {
162:                    return 1;
163:                } else {
164:                    if (t0 < t2) {
165:                        return -1;
166:                    } else if (t0 > t2) {
167:                        return 1;
168:                    } else {
169:                        if (t1 < t3) {
170:                            return -1;
171:                        } else if (t1 > t3) {
172:                            return 1;
173:                        } else {
174:                            return 0;
175:                        }
176:                    }
177:                }
178:            }
179:
180:            /**
181:             * Returns a hash code for this object instance.  The approach described by
182:             * Joshua Bloch in "Effective Java" has been used here - see:
183:             * <p>
184:             * <code>http://developer.java.sun.com/
185:             * developer/Books/effectivejava/Chapter3.pdf</code>
186:             * 
187:             * @return A hash code.
188:             */
189:            public int hashCode() {
190:                int result = 17;
191:                result = 37 * result + this .start.hashCode();
192:                result = 37 * result + this.end.hashCode();
193:                return result;
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.