Source Code Cross Referenced for DateGenerator.java in  » Testing » databene-benerator » org » databene » benerator » primitive » 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 » Testing » databene benerator » org.databene.benerator.primitive 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (c) Copyright 2006 by Volker Bergmann. All rights reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without
005:         * modification, is permitted under the terms of the
006:         * GNU General Public License.
007:         *
008:         * For redistributing this software or a derivative work under a license other
009:         * than the GPL-compatible Free Software License as defined by the Free
010:         * Software Foundation or approved by OSI, you must first obtain a commercial
011:         * license to this software product from Volker Bergmann.
012:         *
013:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014:         * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015:         * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017:         * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024:         * POSSIBILITY OF SUCH DAMAGE.
025:         */
026:
027:        package org.databene.benerator.primitive;
028:
029:        import org.databene.benerator.primitive.number.adapter.LongGenerator;
030:        import org.databene.benerator.Sequence;
031:        import org.databene.benerator.Distribution;
032:        import org.databene.benerator.Generator;
033:        import org.databene.commons.Period;
034:
035:        import java.util.Date;
036:        import java.util.GregorianCalendar;
037:
038:        /**
039:         * creates date values by a LongGenerator.
040:         * @see LongGenerator<br/>
041:         * <br/>
042:         * Created: 07.06.2006 22:54:28
043:         */
044:        public class DateGenerator implements  Generator<Date> {
045:
046:            /** The generator to use for generating millisecond values */
047:            private LongGenerator source;
048:
049:            // constructors ----------------------------------------------------------------------------------------------------
050:
051:            /** Initializes the generator to create days within about the last 80 years with a one-day resolution */
052:            public DateGenerator() {
053:                this (defaultStartDate(), currentDay(), Period.DAY.getMillis());
054:            }
055:
056:            /** Initializes the generator to create dates with a uniform distribution */
057:            public DateGenerator(Date min, Date max, long precision) {
058:                this (min, max, precision, Sequence.RANDOM);
059:            }
060:
061:            /** Initializes the generator to create dates of a Sequence or WeightFunction */
062:            public DateGenerator(Date min, Date max, long precision,
063:                    Distribution distribution) {
064:                source = new LongGenerator((min != null ? min.getTime()
065:                        : Long.MIN_VALUE), (max != null ? max.getTime()
066:                        : Long.MAX_VALUE), precision, distribution);
067:            }
068:
069:            // config properties -----------------------------------------------------------------------------------------------
070:
071:            /** Returns the earliest date to generate */
072:            public Date getMin() {
073:                return new Date(source.getMin());
074:            }
075:
076:            /** Sets the earliest date to generate */
077:            public void setMin(Date min) {
078:                source.setMin(min.getTime());
079:            }
080:
081:            /** Returns the latest date to generate */
082:            public Date getMax() {
083:                return new Date(source.getMax());
084:            }
085:
086:            /** Sets the latest date to generate */
087:            public void setMax(Date max) {
088:                source.setMax(max.getTime());
089:            }
090:
091:            /** Returns the date precision in milliseconds */
092:            public Long getPrecision() {
093:                return source.getPrecision();
094:            }
095:
096:            /** Sets the date precision in milliseconds */
097:            public void setPrecision(Long precision) {
098:                source.setPrecision(precision);
099:            }
100:
101:            /** Returns the distribution used */
102:            public Distribution getDistribution() {
103:                return source.getDistribution();
104:            }
105:
106:            /** Sets the distribution to use */
107:            public void setDistribution(Distribution distribution) {
108:                source.setDistribution(distribution);
109:            }
110:
111:            /** Returns the first sequence-specific variation parameter */
112:            public Long getVariation1() {
113:                return source.getVariation1();
114:            }
115:
116:            /** Sets the first sequence-specific variation parameter */
117:            public void setVariation1(Long varation1) {
118:                source.setVariation1(varation1);
119:            }
120:
121:            /** Returns the second sequence-specific variation parameter */
122:            public Long getVariation2() {
123:                return source.getVariation2();
124:            }
125:
126:            /** Sets the second sequence-specific variation parameter */
127:            public void setVariation2(Long variation2) {
128:                source.setVariation2(variation2);
129:            }
130:
131:            // source interface ---------------------------------------------------------------------------------------------
132:
133:            public Class<Date> getGeneratedType() {
134:                return Date.class;
135:            }
136:
137:            public void validate() {
138:                source.validate();
139:            }
140:
141:            /** Generates a Date by creating a millisecond value from the source generator and wrapping it into a Date */
142:            public Date generate() {
143:                return new Date(source.generate());
144:            }
145:
146:            public void reset() {
147:                source.reset();
148:            }
149:
150:            public void close() {
151:                source.close();
152:            }
153:
154:            public boolean available() {
155:                return source.available();
156:            }
157:
158:            // implementation --------------------------------------------------------------------------------------------------
159:
160:            /** Returns the default start date as 80 years ago */
161:            private static Date defaultStartDate() {
162:                return new Date(currentDay().getTime() - 80L * 365
163:                        * Period.DAY.getMillis());
164:            }
165:
166:            /** Returns the current day as Date value rounded to midnight */
167:            private static Date currentDay() {
168:                GregorianCalendar calendar = new GregorianCalendar();
169:                calendar.set(calendar.get(GregorianCalendar.YEAR), calendar
170:                        .get(GregorianCalendar.MONTH), calendar
171:                        .get(GregorianCalendar.DAY_OF_MONTH), 0, 0, 0);
172:                calendar.set(GregorianCalendar.MILLISECOND, 0);
173:                return new Date();
174:            }
175:
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.