use of oap.tree.Dimension.ENUM in project oap by oaplatform.
the class TreePerformance method fill.
@SneakyThrows
private void fill(ArrayList<Dimension> dimensions, ArrayList<Tree.ValueData<String>> data, int count) {
val map = new HashMap<String, ArrayList<String>>();
val mapSize = new HashMap<String, Integer>();
val enums = new HashMap<String, ArrayList<Enum<?>>>();
for (int i = 0; i < count; i++) {
val selection = new ArrayList<Object>();
for (Dimension dimension : dimensions) {
if (dimension.name.startsWith("string")) {
val list = map.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
if (list.isEmpty()) {
for (int r = 0; r < 100; r++) {
list.add(RandomStringUtils.randomAlphabetic(10) + i);
}
}
selection.add(Lists.random(list).get());
} else if (dimension.name.startsWith("long")) {
selection.add(RandomUtils.nextLong(0, 1000000));
} else if (dimension.name.startsWith("boolean")) {
selection.add(RandomUtils.nextBoolean());
} else if (dimension.name.startsWith("arrayString")) {
val size = mapSize.computeIfAbsent(dimension.name, ss -> {
final Matcher matcher = ARRAY_STRING_PATTERN.matcher(dimension.name);
assert matcher.find();
return Integer.parseInt(matcher.group(1));
});
val list = map.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
if (list.isEmpty()) {
for (int r = 0; r < 100; r++) {
list.add(RandomStringUtils.randomAlphabetic(10) + i);
}
}
val array = new ArrayList<String>();
for (int s = 0; s < size; s++) {
array.add(Lists.random(list).get());
}
selection.add(new Tree.Array(array, true));
} else if (dimension.name.startsWith("arrayEnum")) {
val size = mapSize.computeIfAbsent(dimension.name, ss1 -> {
final Matcher matcher = ARRAY_ENUM_PATTERN.matcher(dimension.name);
assert matcher.find();
return Integer.parseInt(matcher.group(1));
});
val list = enums.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
if (list.isEmpty()) {
final Matcher matcher = ARRAY_ENUM_PATTERN.matcher(dimension.name);
assert matcher.find();
final Class<Enum<?>> clazz = (Class<Enum<?>>) Class.forName(matcher.group(2));
final Enum<?>[] enumConstants = clazz.getEnumConstants();
list.addAll(asList(enumConstants));
}
val array = new ArrayList<Enum<?>>();
for (int s = 0; s < size; s++) {
array.add(Lists.random(list).get());
}
selection.add(new Tree.Array(array, true));
} else if (dimension.name.startsWith("arrayLong")) {
val array = new ArrayList<Long>();
val size = mapSize.computeIfAbsent(dimension.name, ss1 -> {
final Matcher matcher = ARRAY_LONG_PATTERN.matcher(dimension.name);
matcher.find();
return Integer.parseInt(matcher.group(1));
});
for (int s = 0; s < size; s++) {
array.add(RandomUtils.nextLong(0, size));
}
selection.add(new Tree.Array(array, true));
} else if (dimension.name.startsWith("enum")) {
val list = enums.computeIfAbsent(dimension.name, (dn) -> new ArrayList<>());
if (list.isEmpty()) {
final Matcher matcher = ENUM_PATTERN.matcher(dimension.name);
assert matcher.find();
final Class<Enum<?>> clazz = (Class<Enum<?>>) Class.forName(matcher.group(1));
final Enum<?>[] enumConstants = clazz.getEnumConstants();
list.addAll(asList(enumConstants));
}
selection.add(Lists.random(list).get());
} else {
throw new IllegalStateException("Unknown dimension type " + dimension.name);
}
}
data.add(new Tree.ValueData<>(selection, "data" + i));
}
}
Aggregations