Source Code Cross Referenced for UnsupportedDurationField.java in  » Development » Joda-Time » org » joda » time » field » 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 » Joda Time » org.joda.time.field 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright 2001-2005 Stephen Colebourne
003:         *
004:         *  Licensed under the Apache License, Version 2.0 (the "License");
005:         *  you may not use this file except in compliance with the License.
006:         *  You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         *  Unless required by applicable law or agreed to in writing, software
011:         *  distributed under the License is distributed on an "AS IS" BASIS,
012:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         *  See the License for the specific language governing permissions and
014:         *  limitations under the License.
015:         */
016:        package org.joda.time.field;
017:
018:        import java.io.Serializable;
019:        import java.util.HashMap;
020:        import org.joda.time.DurationField;
021:        import org.joda.time.DurationFieldType;
022:
023:        /**
024:         * A placeholder implementation to use when a duration field is not supported.
025:         * <p>
026:         * UnsupportedDurationField is thread-safe and immutable.
027:         *
028:         * @author Brian S O'Neill
029:         * @since 1.0
030:         */
031:        public final class UnsupportedDurationField extends DurationField
032:                implements  Serializable {
033:
034:            /** Serialization lock. */
035:            private static final long serialVersionUID = -6390301302770925357L;
036:
037:            /** The cache of unsupported duration field instances */
038:            private static HashMap cCache;
039:
040:            /**
041:             * Gets an instance of UnsupportedDurationField for a specific named field.
042:             * The returned instance is cached.
043:             * 
044:             * @param type  the type to obtain
045:             * @return the instance
046:             */
047:            public static synchronized UnsupportedDurationField getInstance(
048:                    DurationFieldType type) {
049:                UnsupportedDurationField field;
050:                if (cCache == null) {
051:                    cCache = new HashMap(7);
052:                    field = null;
053:                } else {
054:                    field = (UnsupportedDurationField) cCache.get(type);
055:                }
056:                if (field == null) {
057:                    field = new UnsupportedDurationField(type);
058:                    cCache.put(type, field);
059:                }
060:                return field;
061:            }
062:
063:            /** The name of the field */
064:            private final DurationFieldType iType;
065:
066:            /**
067:             * Constructor.
068:             * 
069:             * @param type  the type to use
070:             */
071:            private UnsupportedDurationField(DurationFieldType type) {
072:                iType = type;
073:            }
074:
075:            //-----------------------------------------------------------------------
076:            // Design note: Simple Accessors return a suitable value, but methods
077:            // intended to perform calculations throw an UnsupportedOperationException.
078:
079:            public final DurationFieldType getType() {
080:                return iType;
081:            }
082:
083:            public String getName() {
084:                return iType.getName();
085:            }
086:
087:            /**
088:             * This field is not supported.
089:             *
090:             * @return false always
091:             */
092:            public boolean isSupported() {
093:                return false;
094:            }
095:
096:            /**
097:             * This field is precise.
098:             * 
099:             * @return true always
100:             */
101:            public boolean isPrecise() {
102:                return true;
103:            }
104:
105:            /**
106:             * Always throws UnsupportedOperationException
107:             *
108:             * @throws UnsupportedOperationException
109:             */
110:            public int getValue(long duration) {
111:                throw unsupported();
112:            }
113:
114:            /**
115:             * Always throws UnsupportedOperationException
116:             *
117:             * @throws UnsupportedOperationException
118:             */
119:            public long getValueAsLong(long duration) {
120:                throw unsupported();
121:            }
122:
123:            /**
124:             * Always throws UnsupportedOperationException
125:             *
126:             * @throws UnsupportedOperationException
127:             */
128:            public int getValue(long duration, long instant) {
129:                throw unsupported();
130:            }
131:
132:            /**
133:             * Always throws UnsupportedOperationException
134:             *
135:             * @throws UnsupportedOperationException
136:             */
137:            public long getValueAsLong(long duration, long instant) {
138:                throw unsupported();
139:            }
140:
141:            /**
142:             * Always throws UnsupportedOperationException
143:             *
144:             * @throws UnsupportedOperationException
145:             */
146:            public long getMillis(int value) {
147:                throw unsupported();
148:            }
149:
150:            /**
151:             * Always throws UnsupportedOperationException
152:             *
153:             * @throws UnsupportedOperationException
154:             */
155:            public long getMillis(long value) {
156:                throw unsupported();
157:            }
158:
159:            /**
160:             * Always throws UnsupportedOperationException
161:             *
162:             * @throws UnsupportedOperationException
163:             */
164:            public long getMillis(int value, long instant) {
165:                throw unsupported();
166:            }
167:
168:            /**
169:             * Always throws UnsupportedOperationException
170:             *
171:             * @throws UnsupportedOperationException
172:             */
173:            public long getMillis(long value, long instant) {
174:                throw unsupported();
175:            }
176:
177:            /**
178:             * Always throws UnsupportedOperationException
179:             *
180:             * @throws UnsupportedOperationException
181:             */
182:            public long add(long instant, int value) {
183:                throw unsupported();
184:            }
185:
186:            /**
187:             * Always throws UnsupportedOperationException
188:             *
189:             * @throws UnsupportedOperationException
190:             */
191:            public long add(long instant, long value) {
192:                throw unsupported();
193:            }
194:
195:            /**
196:             * Always throws UnsupportedOperationException
197:             *
198:             * @throws UnsupportedOperationException
199:             */
200:            public int getDifference(long minuendInstant, long subtrahendInstant) {
201:                throw unsupported();
202:            }
203:
204:            /**
205:             * Always throws UnsupportedOperationException
206:             *
207:             * @throws UnsupportedOperationException
208:             */
209:            public long getDifferenceAsLong(long minuendInstant,
210:                    long subtrahendInstant) {
211:                throw unsupported();
212:            }
213:
214:            /**
215:             * Always returns zero.
216:             *
217:             * @return zero always
218:             */
219:            public long getUnitMillis() {
220:                return 0;
221:            }
222:
223:            /**
224:             * Always returns zero, indicating that sort order is not relevent.
225:             *
226:             * @return zero always
227:             */
228:            public int compareTo(Object durationField) {
229:                return 0;
230:            }
231:
232:            //------------------------------------------------------------------------
233:            /**
234:             * Compares this duration field to another.
235:             * 
236:             * @param obj  the object to compare to
237:             * @return true if equal
238:             */
239:            public boolean equals(Object obj) {
240:                if (this  == obj) {
241:                    return true;
242:                } else if (obj instanceof  UnsupportedDurationField) {
243:                    UnsupportedDurationField other = (UnsupportedDurationField) obj;
244:                    if (other.getName() == null) {
245:                        return (getName() == null);
246:                    }
247:                    return (other.getName().equals(getName()));
248:                }
249:                return false;
250:            }
251:
252:            /**
253:             * Gets a suitable hashcode.
254:             * 
255:             * @return the hashcode
256:             */
257:            public int hashCode() {
258:                return getName().hashCode();
259:            }
260:
261:            /**
262:             * Get a suitable debug string.
263:             * 
264:             * @return debug string
265:             */
266:            public String toString() {
267:                return "UnsupportedDurationField[" + getName() + ']';
268:            }
269:
270:            /**
271:             * Ensure proper singleton serialization
272:             */
273:            private Object readResolve() {
274:                return getInstance(iType);
275:            }
276:
277:            private UnsupportedOperationException unsupported() {
278:                return new UnsupportedOperationException(iType
279:                        + " field is unsupported");
280:            }
281:
282:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.