Source Code Cross Referenced for ZeroIsMaxDateTimeField.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 org.joda.time.DateTimeField;
019:        import org.joda.time.DateTimeFieldType;
020:        import org.joda.time.DurationField;
021:        import org.joda.time.ReadablePartial;
022:
023:        /**
024:         * Wraps another field such that zero values are replaced with one more than
025:         * it's maximum. This is particularly useful for implementing an clockhourOfDay
026:         * field, where the midnight value of 0 is replaced with 24.
027:         * <p>
028:         * ZeroIsMaxDateTimeField is thread-safe and immutable.
029:         *
030:         * @author Brian S O'Neill
031:         * @since 1.0
032:         */
033:        public final class ZeroIsMaxDateTimeField extends
034:                DecoratedDateTimeField {
035:
036:            private static final long serialVersionUID = 961749798233026866L;
037:
038:            /**
039:             * Constructor.
040:             * 
041:             * @param field  the base field
042:             * @param type  the field type this field will actually use
043:             * @throws IllegalArgumentException if wrapped field's minimum value is not zero
044:             */
045:            public ZeroIsMaxDateTimeField(DateTimeField field,
046:                    DateTimeFieldType type) {
047:                super (field, type);
048:                if (field.getMinimumValue() != 0) {
049:                    throw new IllegalArgumentException(
050:                            "Wrapped field's minumum value must be zero");
051:                }
052:            }
053:
054:            public int get(long instant) {
055:                int value = getWrappedField().get(instant);
056:                if (value == 0) {
057:                    value = getMaximumValue();
058:                }
059:                return value;
060:            }
061:
062:            public long add(long instant, int value) {
063:                return getWrappedField().add(instant, value);
064:            }
065:
066:            public long add(long instant, long value) {
067:                return getWrappedField().add(instant, value);
068:            }
069:
070:            public long addWrapField(long instant, int value) {
071:                return getWrappedField().addWrapField(instant, value);
072:            }
073:
074:            public int[] addWrapField(ReadablePartial instant, int fieldIndex,
075:                    int[] values, int valueToAdd) {
076:                return getWrappedField().addWrapField(instant, fieldIndex,
077:                        values, valueToAdd);
078:            }
079:
080:            public int getDifference(long minuendInstant, long subtrahendInstant) {
081:                return getWrappedField().getDifference(minuendInstant,
082:                        subtrahendInstant);
083:            }
084:
085:            public long getDifferenceAsLong(long minuendInstant,
086:                    long subtrahendInstant) {
087:                return getWrappedField().getDifferenceAsLong(minuendInstant,
088:                        subtrahendInstant);
089:            }
090:
091:            public long set(long instant, int value) {
092:                int max = getMaximumValue();
093:                FieldUtils.verifyValueBounds(this , value, 1, max);
094:                if (value == max) {
095:                    value = 0;
096:                }
097:                return getWrappedField().set(instant, value);
098:            }
099:
100:            public boolean isLeap(long instant) {
101:                return getWrappedField().isLeap(instant);
102:            }
103:
104:            public int getLeapAmount(long instant) {
105:                return getWrappedField().getLeapAmount(instant);
106:            }
107:
108:            public DurationField getLeapDurationField() {
109:                return getWrappedField().getLeapDurationField();
110:            }
111:
112:            /**
113:             * Always returns 1.
114:             * 
115:             * @return the minimum value of 1
116:             */
117:            public int getMinimumValue() {
118:                return 1;
119:            }
120:
121:            /**
122:             * Always returns 1.
123:             * 
124:             * @return the minimum value of 1
125:             */
126:            public int getMinimumValue(long instant) {
127:                return 1;
128:            }
129:
130:            /**
131:             * Always returns 1.
132:             * 
133:             * @return the minimum value of 1
134:             */
135:            public int getMinimumValue(ReadablePartial instant) {
136:                return 1;
137:            }
138:
139:            /**
140:             * Always returns 1.
141:             * 
142:             * @return the minimum value of 1
143:             */
144:            public int getMinimumValue(ReadablePartial instant, int[] values) {
145:                return 1;
146:            }
147:
148:            /**
149:             * Get the maximum value for the field, which is one more than the wrapped
150:             * field's maximum value.
151:             * 
152:             * @return the maximum value
153:             */
154:            public int getMaximumValue() {
155:                return getWrappedField().getMaximumValue() + 1;
156:            }
157:
158:            /**
159:             * Get the maximum value for the field, which is one more than the wrapped
160:             * field's maximum value.
161:             * 
162:             * @return the maximum value
163:             */
164:            public int getMaximumValue(long instant) {
165:                return getWrappedField().getMaximumValue(instant) + 1;
166:            }
167:
168:            /**
169:             * Get the maximum value for the field, which is one more than the wrapped
170:             * field's maximum value.
171:             * 
172:             * @return the maximum value
173:             */
174:            public int getMaximumValue(ReadablePartial instant) {
175:                return getWrappedField().getMaximumValue(instant) + 1;
176:            }
177:
178:            /**
179:             * Get the maximum value for the field, which is one more than the wrapped
180:             * field's maximum value.
181:             * 
182:             * @return the maximum value
183:             */
184:            public int getMaximumValue(ReadablePartial instant, int[] values) {
185:                return getWrappedField().getMaximumValue(instant, values) + 1;
186:            }
187:
188:            public long roundFloor(long instant) {
189:                return getWrappedField().roundFloor(instant);
190:            }
191:
192:            public long roundCeiling(long instant) {
193:                return getWrappedField().roundCeiling(instant);
194:            }
195:
196:            public long roundHalfFloor(long instant) {
197:                return getWrappedField().roundHalfFloor(instant);
198:            }
199:
200:            public long roundHalfCeiling(long instant) {
201:                return getWrappedField().roundHalfCeiling(instant);
202:            }
203:
204:            public long roundHalfEven(long instant) {
205:                return getWrappedField().roundHalfEven(instant);
206:            }
207:
208:            public long remainder(long instant) {
209:                return getWrappedField().remainder(instant);
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.