org.gridkit.jvmtool.stacktrace.analytics.SimpleCategorizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sjk-stacktrace Show documentation
Show all versions of sjk-stacktrace Show documentation
Thread dumps: capture and encoding
package org.gridkit.jvmtool.stacktrace.analytics;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.gridkit.jvmtool.stacktrace.ThreadSnapshot;
public class SimpleCategorizer implements ThreadSnapshotCategorizer {
private String[] categories = new String[0];
private ThreadSnapshotFilter[] filters = new ThreadSnapshotFilter[0];
public SimpleCategorizer() {
}
public SimpleCategorizer(Map categories) {
for(Map.Entry cat: categories.entrySet()) {
addCategory(cat.getKey(), cat.getValue());
}
}
public void addCategory(String category, ThreadSnapshotFilter filter) {
for(String cat: categories) {
if (cat.equals(category)) {
throw new IllegalArgumentException("Dupplicate category [" + cat + "]");
}
}
int n = categories.length;
categories = Arrays.copyOf(categories, n + 1);
filters = Arrays.copyOf(filters, n + 1);
categories[n] = category;
filters[n] = filter;
}
@Override
public List getCategories() {
return Arrays.asList(categories);
}
@Override
public String categorize(ThreadSnapshot snap) {
for(int i = 0; i != categories.length; ++i) {
if (filters[i].evaluate(snap)) {
return categories[i];
}
}
return null;
}
}