use of com.evolveum.midpoint.util.KeyValueTreeNode in project midpoint by Evolveum.
the class InternalsCachePanel method getCacheInformation.
private String getCacheInformation() {
StringBuilder sb = new StringBuilder();
CachesStateInformationType state = MidPointApplication.get().getCacheRegistry().getStateInformation();
List<KeyValueTreeNode<String, SizeInformation>> trees = new ArrayList<>();
for (SingleCacheStateInformationType entry : state.getEntry()) {
KeyValueTreeNode<String, SizeInformation> root = new KeyValueTreeNode<>(entry.getName(), new SizeInformation(entry));
trees.add(root);
addComponents(root, entry.getComponent());
}
Holder<Integer> maxLabelLength = new Holder<>(0);
// to avoid issues with log10
Holder<Integer> maxSize = new Holder<>(1);
// to avoid issues with log10
Holder<Integer> maxSecondarySize = new Holder<>(1);
trees.forEach(tree -> tree.acceptDepthFirst(node -> {
int labelLength = node.getUserObject().getKey().length() + node.getDepth() * 2;
int size = node.getUserObject().getValue().size;
int secondarySize = node.getUserObject().getValue().secondarySize;
if (labelLength > maxLabelLength.getValue()) {
maxLabelLength.setValue(labelLength);
}
if (size > maxSize.getValue()) {
maxSize.setValue(size);
}
if (secondarySize > maxSecondarySize.getValue()) {
maxSecondarySize.setValue(secondarySize);
}
}));
int labelSize = Math.max(maxLabelLength.getValue() + 1, 30);
int sizeSize = Math.max((int) Math.log10(maxSize.getValue()) + 2, 7);
int secondarySizeSize = Math.max((int) Math.log10(maxSecondarySize.getValue()) + 2, 8);
int firstPart = labelSize + 3;
int secondPart = sizeSize + 2;
int thirdPart = secondarySizeSize + 3;
String headerFormatString = " %-" + labelSize + "s | %" + sizeSize + "s | %" + secondarySizeSize + "s\n";
String valueFormatString = " %-" + labelSize + "s | %" + sizeSize + "d | %" + secondarySizeSize + "s\n";
sb.append("\n");
sb.append(String.format(headerFormatString, "Cache", "Size", "Sec. size"));
sb.append(StringUtils.repeat("=", firstPart)).append("+").append(StringUtils.repeat("=", secondPart)).append("+").append(StringUtils.repeat("=", thirdPart)).append("\n");
trees.forEach(tree -> {
tree.acceptDepthFirst(node -> printNode(sb, valueFormatString, node));
sb.append(StringUtils.repeat("-", firstPart)).append("+").append(StringUtils.repeat("-", secondPart)).append("+").append(StringUtils.repeat("-", thirdPart)).append("\n");
});
return sb.toString();
}
Aggregations