Source Code Cross Referenced for Time.java in  » Science » jscience-4.3.1 » org » jscience » geography » coordinates » 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 » Science » jscience 4.3.1 » org.jscience.geography.coordinates 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
003:         * Copyright (C) 2006 - JScience (http://jscience.org/)
004:         * All rights reserved.
005:         * 
006:         * Permission to use, copy, modify, and distribute this software is
007:         * freely granted, provided that this notice is preserved.
008:         */
009:        package org.jscience.geography.coordinates;
010:
011:        import java.util.Date;
012:
013:        import javax.measure.Measurable;
014:        import javax.measure.converter.UnitConverter;
015:        import javax.measure.quantity.Duration;
016:        import static javax.measure.unit.SI.*;
017:        import javax.measure.unit.Unit;
018:
019:        import javolution.context.ObjectFactory;
020:        import javolution.xml.XMLFormat;
021:        import javolution.xml.stream.XMLStreamException;
022:
023:        import org.jscience.geography.coordinates.crs.TemporalCRS;
024:        import org.opengis.referencing.cs.CoordinateSystem;
025:
026:        /**
027:         * This class represents the {@link TemporalCRS temporal} UTC time coordinates.
028:         * 
029:         * @author <a href="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
030:         * @version 3.0, February 6, 2006
031:         */
032:        public final class Time extends Coordinates<TemporalCRS<?>> implements 
033:                Measurable<Duration> {
034:
035:            /**
036:             * Holds the coordinate reference system for all instances of this class. 
037:             */
038:            public static final TemporalCRS<Time> CRS = new TemporalCRS<Time>() {
039:
040:                @Override
041:                protected Time coordinatesOf(AbsolutePosition position) {
042:                    if (position.timeUTC instanceof  Time)
043:                        return (Time) position.timeUTC;
044:                    return Time.valueOf(position.timeUTC.doubleValue(SECOND),
045:                            SECOND);
046:                }
047:
048:                @Override
049:                protected AbsolutePosition positionOf(Time coordinates,
050:                        AbsolutePosition position) {
051:                    position.timeUTC = coordinates;
052:                    return position;
053:                }
054:
055:                @Override
056:                public CoordinateSystem getCoordinateSystem() {
057:                    return TemporalCRS.TIME_CS;
058:                }
059:
060:            };
061:
062:            /**
063:             * Holds the time in second since midnight, January 1, 1970 UTC. 
064:             */
065:            private double _seconds;
066:
067:            /**
068:             * Returns the temporal position corresponding to the specified coordinates.
069:             * 
070:             * @param value the time since midnight, January 1, 1970 UTC stated in the  
071:             *        specified unit.
072:             * @param unit the duration unit in which the time value is stated.
073:             * @return the corresponding temporal position.
074:             */
075:            public static Time valueOf(double value, Unit<Duration> unit) {
076:                Time time = FACTORY.object();
077:                if (unit == SECOND) {
078:                    time._seconds = value;
079:                } else {
080:                    UnitConverter toSecond = unit.getConverterTo(SECOND);
081:                    time._seconds = toSecond.convert(value);
082:                }
083:                return time;
084:            }
085:
086:            private static final ObjectFactory<Time> FACTORY = new ObjectFactory<Time>() {
087:
088:                @Override
089:                protected Time create() {
090:                    return new Time();
091:                }
092:            };
093:
094:            private Time() {
095:            }
096:
097:            /**
098:             * Returns the temporal position corresponding to the specified date.
099:             * 
100:             * @param date the date.
101:             * @return the corresponding temporal position.
102:             */
103:            public static Time valueOf(Date date) {
104:                return Time.valueOf(date.getTime(), MILLI(SECOND));
105:            }
106:
107:            /**
108:             * Creates the temporal position corresponding to the specified coordinates.
109:             * 
110:             * @param value the time since midnight, January 1, 1970 UTC stated in the  
111:             *        specified unit.
112:             * @param unit the duration unit in which the time value is stated.
113:             */
114:            public Time(double value, Unit<Duration> unit) {
115:            }
116:
117:            @Override
118:            public TemporalCRS<?> getCoordinateReferenceSystem() {
119:                return CRS;
120:            }
121:
122:            // OpenGIS Interface.
123:            public int getDimension() {
124:                return 1;
125:            }
126:
127:            // OpenGIS Interface.
128:            public double getOrdinate(int dimension)
129:                    throws IndexOutOfBoundsException {
130:                if (dimension == 0) {
131:                    Unit<?> u = TemporalCRS.TIME_CS.getAxis(0).getUnit();
132:                    return SECOND.getConverterTo(u).convert(_seconds);
133:                } else {
134:                    throw new IndexOutOfBoundsException();
135:                }
136:            }
137:
138:            // Implements Scalar<Duration>
139:            public final double doubleValue(Unit<Duration> unit) {
140:                return unit.equals(SECOND) ? _seconds : SECOND.getConverterTo(
141:                        unit).convert(_seconds);
142:            }
143:
144:            // Implements Scalar<Duration>
145:            public final long longValue(Unit<Duration> unit) {
146:                return Math.round(doubleValue(unit));
147:            }
148:
149:            // Implements Scalar<Duration>
150:            public int compareTo(Measurable<Duration> arg0) {
151:                double arg0InSecond = arg0.doubleValue(SECOND);
152:                return (_seconds > arg0InSecond) ? 1
153:                        : (_seconds < arg0InSecond) ? -1 : 0;
154:            }
155:
156:            // Implements Realtime.
157:            public Time copy() {
158:                return Time.valueOf(_seconds, SECOND);
159:            }
160:
161:            // Default serialization.
162:            //
163:
164:            static final XMLFormat<Time> XML = new XMLFormat<Time>(Time.class) {
165:
166:                @Override
167:                public Time newInstance(Class<Time> cls, InputElement xml)
168:                        throws XMLStreamException {
169:                    return FACTORY.object();
170:                }
171:
172:                public void write(Time time, OutputElement xml)
173:                        throws XMLStreamException {
174:                    xml.setAttribute("seconds", time._seconds);
175:                }
176:
177:                public void read(InputElement xml, Time time)
178:                        throws XMLStreamException {
179:                    time._seconds = xml.getAttribute("seconds", 0.0);
180:                }
181:            };
182:
183:            private static final long serialVersionUID = 1L;
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.