Source Code Cross Referenced for Duration.java in  » Workflow-Engines » jbpm-jpdl-3.2.2 » org » jbpm » calendar » 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 » Workflow Engines » jbpm jpdl 3.2.2 » org.jbpm.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source
003:         * Copyright 2005, JBoss Inc., and individual contributors as indicated
004:         * by the @authors tag. See the copyright.txt in the distribution for a
005:         * full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jbpm.calendar;
023:
024:        import java.io.Serializable;
025:        import java.util.HashMap;
026:        import java.util.Map;
027:        import java.util.Properties;
028:
029:        import org.jbpm.JbpmException;
030:
031:        /**
032:         * interpretes textual descriptions of a duration.
033:         * <p>Syntax: &lt;quantity&gt; [business] &lt;unit&gt; <br />
034:         * Where 
035:         * <ul>
036:         *   <li>&lt;quantity&gt; is a piece of text that is parsable 
037:         *       with <code>Double.parseDouble(quantity)</code>.
038:         *   </li>
039:         *   <li>&lt;unit&gt; is one of {second, seconds, minute, minutes, 
040:         *       hour, hours, day, days, week, weeks, month, months, year, years}.
041:         *   </li>
042:         *   <li>And adding the optional indication <code>business</code> means that 
043:         *       only business hours should be taken into account for this duration.
044:         *   </li>
045:         * </ul>
046:         * </p> 
047:         */
048:        public class Duration implements  Serializable {
049:
050:            private static final long serialVersionUID = 1L;
051:
052:            static final long SECOND = 1000;
053:            static final long MINUTE = 60 * SECOND;
054:            static final long HOUR = 60 * MINUTE;
055:            static final long DAY = 24 * HOUR;
056:            static final long WEEK = 7 * DAY;
057:            static final long MONTH = 30 * DAY;
058:            static final long YEAR = 365 * DAY;
059:
060:            static long BUSINESS_DAY = -1;
061:            static long BUSINESS_WEEK = -1;
062:            static long BUSINESS_MONTH = -1;
063:            static long BUSINESS_YEAR = -1;
064:
065:            static {
066:                Properties businessCalendarProperties = BusinessCalendar
067:                        .getBusinessCalendarProperties();
068:                String businessDayText = businessCalendarProperties
069:                        .getProperty("business.day.expressed.in.hours");
070:                String businessWeekText = businessCalendarProperties
071:                        .getProperty("business.week.expressed.in.hours");
072:                String businessMonthText = businessCalendarProperties
073:                        .getProperty("business.month.expressed.in.business.days");
074:                String businessYearText = businessCalendarProperties
075:                        .getProperty("business.year.expressed.in.business.days");
076:
077:                BUSINESS_DAY = (long) (Double.parseDouble(businessDayText) * HOUR);
078:                BUSINESS_WEEK = (long) (Double.parseDouble(businessWeekText) * HOUR);
079:                BUSINESS_MONTH = (long) (Double.parseDouble(businessMonthText) * BUSINESS_DAY);
080:                BUSINESS_YEAR = (long) (Double.parseDouble(businessYearText) * BUSINESS_DAY);
081:            }
082:
083:            static Map units = null;
084:            static {
085:                units = new HashMap();
086:                units.put("second", new Long(SECOND));
087:                units.put("seconds", new Long(SECOND));
088:                units.put("business second", new Long(SECOND));
089:                units.put("business seconds", new Long(SECOND));
090:                units.put("minute", new Long(MINUTE));
091:                units.put("minutes", new Long(MINUTE));
092:                units.put("business minute", new Long(MINUTE));
093:                units.put("business minutes", new Long(MINUTE));
094:                units.put("hour", new Long(HOUR));
095:                units.put("hours", new Long(HOUR));
096:                units.put("business hour", new Long(HOUR));
097:                units.put("business hours", new Long(HOUR));
098:                units.put("day", new Long(DAY));
099:                units.put("days", new Long(DAY));
100:                units.put("business day", new Long(BUSINESS_DAY));
101:                units.put("business days", new Long(BUSINESS_DAY));
102:                units.put("week", new Long(WEEK));
103:                units.put("weeks", new Long(WEEK));
104:                units.put("business week", new Long(BUSINESS_WEEK));
105:                units.put("business weeks", new Long(BUSINESS_WEEK));
106:                units.put("month", new Long(MONTH));
107:                units.put("months", new Long(MONTH));
108:                units.put("business month", new Long(BUSINESS_MONTH));
109:                units.put("business months", new Long(BUSINESS_MONTH));
110:                units.put("year", new Long(YEAR));
111:                units.put("years", new Long(YEAR));
112:                units.put("business year", new Long(BUSINESS_YEAR));
113:                units.put("business years", new Long(BUSINESS_YEAR));
114:            }
115:
116:            long milliseconds = 0;
117:            boolean isBusinessTime = false;
118:
119:            Duration() {
120:            }
121:
122:            public Duration(long milliseconds) {
123:                this .milliseconds = milliseconds;
124:            }
125:
126:            public Duration(Duration duration) {
127:                this .milliseconds = duration.milliseconds;
128:                this .isBusinessTime = duration.isBusinessTime;
129:            }
130:
131:            /**
132:             * creates a duration from a textual description.
133:             * syntax: {number} space {unit}
134:             * where number is parsable to a java.lang.Number and 
135:             * unit is one of
136:             * <ul>
137:             *   <li>second</li>
138:             *   <li>seconds</li>
139:             *   <li>minute</li>
140:             *   <li>minutes</li>
141:             *   <li>hour</li>
142:             *   <li>hours</li>
143:             *   <li>day</li>
144:             *   <li>days</li>
145:             *   <li>week</li>
146:             *   <li>weeks</li>
147:             *   <li>month (30 days)</li>
148:             *   <li>months (30 days)</li>
149:             *   <li>year (355 days)</li>
150:             *   <li>years (355 days)</li>
151:             * </ul>
152:             */
153:            public Duration(String duration) {
154:                if (duration == null)
155:                    throw new JbpmException("duration is null");
156:                int separatorIndex = duration.indexOf(' ');
157:                if (separatorIndex == -1)
158:                    throw new IllegalArgumentException(
159:                            "improper format of duration '" + duration + "'");
160:                String quantityText = duration.substring(0, separatorIndex)
161:                        .trim().toLowerCase();
162:                String unitText = duration.substring(separatorIndex + 1).trim()
163:                        .toLowerCase();
164:                if (unitText.startsWith("business")) {
165:                    isBusinessTime = true;
166:                }
167:                double amount = Double.parseDouble(quantityText);
168:                Long unit = (Long) units.get(unitText);
169:                if (unit == null)
170:                    throw new IllegalArgumentException(
171:                            "improper format of duration '" + duration + "'");
172:                this .milliseconds = (long) (amount * unit.longValue());
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.