Source Code Cross Referenced for DateTimeStamp.java in  » Development » jodd » jodd » datetime » 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 » jodd » jodd.datetime 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
002:
003:        package jodd.datetime;
004:
005:        import jodd.util.ObjectUtil;
006:        import jodd.util.HashCodeUtil;
007:
008:        /**
009:         * Generic date time stamp just stores and holds date and time information.
010:         * This class does not contain any date/time logic, neither guarantees
011:         * that date is valid.
012:         *
013:         * @see JDateTime
014:         * @see JulianDateStamp
015:         */
016:        public class DateTimeStamp implements  Comparable, java.io.Serializable,
017:                Cloneable {
018:
019:            /**
020:             * Default empty constructor.
021:             */
022:            public DateTimeStamp() {
023:            }
024:
025:            /**
026:             * Constructor that sets date and time.
027:             */
028:            public DateTimeStamp(int year, int month, int day, int hour,
029:                    int minute, double second) {
030:                this .year = year;
031:                this .month = month;
032:                this .day = day;
033:                this .hour = hour;
034:                this .minute = minute;
035:                this .second = second;
036:            }
037:
038:            /**
039:             * Constructor that sets just date. Time is set to zeros.
040:             */
041:            public DateTimeStamp(int year, int month, int day) {
042:                this (year, month, day, 0, 0, 0);
043:            }
044:
045:            /**
046:             * Year.
047:             */
048:            public int year;
049:
050:            /**
051:             * Month, range: [1 - 12]
052:             */
053:            public int month = 1;
054:
055:            /**
056:             * Day, range: [1 - 31]
057:             */
058:            public int day = 1;
059:
060:            /**
061:             * Hour, range: [0 - 23]
062:             */
063:            public int hour;
064:
065:            /**
066:             * Minute, range [0 - 59]
067:             */
068:            public int minute;
069:
070:            /**
071:             * Second, range: [0.000 - 59.999]
072:             */
073:            public double second;
074:
075:            // ---------------------------------------------------------------- get/set
076:
077:            public int getYear() {
078:                return year;
079:            }
080:
081:            public void setYear(int year) {
082:                this .year = year;
083:            }
084:
085:            public int getMonth() {
086:                return month;
087:            }
088:
089:            public void setMonth(int month) {
090:                this .month = month;
091:            }
092:
093:            public int getDay() {
094:                return day;
095:            }
096:
097:            public void setDay(int day) {
098:                this .day = day;
099:            }
100:
101:            public int getHour() {
102:                return hour;
103:            }
104:
105:            public void setHour(int hour) {
106:                this .hour = hour;
107:            }
108:
109:            public int getMinute() {
110:                return minute;
111:            }
112:
113:            public void setMinute(int minute) {
114:                this .minute = minute;
115:            }
116:
117:            public double getSecond() {
118:                return second;
119:            }
120:
121:            public void setSecond(double second) {
122:                this .second = second;
123:            }
124:
125:            // ---------------------------------------------------------------- compare
126:
127:            /**
128:             * Compares this object with the specified object for order.  Returns a
129:             * negative integer, zero, or a positive integer as this object is less
130:             * than, equal to, or greater than the specified object.
131:             *
132:             * @param   o the Object to be compared.
133:             * @return  a negative integer, zero, or a positive integer as this object
134:             *		is less than, equal to, or greater than the specified object.
135:             *
136:             * @throws ClassCastException if the specified object's type prevents it
137:             *         from being compared to this Object.
138:             */
139:            public int compareTo(Object o) {
140:                DateTimeStamp gts = (DateTimeStamp) o;
141:
142:                int date1 = year * 10000 + month * 100 + day;
143:                int date2 = gts.year * 10000 + gts.month * 100 + gts.day;
144:
145:                if (date1 < date2) {
146:                    return -1;
147:                }
148:                if (date1 > date2) {
149:                    return 1;
150:                }
151:
152:                date1 = hour * 10000000 + minute * 100000
153:                        + (int) (second * 1000);
154:                date2 = gts.hour * 10000000 + gts.minute * 100000
155:                        + (int) (gts.second * 1000);
156:
157:                if (date1 < date2) {
158:                    return -1;
159:                }
160:                if (date1 > date2) {
161:                    return 1;
162:                }
163:
164:                return 0;
165:            }
166:
167:            // ---------------------------------------------------------------- toString
168:
169:            /**
170:             * Simple to string conversion.
171:             *
172:             * @return date/time string in 'y-m-d h:m:m.s' format
173:             */
174:            @Override
175:            public String toString() {
176:                double sec = (int) (second * 1000) / 1000.0;
177:                return year + "-" + month + '-' + day + ' ' + hour + ':'
178:                        + minute + ':' + sec;
179:            }
180:
181:            // ---------------------------------------------------------------- equals & hashCode
182:
183:            @Override
184:            public boolean equals(Object object) {
185:                if (this  == object) {
186:                    return true;
187:                }
188:                if (ObjectUtil.equalsType(object, this ) == false) {
189:                    return false;
190:                }
191:                final DateTimeStamp stamp = (DateTimeStamp) object;
192:
193:                return (stamp.year == this .year)
194:                        && (stamp.month == this .minute)
195:                        && (stamp.day == this .day)
196:                        && (stamp.hour == this .hour)
197:                        && (stamp.minute == this .minute)
198:                        && (Double.doubleToLongBits(stamp.second) == Double
199:                                .doubleToLongBits(this .second));
200:            }
201:
202:            @Override
203:            public int hashCode() {
204:                int result = HashCodeUtil.SEED;
205:                result = HashCodeUtil.hash(result, this .year);
206:                result = HashCodeUtil.hash(result, this .month);
207:                result = HashCodeUtil.hash(result, this .day);
208:                result = HashCodeUtil.hash(result, this .hour);
209:                result = HashCodeUtil.hash(result, this .minute);
210:                result = HashCodeUtil.hash(result, this .second);
211:                return result;
212:            }
213:
214:            // ---------------------------------------------------------------- clone
215:
216:            @Override
217:            protected Object clone() {
218:                DateTimeStamp dts = new DateTimeStamp();
219:                dts.year = this.year;
220:                dts.month = this.month;
221:                dts.day = this.day;
222:                dts.hour = this.hour;
223:                dts.minute = this.minute;
224:                dts.second = this.second;
225:                return dts;
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.