Changeset 8655 in josm for trunk/test
- Timestamp:
- 2015-08-09T23:25:03+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/performance/org/openstreetmap/josm/data/osm/OsmDataGenerator.java
r8632 r8655 24 24 25 25 /** 26 * This is a list of randomly generated strings. 27 * <p> 28 * It provides methods to get them both interned and uninterned. 29 * 30 * @author Michael Zangl 31 */ 32 public static final class RandomStringList { 33 private final Random random; 34 private final String[] strings; 35 private final String[] interned; 36 37 /** 38 * Creates a new, random List of Strings. 39 * @param seed The seed to use. 40 * @param size The size of the list. 41 */ 42 public RandomStringList(int seed, int size) { 43 random = new Random(seed); 44 strings = new String[size]; 45 interned = new String[size]; 46 for (int i = 0; i < size; i++) { 47 strings[i] = randomString(); 48 interned[i] = strings[i].intern(); 49 } 50 } 51 52 protected String randomString() { 53 return RandomStringUtils.random(12, 0, 0, true, true, null, random); 54 } 55 56 /** 57 * Gets a String that was not interned. 58 * @return The String. 59 */ 60 public String get() { 61 int n = random.nextInt(strings.length); 62 return strings[n]; 63 } 64 65 /** 66 * Gets a String that was interned. 67 * @return The String. 68 */ 69 public String getInterned() { 70 int n = random.nextInt(interned.length); 71 return interned[n]; 72 } 73 } 74 75 /** 26 76 * A generator that generates test data by filling a data set. 27 77 * @author Michael Zangl … … 70 120 } 71 121 72 protected String randomString() {73 return RandomStringUtils.random(12, 0, 0, true, true, null, random);74 }75 76 122 /** 77 123 * Gets a file path where this data could be stored. … … 135 181 private static final int KEY_COUNT = 150; 136 182 private final double tagNodeRation; 137 private ArrayList<String>keys;138 private ArrayList<String>values;183 private RandomStringList keys; 184 private RandomStringList values; 139 185 140 186 private KeyValueDataGenerator(String datasetName, int nodeCount, double tagNodeRation) { … … 146 192 public void fillData(DataSet ds) { 147 193 super.fillData(ds); 148 keys = new ArrayList<>(); 149 for (int i = 0; i < KEY_COUNT; i++) { 150 keys.add(randomString()); 151 } 152 values = new ArrayList<>(); 153 for (int i = 0; i < VALUE_COUNT; i++) { 154 values.add(randomString()); 155 } 194 keys = new RandomStringList(random.nextInt(), KEY_COUNT); 195 values = new RandomStringList(random.nextInt(), VALUE_COUNT); 156 196 157 197 double tags = nodes.size() * tagNodeRation; 158 198 for (int i = 0; i < tags; i++) { 159 String key = randomKey();160 String value = randomValue();199 String key = keys.get(); 200 String value = values.get(); 161 201 nodes.get(random.nextInt(nodes.size())).put(key, value); 162 202 } … … 164 204 165 205 /** 206 * Gets the values that were used to fill the tags. 207 * @return The list of strings. 208 */ 209 public RandomStringList randomValues() { 210 ensureInitialized(); 211 return values; 212 } 213 214 /** 215 * Gets the list of keys that was used to fill the tags. 216 * @return The list of strings. 217 */ 218 public RandomStringList randomKeys() { 219 ensureInitialized(); 220 return keys; 221 } 222 223 /** 166 224 * Gets a random value that was used to fill the tags. 167 * @return A random String probably used in as value somewhere. 225 * @return A random String probably used in as value somewhere. Not interned. 168 226 */ 169 227 public String randomValue() { 170 ensureInitialized(); 171 return values.get(random.nextInt(values.size())); 228 return randomValues().get(); 172 229 } 173 230 174 231 /** 175 232 * Gets a random key that was used to fill the tags. 176 * @return A random String probably used in as key somewhere. 233 * @return A random String probably used in as key somewhere. Not interned. 177 234 */ 178 235 public String randomKey() { 179 ensureInitialized(); 180 return keys.get(random.nextInt(keys.size())); 236 return randomKeys().get(); 181 237 } 182 238 }
Note:
See TracChangeset
for help on using the changeset viewer.