1 /**
2 * Licensed under the Artistic License; you may not use this file
3 * except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://displaytag.sourceforge.net/license.html
7 *
8 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 */
12 package org.displaytag.sample;
13
14 import java.util.Calendar;
15 import java.util.Date;
16 import java.util.Random;
17
18
19 /**
20 * Utility class used to get random word and sentences used in examples.
21 * @author Fabrizio Giustina
22 * @version $Revision$ ($Author$)
23 */
24 public final class RandomSampleUtil
25 {
26
27 /**
28 * list of words.
29 */
30 private static String[] words = new String[]{"Lorem", //$NON-NLS-1$
31 "ipsum", //$NON-NLS-1$
32 "dolor", //$NON-NLS-1$
33 "sit", //$NON-NLS-1$
34 "amet", //$NON-NLS-1$
35 "consetetur", //$NON-NLS-1$
36 "sadipscing", //$NON-NLS-1$
37 "elitr", //$NON-NLS-1$
38 "sed", //$NON-NLS-1$
39 "diam", //$NON-NLS-1$
40 "nonumy", //$NON-NLS-1$
41 "eirmod", //$NON-NLS-1$
42 "tempor", //$NON-NLS-1$
43 "invidunt", //$NON-NLS-1$
44 "ut", //$NON-NLS-1$
45 "labore", //$NON-NLS-1$
46 "et", //$NON-NLS-1$
47 "dolore", //$NON-NLS-1$
48 "magna", //$NON-NLS-1$
49 "aliquyam", //$NON-NLS-1$
50 "erat", //$NON-NLS-1$
51 "sed", //$NON-NLS-1$
52 "diam", //$NON-NLS-1$
53 "voluptua", //$NON-NLS-1$
54 "At", //$NON-NLS-1$
55 "vero", //$NON-NLS-1$
56 "eos", //$NON-NLS-1$
57 "et", //$NON-NLS-1$
58 "accusam", //$NON-NLS-1$
59 "et", //$NON-NLS-1$
60 "justo", //$NON-NLS-1$
61 "duo", //$NON-NLS-1$
62 "dolores", //$NON-NLS-1$
63 "et", //$NON-NLS-1$
64 "ea", //$NON-NLS-1$
65 "rebum", //$NON-NLS-1$
66 "Stet", //$NON-NLS-1$
67 "clita", //$NON-NLS-1$
68 "kasd", //$NON-NLS-1$
69 "gubergren", //$NON-NLS-1$
70 "no", //$NON-NLS-1$
71 "sea", //$NON-NLS-1$
72 "takimata", //$NON-NLS-1$
73 "sanctus", //$NON-NLS-1$
74 "est"}; //$NON-NLS-1$
75
76 /**
77 * random number producer.
78 */
79 private static Random random = new Random();
80
81 /**
82 * utility class, don't instantiate.
83 */
84 private RandomSampleUtil()
85 {
86 super();
87 }
88
89 /**
90 * returns a random word.
91 * @return random word
92 */
93 public static String getRandomWord()
94 {
95 return words[random.nextInt(words.length)];
96 }
97
98 /**
99 * returns a random sentence.
100 * @param wordNumber number of word in the sentence
101 * @return random sentence made of <code>wordNumber</code> words
102 */
103 public static String getRandomSentence(int wordNumber)
104 {
105 StringBuffer buffer = new StringBuffer(wordNumber * 12);
106
107 int j = 0;
108 while (j < wordNumber)
109 {
110 buffer.append(getRandomWord());
111 buffer.append(" "); //$NON-NLS-1$
112 j++;
113 }
114 return buffer.toString();
115 }
116
117 /**
118 * returns a random email.
119 * @return random email
120 */
121 public static String getRandomEmail()
122 {
123 return getRandomWord() + "@" + getRandomWord() + ".com"; //$NON-NLS-1$ //$NON-NLS-2$
124 }
125
126 /**
127 * returns a random date.
128 * @return random date
129 */
130 public static Date getRandomDate()
131 {
132
133 Calendar calendar = Calendar.getInstance();
134 calendar.add(Calendar.DATE, 365 - random.nextInt(730));
135 return calendar.getTime();
136 }
137 }