Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.hubspot.chi.jobs;
- import com.google.common.base.Predicate;
- import com.hubspot.data.ProductFamily;
- import com.hubspot.data.ProductType;
- /**
- * This class provides several Predicate classes and objects for use with filters against Iterable
- * collections of ProductType.
- *
- * @author wlee
- *
- */
- public class ChiJobPredicates
- {
- /**
- * Private static member class that implements Predicate. Instances can be used in filters
- * to determine if a ProductType instance has a particular ProductFamily.
- *
- * @author wlee
- *
- */
- private static class ProductFamilyEqualToPredicate implements Predicate<ProductType>
- {
- /**
- * The ProductFamily that this predicate will use to compare a ProductType's product family against.
- */
- private final ProductFamily productFamily;
- /**
- * Constructor. This creates a Predicate instance for use in filtering Iterable collections.
- * @param productFamily
- */
- private ProductFamilyEqualToPredicate(final ProductFamily productFamily)
- {
- this.productFamily = productFamily;
- }
- @Override
- public boolean apply(final ProductType type)
- {
- return (type.getFamily() == productFamily);
- }
- }
- /**
- * Predicate to determine that this product type is of type HUBSPOT_FREE
- */
- public static final Predicate<ProductType> HUBSPOT_FREE_FILTER = new Predicate<ProductType>()
- {
- @Override
- public boolean apply(final ProductType type)
- {
- return type == ProductType.HUBSPOT_FREE;
- }
- };
- /*
- * Predicate to determine if this product is a trial
- */
- public static final Predicate<ProductType> TRIAL_FILTER = new Predicate<ProductType>()
- {
- @Override
- public boolean apply(final ProductType type)
- {
- return type.getIsTrial();
- }
- };
- /**
- * Wrapper around the ProductFamilyEqualToPredicate class for creating a predicate object
- * to compare a ProductType's ProductFamily to the provided ProductFamily.
- *
- * @param family - The Product Family to use for this predicate
- * @return a new Predicate<ProductType>
- */
- public static Predicate<ProductType> productFamilyEqualTo( final ProductFamily family )
- {
- return new ProductFamilyEqualToPredicate(family);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement