├── .gitignore
├── src
├── main
│ └── java
│ │ └── org
│ │ └── fluttercode
│ │ └── datafactory
│ │ ├── NameDataValues.java
│ │ ├── ContentDataValues.java
│ │ ├── AddressDataValues.java
│ │ └── impl
│ │ ├── DefaultContentDataValues.java
│ │ ├── DefaultNameDataValues.java
│ │ ├── DefaultAddressDataValues.java
│ │ └── DataFactory.java
└── test
│ └── java
│ └── org
│ └── fluttercode
│ └── datafactory
│ └── impl
│ └── DataFactoryTextTest.java
├── pom.xml
├── license.txt
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | # binar
2 | target/*
3 | .project
4 | .settings
5 | .classpath/target
6 | .classpath
7 | .idea/*
8 | *.iml
9 |
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/NameDataValues.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * DataFactory is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with DataFactory. If not, see .
23 | *
24 | */
25 |
26 |
27 | public interface NameDataValues {
28 |
29 | String[] getFirstNames();
30 | String[] getLastNames();
31 | String[] getPrefixes();
32 | String[] getSuffixes();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/ContentDataValues.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * DataFactory is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with DataFactory. If not, see .
23 | *
24 | */
25 |
26 | public interface ContentDataValues {
27 |
28 | String[] getWords();
29 |
30 | String[] getBusinessTypes();
31 |
32 | String[] getEmailHosts();
33 |
34 | String[] getTlds();
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/AddressDataValues.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * DataFactory is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with DataFactory. If not, see .
23 | *
24 | */
25 |
26 |
27 | public interface AddressDataValues {
28 |
29 | /**
30 | * @return Array of street address
31 | */
32 | String[] getStreetNames();
33 |
34 | /**
35 | * @return Array of cities
36 | */
37 | String[] getCities();
38 |
39 | /**
40 | * Returns a list of address suffixes such as "Lane", "Drive","Parkway"
41 | * @return Array of address suffixes
42 | */
43 | String[] getAddressSuffixes();
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | org.fluttercode.datafactory
4 | datafactory
5 | 0.9-SNAPSHOT
6 |
7 | DataFactory
8 | Library to generate data for testing
9 |
10 |
11 | org.sonatype.oss
12 | oss-parent
13 | 3
14 |
15 |
16 | http://www.andygibson.net/blog/projects/
17 |
18 |
19 |
20 | Andy Gibson
21 |
22 | Developer
23 |
24 | contact@andygibson.net
25 | www.andygibson.net
26 |
27 |
28 |
29 |
30 |
31 | LGPL Version 3
32 | http://www.gnu.org/licenses/lgpl-3.0.txt
33 | repo
34 |
35 |
36 |
37 |
38 |
39 | scm:git:git://github.com/andygibson/datafactory.git
40 | scm:git:git://github.com/andygibson/datafactory
41 | scm:git:git@github.com:andygibson/datafactory.git
42 |
43 |
44 |
45 |
46 | junit
47 | junit
48 | 4.8.2
49 | jar
50 | test
51 |
52 |
53 |
54 |
55 |
56 | org.apache.maven.plugins
57 | maven-release-plugin
58 |
59 | forked-path
60 | true
61 |
62 |
63 |
64 |
65 | org.apache.maven.plugins
66 | maven-install-plugin
67 | 2.3.1
68 |
69 |
70 |
71 | org.apache.maven.plugins
72 | maven-resources-plugin
73 | 2.4.3
74 |
75 |
76 |
77 | org.apache.maven.plugins
78 | maven-deploy-plugin
79 | 2.5
80 |
81 |
82 |
83 |
84 | org.apache.maven.plugins
85 |
86 | maven-compiler-plugin
87 | 2.0.2
88 |
89 | 1.5
90 | 1.5
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/impl/DefaultContentDataValues.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory.impl;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * DataFactory is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with DataFactory. If not, see .
23 | *
24 | */
25 |
26 | import org.fluttercode.datafactory.ContentDataValues;
27 |
28 | public class DefaultContentDataValues implements ContentDataValues {
29 |
30 | public static String[] words = { "throw", "ball", "hat", "red", "worn",
31 | "list", "words", "computer", "in", "out", "hot", "cold", "warp",
32 | "speed", "captain", "assert", "hold", "room", "ship", "lost", "is",
33 | "television", "show", "about", "plane", "crash", "island",
34 | "monster", "trees", "banging", "smoke", "where", "are", "we",
35 | "was", "asked", "no", "rescue", "came", "build", "fire", "waited",
36 | "days", "moved", "to", "caves", "found", "with", "ghost", "dad",
37 | "in", "white", "rabbit", "lock", "discovered", "hatch", "with",
38 | "boon", "secretly", "hid", "it", "while", "trying", "to", "open",
39 | "it", "until", "sidekick", "died", "as", "sacrifice", "island",
40 | "demanded", "many", "had", "dreams", "or", "visions", "others",
41 | "came", "took", "people", "who", "are", "they", "what", "do",
42 | "they", "want", "light", "came", "on", "through", "window",
43 | "leader", "is", "a", "good", "man", "numbers", "in", "room",
44 | "enter", "keys", "computer", "end", "of", "world", "wicket",
45 | "magnetic", "pull", "shepherd", "always", "wrong", "much",
46 | "suspense", "what", "to", "do", "when", "it", "ends", "I", "will",
47 | "have", "to", "find", "something", "else", "to", "pique", "my",
48 | "interest", "or maybe", "write", "lots", "of", "code", "probably",
49 | "should", "have", "generated", "this", "text", "automatically",
50 | "so", "will", "from", "the", "web", "ending", "badly", "library",
51 | "handled", "books", "constantly", "headphones", "of", "ill", "on",
52 | "it's", "sill","sits","sofa" };
53 |
54 | private static String[] businessTypes = { "Furnishings", "Bakery",
55 | "Accounting", "Textiles", "Manufacturing", "Industries",
56 | "Pro Services", "Landscaping", "Realty", "Travel",
57 | "Medical supplies", "Office supplies", "Insurance", "Software",
58 | "Motors", "Cafe", "Services", "Gymnasium", "Motor Services",
59 | "Signs", "Development", "Studios", "Engineering", "Development" };
60 |
61 | private static String[] emailHosts = { "gma1l", "hotma1l", "yah00",
62 | "somema1l", "everyma1l", "ma1lbox", "b1zmail", "ma1l2u" };
63 |
64 | private static String[] tlds = { "org", "net", "com", "biz", "us", "co.uk" };
65 |
66 | public String[] getWords() {
67 | return words;
68 | }
69 |
70 | public String[] getBusinessTypes() {
71 | return businessTypes;
72 | }
73 |
74 | public String[] getEmailHosts() {
75 | return emailHosts;
76 | }
77 |
78 | public String[] getTlds() {
79 | return tlds;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/test/java/org/fluttercode/datafactory/impl/DataFactoryTextTest.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory.impl;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 |
7 | public class DataFactoryTextTest {
8 |
9 | private DataFactory dataFactory;
10 | private final int ITERATION_COUNT = 100000;
11 |
12 | @Before
13 | public void initTest() {
14 | dataFactory = DataFactory.create();
15 | dataFactory.randomize(73438);
16 | }
17 |
18 | @Test
19 | public void shouldReturnRandomWordsOfVariedLength() {
20 | for (int i = 0; i < ITERATION_COUNT; i++) {
21 | int maxLength = dataFactory.getNumberUpTo(12);
22 |
23 | String word = dataFactory.getRandomWord(maxLength, false);
24 | Assert.assertTrue("Wrong size word", word.length() <= maxLength);
25 | }
26 | }
27 |
28 | @Test
29 | public void shouldReturnRandomWordsOfSpecificLength() {
30 | for (int i = 0; i < ITERATION_COUNT; i++) {
31 | int maxLength = dataFactory.getNumberUpTo(12);
32 |
33 | String word = dataFactory.getRandomWord(maxLength, true);
34 | Assert.assertTrue("Wrong size word", word.length() == maxLength);
35 | }
36 | }
37 |
38 | @Test
39 | public void shouldReturnRandomWordsOfSpecificLength2() {
40 | for (int i = 0; i < ITERATION_COUNT; i++) {
41 | int maxLength = dataFactory.getNumberUpTo(12);
42 |
43 | String word = dataFactory.getRandomWord(maxLength, true);
44 | Assert.assertTrue("Wrong size word", word.length() == maxLength);
45 | }
46 | }
47 |
48 | @Test
49 | public void shouldReturnTextOfSpecificLength() {
50 | for (int i = 0; i < ITERATION_COUNT; i++) {
51 | int len = dataFactory.getNumberUpTo(40);
52 | String text = dataFactory.getRandomText(len);
53 | Assert.assertNotNull(text);
54 | Assert.assertTrue(String.format(
55 | "Length does not match (%d, expected %d) '%s' ",
56 | text.length(), len, text), len == text.length());
57 |
58 | }
59 | }
60 |
61 | @Test
62 | public void shouldReturnTextWithWords() {
63 | for (int i = 0; i < ITERATION_COUNT; i++) {
64 | int len = 512 + dataFactory.getNumberUpTo(128);
65 | String text = dataFactory.getRandomText(len);
66 | Assert.assertTrue(String.format(
67 | "Length does not match (%d, expected %d) '%s' ",
68 | text.length(), len, text), len == text.length());
69 | String[] words = text.split(" ");
70 | Assert.assertTrue("long texts should contain spaces",words.length>32);
71 | Assert.assertFalse("text should not contain double spaces",text.contains(" "));
72 |
73 | }
74 | }
75 |
76 | @Test
77 | public void shouldReturnTextWithinBoundedLengths() {
78 | for (int i = 0; i < ITERATION_COUNT; i++) {
79 | int minLen = 10 + dataFactory.getNumberUpTo(20);
80 | int maxLen = minLen + dataFactory.getNumberUpTo(10);
81 |
82 | String text = dataFactory.getRandomText(minLen, maxLen);
83 |
84 | Assert.assertNotNull(text);
85 |
86 | String msg = String
87 | .format("Length (%d) is less than expected minimum (%d) for iteration %d - text = '%s'",
88 | text.length(), minLen, i, text);
89 | Assert.assertTrue(msg, minLen <= text.length());
90 |
91 | msg = String
92 | .format("Length (%d) is more than expected (%d) for iteration %d - text = %s",
93 | text.length(), maxLen, i, text);
94 | Assert.assertTrue(msg, maxLen >= text.length());
95 |
96 | }
97 | }
98 |
99 | @Test
100 | public void shouldReturnRandomWordsUpToLength() {
101 | for (int i = 0; i < ITERATION_COUNT; i++) {
102 | int maxLength = dataFactory.getNumberUpTo(30);
103 |
104 | String word = dataFactory.getRandomWord(maxLength, false);
105 | Assert.assertTrue("Wrong size word", word.length() <= maxLength);
106 | }
107 |
108 | }
109 |
110 | @Test
111 | public void shouldReturnRandomNumber() {
112 | dataFactory.getNumber();
113 | }
114 |
115 | @Test
116 | public void shouldReturnNegativeNumber() {
117 | int random = dataFactory.getNumberBetween(Integer.MIN_VALUE, -1);
118 | Assert.assertTrue(random < 0);
119 | }
120 |
121 | @Test
122 | public void shouldReturnMinValue() {
123 | int random = dataFactory.getNumberBetween(Integer.MIN_VALUE, Integer.MIN_VALUE);
124 | Assert.assertEquals(Integer.MIN_VALUE, random);
125 | }
126 |
127 | @Test
128 | public void shouldReturnMaxValue() {
129 | int random = dataFactory.getNumberBetween(Integer.MAX_VALUE, Integer.MAX_VALUE);
130 | Assert.assertEquals(Integer.MAX_VALUE, random);
131 | }
132 |
133 | //Test param checking on randomWord()
134 |
135 | @Test(expected=IllegalArgumentException.class)
136 | public void shouldErrorOnNegativeLengthForRandomWord() {
137 | dataFactory.getRandomWord(-1);
138 | }
139 |
140 | @Test(expected=IllegalArgumentException.class)
141 | public void shouldErrorOnNegativeMinLenForRandomWord() {
142 | dataFactory.getRandomWord(-1,10);
143 | }
144 | @Test(expected=IllegalArgumentException.class)
145 | public void shouldErrorOnNegativeMaxLenForRandomWord() {
146 | dataFactory.getRandomWord(0,-10);
147 | }
148 |
149 |
150 | @Test(expected=IllegalArgumentException.class)
151 | public void shouldErrorOnInvalidSizeLenForRandomWord() {
152 | dataFactory.getRandomWord(10,2);
153 | }
154 |
155 |
156 | //Test param checking on randomText()
157 |
158 | @Test(expected=IllegalArgumentException.class)
159 | public void shouldErrorOnNegativeLengthForRandomText() {
160 | dataFactory.getRandomText(-1);
161 | }
162 |
163 | @Test(expected=IllegalArgumentException.class)
164 | public void shouldErrorOnNegativeMinLenForRandomText() {
165 | dataFactory.getRandomText(-1,10);
166 | }
167 | @Test(expected=IllegalArgumentException.class)
168 | public void shouldErrorOnNegativeMaxLenForRandomText() {
169 | dataFactory.getRandomText(0,-10);
170 | }
171 |
172 |
173 | @Test(expected=IllegalArgumentException.class)
174 | public void shouldErrorOnInvalidSizeLenForRandomText() {
175 | dataFactory.getRandomText(10,2);
176 | }
177 |
178 |
179 | //Test param checking on randomChars()
180 |
181 | @Test(expected=IllegalArgumentException.class)
182 | public void shouldErrorOnNegativeLengthForRandomChars() {
183 | dataFactory.getRandomChars(-1);
184 | }
185 |
186 | @Test(expected=IllegalArgumentException.class)
187 | public void shouldErrorOnNegativeMinLenForRandomChars() {
188 | dataFactory.getRandomChars(-1,10);
189 | }
190 | @Test(expected=IllegalArgumentException.class)
191 | public void shouldErrorOnNegativeMaxLenForRandomChars() {
192 | dataFactory.getRandomChars(0,-10);
193 | }
194 |
195 |
196 | @Test(expected=IllegalArgumentException.class)
197 | public void shouldErrorOnInvalidSizeLenForRandomChars() {
198 | dataFactory.getRandomChars(10,2);
199 | }
200 | }
201 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #Generate Test Data with DataFactory
2 |
3 | Feb 8th, 2011 in Articles by Andy Gibson
4 |
5 | DataFactory is a project I just released which allows you to easily generate test data. It was primarily written for populating database for dev or test environments by providing values for names, addresses, email addresses, phone numbers, text, and dates.
6 |
7 | To add DataFactory to your maven project, just add it as a dependency in your pom.xml file.
8 |
9 |
10 |
11 | org.fluttercode.datafactory
12 | datafactory
13 | 0.8
14 | jar
15 |
16 |
17 | ##Generating Test Data
18 | Now you can create instances of the DataFactory class and create data :
19 |
20 | public class Main {
21 |
22 | public static void main(String[] args) {
23 | DataFactory df = new DataFactory();
24 | for (int i = 0; i < 100; i++) {
25 | String name = df.getFirstName() + " "+ df.getLastName();
26 | System.out.println(name);
27 | }
28 | }
29 | }
30 |
31 | The produced output is :
32 |
33 | Lindsey Craft
34 | Erica Larsen
35 | Ryan Levine
36 | Erika Smith
37 | Brooklyn Sloan
38 | Karen Mayer
39 | Eddie O'neill
40 | Nancy Stevens
41 |
42 | The DataFactory class can generate different types of values, from addresses to random text to random dates, to dates within a fixed time period. Addresses and business names can be created using the following code :
43 |
44 | DataFactory df = new DataFactory();
45 | for (int i = 0; i < 100; i++) {
46 | String address = df.getAddress()+","+df.getCity()+","+df.getNumberText(5);
47 | String business = df.getBusinessName();
48 | System.out.println(business + " located at " + address);
49 | }
50 |
51 | to produce :
52 |
53 | Uvalda Signs located at 1383 Beam Way,Lyons,19316
54 | Alma Accounting located at 1386 Countiss St,Nashville,14967
55 | Fort Stewart Engineering located at 1753 Bethesda Rd,Springfield,26306
56 | Sugar Hill Textiles located at 1141 Loudon Circle,Cordele,83937
57 | Albany Engineering located at 1185 Grieves Avenue,Sugar Hill,36753
58 | Poulan Insurance located at 816 Cohen Blvd,Lake City,74839
59 | Crescent Services located at 1085 Cloveridge Boulevard,Bemiss,08769
60 |
61 | ##Dates
62 | There are a number of features to create dates, the first being creating a random date which is usually in a given sensible date range.
63 |
64 | DataFactory df = new DataFactory();
65 | Date minDate = df.getDate(2000, 1, 1);
66 | Date maxDate = new Date();
67 | for (int i = 0; i < 10; i++) {
68 | Date start = df.getDateBetween(minDate, maxDate);
69 | System.out.println("Date = "+start);
70 | }
71 |
72 | This produces a list of random dates between 1/1/2000 and the current date. Typically, a random date might be constrained by some other date, for example you can’t have an end date that occurs before the start date. In this case, you would plug the start date in as the minimum date value :
73 |
74 | DataFactory df = new DataFactory();
75 | Date minDate = df.getDate(2000, 1, 1);
76 | Date maxDate = new Date();
77 |
78 | for (int i = 0; i < 10; i++) {
79 | Date start = df.getDateBetween(minDate, maxDate);
80 | Date end = df.getDateBetween(start, maxDate);
81 | System.out.println("Date range = " + dateToString(start) + " to " + dateToString(end));
82 | }
83 |
84 | The result is a list of dates where the second date is always later than the first :
85 |
86 | Date range = 04/29/2005 to 07/16/2006
87 | Date range = 08/07/2009 to 01/19/2010
88 | Date range = 09/22/2000 to 12/15/2003
89 | Date range = 07/31/2004 to 03/24/2009
90 | Date range = 06/27/2003 to 01/10/2007
91 | Date range = 07/10/2003 to 04/02/2008
92 | Date range = 01/04/2003 to 01/12/2005
93 |
94 | In many cases, you might want your end date to be only within a few days of the start date. For example, helpdesk support tickets or hotel stays don’t last for years. To do this, you can specify the number of days from the base date you want to generate a result. In this case, we make the end date within 10 days of the begin date :
95 |
96 |
97 | for (int i = 0; i < 10; i++) {
98 | Date start = df.getDateBetween(minDate, maxDate);
99 | Date end = df.getDate(start, 0, 10); //set end to within 10 days of the start
100 | System.out.println("Date range = " + dateToString(start) + " to " + dateToString(end));
101 | }
102 |
103 | And the result :
104 |
105 | Date range = 04/29/2005 to 04/30/2005
106 | Date range = 12/29/2003 to 12/30/2003
107 | Date range = 06/25/2003 to 07/03/2003
108 | Date range = 10/19/2009 to 10/19/2009
109 |
110 | You can also specify a negative minimum days value that could return a date prior to the base date or a positive minimum date value to get a later date. Here’s a more complex example that uses different date rules to come up with some complex test data.
111 |
112 |
113 | for (int i = 0; i < 10; i++) {
114 | //generate an order date
115 | Date orderDate = df.getDateBetween(minDate, maxDate);
116 |
117 | //estimate delivery 4-10 days after ordering
118 | Date estimatedDeliveryDate = df.getDate(orderDate, 4, 10);
119 |
120 | //deliver between 2 days prior and 3 days after delivery estimate
121 | Date actualDeliveryDate = df.getDate(estimatedDeliveryDate, -2, 3);
122 |
123 | String msg = "Ordered on "+dateToString(orderDate) +
124 | " deliver by = "+dateToString(estimatedDeliveryDate)+
125 | " delivered on " + dateToString(actualDeliveryDate);
126 |
127 | if (estimatedDeliveryDate.before(actualDeliveryDate)) {
128 | msg = msg + " - LATE";
129 | }
130 | if (estimatedDeliveryDate.after(actualDeliveryDate)) {
131 | msg = msg + " - EARLY";
132 | }
133 | System.out.println(msg);
134 | }
135 |
136 | Here we calculate an order date, and create a delivery date that is at least 4 days out but no more than 10, and then we created an actual delivery date that is between 2 days prior and 3 days after the expected delivery date.
137 | Notice how we cherry picked the dates, the estimated delivery date is at least 4 days out from the order date, and the actual delivery date will only be at most 2 days prior to the estimated date. This means the actual delivery date is always at least 2 days out from the order date and we won’t get a delivery date value that is before the item was ordered. This code produces the following values :
138 |
139 |
140 | Ordered on 04/29/2005 deliver by = 05/06/2005 delivered on 05/06/2005
141 | Ordered on 08/07/2009 deliver by = 08/13/2009 delivered on 08/13/2009
142 | Ordered on 09/22/2000 deliver by = 09/27/2000 delivered on 09/25/2000 - EARLY
143 | Ordered on 07/31/2004 deliver by = 08/07/2004 delivered on 08/09/2004 - LATE
144 | Ordered on 06/27/2003 deliver by = 07/04/2003 delivered on 07/04/2003
145 | Ordered on 07/10/2003 deliver by = 07/19/2003 delivered on 07/18/2003 - EARLY
146 | Ordered on 01/04/2003 deliver by = 01/08/2003 delivered on 01/08/2003
147 |
148 | ##Custom Random Values
149 |
150 | If there is a set of values that is very specific to your application that you might want to generate data from, you can use methods on the DataFactory class to return values with the option for it to be randomly be a default value.
151 |
152 | public static void main(String[] args) {
153 | DataFactory df = new DataFactory();
154 |
155 | //favorite animal
156 | String[] values = {"Cat","Dog","Goat","Horse","Sheep"};
157 | for (int i = 0; i < 100; i++) {
158 | System.out.println(df.getItem(values,80,"None"));
159 | }
160 | }
161 |
162 | This example uses the array of animals and returns a value with a 20% chance of being the default value of “None” to produce the following :
163 |
164 | Sheep
165 | None
166 | Dog
167 | Horse
168 |
169 | ##Textual Data
170 |
171 | Random text data comes in two forms, absolutely random data and text data made up of words. You can generate either using the following methods :
172 |
173 | DataFactory df = new DataFactory();
174 | System.out.println(df.getRandomText(20, 25));
175 | System.out.println(df.getRandomChars(20));
176 | System.out.println(df.getRandomWord(4, 10))
177 |
178 | which produces
179 |
180 | badly numbers good hot I
181 | ywyypgqorighfawpftjq
182 | demanded
183 |
184 | All three of these methods can be passed a single length which returns a fixed length string, or a min/max length which produces a random string with a length somewhere between the min/max. For the single word method, if there are no words in the dictionary of suitable length, then a word is generated using random characters.
185 |
186 | Changing the test data values produced
187 | The data used to generate the values come from classes that can be replaced with other versions. For example, the name values can be changed by providing the DataFactory instance with an object that implements the NameDataValues interface. Here is a simple class that does that to return Scandinavian first names and delegates to the the default implementation to return all the other values.
188 |
189 |
190 | public class ScandinavianNames implements NameDataValues {
191 |
192 | //first name values to use
193 | String[] firstNames = {"Anders","Freydís","Gerlach","Sigdis"};
194 |
195 | //delegate to the default implementation for the other values
196 | NameDataValues defaults = new DefaultNameDataValues();
197 |
198 | public String[] getFirstNames() {
199 | //return our custom list of names
200 | return firstNames;
201 | }
202 |
203 | //for the other values, just use the defaults
204 | public String[] getLastNames() {
205 | return defaults.getLastNames();
206 | }
207 |
208 | public String[] getPrefixes() {
209 | return defaults.getPrefixes();
210 | }
211 |
212 | public String[] getSuffixes() {
213 | return defaults.getSuffixes();
214 | }
215 |
216 | }
217 |
218 | Obviously, to use all your own names you would add and return values for last name and the suffix/prefix values. To use this new implementation, just create an instance of the data provider and pass it to the instance of the data factory.
219 |
220 |
221 | public static void main(String[] args) {
222 | DataFactory df = new DataFactory();
223 | df.setNameDataValues(new ScandinavianNames());
224 | for (int i = 0; i < 10; i++) {
225 | System.out.println(df.getName());
226 | }
227 | }
228 |
229 | Our results are:
230 |
231 | Sigdis Craft
232 | Gerlach Larsen
233 | Sigdis Levine
234 | Sigdis Smith
235 | Freydís Sloan
236 | Gerlach Mayer
237 |
238 | You can always start working with the default implementation and use a more locale specific implementation if you need it later.
239 |
240 | The different pieces that can be replaced are as follows :
241 |
242 | NameDataValues – Generates names and suffix/prefixes
243 | ContentDataValues.java – Generates words, business types, email domain names and top level domain values
244 | AddressDataValues – Generates city names, street names and address suffixes
245 | Note that if you intend on replacing the component that generates words, you should have a good collection of words of various lengths from 2 up to say 8 or more characters.
246 |
247 | Hopefully this will give you a head start in generating data in development and test environments for new projects. Now I have DataFactory in the Central Maven Repository I plan on using this in the Knappsack archetypes rather than hard coding the data which was in fact generated from an earlier DataFactory implementation.
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/impl/DefaultNameDataValues.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory.impl;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * DataFactory is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with DataFactory. If not, see .
23 | *
24 | */
25 |
26 | import org.fluttercode.datafactory.NameDataValues;
27 |
28 | public class DefaultNameDataValues implements NameDataValues {
29 |
30 | private static String[] suffixes = { "II", "III", "Phd", "Jr", "Sr" };
31 | private static String[] prefixes = { "Mr", "Mrs", "Ms" };
32 | private static String[] firstNames = { "Aaron", "Abby", "Abigail", "Adam",
33 | "Alan", "Albert", "Alex", "Alexandra", "Alexis", "Alice", "Alicia",
34 | "Alisha", "Alissa", "Allen", "Allison", "Alyssa", "Amanda",
35 | "Amber", "Amy", "Andrea", "Andrew", "Andy", "Angel", "Angela",
36 | "Angie", "Anita", "Ann", "Anna", "Annette", "Anthony", "Antonio",
37 | "April", "Arthur", "Ashley", "Audrey", "Austin", "Autumn", "Baby",
38 | "Barb", "Barbara", "Becky", "Benjamin", "Beth", "Bethany", "Betty",
39 | "Beverly", "Bill", "Billie", "Billy", "Blake", "Bob", "Bobbie",
40 | "Bobby", "Bonnie", "Brad", "Bradley", "Brady", "Brandi", "Brandon",
41 | "Brandy", "Breanna", "Brenda", "Brent", "Brett", "Brian",
42 | "Brianna", "Brittany", "Brooke", "Brooklyn", "Bruce", "Bryan",
43 | "Caleb", "Cameron", "Candy", "Carl", "Carla", "Carmen", "Carol",
44 | "Carolyn", "Carrie", "Casey", "Cassandra", "Catherine", "Cathy",
45 | "Chad", "Charlene", "Charles", "Charlie", "Charlotte", "Chase",
46 | "Chasity", "Chastity", "Chelsea", "Cheryl", "Chester", "Cheyenne",
47 | "Chris", "Christian", "Christina", "Christine", "Christoph",
48 | "Christopher", "Christy", "Chuck", "Cindy", "Clara", "Clarence",
49 | "Clayton", "Clifford", "Clint", "Cody", "Colton", "Connie",
50 | "Corey", "Cory", "Courtney", "Craig", "Crystal", "Curtis",
51 | "Cynthia", "Dakota", "Dale", "Dallas", "Dalton", "Dan", "Dana",
52 | "Daniel", "Danielle", "Danny", "Darla", "Darlene", "Darrell",
53 | "Darren", "Dave", "David", "Dawn", "Dean", "Deanna", "Debbie",
54 | "Deborah", "Debra", "Denise", "Dennis", "Derek", "Derrick",
55 | "Destiny", "Devin", "Diana", "Diane", "Dillon", "Dixie", "Dominic",
56 | "Don", "Donald", "Donna", "Donnie", "Doris", "Dorothy", "Doug",
57 | "Douglas", "Drew", "Duane", "Dustin", "Dusty", "Dylan", "Earl",
58 | "Ed", "Eddie", "Edward", "Elaine", "Elizabeth", "Ellen", "Emily",
59 | "Eric", "Erica", "Erika", "Erin", "Ernest", "Ethan", "Eugene",
60 | "Eva", "Evelyn", "Everett", "Faith", "Father", "Felicia", "Floyd",
61 | "Francis", "Frank", "Fred", "Gabriel", "Gage", "Gail", "Gary",
62 | "Gene", "George", "Gerald", "Gina", "Ginger", "Glen", "Glenn",
63 | "Gloria", "Grace", "Greg", "Gregory", "Haley", "Hannah", "Harley",
64 | "Harold", "Harry", "Heath", "Heather", "Heidi", "Helen", "Herbert",
65 | "Holly", "Hope", "Howard", "Hunter", "Ian", "Isaac", "Jack",
66 | "Jackie", "Jacob", "Jade", "Jake", "James", "Jamie", "Jan", "Jane",
67 | "Janet", "Janice", "Jared", "Jasmine", "Jason", "Jay", "Jean",
68 | "Jeannie", "Jeff", "Jeffery", "Jeffrey", "Jenna", "Jennifer",
69 | "Jenny", "Jeremiah", "Jeremy", "Jerry", "Jesse", "Jessica",
70 | "Jessie", "Jill", "Jim", "Jimmy", "Joann", "Joanne", "Jodi",
71 | "Jody", "Joe", "Joel", "Joey", "John", "Johnathan", "Johnny",
72 | "Jon", "Jonathan", "Jonathon", "Jordan", "Joseph", "Josh",
73 | "Joshua", "Joyce", "Juanita", "Judy", "Julia", "Julie", "Justin",
74 | "Kaitlyn", "Karen", "Katelyn", "Katherine", "Kathleen", "Kathryn",
75 | "Kathy", "Katie", "Katrina", "Kay", "Kayla", "Kaylee", "Keith",
76 | "Kelly", "Kelsey", "Ken", "Kendra", "Kenneth", "Kenny", "Kevin",
77 | "Kim", "Kimberly", "Kris", "Krista", "Kristen", "Kristin",
78 | "Kristina", "Kristy", "Kyle", "Kylie", "Lacey", "Laken", "Lance",
79 | "Larry", "Laura", "Lawrence", "Leah", "Lee", "Leonard", "Leroy",
80 | "Leslie", "Levi", "Lewis", "Linda", "Lindsay", "Lindsey", "Lisa",
81 | "Lloyd", "Logan", "Lois", "Loretta", "Lori", "Louis", "Lynn",
82 | "Madison", "Mandy", "Marcus", "Margaret", "Maria", "Mariah",
83 | "Marie", "Marilyn", "Marion", "Mark", "Marlene", "Marsha",
84 | "Martha", "Martin", "Marty", "Marvin", "Mary", "Mary ann", "Mason",
85 | "Matt", "Matthew", "Max", "Megan", "Melanie", "Melinda", "Melissa",
86 | "Melody", "Michael", "Michelle", "Mickey", "Mike", "Mindy",
87 | "Miranda", "Misty", "Mitchell", "Molly", "Monica", "Morgan",
88 | "Mother", "Myron", "Nancy", "Natasha", "Nathan", "Nicholas",
89 | "Nick", "Nicole", "Nina", "Noah", "Norma", "Norman", "Olivia",
90 | "Paige", "Pam", "Pamela", "Pat", "Patricia", "Patrick", "Patty",
91 | "Paul", "Paula", "Peggy", "Penny", "Pete", "Phillip", "Phyllis",
92 | "Rachael", "Rachel", "Ralph", "Randall", "Randi", "Randy", "Ray",
93 | "Raymond", "Rebecca", "Regina", "Renee", "Rex", "Rhonda",
94 | "Richard", "Rick", "Ricky", "Rita", "Rob", "Robbie", "Robert",
95 | "Roberta", "Robin", "Rochelle", "Rocky", "Rod", "Rodney", "Roger",
96 | "Ron", "Ronald", "Ronda", "Ronnie", "Rose", "Roxanne", "Roy",
97 | "Russ", "Russell", "Rusty", "Ruth", "Ryan", "Sabrina", "Sally",
98 | "Sam", "Samantha", "Samuel", "Sandra", "Sandy", "Sara", "Sarah",
99 | "Savannah", "Scott", "Sean", "Seth", "Shanda", "Shane", "Shanna",
100 | "Shannon", "Sharon", "Shaun", "Shawn", "Shawna", "Sheila",
101 | "Shelly", "Sher", "Sherri", "Sherry", "Shirley", "Sierra",
102 | "Skyler", "Stacey", "Stacy", "Stanley", "Stephanie", "Stephen",
103 | "Steve", "Steven", "Sue", "Summer", "Susan", "Sydney", "Tabatha",
104 | "Tabitha", "Tamara", "Tammy", "Tara", "Tasha", "Tashia", "Taylor",
105 | "Ted", "Teresa", "Terri", "Terry", "Tessa", "Thelma", "Theresa",
106 | "Thomas", "Tia", "Tiffany", "Tim", "Timmy", "Timothy", "Tina",
107 | "Todd", "Tom", "Tommy", "Toni", "Tony", "Tonya", "Tracey",
108 | "Tracie", "Tracy", "Travis", "Trent", "Trevor", "Trey", "Trisha",
109 | "Tristan", "Troy", "Tyler", "Tyrone", "Unborn", "Valerie",
110 | "Vanessa", "Vernon", "Veronica", "Vicki", "Vickie", "Vicky",
111 | "Victor", "Victoria", "Vincent", "Virginia", "Vivian", "Walter",
112 | "Wanda", "Wayne", "Wendy", "Wesley", "Whitney", "William",
113 | "Willie", "Wyatt", "Zachary" };
114 |
115 | private static String[] lastNames = { "Abbott", "Acevedo", "Acosta",
116 | "Adams", "Adkins", "Aguilar", "Aguirre", "Albert", "Alexander",
117 | "Alford", "Allen", "Allison", "Alston", "Alvarado", "Alvarez",
118 | "Anderson", "Andrews", "Anthony", "Armstrong", "Arnold", "Ashley",
119 | "Atkins", "Atkinson", "Austin", "Avery", "Avila", "Ayala", "Ayers",
120 | "Bailey", "Baird", "Baker", "Baldwin", "Ball", "Ballard", "Banks",
121 | "Barber", "Smith", "Johnson", "Williams", "Jones", "Brown",
122 | "Davis", "Miller", "Wilson", "Moore", "Taylor", "Thomas",
123 | "Jackson", "Barker", "Barlow", "Barnes", "Barnett", "Barr",
124 | "Barrera", "Barrett", "Barron", "Barry", "Bartlett", "Barton",
125 | "Bass", "Bates", "Battle", "Bauer", "Baxter", "Beach", "Bean",
126 | "Beard", "Beasley", "Beck", "Becker", "Bell", "Bender", "Benjamin",
127 | "Bennett", "Benson", "Bentley", "Benton", "Berg", "Berger",
128 | "Bernard", "Berry", "Best", "Bird", "Bishop", "Black", "Blackburn",
129 | "Blackwell", "Blair", "Blake", "Blanchard", "Blankenship",
130 | "Blevins", "Bolton", "Bond", "Bonner", "Booker", "Boone", "Booth",
131 | "Bowen", "Bowers", "Bowman", "Boyd", "Boyer", "Boyle", "Bradford",
132 | "Bradley", "Bradshaw", "Brady", "Branch", "Bray", "Brennan",
133 | "Brewer", "Bridges", "Briggs", "Bright", "Britt", "Brock",
134 | "Brooks", "Browning", "Bruce", "Bryan", "Bryant", "Buchanan",
135 | "Buck", "Buckley", "Buckner", "Bullock", "Burch", "Burgess",
136 | "Burke", "Burks", "Burnett", "Burns", "Burris", "Burt", "Burton",
137 | "Bush", "Butler", "Byers", "Byrd", "Cabrera", "Cain", "Calderon",
138 | "Caldwell", "Calhoun", "Callahan", "Camacho", "Cameron",
139 | "Campbell", "Campos", "Cannon", "Cantrell", "Cantu", "Cardenas",
140 | "Carey", "Carlson", "Carney", "Carpenter", "Carr", "Carrillo",
141 | "Carroll", "Carson", "Carter", "Carver", "Case", "Casey", "Cash",
142 | "Castaneda", "Castillo", "Castro", "Cervantes", "Chambers", "Chan",
143 | "Chandler", "Chaney", "Chang", "Chapman", "Charles", "Chase",
144 | "Chavez", "Chen", "Cherry", "Christensen", "Christian", "Church",
145 | "Clark", "Clarke", "Clay", "Clayton", "Clements", "Clemons",
146 | "Cleveland", "Cline", "Cobb", "Cochran", "Coffey", "Cohen", "Cole",
147 | "Coleman", "Collier", "Collins", "Colon", "Combs", "Compton",
148 | "Conley", "Conner", "Conrad", "Contreras", "Conway", "Cook",
149 | "Cooke", "Cooley", "Cooper", "Copeland", "Cortez", "Cote",
150 | "Cotton", "Cox", "Craft", "Craig", "Crane", "Crawford", "Crosby",
151 | "Cross", "Cruz", "Cummings", "Cunningham", "Curry", "Curtis",
152 | "Dale", "Dalton", "Daniel", "Daniels", "Daugherty", "Davenport",
153 | "David", "Davidson", "Dawson", "Day", "Dean", "Decker", "Dejesus",
154 | "Delacruz", "Delaney", "Deleon", "Delgado", "Dennis", "Diaz",
155 | "Dickerson", "Dickinson", "Dillard", "Dillon", "Dixon", "Dodson",
156 | "Dominguez", "Donaldson", "Donovan", "Dorsey", "Dotson", "Douglas",
157 | "Downs", "Doyle", "Drake", "Dudley", "Duffy", "Duke", "Duncan",
158 | "Dunlap", "Dunn", "Duran", "Durham", "Dyer", "Eaton", "Edwards",
159 | "Elliott", "Ellis", "Ellison", "Emerson", "England", "English",
160 | "Erickson", "Espinoza", "Estes", "Estrada", "Evans", "Everett",
161 | "Ewing", "Farley", "Farmer", "Farrell", "Faulkner", "Ferguson",
162 | "Fernandez", "Ferrell", "Fields", "Figueroa", "Finch", "Finley",
163 | "Fischer", "Fisher", "Fitzgerald", "Fitzpatrick", "Fleming",
164 | "Fletcher", "Flores", "Flowers", "Floyd", "Flynn", "Foley",
165 | "Forbes", "Ford", "Foreman", "Foster", "Fowler", "Fox", "Francis",
166 | "Franco", "Frank", "Franklin", "Franks", "Frazier", "Frederick",
167 | "Freeman", "French", "Frost", "Fry", "Frye", "Fuentes", "Fuller",
168 | "Fulton", "Gaines", "Gallagher", "Gallegos", "Galloway", "Gamble",
169 | "Garcia", "Gardner", "Garner", "Garrett", "Garrison", "Garza",
170 | "Gates", "Gay", "Gentry", "George", "Gibbs", "Gibson", "Gilbert",
171 | "Giles", "Gill", "Gillespie", "Gilliam", "Gilmore", "Glass",
172 | "Glenn", "Glover", "Goff", "Golden", "Gomez", "Gonzales",
173 | "Gonzalez", "Good", "Goodman", "Goodwin", "Gordon", "Gould",
174 | "Graham", "Grant", "Graves", "Gray", "Green", "Greene", "Greer",
175 | "Gregory", "Griffin", "Griffith", "Grimes", "Gross", "Guerra",
176 | "Guerrero", "Guthrie", "Gutierrez", "Guy", "Guzman", "Hahn",
177 | "Hale", "Haley", "Hall", "Hamilton", "Hammond", "Hampton",
178 | "Hancock", "Haney", "Hansen", "Hanson", "Hardin", "Harding",
179 | "Hardy", "Harmon", "Harper", "Harris", "Harrington", "Harrison",
180 | "Hart", "Hartman", "Harvey", "Hatfield", "Hawkins", "Hayden",
181 | "Hayes", "Haynes", "Hays", "Head", "Heath", "Hebert", "Henderson",
182 | "Hendricks", "Hendrix", "Henry", "Hensley", "Henson", "Herman",
183 | "Hernandez", "Herrera", "Herring", "Hess", "Hester", "Hewitt",
184 | "Hickman", "Hicks", "Higgins", "Hill", "Hines", "Hinton", "Hobbs",
185 | "Hodge", "Hodges", "Hoffman", "Hogan", "Holcomb", "Holden",
186 | "Holder", "Holland", "Holloway", "Holman", "Holmes", "Holt",
187 | "Hood", "Hooper", "Hoover", "Hopkins", "Hopper", "Horn", "Horne",
188 | "Horton", "House", "Houston", "Howard", "Howe", "Howell",
189 | "Hubbard", "Huber", "Hudson", "Huff", "Huffman", "Hughes", "Hull",
190 | "Humphrey", "Hunt", "Hunter", "Hurley", "Hurst", "Hutchinson",
191 | "Hyde", "Ingram", "Irwin", "Jacobs", "Jacobson", "James", "Jarvis",
192 | "Jefferson", "Jenkins", "Jennings", "Jensen", "Jimenez", "Johns",
193 | "Johnston", "Jordan", "Joseph", "Joyce", "Joyner", "Juarez",
194 | "Justice", "Kane", "Kaufman", "Keith", "Keller", "Kelley", "Kelly",
195 | "Kemp", "Kennedy", "Kent", "Kerr", "Key", "Kidd", "Kim", "King",
196 | "Kinney", "Kirby", "Kirk", "Kirkland", "Klein", "Kline", "Knapp",
197 | "Knight", "Knowles", "Knox", "Koch", "Kramer", "Lamb", "Lambert",
198 | "Lancaster", "Landry", "Lane", "Lang", "Langley", "Lara", "Larsen",
199 | "Larson", "Lawrence", "Lawson", "Le", "Leach", "Leblanc", "Lee",
200 | "Leon", "Leonard", "Lester", "Levine", "Levy", "Lewis", "Lindsay",
201 | "Lindsey", "Little", "Livingston", "Lloyd", "Logan", "Long",
202 | "Lopez", "Lott", "Love", "Lowe", "Lowery", "Lucas", "Luna",
203 | "Lynch", "Lynn", "Lyons", "Macdonald", "Macias", "Mack", "Madden",
204 | "Maddox", "Maldonado", "Malone", "Mann", "Manning", "Marks",
205 | "Marquez", "Marsh", "Marshall", "Martin", "Martinez", "Mason",
206 | "Massey", "Mathews", "Mathis", "Matthews", "Maxwell", "May",
207 | "Mayer", "Maynard", "Mayo", "Mays", "McBride", "McCall",
208 | "McCarthy", "McCarty", "McClain", "McClure", "McConnell",
209 | "McCormick", "McCoy", "McCray", "McCullough", "McDaniel",
210 | "McDonald", "McDowell", "McFadden", "McFarland", "McGee",
211 | "McGowan", "McGuire", "McIntosh", "McIntyre", "McKay", "McKee",
212 | "McKenzie", "McKinney", "McKnight", "McLaughlin", "McLean",
213 | "McLeod", "McMahon", "McMillan", "McNeil", "McPherson", "Meadows",
214 | "Medina", "Mejia", "Melendez", "Melton", "Mendez", "Mendoza",
215 | "Mercado", "Mercer", "Merrill", "Merritt", "Meyer", "Meyers",
216 | "Michael", "Middleton", "Miles", "Mills", "Miranda", "Mitchell",
217 | "Molina", "Monroe", "Montgomery", "Montoya", "Moody", "Moon",
218 | "Mooney", "Morales", "Moran", "Moreno", "Morgan", "Morin",
219 | "Morris", "Morrison", "Morrow", "Morse", "Morton", "Moses",
220 | "Mosley", "Moss", "Mueller", "Mullen", "Mullins", "Munoz",
221 | "Murphy", "Murray", "Myers", "Nash", "Navarro", "Neal", "Nelson",
222 | "Newman", "Newton", "Nguyen", "Nichols", "Nicholson", "Nielsen",
223 | "Nieves", "Nixon", "Noble", "Noel", "Nolan", "Norman", "Norris",
224 | "Norton", "Nunez", "Obrien", "Ochoa", "Oconnor", "Odom",
225 | "Odonnell", "Oliver", "Olsen", "Olson", "O'neal", "O'neil",
226 | "O'neill", "Orr", "Ortega", "Ortiz", "Osborn", "Osborne", "Owen",
227 | "Owens", "Pace", "Pacheco", "Padilla", "Page", "Palmer", "Park",
228 | "Parker", "Parks", "Parrish", "Parsons", "Pate", "Patel",
229 | "Patrick", "Patterson", "Patton", "Paul", "Payne", "Pearson",
230 | "Peck", "Pena", "Pennington", "Perez", "Perkins", "Perry",
231 | "Peters", "Petersen", "Peterson", "Petty", "Phelps", "Phillips",
232 | "Pickett", "Pierce", "Pittman", "Pitts", "Pollard", "Poole",
233 | "Pope", "Porter", "Potter", "Potts", "Powell", "Powers", "Pratt",
234 | "Preston", "Price", "Prince", "Pruitt", "Puckett", "Pugh", "Quinn",
235 | "Ramirez", "Ramos", "Ramsey", "Randall", "Randolph", "Rasmussen",
236 | "Ratliff", "Ray", "Raymond", "Reed", "Reese", "Reeves", "Reid",
237 | "Reilly", "Reyes", "Reynolds", "Rhodes", "Rice", "Rich", "Richard",
238 | "Richards", "Richardson", "Richmond", "Riddle", "Riggs", "Riley",
239 | "Rios", "Rivas", "Rivera", "Rivers", "Roach", "Robbins",
240 | "Roberson", "Roberts", "Robertson", "Robinson", "Robles", "Rocha",
241 | "Rodgers", "Rodriguez", "Rodriquez", "Rogers", "Rojas", "Rollins",
242 | "Roman", "Romero", "Rosa", "Rosales", "Rosario", "Rose", "Ross",
243 | "Roth", "Rowe", "Rowland", "Roy", "Ruiz", "Rush", "Russell",
244 | "Russo", "Rutledge", "Ryan", "Salas", "Salazar", "Salinas",
245 | "Sampson", "Sanchez", "Sanders", "Sandoval", "Sanford", "Santana",
246 | "Santiago", "Santos", "Sargent", "Saunders", "Savage", "Sawyer",
247 | "Schmidt", "Schneider", "Schroeder", "Schultz", "Schwartz",
248 | "Scott", "Sears", "Sellers", "Serrano", "Sexton", "Shaffer",
249 | "Shannon", "Sharp", "Sharpe", "Shaw", "Shelton", "Shepard",
250 | "Shepherd", "Sheppard", "Sherman", "Shields", "Short", "Silva",
251 | "Simmons", "Simon", "Simpson", "Sims", "Singleton", "Skinner",
252 | "Slater", "Sloan", "Small", "Snider", "Snow", "Snyder", "Solis",
253 | "Solomon", "Sosa", "Soto", "Sparks", "Spears", "Spence", "Spencer",
254 | "Stafford", "Stanley", "Stanton", "Stark", "Steele", "Stein",
255 | "Stephens", "Stephenson", "Stevens", "Stevenson", "Stewart",
256 | "Stokes", "Stone", "Stout", "Strickland", "Strong", "Stuart",
257 | "Suarez", "Sullivan", "Summers", "Sutton", "Swanson", "Sweeney",
258 | "Sweet", "Sykes", "Talley", "Tanner", "Tate", "Terrell", "Terry",
259 | "Thompson", "Thornton", "Tillman", "Todd", "Torres", "Townsend",
260 | "Tran", "Travis", "Trevino", "Trujillo", "Tucker", "Turner",
261 | "Tyler", "Tyson", "Underwood", "Valdez", "Valencia", "Valentine",
262 | "Valenzuela", "Vance", "Vang", "Vargas", "Vasquez", "Vaughan",
263 | "Vaughn", "Vazquez", "Vega", "Velasquez", "Velazquez", "Velez",
264 | "Van halen", "Vincent", "Vinson", "Wade", "Wagner", "Walker",
265 | "Wall", "Wallace", "Waller", "Walls", "Walsh", "Walter", "Walters",
266 | "Walton", "Ward", "Ware", "Warner", "Warren", "Washington",
267 | "Waters", "Watkins", "Watson", "Watts", "Weaver", "Webb", "Weber",
268 | "Webster", "Weeks", "Weiss", "Welch", "Wells", "West", "Wheeler",
269 | "Whitaker", "White", "Whitehead", "Whitfield", "Whitley",
270 | "Whitney", "Wiggins", "Wilcox", "Wilder", "Wiley", "Wilkerson",
271 | "Wilkins", "Wilkinson", "William", "Williamson", "Willis",
272 | "Winters", "Wise", "Witt", "Wolf", "Wolfe", "Wong", "Wood",
273 | "Woodard", "Woods", "Woodward", "Wooten", "Workman", "Wright",
274 | "Wyatt", "Wynn", "Yang", "Yates", "York", "Young", "Zamora",
275 | "Zimmerman"
276 |
277 | };
278 |
279 | public String[] getFirstNames() {
280 | return firstNames;
281 | }
282 |
283 | public String[] getLastNames() {
284 | return lastNames;
285 | }
286 |
287 | public String[] getPrefixes() {
288 | return prefixes;
289 | }
290 |
291 | public String[] getSuffixes() {
292 | return suffixes;
293 | }
294 |
295 | }
296 |
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/impl/DefaultAddressDataValues.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory.impl;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU Lesser General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * DataFactory is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU Lesser General Public License for more details.
19 | *
20 | *
21 | * You should have received a copy of the GNU Lesser General Public License
22 | * along with DataFactory. If not, see .
23 | *
24 | */
25 |
26 | import org.fluttercode.datafactory.AddressDataValues;
27 |
28 | public class DefaultAddressDataValues implements AddressDataValues {
29 |
30 | private static String[] streetNames = { "Aberdeen", "Abington", "Academy",
31 | "Adair", "Adams", "Adamsville", "Aeryview", "Agines", "Airport",
32 | "Airwood", "Akron", "Alameda", "Albert", "Albright", "Alburn",
33 | "Alexis", "Alfred", "Alice", "Alkire", "Allen", "Allison", "Alvin",
34 | "Ambarassdor", "Amber", "Amhurst", "Amsterdam", "Antigua",
35 | "Applegate", "Arborwood", "Arcadia", "Arch", "Archer", "Arlington",
36 | "Armco", "Armstrong", "Arnold", "Arrowhead", "Arthur", "Ashburton",
37 | "Ashley", "Aspen", "Athena", "Athens", "Atlantic", "Auburn",
38 | "Austin", "Avalon", "Avon", "Axline", "Ayers", "Babbs", "Back",
39 | "Bagley", "Bailey", "Baird", "Baker", "Ball", "Ballard", "Ballov",
40 | "Bank", "Bardith", "Barkey", "Barkley", "Barnes", "Barr", "Basil",
41 | "Basin", "Bateman", "Baughman", "Beam", "Beard", "Beatty",
42 | "Beauty", "Beech", "Beechcreek", "Beechmont", "Beeline", "Belden",
43 | "Bell", "Bellflower", "Bellview", "Bellwood", "Belmont",
44 | "Benjamin", "Bennett", "Benwood", "Berkley", "Best", "Bethesda",
45 | "Beulah", "Beverly", "Bexley", "Billingsley", "Bissett", "Bisson",
46 | "Black", "Blackburn", "Blackrun", "Blackstone", "Blackwood",
47 | "Blaine", "Blalock", "Blandy", "Blennerhassett", "Blocksom",
48 | "Bloomfield", "Blossom", "Blue", "Bluff", "Bobby", "Bodmann",
49 | "Boggs", "Bolen", "Bolton", "Bonaparte", "Bonifield", "Bonnair",
50 | "Bonsels", "Boston", "Bottom", "Bowman", "Bowser", "Bowtown",
51 | "Bradington", "Branch", "Brandywine", "Breezewood", "Brewers",
52 | "Briarbush", "Briarcliff", "Briarleigh", "Brick", "Bridge",
53 | "Brighton", "Brill", "Bristol", "Britton", "Broad", "Broadvue",
54 | "Broadway", "Brookfield", "Brookover", "Brookside", "Brown",
55 | "Browns", "Bryan", "Buck", "Buckeye", "Buckingham", "Burbank",
56 | "Burlington", "Burnell", "Burnet", "Burns", "Busch", "Butler",
57 | "Butter", "Buttermilk", "Byrne", "Caleb", "Calvert", "Cambon",
58 | "Cambridge", "Camden", "Camp", "Campbell", "Canal", "Candlestick",
59 | "Canewood", "Canfield", "Cannelville", "Canneville", "Cannon",
60 | "Carbondale", "Carey", "Carl", "Carlisle", "Carlton", "Carlysle",
61 | "Carmen", "Carol", "Carpenter", "Carroll", "Carson", "Carver",
62 | "Cass", "Caston", "Castor", "Catalpa", "Cathy", "Catt", "Cattail",
63 | "Cattle", "Cecil", "Cedar", "Cedarhurst", "Celina", "Cementary",
64 | "Cemetery", "Center", "Central", "Ceramic", "Chalfant",
65 | "Chandlersville", "Chapman", "Chardon", "Charlene", "Charles",
66 | "Chase", "Chatauqua", "Chatham", "Cheney", "Cherlick", "Cherry",
67 | "Chesapeake", "Chester", "Chesterfield", "Chestnut", "Chevington",
68 | "Chewelah", "Childrens", "Chillicothe", "China", "Choctaw",
69 | "Christopher", "Christy", "Church", "Churchfield", "Circle",
70 | "Circleville", "Clairbourne", "Claire", "Clarence", "Clarendon",
71 | "Clarice", "Clark", "Clary", "Clay", "Claysville", "Clearcreek",
72 | "Clearey", "Clearport", "Clearview", "Cleve", "Cleveland",
73 | "Clevenger", "Cliffrock", "Cliffwood", "Clinton", "Clover",
74 | "Cloveridge", "Clyde", "Coburg", "Cochran", "Codell", "Cohen",
75 | "Colburn", "College", "Collingwood", "Collins", "Colony",
76 | "Columbia", "Columbus", "Comin", "Commissioner", "Commonwealth",
77 | "Conn", "Convers", "Coopermill", "Cooperriders", "Cooperwell",
78 | "Cornell", "Cornstill", "Coronado", "Corvus", "Corwin", "Cosgrave",
79 | "Coshocton", "Cottage", "Countiss", "Countryside", "Court", "Cove",
80 | "Coventry", "Cowden", "Cranfield", "Crawford", "Creamery",
81 | "Creedmoor", "Creekview", "Crestway", "Crock", "Crooks", "Crosier",
82 | "Cross", "Crossgate", "Crow", "Crown", "Culbertson", "Curtis",
83 | "Dads", "Daisy", "Dale", "Dallman", "Dana", "Daniels", "Danville",
84 | "Darcie", "Darla", "Darlington", "Date", "Davis", "Dawnlight",
85 | "Dawson", "Dearborn", "December", "Decrow", "Deer", "Deerfield",
86 | "Deerpath", "Deewood", "Dellwood", "Delmont", "Delwood", "Denbigh",
87 | "Denlinger", "Denmark", "Denning", "Dennis", "Denny", "Depot",
88 | "Detroit", "Devin", "Devlin", "Dewey", "Diagonal", "Dickinson",
89 | "Dickson", "Dietz", "Dillon", "Discovery", "Dixie", "Dixon",
90 | "Dogwood", "Dona", "Donald", "Dooleys", "Dorothy", "Doru",
91 | "Douglas", "Dowling", "Downard", "Downing", "Dragoo", "Dresden",
92 | "Dryden", "Dundee", "Dunham", "Dunzweiler", "Durban", "Duvall",
93 | "Dyer", "East", "Easter", "Eastern", "Eastfield", "Eastlawn",
94 | "Eastman", "Eastmoor", "Eastport", "Eastview", "Eastward",
95 | "Eastwood", "Eaton", "Echo", "Edalbert", "Eddie", "Eddy", "Ederer",
96 | "Edgewater", "Edison", "Edna", "Edward", "Edwards", "Eldwood",
97 | "Elfin", "Elida", "Elizabeth", "Ellen", "Eller", "Ellis",
98 | "Ellsworth", "Elmville", "Emily", "Englewood", "Enon", "Eppley",
99 | "Erie", "Erin", "Essex", "Euclid", "Evans", "Evansport", "Evelyn",
100 | "Evergreen", "Ewing", "Exchange", "Extension", "Fair", "Fairall",
101 | "Fairbanks", "Faircrest", "Fairmont", "Fairmount", "Fairview",
102 | "Fairway", "Fallsburg", "Falt", "Farson", "Fawn", "Faye",
103 | "Fayette", "Federal", "Ferncliff", "Fernstone", "Ferrell", "Fess",
104 | "Field", "Findley", "First", "Fishers", "Fitzgerald", "Fleek",
105 | "Fleming", "Flint", "Flintridge", "Flintwood", "Florence",
106 | "Forest", "Forry", "Foster", "Founds", "Fountain", "Fowlers",
107 | "Foxfire", "Frame", "Francis", "Franklin", "Frazeysburg",
108 | "Freeborn", "Freedom", "Frick", "Friendship", "Frisco", "Fritter",
109 | "Front", "Frontier", "Fulbrook", "Fulton", "Fultonrose",
110 | "Galbraith", "Galena", "Galigher", "Galighner", "Gallia", "Galway",
111 | "Gant", "Gantz", "Garden", "Gardenway", "Garey", "Garfield",
112 | "Garner", "Garrell", "Garrett", "Garst", "Gaslight", "Gayla",
113 | "Genessee", "George", "Gest", "Gibbard", "Gifford", "Gilbert",
114 | "Glade", "Glena", "Glenaven", "Glendale", "Glenhaven", "Glenn",
115 | "Glenwillow", "Glenwood", "Glessner", "Goddard", "Gomber",
116 | "Goosecreek", "Gordon", "Gorrell", "Gorsuch", "Goslen", "Grace",
117 | "Graffis", "Grand", "Grandview", "Granger", "Grant", "Granville",
118 | "Gratiot-Newark", "Gray", "Graylock", "Green", "Greenbriar",
119 | "Greenbrier", "Greengold", "Greenhouse", "Greenville", "Greenwood",
120 | "Greiner", "Grieves", "Grove", "Guava", "Haessler", "Hale", "Hall",
121 | "Hamburg", "Hamilton", "Hamline", "Hampton", "Hanawalt", "Hannah",
122 | "Hannawalt", "Hanover", "Hanson", "Harbor", "Hardesty", "Harding",
123 | "Hardy", "Harkers", "Harlan", "Harmon", "Harmony", "Harper",
124 | "Harris", "Harrison", "Harshman", "Hartford", "Hartman",
125 | "Hartville", "Hartwell", "Harvey", "Haught", "Hawk", "Hawkes",
126 | "Hayes", "Hazel", "Hazlett", "Heath", "Heber", "Hebron", "Heckak",
127 | "Heckel", "Hedgewood", "Helene", "Helpar", "Hendershot", "Henry",
128 | "Heritage", "Herron", "Hewitt", "Hickam", "Hickman", "Hickory",
129 | "Hicks", "Hideaway", "Higgins", "High", "Highland", "Highview",
130 | "Hilbish", "Hildreth", "Hill", "Hinman", "Hogans", "Hoge",
131 | "Hoiles", "Holbein", "Holbert", "Holliday", "Holmes", "Home",
132 | "Homeless", "Homer", "Homes", "Homestead", "Homewood", "Hoover",
133 | "Hopewell", "Hospital", "Howard", "Howell", "Hudson", "Huey",
134 | "Hughes", "Humphrey", "Hunt", "Hunter", "Hunterdon", "Huntington",
135 | "Idaho", "Idlewood", "Ildewood", "Iliamna", "Imlay",
136 | "Independence", "Indiana", "Indianola", "Inwood", "Ireland",
137 | "Iron", "Island", "Jackson", "James", "Jamestown", "Jannett",
138 | "Jefferson", "Jenkins", "Jensen", "Jessamine", "Jewett", "Jewitt",
139 | "Jody", "John", "Johnson", "Johnstown", "Jonathan", "Jones",
140 | "Jordan", "Joyce", "Juanita", "Julian", "Juniper", "Kahler",
141 | "Katherine", "Kauffman", "Kearns", "Keen", "Kegs", "Kelly",
142 | "Kennedy", "Kenny", "Kensington", "Kenton", "Kerri", "Kettering",
143 | "Kevrob", "Keystone", "Kibler", "Kimes", "King", "Kings",
144 | "Kingsley", "Kingswood", "Kinsman", "Kinzel", "Kirk", "Klotz",
145 | "Knipe", "Knox", "Kopchak", "Kossuch", "Lacon", "Lafayette",
146 | "Lagonda", "Lake", "Lakeside", "Lakewood", "Lambert", "Lancaster",
147 | "Lancaster-Chillicoth", "Lander", "Laneway", "Langan", "Lark",
148 | "Larkspur", "Larry", "Larzelere", "Lasalle", "Lashley", "Laurel",
149 | "Lavona", "Lawhead", "Lawn", "Lawndale", "Lawson", "Lawyers",
150 | "Layton", "Lazelere", "Lectric", "Ledbetter", "Leedom", "Leffler",
151 | "Lefter", "Legion", "Lenox", "Lent", "Leon", "Leonard",
152 | "Leonardville", "Leslie", "Lesslar", "Lewis", "Lexington",
153 | "Liberty", "Licking", "Lillian", "Lima", "Limestone", "Lincoln",
154 | "Lincolnway", "Lindale", "Lindbergh", "Linden", "Lindsay", "Linn",
155 | "Linwood", "Lisa", "Lithopolis", "Livingston", "Lock", "Locksmith",
156 | "Locust", "Lodge", "Lomita", "London", "Long", "Lookout", "Lost",
157 | "Loudon", "Louise", "Lovers", "Lubring", "Lucas", "Lucasburg",
158 | "Luck", "Lundgren", "Lutz", "Macedonia", "Mackenzie", "Madison",
159 | "Mailey", "Main", "Malibu", "Manning", "Manor", "Mansfield",
160 | "Maple", "Maplecraft", "Mapleview", "Maplewood", "Marchmont",
161 | "Marietta", "Marion", "Mark", "Market", "Marketing", "Marlo",
162 | "Marne", "Marsha", "Marshdale", "Martin", "Martinel", "Mary",
163 | "Mast", "Matthews", "Mayfair", "Maysville", "Mcarthur", "Mccarley",
164 | "Mccaslin", "Mcclain", "Mcclure", "Mcconnell", "Mcconnellsville",
165 | "Mcdaniel", "Mcdonald", "Mcfarland", "Mcintire", "Mckaig",
166 | "Mckeever", "Mckinley", "Mcmillan", "Mcowens", "Mead", "Meadow",
167 | "Meadowbrook", "Meadowhaven", "Meadowood", "Mechanicsburg", "Meek",
168 | "Melick", "Melrose", "Memory", "Meridian", "Meriwether", "Merlin",
169 | "Merriam", "Merrick", "Merrimac", "Merryhill", "Mershon",
170 | "Messimer", "Metro", "Miami", "Michael", "Michigan", "Middle",
171 | "Middlefork", "Middleton", "Midway", "Milagra", "Military", "Mill",
172 | "Miller", "Millers", "Milton", "Miner", "Missouri", "Mitchell",
173 | "Moccasin", "Mock", "Mohawk", "Mollysrock", "Mona", "Monroe",
174 | "Montague", "Montgomery", "Moonlight", "Moore", "Moorehead",
175 | "Moores", "Moorewood", "Morgan", "Morgantown", "Morganville",
176 | "Morningstar", "Morrison", "Morse", "Mound", "Moxadarla",
177 | "Moxahala", "Muirwood", "Mulberry", "Mundy", "Munson", "Murray",
178 | "Muskingum", "Musselman", "Myrtle", "Nancy", "Narrows", "National",
179 | "Navy", "Neal", "Neil", "Nelson", "Neptune", "Newark", "Newgate",
180 | "Newlon", "Newman", "Newport", "Nichalas", "Nolan", "None",
181 | "Nor-Bixbey", "Nora", "Norfield", "Normandy", "Norris", "North",
182 | "Northcrest", "Northland", "Norwich", "Norwood", "Nottingham",
183 | "Nottinghamshire", "Nugent", "Oakland", "Oakwood", "Obetz",
184 | "Odell", "Ohio", "Okey", "Olive", "Olney", "Ontario", "Opera",
185 | "Orange", "Orchard", "Orders", "Orton", "Osage", "Osceola",
186 | "Otterbein", "Overlook", "Owens", "Oxford", "Paint", "Palamino",
187 | "Pallas", "Palmer", "Palmeraway", "Palmwood", "Palomino",
188 | "Paragon", "Parish", "Park", "Parker", "Parks", "Parkview",
189 | "Parkway", "Parkwood", "Parliament", "Parry", "Partridge", "Patch",
190 | "Patricia", "Peachblow", "Pear", "Pearl", "Pembroke", "Penn",
191 | "Penney", "Pennisula", "Pennsylvania", "Penrick", "Perdue",
192 | "Perine", "Perkins", "Perry", "Perryton", "Pershing", "Peters",
193 | "Petersburg", "Peterson", "Pfeifer", "Pfeiffer", "Philadelphia",
194 | "Phillips", "Pickwick", "Pierce", "Pike", "Pine", "Pinecrest",
195 | "Pinetown", "Pineview", "Pinewood", "Pinkerton", "Pinkley",
196 | "Pioneer", "Piper", "Plainfield", "Plantation", "Playford",
197 | "Pleasant", "Pleasantview", "Pleasantville", "Pointe", "Poplar",
198 | "Portage", "Porter", "Portland", "Potters", "Potts", "Powell",
199 | "Prame", "Pratt", "Price", "Princeton", "Prior", "Prison",
200 | "Promway", "Prospect", "Pryor", "Public", "Purdy", "Purvis",
201 | "Putnam", "Quarry", "Quick", "Quincy", "Quinlan", "Race", "Radnor",
202 | "Raiders", "Railroad", "Rains", "Raintree", "Range", "Rankin",
203 | "Ransbottom", "Raven", "Ravenwood", "Rawson", "Reading", "Ream",
204 | "Redman", "Redondo", "Reed", "Reeves", "Rehl", "Restless",
205 | "Reynolds", "Rhonda", "Rice", "Richards", "Richey", "Richman",
206 | "Richmond", "Richvale", "Richwood", "Rider", "Ridge", "Ridgefield",
207 | "Ridgeland", "Ridgeview", "Ridgewood", "Rigby", "Riggin", "Rigny",
208 | "Ritchey", "Ritenour", "River", "Riverside", "Riverview",
209 | "Roadayle", "Robertson", "Robin", "Robinson", "Robinwood", "Rock",
210 | "Rockville", "Roemer", "Roland", "Rollins", "Rondayle",
211 | "Roosevelt", "Roper", "Rose", "Roseville", "Rosewood", "Rowland",
212 | "Royalton", "Royma", "Rucker", "Runyan", "Russell", "Rustle",
213 | "Ruth", "Ryan", "Salem", "Salgarber", "Sally", "Saltzgaber",
214 | "Sampson", "Samuel", "Sand", "Sandhurst", "Sandra", "Sandusky",
215 | "Sandvik", "Santoy", "Sarah", "Scarborough", "Scenic", "Schaum",
216 | "Schneider", "Scholl", "School", "Schuler", "Schultz", "Schwallie",
217 | "Scott", "Scout", "Sealover", "Seaman", "Seborn", "Sells",
218 | "Selsam", "Senator", "Seroco", "Sevall", "Severt", "Seward",
219 | "Seymore", "Shady", "Shagbark", "Shaliman", "Shandon", "Sharon",
220 | "Sharonwood", "Shasta", "Shaw", "Shawnee", "Sheandoah", "Sheila",
221 | "Shellhart", "Shenandoah", "Shepherd", "Sherborne", "Sheridan",
222 | "Sherman", "Sherwood", "Shindern", "Shinick", "Shinnick",
223 | "Shiplett", "Shoop", "Shore", "Short", "Shumaker", "Sibley",
224 | "Silliman", "Silmore", "Skyline", "Skyview", "Slack", "Smithfield",
225 | "Smithwood", "Snoke", "Snyder", "Sofin", "Solida", "Somers",
226 | "Somerset", "Sonora", "Souder", "South", "Southard", "Southeast",
227 | "Southern", "Southward", "Spangler", "Sparling", "Spellman",
228 | "Spence", "Spencer", "Spielbusch", "Spratt", "Spring",
229 | "Springdale", "Spruce", "Spry", "Stacy", "Stalder", "Stalling",
230 | "Stanley", "Stansberry", "Stanton", "Stanway", "State", "Steele",
231 | "Stein", "Stephens", "Stevens", "Stevy", "Stewart", "Stiers",
232 | "Stillmeadow", "Stillwell", "Stine", "Stiver", "Stokely", "Stone",
233 | "Stonecreek", "Stormont", "Stout", "Stoutsville", "Strawberry",
234 | "Street", "Sturtz", "Stygler", "Sudbury", "Sugargrove",
235 | "Sugartree", "Summit", "Sundale", "Sunflower", "Sunkel", "Sunray",
236 | "Sunrise", "Sunset", "Superior", "Surger", "Swans", "Swartz",
237 | "Swingle", "Sycamore", "Talford", "Talley", "Tamarron", "Tammy",
238 | "Tannehill", "Tarkman", "Taylor", "Teakwood", "Tedrick", "Temple",
239 | "Terrace", "Terry", "Theobald", "Third", "Thomas", "Thompson",
240 | "Thorn", "Thornberry", "Thornhill", "Thurman", "Tiffany",
241 | "Tileston", "Titus", "Todd", "Toni", "Towers", "Town", "Trabue",
242 | "Traci", "Traco", "Tranquility", "Treehouse", "Tremont", "Trend",
243 | "Tridelphia", "Tupedo", "Turner", "Turtle", "Tuscarawas",
244 | "Twimenhill", "Tyman", "Underwood", "Uneeda", "Union", "Unknown",
245 | "Valley", "Vance", "Vaughn", "Venture", "Venus", "Vernon",
246 | "Vetter", "Vicki", "Victory", "Villa", "Village", "Vine", "Vinsel",
247 | "Virginia", "Vista", "Vroom", "Wabash", "Wacker", "Wakatomika",
248 | "Waldolf", "Walker", "Wall", "Wallwork", "Walnut", "Walter",
249 | "Waltham", "Ward", "Wargo", "Warner", "Warners", "Warren",
250 | "Warwick", "Washington", "Water", "Waters", "Watkins", "Watson",
251 | "Watts", "Wayne", "Weaver", "Webb", "Webster", "Wedgewood",
252 | "Weedon", "Weller", "Wells", "Wentz", "Wessex", "West",
253 | "Westbourne", "Western", "Westmoor", "Westmore", "Westwood",
254 | "Wetsell", "Whaley", "Wheatland", "Wheelabout", "Wheeler",
255 | "Wheeling", "Whipple", "Whites", "Whitman", "Wilhelm", "Wilkins",
256 | "Williams", "Willis", "Willow", "Wilmer", "Wilmington", "Wilshire",
257 | "Wilson", "Winding", "Windmill", "Windsong", "Winfield",
258 | "Winlwood", "Winter", "Winton", "Wise", "Wisteria", "Wogan",
259 | "Wolfe", "Wolford", "Woodberry", "Woodbrook", "Woodland",
260 | "Woodlawn", "Woolper", "Workman", "Wortman", "Wrexham", "Yale",
261 | "Yingling", "Yost", "Young", "Zane", "Zanesville", "Zella"
262 |
263 | };
264 |
265 | private static String[] addressSuffixes = { "Avenue", "Boulevard",
266 | "Circle", "Crescent", "Court", "Drive", "Heights", "Lane", "Park",
267 | "Path", "Parkway", "Place", "Road", "Ridge", "Run", "Square",
268 | "Street", "Station", "Terrace", "Trail", "Way", "Rd", "Ln", "St",
269 | "Blvd", "Ave", "Drv" };
270 |
271 | private static String[] cities = { "Abba", "Abbeville", "Acworth",
272 | "Adairsville", "Adel", "Adrian", "Ailey", "Alamo", "Alapaha",
273 | "Albany", "Allenhurst", "Alma", "Alma", "Alpharetta", "Alston",
274 | "Amboy", "Ambrose", "Americus", "Appling", "Arlington", "Ashburn",
275 | "Athens", "Atkinson", "Atlanta", "Attapulgus", "Auburn", "Augusta",
276 | "Augusta-Richmond County", "Austell", "Avondale Estates", "Axson",
277 | "Baconton", "Baden", "Bainbridge", "Bainbridge", "Baldwin",
278 | "Bannockburn", "Barnesville", "Barney", "Barretts", "Barwick",
279 | "Baxley", "Bemiss", "Berkeley Lake", "Berlin", "Blackshear",
280 | "Blairsville", "Blakely", "Bloomingdale", "Blue Ridge", "Bogart",
281 | "Boston", "Bowdon", "Bowens Mill", "Bowman", "Braselton", "Bremen",
282 | "Brinson", "Bristol", "Bronwood", "Brookfield", "Brooklet",
283 | "Brooks", "Broxton", "Brunswick", "Buchanan", "Buena Vista",
284 | "Buford", "Bushnell", "Byromville", "Byron", "Cairo", "Camilla",
285 | "Canton", "Carnesville", "Carrollton", "Cartersville",
286 | "Cave Spring", "Cecil", "Cedartown", "Centerville", "Chamblee",
287 | "Chatsworth", "Chauncey", "Chester", "Chickamauga", "Chula",
288 | "Clarkston", "Claxton", "Clayton", "Cleveland", "Clyatteville",
289 | "Clyo", "Cobbtown", "Cochran", "Cogdell", "Cohutta", "Colesburg",
290 | "College Park", "Collins", "Colquitt", "Columbus", "Commerce",
291 | "Conyers", "Coolidge", "Cordele", "Cornelia", "Council",
292 | "Country Club Estate", "Coverdale", "Covington", "Cox",
293 | "Crawfordville", "Crescent", "Culloden", "Cumming", "Cusseta",
294 | "Cuthbert", "Dacula", "Dahlonega", "Daisy", "Dakota", "Dallas",
295 | "Dalton", "Damascus", "Danielsville", "Darien", "Dasher", "Dawson",
296 | "Dawsonville", "Decatur", "Denmark", "Dillard", "Dixie",
297 | "Dock Junction", "Doerun", "Donalsonville", "Doraville", "Douglas",
298 | "Douglasville", "Dover Bluff", "Dupont", "Dublin", "Dudley",
299 | "Duluth", "Dunwoody", "East Dublin", "East Point", "Eastman",
300 | "Eatonton", "Ebenezer", "Edison", "Edith", "Egypt", "Elberton",
301 | "Eldorado", "Ellabelle", "Ellaville", "Ellenton", "Ellijay",
302 | "Enigma", "Euharlee", "Eulonia", "Everitt", "Fairburn", "Fairmont",
303 | "Fargo", "Fayetteville", "Fitzgerald", "Flemington",
304 | "Flowery Branch", "Folkston", "Forest Park", "Forsyth",
305 | "Fort Gaines", "Fort Oglethorpe", "Fort Stewart", "Fort Valley",
306 | "Franklin", "Fruitland", "Funston", "Gainesville", "Garden City",
307 | "Garfield", "Geneva", "Georgetown", "Gibson", "Glennville",
308 | "Glenwood", "Glory", "Graham", "Gray", "Greensboro", "Greenville",
309 | "Griffin", "Grooverville", "Groveland", "Grovetown", "Gumbranch",
310 | "Guyton", "Hagan", "Hahira", "Hamilton", "Hampton", "Hapeville",
311 | "Harding", "Harding", "Hardwicke", "Harrietts Bluff", "Hartwell",
312 | "Hawkinsville", "Haylon", "Hazlehurst", "Helena", "Hepzibah",
313 | "Hiawassee", "Hickox", "Higgston", "Hinesville", "Hiram",
314 | "Hoboken", "Hogansville", "Holly Springs", "Holt", "Homeland",
315 | "Homer", "Homerville", "Hopeulikit", "Hortense", "Howell", "Inaha",
316 | "Iron City", "Irwinton", "Irwinville", "Isle Of Hope-Dutch Island",
317 | "Jackson", "Janis", "Jasper", "Jefferson", "Jeffersonville",
318 | "Jesup", "Johns Creek", "Jonesboro", "Keller", "Kennesaw",
319 | "Kinderlou", "Kings Bay Base", "Kingsland", "Kirkland", "Kite",
320 | "Lafayette", "Lagrange", "Lake City", "Lake Park", "Lakeland",
321 | "Lanier", "Lawrenceville", "Lax", "Leary", "Leefield", "Leesburg",
322 | "Lenox", "Lexington", "Lilburn", "Lincolnton", "Lithonia",
323 | "Locust Grove", "Loganville", "Lookout Mountain", "Louisville",
324 | "Lovejoy", "Ludowici", "Lulaton", "Lumber City", "Lumpkin",
325 | "Lyons", "Macon", "Madison", "Manassas", "Manchester", "Marietta",
326 | "Maxeys", "Mayday", "Mcdonough", "Mcintosh", "Mcintyre", "Mcrae",
327 | "Meigs", "Meldrim", "Mershon", "Metter", "Midway", "Milan",
328 | "Milledgeville", "Millen", "Milton", "Moniac", "Monroe",
329 | "Montezuma", "Montgomery", "Monticello", "Montrose", "Mora",
330 | "Morgan", "Morrow", "Morven", "Moultrie", "Mount Vernon",
331 | "Mount Zion", "Mountain Park", "Mystic", "Nahunta", "Nankin",
332 | "Nashville", "Needmore", "Nelson", "Nevils", "New Rock Hill",
333 | "Newnan", "Newton", "Nicholls", "Norcross", "Norman Park",
334 | "Oakwood", "Ochlocknee", "Ocilla", "Odum", "Offerman", "Offerman",
335 | "Oglethorpe", "Omega", "Osterfield", "Ousley", "Oxford",
336 | "Palmetto", "Parrott", "Patterson", "Peachtree City Website",
337 | "Pearson", "Pelham", "Pembroke", "Perry", "Phillipsburg",
338 | "Pine Lake", "Pineora", "Pineview", "Pooler", "Port Wentworth",
339 | "Portal", "Potter", "Poulan", "Powder Springs", "Preston",
340 | "Pridgen", "Pulaski", "Queensland", "Quitman", "Ray City",
341 | "Rebecca", "Register", "Reidsville", "Remerton", "Rentz",
342 | "Retreat", "Riceboro", "Richmond Hill", "Ridgeville", "Rincon",
343 | "Ringgold", "Riverdale", "Riverside", "Rochelle", "Rockingham",
344 | "Rockmart", "Rome", "Roswell", "Royston", "Rutledge",
345 | "Saint George", "Sale City", "Sandersville", "Sandy Springs",
346 | "Sasser", "Savannah", "Screven", "Senoia", "Sessoms", "Shawnee",
347 | "Shellman Bluff", "Sirmans", "Skidaway Island", "Smithville",
348 | "Smyrna", "Snellville", "Social Circle", "Soperton",
349 | "South Newport", "Sparks", "Sparta", "Springfield", "Strongsville",
350 | "St. Simons Island", "Statenville", "Statesboro", "Sterling",
351 | "Stillmore", "Stillwell", "Stilson", "Stockbridge", "Stockton",
352 | "Stone Mountain", "Sugar Hill", "Sumner", "Sunbury", "Sunsweet",
353 | "Surrency", "Suwanee", "Swainsboro", "Sycamore", "Sylvania",
354 | "Sylvester", "Talbotton", "Tallapoosa", "Tarboro", "Tarver",
355 | "Temple", "Thalman", "Thelma", "Thomaston", "Thomasville",
356 | "Thomson", "Thunderbolt", "Tifton", "Toccoa", "Toomsboro",
357 | "Townsend", "Trenton", "Trudie", "Tucker", "Twin City",
358 | "Twin Peaks", "Tybee Island", "Tyrone", "Unadilla", "Union City",
359 | "Unionville", "Upton", "Uvalda", "Valdosta", "Valona",
360 | "Vernonburg", "Vidalia", "Vienna", "Villa Rica", "Walthourville",
361 | "Warrenton", "Warwick", "Washington", "Waterloo", "Watkinsville",
362 | "Waverly", "Waycross", "Waynesboro", "Waynesville", "Weber",
363 | "West Green", "West Point", "Westwood", "Whigham", "White Oak",
364 | "Whitmarsh Island", "Willacoochee", "Wilmington Island", "Winder",
365 | "Winokur", "Withers", "Woodbine", "Woodstock", "Worth", "Wray",
366 | "Wrightsville" };
367 |
368 | public String[] getCities() {
369 | return cities;
370 | }
371 |
372 | public String[] getStreetNames() {
373 | return streetNames;
374 | }
375 |
376 | public String[] getAddressSuffixes() {
377 | return addressSuffixes;
378 | }
379 |
380 | }
381 |
--------------------------------------------------------------------------------
/src/main/java/org/fluttercode/datafactory/impl/DataFactory.java:
--------------------------------------------------------------------------------
1 | package org.fluttercode.datafactory.impl;
2 |
3 | /*
4 | * Copyright 2011, Andrew M Gibson
5 | *
6 | * www.andygibson.net
7 | *
8 | * This file is part of DataFactory.
9 | *
10 | * DataValve is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
11 | * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12 | * version.
13 | *
14 | * DataValve is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 | * details.
17 | *
18 | *
19 | * You should have received a copy of the GNU Lesser General Public License along with DataValve. If not, see
20 | * .
21 | *
22 | */
23 |
24 | import java.util.Calendar;
25 | import java.util.Date;
26 | import java.util.List;
27 | import java.util.Random;
28 |
29 | import org.fluttercode.datafactory.AddressDataValues;
30 | import org.fluttercode.datafactory.ContentDataValues;
31 | import org.fluttercode.datafactory.NameDataValues;
32 |
33 | /**
34 | * Class that provides a number of methods for generating test data through helper components. These components
35 | * implement interfaces that provide an interface to accessing the test data. Components can be replaced with other
36 | * components to allow more suitable data to be used.
37 | *
38 | * @author Andy Gibson
39 | *
40 | */
41 | /**
42 | * @author GIBSOA01
43 | *
44 | */
45 | public final class DataFactory {
46 |
47 | // used for backwards compatibility
48 | private static Random original_random = new Random(93285);
49 |
50 | private NameDataValues nameDataValues = new DefaultNameDataValues();
51 | private AddressDataValues addressDataValues = new DefaultAddressDataValues();
52 | private ContentDataValues contentDataValues = new DefaultContentDataValues();
53 |
54 | private Random random = new Random();
55 |
56 | /**
57 | * Deprecated as of Aug 2015, use one of the static constructor methods:
58 | *
59 | *
60 | * dataFactory = DataFactory create();
61 | * or
62 | * dataFactory = DataFactory create(5765297);
63 | * or
64 | * dataFactory = DataFactory create(someRandom);
65 | *
66 | *
67 | *
68 | * If you want to use the same static fixed seed Random object that was implemented originally, you can just create
69 | * the factories using :
70 | *
71 | *
72 | * DataFactory createWithOriginalRandom();
73 | *
74 | *
75 | * Using this constructor will also create a datafactory that uses the same static fixed seed Random
76 | */
77 | @Deprecated
78 | public DataFactory() {
79 | this(original_random);
80 | }
81 |
82 | private DataFactory(final Random random) {
83 | this.random = random;
84 | }
85 |
86 | public static DataFactory create() {
87 | return new DataFactory();
88 | }
89 |
90 | public static DataFactory create(final long seed) {
91 | return new DataFactory(new Random(seed));
92 | }
93 |
94 | /**
95 | * Backwards compatible constructor that creates a datafactory driven by the original instance of random.
96 | *
97 | * @return DataFactory instance with a shared random
98 | */
99 | public static DataFactory createWithOriginalRandom() {
100 | return new DataFactory(original_random);
101 | }
102 |
103 | /**
104 | * Returns a random item from a list of items.
105 | *
106 | * @param Item type in the list and to return
107 | * @param items List of items to choose from
108 | * @return Item from the list
109 | */
110 | public T getItem(final List items) {
111 | return getItem(items, 100, null);
112 | }
113 |
114 | /**
115 | * Returns a random item from a list of items or the null depending on the probability parameter. The probability
116 | * determines the chance (in %) of returning an item off the list versus null.
117 | *
118 | * @param Item type in the list and to return
119 | * @param items List of items to choose from
120 | * @param probability chance (in %, 100 being guaranteed) of returning an item from the list
121 | * @return Item from the list or null if the probability test fails.
122 | */
123 | public T getItem(final List items, final int probability) {
124 | return getItem(items, probability, null);
125 | }
126 |
127 | /**
128 | * Returns a random item from a list of items or the defaultItem depending on the probability parameter. The
129 | * probability determines the chance (in %) of returning an item off the list versus the default value.
130 | *
131 | * @param Item type in the list and to return
132 | * @param items List of items to choose from
133 | * @param probability chance (in %, 100 being guaranteed) of returning an item from the list
134 | * @param defaultItem value to return if the probability test fails
135 | * @return Item from the list or the default value
136 | */
137 | public T getItem(final List items, final int probability, final T defaultItem) {
138 | if (items == null) {
139 | throw new IllegalArgumentException("Item list cannot be null");
140 | }
141 | if (items.isEmpty()) {
142 | throw new IllegalArgumentException("Item list cannot be empty");
143 | }
144 |
145 | return chance(probability) ? items.get(random.nextInt(items.size())) : defaultItem;
146 | }
147 |
148 | /**
149 | * Returns a random item from an array of items
150 | *
151 | * @param Array item type and the type to return
152 | * @param items Array of items to choose from
153 | * @return Item from the array
154 | */
155 | public T getItem(final T[] items) {
156 | return getItem(items, 100, null);
157 | }
158 |
159 | /**
160 | * Returns a random item from an array of items or null depending on the probability parameter. The probability
161 | * determines the chance (in %) of returning an item from the array versus null.
162 | *
163 | * @param Array item type and the type to return
164 | * @param items Array of items to choose from
165 | * @param probability chance (in %, 100 being guaranteed) of returning an item from the array
166 | * @return Item from the array or the default value
167 | */
168 | public T getItem(final T[] items, final int probability) {
169 | return getItem(items, probability, null);
170 | }
171 |
172 | /**
173 | * Returns a random item from an array of items or the defaultItem depending on the probability parameter. The
174 | * probability determines the chance (in %) of returning an item from the array versus the default value.
175 | *
176 | * @param Array item type and the type to return
177 | * @param items Array of items to choose from
178 | * @param probability chance (in %, 100 being guaranteed) of returning an item from the array
179 | * @param defaultItem value to return if the probability test fails
180 | * @return Item from the array or the default value
181 | */
182 | public T getItem(final T[] items, final int probability, final T defaultItem) {
183 | if (items == null) {
184 | throw new IllegalArgumentException("Item array cannot be null");
185 | }
186 | if (items.length == 0) {
187 | throw new IllegalArgumentException("Item array cannot be empty");
188 | }
189 | return chance(probability) ? items[random.nextInt(items.length)] : defaultItem;
190 | }
191 |
192 | /**
193 | * @return A random first name
194 | */
195 | public String getFirstName() {
196 | return getItem(nameDataValues.getFirstNames());
197 | }
198 |
199 | /**
200 | * Returns a combination of first and last name values in one string
201 | *
202 | * @return First and last name value
203 | */
204 | public String getName() {
205 | return getItem(nameDataValues.getFirstNames()) + " " + getItem(nameDataValues.getLastNames());
206 | }
207 |
208 | /**
209 | * @return A random last name
210 | */
211 | public String getLastName() {
212 | return getItem(nameDataValues.getLastNames());
213 | }
214 |
215 | /**
216 | * @return A random street name
217 | */
218 | public String getStreetName() {
219 | return getItem(addressDataValues.getStreetNames());
220 | }
221 |
222 | /**
223 | * @return A random street suffix
224 | */
225 | public String getStreetSuffix() {
226 | return getItem(addressDataValues.getAddressSuffixes());
227 | }
228 |
229 | /**
230 | * Generates a random city value
231 | *
232 | * @return City as a string
233 | */
234 | public String getCity() {
235 | return getItem(addressDataValues.getCities());
236 | }
237 |
238 | /**
239 | * Generates an address value consisting of house number, street name and street suffix. i.e.
240 | * 543 Larkhill Road
241 | *
242 | * @return Address as a string
243 | */
244 | public String getAddress() {
245 | int num = 404 + random.nextInt(1400);
246 | return num + " " + getStreetName() + " " + getStreetSuffix();
247 | }
248 |
249 | /**
250 | * Generates line 2 for a street address (usually an Apt. or Suite #). Returns null if the probabilty test fails.
251 | *
252 | * @param probability Chance as % of have a value returned instead of null.
253 | * @return Street address line two or null if the probability test fails
254 | */
255 | public String getAddressLine2(final int probability) {
256 | return getAddressLine2(probability, null);
257 | }
258 |
259 | /**
260 | * Generates line 2 for a street address (usually an Apt. or Suite #). Returns default value if the probabilty test
261 | * fails.
262 | *
263 | * @param probability Chance as % of have a value returned instead of null.
264 | * @param defaultValue Value to return if the probability test fails.
265 | * @return Street address line two or null if the probability test fails
266 | */
267 | public String getAddressLine2(final int probability, final String defaultValue) {
268 | return chance(probability) ? getAddressLine2() : defaultValue;
269 | }
270 |
271 | /**
272 | * Generates line 2 for a street address (usually an Apt. or Suite #). Returns default value if the probabilty test
273 | * fails.
274 | *
275 | * @return Street address line 2
276 | */
277 | public String getAddressLine2() {
278 | int test = random.nextInt(100);
279 | if (test < 50) {
280 | return "Apt #" + 100 + random.nextInt(1000);
281 | } else {
282 | return "Suite #" + 100 + random.nextInt(1000);
283 | }
284 | }
285 |
286 | /**
287 | * Creates a random birthdate within the range of 1955 to 1985
288 | *
289 | * @return Date representing a birthdate
290 | */
291 | public Date getBirthDate() {
292 | Date base = new Date(0);
293 | return getDate(base, -365 * 15, 365 * 15);
294 | }
295 |
296 | /**
297 | * Returns a random int value.
298 | *
299 | * @return random number
300 | */
301 | public int getNumber() {
302 | return random.nextInt();
303 | }
304 |
305 | /**
306 | * Returns a random number between 0 and max
307 | *
308 | * @param max Maximum value of result
309 | * @return random number no more than max
310 | */
311 | public int getNumberUpTo(final int max) {
312 | return getNumberBetween(0, max);
313 | }
314 |
315 | /**
316 | * Returns a number betwen min and max
317 | *
318 | * @param min minimum value of result
319 | * @param max maximum value of result
320 | * @return Random number within range
321 | */
322 | public int getNumberBetween(final int min, final int max) {
323 |
324 | if (max < min) {
325 | throw new IllegalArgumentException(String.format("Minimum must be less than minimum (min=%d, max=%d)", min, max));
326 | }
327 | if (max == min) {
328 | return min;
329 | }
330 |
331 | return min + random.nextInt(max - min);
332 | }
333 |
334 | /**
335 | * Builds a date from the year, month, day values passed in
336 | *
337 | * @param year The year of the final {@link Date} result
338 | * @param month The month of the final {@link Date} result (from 1-12)
339 | * @param day The day of the final {@link Date} result
340 | * @return Date representing the passed in values.
341 | */
342 | public Date getDate(final int year, final int month, final int day) {
343 | Calendar cal = Calendar.getInstance();
344 | cal.clear();
345 | cal.set(year, month - 1, day, 0, 0, 0);
346 | return cal.getTime();
347 | }
348 |
349 | /**
350 | * Returns a random date which is in the range baseData + minDaysFromData to
351 | * baseData + maxDaysFromData. This method does not alter the time component and the time is
352 | * set to the time value of the base date.
353 | *
354 | * @param baseDate Date to start from
355 | * @param minDaysFromDate minimum number of days from the baseDate the result can be
356 | * @param maxDaysFromDate maximum number of days from the baseDate the result can be
357 | * @return A random date
358 | */
359 | public Date getDate(final Date baseDate, final int minDaysFromDate, final int maxDaysFromDate) {
360 | Calendar cal = Calendar.getInstance();
361 | cal.setTime(baseDate);
362 | int diff = minDaysFromDate + (random.nextInt(maxDaysFromDate - minDaysFromDate));
363 | cal.add(Calendar.DATE, diff);
364 | return cal.getTime();
365 | }
366 |
367 | /**
368 | * Returns a random date between two dates. This method will alter the time component of the dates
369 | *
370 | * @param minDate Minimum date that can be returned
371 | * @param maxDate Maximum date that can be returned
372 | * @return random date between these two dates.
373 | */
374 | public Date getDateBetween(final Date minDate, final Date maxDate) {
375 | // this can break if seconds is an int
376 | long seconds = (maxDate.getTime() - minDate.getTime()) / 1000;
377 | seconds = (long) (random.nextDouble() * seconds);
378 | Date result = new Date();
379 | result.setTime(minDate.getTime() + (seconds * 1000));
380 | return result;
381 | }
382 |
383 | /**
384 | * Returns random text made up of english words of length length
385 | *
386 | * @param length length of returned string
387 | *
388 | * @return string made up of actual words with length length
389 | */
390 | public String getRandomText(final int length) {
391 | return getRandomText(length, length);
392 | }
393 |
394 | /**
395 | * Returns random text made up of english words
396 | *
397 | * @param minLength minimum length of returned string
398 | * @param maxLength maximum length of returned string
399 | * @return string of length between min and max length
400 | */
401 | public String getRandomText(final int minLength, final int maxLength) {
402 | validateMinMaxParams(minLength, maxLength);
403 |
404 | StringBuilder sb = new StringBuilder(maxLength);
405 | int length = minLength;
406 | if (maxLength != minLength) {
407 | length = length + random.nextInt(maxLength - minLength);
408 | }
409 | while (length > 0) {
410 | if (sb.length() != 0) {
411 | sb.append(" ");
412 | length--;
413 | }
414 | final double desiredWordLengthNormalDistributed = 1.0 + Math.abs(random.nextGaussian()) * 6;
415 | int usedWordLength = (int) (Math.min(length, desiredWordLengthNormalDistributed));
416 | String word = getRandomWord(usedWordLength);
417 | sb.append(word);
418 | length = length - word.length();
419 | }
420 | return sb.toString();
421 |
422 | }
423 |
424 | private void validateMinMaxParams(final int minLength, final int maxLength) {
425 | if (minLength < 0) {
426 | throw new IllegalArgumentException("Minimum length must be a non-negative number");
427 | }
428 |
429 | if (maxLength < 0) {
430 | throw new IllegalArgumentException("Maximum length must be a non-negative number");
431 | }
432 |
433 | if (maxLength < minLength) {
434 | throw new IllegalArgumentException(
435 | String.format("Minimum length must be less than maximum length (min=%d, max=%d)", minLength, maxLength));
436 | }
437 | }
438 |
439 | /**
440 | * @return a random character
441 | */
442 | public char getRandomChar() {
443 | return (char) (random.nextInt(26) + 'a');
444 | }
445 |
446 | /**
447 | * Return a string containing length random characters
448 | *
449 | * @param length number of characters to use in the string
450 | * @return A string containing length random characters
451 | */
452 | public String getRandomChars(final int length) {
453 | return getRandomChars(length, length);
454 | }
455 |
456 | /**
457 | * Return a string containing between length random characters
458 | *
459 | * @param minLength minimum number of characters to use in the string
460 | * @param maxLength maximum number of characters to use in the string
461 | *
462 | * @return A string containing length random characters
463 | */
464 | public String getRandomChars(final int minLength, final int maxLength) {
465 | validateMinMaxParams(minLength, maxLength);
466 | StringBuilder sb = new StringBuilder(maxLength);
467 |
468 | int length = minLength;
469 | if (maxLength != minLength) {
470 | length = length + random.nextInt(maxLength - minLength);
471 | }
472 | while (length > 0) {
473 | sb.append(getRandomChar());
474 | length--;
475 | }
476 | return sb.toString();
477 | }
478 |
479 | /**
480 | * Returns a word of a length between 1 and 10 characters.
481 | *
482 | * @return A work of max length 10
483 | */
484 | public String getRandomWord() {
485 | return getItem(contentDataValues.getWords());
486 | }
487 |
488 | /**
489 | * Returns a valid word with a length of length characters.
490 | *
491 | * @param length maximum length of the word
492 | * @return a word of a length up to length characters
493 | */
494 | public String getRandomWord(final int length) {
495 | return getRandomWord(length, length);
496 | }
497 |
498 | /**
499 | * Returns a valid word with a length of up to length characters. If the exactLength
500 | * parameter is set, then the word will be exactly length characters in length.
501 | *
502 | * @param length maximum length of the returned string
503 | * @param exactLength indicates if the word should have a length of length
504 | * @return a string with a length that matches the specified parameters.
505 | */
506 | public String getRandomWord(final int length, final boolean exactLength) {
507 | if (exactLength) {
508 | return getRandomWord(length, length);
509 | }
510 | return getRandomWord(0, length);
511 | }
512 |
513 | /**
514 | * Returns a valid word based on the length range passed in. The length will always be between the min and max length
515 | * range inclusive.
516 | *
517 | * @param minLength minimum length of the word
518 | * @param maxLength maximum length of the word
519 | * @return a word of a length between min and max length
520 | */
521 | public String getRandomWord(final int minLength, final int maxLength) {
522 | validateMinMaxParams(minLength, maxLength);
523 |
524 | // special case if we need a single char
525 | if (maxLength == 1) {
526 | if (chance(50)) {
527 | return "a";
528 | }
529 | return "I";
530 | }
531 |
532 |
533 | // start from random pos and find the first word of the right size
534 | String[] words = contentDataValues.getWords();
535 | int pos = random.nextInt(words.length);
536 | for (int i = 0; i < words.length; i++) {
537 | int idx = (i + pos) % words.length;
538 | String test = words[idx];
539 | if (test.length() >= minLength && test.length() <= maxLength) {
540 | return test;
541 | }
542 | }
543 | // we haven't a word for this length so generate one
544 | return getRandomChars(minLength, maxLength);
545 | }
546 |
547 | /**
548 | *
549 | * @param chance Chance of a suffix being returned
550 | * @return
551 | */
552 | public String getSuffix(final int chance) {
553 | return getItem(nameDataValues.getSuffixes(), chance);
554 | }
555 |
556 | /**
557 | * Return a person prefix or null if the odds are too low.
558 | *
559 | * @param chance Odds of a prefix being returned
560 | * @return Prefix string
561 | */
562 | public String getPrefix(final int chance) {
563 | return getItem(nameDataValues.getPrefixes(), chance);
564 | }
565 |
566 | /**
567 | * Returns a string containing a set of numbers with a fixed number of digits
568 | *
569 | * @param digits number of digits in the final number
570 | * @return Random number as a string with a fixed length
571 | */
572 | public String getNumberText(final int digits) {
573 | String result = "";
574 | for (int i = 0; i < digits; i++) {
575 | result = result + random.nextInt(10);
576 | }
577 | return result;
578 | }
579 |
580 | /**
581 | * Generates a random business name by taking a city name and additing a business onto it.
582 | *
583 | * @return A random business name
584 | */
585 | public String getBusinessName() {
586 | return getCity() + " " + getItem(contentDataValues.getBusinessTypes());
587 | }
588 |
589 | /**
590 | * Generates an email address
591 | *
592 | * @return an email address
593 | */
594 | public String getEmailAddress() {
595 | int test = random.nextInt(100);
596 | String email = "";
597 | if (test < 50) {
598 | // name and initial
599 | email = getFirstName().charAt(0) + getLastName();
600 | } else {
601 | // 2 words
602 | email = getItem(contentDataValues.getWords()) + getItem(contentDataValues.getWords());
603 | }
604 | if (random.nextInt(100) > 80) {
605 | email = email + random.nextInt(100);
606 | }
607 | email = email + "@" + getItem(contentDataValues.getEmailHosts()) + "." + getItem(contentDataValues.getTlds());
608 | return email.toLowerCase();
609 | }
610 |
611 | /**
612 | * Gives you a true/false based on a probability with a random number generator. Can be used to optionally add
613 | * elements.
614 | *
615 | *
616 | * if (DataFactory.chance(70)) {
617 | * // 70% chance of this code being executed
618 | * }
619 | *
620 | *
621 | * @param chance % chance of returning true
622 | * @return true or false value based on the random number generated and the chance value passed in
623 | */
624 | public boolean chance(final int chance) {
625 | return random.nextInt(100) < chance;
626 | }
627 |
628 | public NameDataValues getNameDataValues() {
629 | return nameDataValues;
630 | }
631 |
632 | /**
633 | * Call randomize with a seed value to reset the random number generator. By using the same seed over different tests,
634 | * you will should get the same results out for the same data generation calls.
635 | *
636 | * @param seed Seed value to use to generate random numbers
637 | */
638 | public void randomize(final int seed) {
639 | random = new Random(seed);
640 | }
641 |
642 | /**
643 | * Set this to provide your own list of name data values by passing it a class that implements the
644 | * {@link NameDataValues} interface which just returns the String arrays to use for the test data.
645 | *
646 | * @param nameDataValues Object holding the set of data values to use
647 | */
648 | public void setNameDataValues(final NameDataValues nameDataValues) {
649 | this.nameDataValues = nameDataValues;
650 | }
651 |
652 | /**
653 | * Set this to provide your own list of address data values by passing it a class that implements the
654 | * {@link AddressDataValues} interface which just returns the String arrays to use for the test data.
655 | *
656 | * @param addressDataValues Object holding the set of data values to use
657 | */
658 | public void setAddressDataValues(final AddressDataValues addressDataValues) {
659 | this.addressDataValues = addressDataValues;
660 | }
661 |
662 | /**
663 | * Set this to provide your own list of content data values by passing it a class that implements the
664 | * {@link ContentDataValues} interface which just returns the String arrays to use for the test data.
665 | *
666 | * @param contentDataValues Object holding the set of data values to use
667 | */
668 | public void setContentDataValues(final ContentDataValues contentDataValues) {
669 | this.contentDataValues = contentDataValues;
670 | }
671 |
672 | }
673 |
--------------------------------------------------------------------------------