Repository navigation
Expand file tree
/
Copy pathRandomTextDataGenerator.java
More file actions
68 lines (58 loc) · 2.41 KB
/
Copy pathRandomTextDataGenerator.java
File metadata and controls
68 lines (58 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.apache.hadoop.mapred.gridmix;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
class RandomTextDataGenerator {
static final Log LOG = LogFactory.getLog(RandomTextDataGenerator.class);
static final String GRIDMIX_DATAGEN_RANDOMTEXT_LISTSIZE = "gridmix.datagenerator.randomtext.listsize";
static final String GRIDMIX_DATAGEN_RANDOMTEXT_WORDSIZE = "gridmix.datagenerator.randomtext.wordsize";
static final int DEFAULT_LIST_SIZE = 200;
static final int DEFAULT_WORD_SIZE = 10;
static final long DEFAULT_SEED = 0L;
private String[] words;
private Random random;
RandomTextDataGenerator(int size, int wordSize) {
this(size, DEFAULT_SEED , wordSize);
}
RandomTextDataGenerator(int size, Long seed, int wordSize) {
random = new Random(seed);
words = new String[size];
for (int i = 0; i < size; ++i) {
words[i] =
RandomStringUtils.random(wordSize, 0, 0, true, false, null, random);
}
}
static int getRandomTextDataGeneratorListSize(Configuration conf) {
return conf.getInt(GRIDMIX_DATAGEN_RANDOMTEXT_LISTSIZE, DEFAULT_LIST_SIZE);
}
static void setRandomTextDataGeneratorListSize(Configuration conf,
int listSize) {
if (LOG.isDebugEnabled()) {
LOG.debug("Random text data generator is configured to use a dictionary "
+ " with " + listSize + " words");
}
conf.setInt(GRIDMIX_DATAGEN_RANDOMTEXT_LISTSIZE, listSize);
}
static int getRandomTextDataGeneratorWordSize(Configuration conf) {
return conf.getInt(GRIDMIX_DATAGEN_RANDOMTEXT_WORDSIZE, DEFAULT_WORD_SIZE);
}
static void setRandomTextDataGeneratorWordSize(Configuration conf,
int wordSize) {
if (LOG.isDebugEnabled()) {
LOG.debug("Random text data generator is configured to use a dictionary "
+ " with words of length " + wordSize);
}
conf.setInt(GRIDMIX_DATAGEN_RANDOMTEXT_WORDSIZE, wordSize);
}
String getRandomWord() {
int index = random.nextInt(words.length);
return words[index];
}
List<String> getRandomWords() {
return Arrays.asList(words);
}
}