use of org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor in project opennms by OpenNMS.
the class CollectionSetUtils method flatten.
public static List<String> flatten(CollectionSet collectionSet) {
final List<String> strings = new ArrayList<>();
collectionSet.visit(new AbstractCollectionSetVisitor() {
CollectionResource resource;
AttributeGroup group;
@Override
public void visitResource(CollectionResource resource) {
this.resource = resource;
}
@Override
public void visitGroup(AttributeGroup group) {
this.group = group;
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
strings.add(String.format("%s/%s/%s[%s,%s]", resource.getPath(), group.getName(), attribute.getName(), attribute.getStringValue(), attribute.getNumericValue()));
}
});
return strings;
}
use of org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor in project opennms by OpenNMS.
the class CollectCommand method printCollectionSet.
private void printCollectionSet(CollectionSet collectionSet) {
AtomicBoolean didPrintAttribute = new AtomicBoolean(false);
collectionSet.visit(new AbstractCollectionSetVisitor() {
@Override
public void visitResource(CollectionResource resource) {
System.out.printf("%s\n", resource);
}
@Override
public void visitGroup(AttributeGroup group) {
System.out.printf("\tGroup: %s\n", group.getName());
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
System.out.printf("\t\t%s\n", attribute);
didPrintAttribute.set(true);
}
});
if (!didPrintAttribute.get()) {
System.out.println("(Empty collection set)");
}
}
use of org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor in project opennms by OpenNMS.
the class CollectionSetUtils method getAttributesByName.
public static Map<String, CollectionAttribute> getAttributesByName(CollectionSet collectionSet) {
final Map<String, CollectionAttribute> attributesByName = Maps.newHashMap();
collectionSet.visit(new AbstractCollectionSetVisitor() {
@Override
public void visitAttribute(CollectionAttribute attribute) {
attributesByName.put(attribute.getName(), attribute);
}
});
return attributesByName;
}
use of org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor in project opennms by OpenNMS.
the class CollectionSetUtils method getAttributesByNameByGroup.
public static Map<String, Map<String, CollectionAttribute>> getAttributesByNameByGroup(CollectionSet collectionSet) {
final Map<String, Map<String, CollectionAttribute>> attributesByNameByGroup = Maps.newHashMap();
collectionSet.visit(new AbstractCollectionSetVisitor() {
private String groupName = null;
private Map<String, CollectionAttribute> attributesByName = Maps.newHashMap();
@Override
public void visitGroup(AttributeGroup group) {
groupName = group.getName();
}
@Override
public void visitAttribute(CollectionAttribute attribute) {
attributesByName.put(attribute.getName(), attribute);
}
@Override
public void completeGroup(AttributeGroup group) {
attributesByNameByGroup.put(groupName, attributesByName);
attributesByName = Maps.newHashMap();
}
});
return attributesByNameByGroup;
}
Aggregations