Source Code Cross Referenced for DateSpan.java in  » Project-Management » OpenProj » org » jdesktop » swing » calendar » 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 » Project Management » OpenProj » org.jdesktop.swing.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * $Id: DateSpan.java,v 1.1 2007/08/15 23:28:24 suricate Exp $
004:         *
005:         * This code comes from the dormant jdnc project at https://jdnc.dev.java.net/. It is licensed with the LGPL
006:         * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
007:         * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
008:         */
009:        package org.jdesktop.swing.calendar;
010:
011:        import java.util.Date;
012:
013:        import com.projity.pm.time.HasStartAndEnd;
014:
015:        /**
016:         * An immutable representation of a time range.  The time range is
017:         * internally represented as two longs. The methods that take and return
018:         * <code>Date</code>s create the <code>Date</code>s as needed, so that
019:         * if you modify returned <code>Date</code>s you will <b>not</b> effect
020:         * the <code>DateSpan</code>.  The end points are inclusive.
021:         *
022:         * @version  $Revision: 1.1 $
023:         */
024:        public class DateSpan implements  HasStartAndEnd {
025:            private long _start;
026:            private long _end;
027:
028:            /**
029:             * Creates a <code>DateSpan</code> between the two end points.
030:             *
031:             * @param start Beginning date
032:             * @param end Ending date
033:             * @throws IllegalArgumentException if <code>start</code> is after
034:             *         <code>end</code>
035:             */
036:            public DateSpan(long start, long end) {
037:                _start = start;
038:                _end = end;
039:                if (_start > _end) {
040:                    throw new IllegalArgumentException(
041:                            "Start date must be before end date");
042:                }
043:            }
044:
045:            /**
046:             * Creates a <code>DateSpan</code> between the two end points.  This
047:             * is a conveniance constructor that is equivalent to
048:             * <code>new Date(start.getTime(), end.getTime());</code>.
049:             *
050:             * @param start Beginning date
051:             * @param end Ending date
052:             */
053:            public DateSpan(Date start, Date end) {
054:                this (start.getTime(), end.getTime());
055:            }
056:
057:            /**
058:             * Returns the start of the date span.
059:             *
060:             * @return start of the  span.
061:             */
062:            public long getStart() {
063:                return _start;
064:            }
065:
066:            /**
067:             * Returns the end of the date span.
068:             *
069:             * @return end of the span.
070:             */
071:            public long getEnd() {
072:                return _end;
073:            }
074:
075:            /**
076:             * Returns the start of the date span as a <code>Date</code>.
077:             *
078:             * @return start of the  span.
079:             */
080:            public Date getStartAsDate() {
081:                return new Date(getStart());
082:            }
083:
084:            /**
085:             * Returns the end of the date span as a <code>Date</code>.
086:             *
087:             * @return end of the span.
088:             */
089:            public Date getEndAsDate() {
090:                return new Date(getEnd());
091:            }
092:
093:            /**
094:             * Returns true if this <code>DateSpan</code> contains the specified
095:             * <code>DateSpan</code>.
096:             *
097:             * @param span Date to check
098:             * @return true if this DateSpan contains <code>span</code>.
099:             */
100:            public boolean contains(DateSpan span) {
101:                return (contains(span.getStart()) && contains(span.getEnd()));
102:            }
103:
104:            /**
105:             * Returns whether or not this <code>DateSpan</code> contains the specified
106:             * time.
107:             *
108:             * @param time time check
109:             * @return true if this DateSpan contains <code>time</code>.
110:             */
111:            public boolean contains(long time) {
112:                return (time >= getStart() && time <= getEnd());
113:            }
114:
115:            /**
116:             * Returns whether or not this <code>DateSpan</code> contains the
117:             * specified date span.
118:             *
119:             * @param start Start of time span
120:             * @param end End of time
121:             * @return true if this <code>DateSpan</code> contains the specified
122:             *         date span.
123:             */
124:            public boolean contains(long start, long end) {
125:                return (start >= getStart() && end <= getEnd());
126:            }
127:
128:            /**
129:             * Returns true if the this <code>DateSpan</code> intersects with the
130:             * specified time.
131:             *
132:             * @param start Start time
133:             * @param end End time
134:             * @return true if this <code>DateSpan</code> intersects with the specified
135:             * time.
136:             */
137:            public boolean intersects(long start, long end) {
138:                return (start <= getEnd() && end >= getStart());
139:            }
140:
141:            /**
142:             * Returns true if the this <code>DateSpan</code> intersects with the
143:             * specified <code>DateSpan</code>.
144:             *
145:             * @param span DateSpan to compare to
146:             * @return true if this <code>DateSpan</code> intersects with the specified
147:             * time.
148:             */
149:            public boolean intersects(DateSpan span) {
150:                return intersects(span.getStart(), span.getEnd());
151:            }
152:
153:            /**
154:             * Returns a new <code>DateSpan</code> that is the union of this
155:             * <code>DateSpan</code> and <code>span</code>.
156:             *
157:             * @param span DateSpan to add
158:             * @return union of this DateSpan and <code>span</code>
159:             */
160:            public DateSpan add(DateSpan span) {
161:                return add(span.getStart(), span.getEnd());
162:            }
163:
164:            /**
165:             * Returns a new <code>DateSpan</code> that is the union of this
166:             * <code>DateSpan</code> and the passed in span.
167:             *
168:             * @param start Start of region to add
169:             * @param end End of region to end
170:             * @return union of this DateSpan and <code>start</code>, <code>end</code>
171:             */
172:            public DateSpan add(long start, long end) {
173:                return new DateSpan(Math.min(start, getStart()), Math.max(end,
174:                        getEnd()));
175:            }
176:
177:            public boolean equals(Object o) {
178:                if (o == this ) {
179:                    return true;
180:                }
181:                if (o instanceof  DateSpan) {
182:                    DateSpan ds = (DateSpan) o;
183:                    return (_start == ds.getStart() && _end == ds.getEnd());
184:                }
185:                return false;
186:            }
187:
188:            public int hashCode() {
189:                int result = 17;
190:                result = 37 * result + (int) (_start ^ (_start >>> 32));
191:                result = 37 * result + (int) (_end ^ (_end >>> 32));
192:                return result;
193:            }
194:
195:            public String toString() {
196:                return "DateSpan [" + getStartAsDate() + "-" + getEndAsDate()
197:                        + "]";
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.