All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brooklyn.catalog.CatalogPredicates Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.catalog;

import javax.annotation.Nullable;

import brooklyn.catalog.CatalogItem.CatalogItemType;
import brooklyn.entity.Application;
import brooklyn.entity.Entity;
import brooklyn.policy.Policy;

import com.google.common.base.Function;
import com.google.common.base.Predicate;

public class CatalogPredicates {

    public static  Predicate> isCatalogItemType(final CatalogItemType ciType) {
        return new Predicate>() {
            @Override
            public boolean apply(@Nullable CatalogItem item) {
                return item!=null && item.getCatalogItemType()==ciType;
            }
        };
    }

    public static final Predicate> IS_TEMPLATE = 
            CatalogPredicates.isCatalogItemType(CatalogItemType.TEMPLATE);
    public static final Predicate> IS_ENTITY = 
            CatalogPredicates.isCatalogItemType(CatalogItemType.ENTITY);
    public static final Predicate> IS_POLICY = 
            CatalogPredicates.isCatalogItemType(CatalogItemType.POLICY);
    
    public static final Function,String> ID_OF_ITEM_TRANSFORMER = new Function, String>() {
        @Override @Nullable
        public String apply(@Nullable CatalogItem input) {
            if (input==null) return null;
            return input.getId();
        }
    };

    public static  Predicate> name(final Predicate filter) {
        return new Predicate>() {
            @Override
            public boolean apply(@Nullable CatalogItem item) {
                return item!=null && filter.apply(item.getName());
            }
        };
    }

    public static  Predicate> javaType(final Predicate filter) {
        return new Predicate>() {
            @Override
            public boolean apply(@Nullable CatalogItem item) {
                return item!=null && filter.apply(item.getJavaType());
            }
        };
    }

    public static  Predicate> xml(final Predicate filter) {
        return new Predicate>() {
            @Override
            public boolean apply(@Nullable CatalogItem item) {
                return item!=null && filter.apply(item.toXmlString());
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy