Source Code Cross Referenced for PeriodImpl.java in  » Development » rapla » org » rapla » entities » domain » internal » 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 » Development » rapla » org.rapla.entities.domain.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*--------------------------------------------------------------------------*
002:         | Copyright (C) 2006 Christopher Kohlhaas                                  |
003:         |                                                                          |
004:         | This program is free software; you can redistribute it and/or modify     |
005:         | it under the terms of the GNU General Public License as published by the |
006:         | Free Software Foundation. A copy of the license has been included with   |
007:         | these distribution in the COPYING file, if not go to www.fsf.org         |
008:         |                                                                          |
009:         | As a special exception, you are granted the permissions to link this     |
010:         | program with every library, which license fulfills the Open Source       |
011:         | Definition as published by the Open Source Initiative (OSI).             |
012:         *--------------------------------------------------------------------------*/
013:        package org.rapla.entities.domain.internal;
014:
015:        import java.util.Calendar;
016:        import java.util.Date;
017:        import java.util.Locale;
018:        import java.util.NoSuchElementException;
019:
020:        import org.rapla.components.util.DateTools;
021:        import org.rapla.entities.RaplaType;
022:        import org.rapla.entities.domain.Period;
023:        import org.rapla.entities.storage.Mementable;
024:        import org.rapla.entities.storage.internal.SimpleEntity;
025:
026:        public class PeriodImpl extends SimpleEntity implements  Period,
027:                java.io.Serializable, Mementable {
028:            // Don't forget to increase the serialVersionUID when you change the fields
029:            private static final long serialVersionUID = 1;
030:
031:            private final static long WEEK_MILLIS = DateTools.MILLISECONDS_PER_WEEK;
032:
033:            String name;
034:            Date start;
035:            Date end;
036:            transient Calendar cal;
037:
038:            public PeriodImpl() {
039:
040:            }
041:
042:            public PeriodImpl(Date start, Date end) {
043:                this .start = start;
044:                this .end = end;
045:            }
046:
047:            final public RaplaType getRaplaType() {
048:                return TYPE;
049:            }
050:
051:            public Date getStart() {
052:                return start;
053:            }
054:
055:            public void setStart(Date start) {
056:                checkWritable();
057:                this .start = start;
058:            }
059:
060:            public Date getEnd() {
061:                return end;
062:            }
063:
064:            public void setEnd(Date end) {
065:                checkWritable();
066:                this .end = end;
067:            }
068:
069:            public int getWeeks() {
070:                long diff = end.getTime() - start.getTime();
071:                return (int) (((diff - 1) / WEEK_MILLIS) + 1);
072:            }
073:
074:            public String getName(Locale locale) {
075:                return name;
076:            }
077:
078:            public String getName() {
079:                return name;
080:            }
081:
082:            public void setName(String name) {
083:                checkWritable();
084:                this .name = name;
085:            }
086:
087:            public boolean contains(Date date) {
088:                return (date.before(end) && !date.before(start));
089:            }
090:
091:            public int weekOf(Date date) {
092:                Calendar cal = Calendar.getInstance(DateTools.getTimeZone());
093:                if (!contains(date))
094:                    throw new NoSuchElementException(
095:                            "Period doesn't contain date " + date);
096:                long duration = date.getTime() - start.getTime();
097:                long weeks = duration / (DateTools.MILLISECONDS_PER_WEEK);
098:                // setTimeInMillis has protected access in JDK 1.3.1
099:                cal.setTime(new Date(date.getTime() - weeks
100:                        * DateTools.MILLISECONDS_PER_WEEK));
101:                int week_of_year = cal.get(Calendar.WEEK_OF_YEAR);
102:                cal.setTime(getStart());
103:                return ((int) weeks)
104:                        + 1
105:                        + (((week_of_year) != cal.get(Calendar.WEEK_OF_YEAR)) ? 1
106:                                : 0);
107:            }
108:
109:            public String toString() {
110:                return getName();
111:            }
112:
113:            public int compareTo(Date date) {
114:                int result = getEnd().compareTo(date);
115:                if (result == 0)
116:                    return 1;
117:                else
118:                    return result;
119:            }
120:
121:            public int compareTo(Period period) {
122:                int result = getStart().compareTo(period.getStart());
123:                if (result != 0)
124:                    return result;
125:
126:                if (equals(period))
127:                    return 0;
128:
129:                return (hashCode() < period.hashCode()) ? -1 : 1;
130:            }
131:
132:            public int compareTo(Object o2) {
133:                if (o2 instanceof  Date) {
134:                    return compareTo((Date) o2);
135:                }
136:                if (o2 instanceof  Period) {
137:                    return compareTo((Period) o2);
138:                }
139:                throw new ClassCastException(
140:                        "Object needs to be an instance of Date or Period");
141:            }
142:
143:            static private void copy(PeriodImpl source, PeriodImpl dest) {
144:                dest.start = source.start;
145:                dest.end = source.end;
146:                dest.name = source.name;
147:            }
148:
149:            public void copy(Object obj) {
150:                super .copy((PeriodImpl) obj);
151:                copy((PeriodImpl) obj, this );
152:            }
153:
154:            public Object deepClone() {
155:                PeriodImpl clone = new PeriodImpl();
156:                super .deepClone(clone);
157:                copy(this , clone);
158:                return clone;
159:            }
160:
161:            public Object clone() {
162:                PeriodImpl clone = new PeriodImpl();
163:                super.clone(clone);
164:                copy(this, clone);
165:                return clone;
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.