Source Code Cross Referenced for Time.java in  » 6.0-JDK-Modules » j2me » com » sun » perseus » model » 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 » 6.0 JDK Modules » j2me » com.sun.perseus.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package com.sun.perseus.model;
027:
028:        import com.sun.perseus.util.SVGConstants;
029:
030:        /**
031:         * This simple class represents the concept of time in the 
032:         * context of SMIL timing. 
033:         * 
034:         * <p>A <code>Time</code> can be <code>RESOLVED</code>, 
035:         * <code>UNRESOLVED</code> or <code>INDEFINITE</code>. When
036:         * times are sorted, times are compared according to their type
037:         * and value. The predefined <code>UNRESOLVED</code> and 
038:         * <code>INDEFINITE</code> values are used to characterize
039:         * the special values and sorting is done with the 
040:         * <code>greaterThan</code> method.
041:         * 
042:         * @see <a href="http://www.w3.org/TR/smil20/smil-timing.html">
043:         *      SMIL 2.0 Timing and Synchronization Module"</a>
044:         * @version $Id: Time.java,v 1.2 2006/04/21 06:39:16 st125089 Exp $
045:         */
046:        public final class Time {
047:            /**
048:             * Un-mutable Time instance used to represent the 'indefinite' 
049:             * time.
050:             */
051:            public static final Time INDEFINITE = new Time(-1);
052:
053:            /**
054:             * Un-mutable Time instance used to represent the 'unresolved'
055:             * time.
056:             */
057:            public static final Time UNRESOLVED = new Time(-2);
058:
059:            /**
060:             * This Time's value.
061:             */
062:            long value;
063:
064:            /**
065:             * Creates a new <code>RESOLVED</code> time with the given value.
066:             *
067:             * @param value the new time's value.
068:             */
069:            public Time(final long value) {
070:                this .value = value;
071:            }
072:
073:            /**
074:             * Compares the input time with this instance.
075:             * The <code>UNRESOLVED</code> value is greater than any
076:             * other <code>Time</code> value. The <code>INDEFINITE</code>
077:             * value is greater than any resolved value.
078:             * A resolved time is greater than another resolved time 
079:             * if its <code>value</code> is greater.
080:             *
081:             * @param cmp the time to compare with this instance.
082:             * @return true if this <code>Time</code> instance is 
083:             *         greater than cmp.
084:             * @throws NullPointerException if cmp is null.
085:             */
086:            public boolean greaterThan(final Time cmp) {
087:                if (this  == UNRESOLVED) {
088:                    return true;
089:                } else if (this  == INDEFINITE) {
090:                    if (cmp == UNRESOLVED) {
091:                        return false;
092:                    }
093:                    return true;
094:                } else {
095:                    if (cmp == UNRESOLVED || cmp == INDEFINITE) {
096:                        return false;
097:                    }
098:                    return value >= cmp.value;
099:                }
100:            }
101:
102:            /**
103:             * @return true if this time is resolved, i.e., if it is neither
104:             *         equal to UNRESOLVED nor equal to INDEFINITE
105:             */
106:            public boolean isResolved() {
107:                return this  != INDEFINITE && this  != UNRESOLVED;
108:            }
109:
110:            /**
111:             * Checks if the input time is the same as this one.
112:             *
113:             * @param cmp the object to compare to.
114:             * @return true if cmp is the same object as this one or if cmp
115:             *         has the same value as tis object.
116:             */
117:            public boolean isSameTime(final Time cmp) {
118:                if (cmp == null) {
119:                    return false;
120:                }
121:
122:                if (cmp == this ) {
123:                    return true;
124:                }
125:
126:                if (cmp.value == value) {
127:                    return true;
128:                }
129:
130:                return false;
131:            }
132:
133:            /**
134:             * Debug
135:             * @return a string describing this TimeInterval
136:             */
137:            public String toString() {
138:                if (this  == UNRESOLVED) {
139:                    return "Time[UNRESOLVED]";
140:                } else if (this  == INDEFINITE) {
141:                    return "Time[INDEFINITE]";
142:                } else {
143:                    return "Time[RESOLVED, " + value + "]";
144:                }
145:            }
146:
147:            /**
148:             * Converst a Time instance to a String trait value.
149:             *
150:             * @param t the time instance to convert. If null, the value 
151:             *        'indefinite' is returned.
152:             * @return a string trait value. 
153:             */
154:            protected static String toStringTrait(final Time t) {
155:                if (t == null || Time.INDEFINITE == t) {
156:                    return SVGConstants.SVG_INDEFINITE_VALUE;
157:                }
158:
159:                // This should never happen because Times converted to traits
160:                // are times specified on timed element attributes and should
161:                // never be unresolved times.
162:                if (Time.UNRESOLVED.isSameTime(t)) {
163:                    throw new IllegalArgumentException();
164:                }
165:
166:                // At this point, we know we are dealing with a resolved time.
167:                // Returns the value in seconds.
168:                return (t.value / 1000f) + "s";
169:            }
170:
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.