Search in sources :

Example 1 with AbstractCollectionSetVisitor

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;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) ArrayList(java.util.ArrayList) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 2 with AbstractCollectionSetVisitor

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)");
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) CollectionResource(org.opennms.netmgt.collection.api.CollectionResource) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 3 with AbstractCollectionSetVisitor

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;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Example 4 with AbstractCollectionSetVisitor

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;
}
Also used : CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) AttributeGroup(org.opennms.netmgt.collection.api.AttributeGroup) Map(java.util.Map) AbstractCollectionSetVisitor(org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)

Aggregations

CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)4 AbstractCollectionSetVisitor (org.opennms.netmgt.collection.support.AbstractCollectionSetVisitor)4 AttributeGroup (org.opennms.netmgt.collection.api.AttributeGroup)3 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1