Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.48 KB | None | 0 0
  1. package com.hubspot.chi.jobs;
  2.  
  3. import com.google.common.base.Predicate;
  4. import com.hubspot.data.ProductFamily;
  5. import com.hubspot.data.ProductType;
  6.  
  7. /**
  8.  * This class provides several Predicate classes and objects for use with filters against Iterable
  9.  * collections of ProductType.
  10.  *
  11.  * @author wlee
  12.  *
  13.  */
  14. public class ChiJobPredicates
  15. {
  16.     /**
  17.      *  Private static member class that implements Predicate. Instances can be used in filters
  18.      *  to determine if a ProductType instance has a particular ProductFamily.
  19.      *
  20.      * @author wlee
  21.      *
  22.      */
  23.     private static class ProductFamilyEqualToPredicate implements Predicate<ProductType>
  24.     {
  25.         /**
  26.          * The ProductFamily that this predicate will use to compare a ProductType's product family against.
  27.          */
  28.         private final ProductFamily productFamily;
  29.        
  30.         /**
  31.          * Constructor. This creates a Predicate instance for use in filtering Iterable collections.
  32.          * @param productFamily
  33.          */
  34.         private ProductFamilyEqualToPredicate(final ProductFamily productFamily)
  35.         {
  36.             this.productFamily = productFamily;
  37.         }
  38.        
  39.         @Override
  40.         public boolean apply(final ProductType type)
  41.         {
  42.             return (type.getFamily() == productFamily);
  43.         }
  44.     }
  45.  
  46.     /**
  47.      *  Predicate to determine that this product type is of type HUBSPOT_FREE
  48.      */
  49.     public static final Predicate<ProductType> HUBSPOT_FREE_FILTER = new Predicate<ProductType>()
  50.     {
  51.         @Override
  52.         public boolean apply(final ProductType type)
  53.         {
  54.             return type == ProductType.HUBSPOT_FREE;
  55.         }
  56.     };
  57.    
  58.     /*
  59.      *  Predicate to determine if this product is a trial
  60.      */
  61.     public static final Predicate<ProductType> TRIAL_FILTER = new Predicate<ProductType>()
  62.     {
  63.         @Override
  64.         public boolean apply(final ProductType type)
  65.         {
  66.             return type.getIsTrial();
  67.         }
  68.     };
  69.    
  70.     /**
  71.      * Wrapper around the ProductFamilyEqualToPredicate class for creating a predicate object
  72.      * to compare a ProductType's ProductFamily to the provided ProductFamily.
  73.      *
  74.      * @param family - The Product Family to use for this predicate
  75.      * @return a new Predicate<ProductType>
  76.      */
  77.     public static Predicate<ProductType> productFamilyEqualTo( final ProductFamily family )
  78.     {
  79.         return new ProductFamilyEqualToPredicate(family);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement