Class GeneralFilter


  • public class GeneralFilter
    extends Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(Object o)
      Cycle over all our fields and check to see if this object matches.
      void addField​(String field, boolean value, int type)
      Add a new field for a boolean comparison.
      void addField​(String field, double max, double min)
      Add a new field for a number range comparison.
      void addField​(String field, double value, int type)
      Add a new field for a number comparison.
      void addField​(String field, Object object, int type)
      Add a new field for an Object comparison.
      void addField​(String field, Object object, Comparator comp, int type)
      Add a new field for an Object comparison.
      void addField​(String field, String value, int type)
      Add a new field for a String comparison.
      void addField​(String field, Date value, int type)
      Add a new field for a Date comparison.
      void addField​(String field, Date max, Date min)
      Add a new field to check for the date to be in the specified range.
      Object[] filter​(Object[] objects)
      Filter an array of objects and return a new array of the filtered objects.
      Collection filter​(Collection collection)
      Iterate over the Collection and filter given our fields, return the filtered objects in a new Collection.
      void filter​(Collection collection, Collection newCollection)
      Iterate over the Collection and filter given our fields.
      List filter​(List list)
      Cycle over the List and filter given our fields.
      void filter​(List list, List newList)
      Cycle over the List and filter given our fields.
      void filter​(List list, Set newSet)
      Iterate over the List and filter the objects it contains.
      Map filter​(Map map, int type)
      Iterate over the Map and filter either the Keys or Values in the Map given our fields.
      void filter​(Map map, int type, Map newMap)
      Iterate over the Map and filter either the Keys or Values in the Map given our fields.
      Set filter​(Set set)
      Iterate over the Set and filter given our fields, return the filtered objects in a new Set.
      void filter​(Set set, List newList)
      Iterate over the Set and filter the objects it contains.
      void filter​(Set set, Set newSet)
      Iterate over the Set and filter the objects it contains.
      SortedMap filter​(SortedMap map, int type)
      Iterate over the SortedMap and filter either the Keys or Values in the SortedMap given our fields.
      SortedSet filter​(SortedSet set)
      Iterate over the SortedSet and filter the objects it contains.
      void filterAndRemove​(Collection col)
      Cycle over the Collection and filter given our fields directly from the passed in Set.
      void filterAndRemove​(List list)
      Cycle over the List and filter given our fields directly from the passed in List.
      void filterAndRemove​(Map map, int type)
      Iterate over the Map and filter given our fields directly from the passed in Map.
      void filterAndRemove​(Set set)
      Cycle over the Set and filter given our fields directly from the passed in Set.
      Class getFilterClass()
      Get the class that we are filtering.
      boolean getNullAcceptPolicy()
      Get the null accept policy, this governs what happens when a null is observed from the result of an accessor chain call, true indicates that the value is accepted, false indicates that it is rejected.
      void setFieldValue​(String field, boolean value)
      Set a new value for the specified boolean filter field.
      void setFieldValue​(String field, double value)
      Set new maximum and minimum values for the specified number filter field.
      void setFieldValue​(String field, double max, double min)
      Set new maximum and minimum values for the specified number filter field.
      void setFieldValue​(String field, Object value)
      Set the value for the specified field.
      void setFieldValue​(String field, String value)
      Set the value for the specified String filter field.
      void setFieldValue​(String field, Date value)
      Set a new date value for the specified date filter field.
      void setFieldValue​(String field, Date max, Date min)
      Set new date range values for the specified date filter field.
      void setNullAcceptPolicy​(boolean policy)
      Specify what the policy should be when a null value is returned from an accesor chain, in other words, when the comparison is made should a null value return true or false.
      String toString()
      Output the filter fields as a String suitable for debugging.
    • Constructor Detail

      • GeneralFilter

        public GeneralFilter​(Class c)
    • Method Detail

      • setNullAcceptPolicy

        public void setNullAcceptPolicy​(boolean policy)
        Specify what the policy should be when a null value is returned from an accesor chain, in other words, when the comparison is made should a null value return true or false.
        Parameters:
        policy - The policy to use.
      • getNullAcceptPolicy

        public boolean getNullAcceptPolicy()
        Get the null accept policy, this governs what happens when a null is observed from the result of an accessor chain call, true indicates that the value is accepted, false indicates that it is rejected.
        Returns:
        The policy.
      • addField

        public void addField​(String field,
                             Date max,
                             Date min)
                      throws IllegalArgumentException
        Add a new field to check for the date to be in the specified range.
        Parameters:
        field - The field spec.
        max - The upper date.
        min - The lower date.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor.
      • setFieldValue

        public void setFieldValue​(String field,
                                  Date max,
                                  Date min)
                           throws IllegalArgumentException
        Set new date range values for the specified date filter field.
        Parameters:
        field - The field spec.
        max - The upper date.
        min - The lower date.
        Throws:
        IllegalArgumentException - If we can't find the specified field.
      • addField

        public void addField​(String field,
                             Date value,
                             int type)
                      throws IllegalArgumentException
        Add a new field for a Date comparison. Note: the only supported types for ths method are: GeneralFilter.EQUALS, GeneralFilter.NOT_EQUALS, GeneralFilter.LESS_THAN, GeneralFilter.GREATER_THAN.
        Parameters:
        field - The field spec.
        value - The Date to check against.
        type - The type, see above for valid values.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor. Or if you pass in an invalid type for this method.
      • setFieldValue

        public void setFieldValue​(String field,
                                  Date value)
                           throws IllegalArgumentException
        Set a new date value for the specified date filter field.
        Parameters:
        field - The field spec.
        value - The new value.
        Throws:
        IllegalArgumentException - If we can't find the specified field.
      • addField

        public void addField​(String field,
                             boolean value,
                             int type)
                      throws IllegalArgumentException
        Add a new field for a boolean comparison. Note: the only supported types for ths method are: GeneralFilter.EQUALS, GeneralFilter.NOT_EQUALS.
        Parameters:
        field - The field spec.
        value - The Date to check against.
        type - The type, see above for valid values.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor. Or if you pass in an invalid type for this method.
      • setFieldValue

        public void setFieldValue​(String field,
                                  boolean value)
                           throws IllegalArgumentException
        Set a new value for the specified boolean filter field.
        Parameters:
        field - The field spec.
        value - The new value.
        Throws:
        IllegalArgumentException - If we can't find the specified field.
      • addField

        public void addField​(String field,
                             double value,
                             int type)
                      throws IllegalArgumentException
        Add a new field for a number comparison. Even though you should pass in a double ANY number can be checked for, regardless of primitive type.

        Note: the only supported types for ths method are: GeneralFilter.EQUALS, GeneralFilter.NOT_EQUALS, GeneralFilter.LESS_THAN, GeneralFilter.GREATER_THAN.

        Warning: it is valid to pass in a value of 4 for the type, which maps to a range check for the values however this is NOT recommended since in this method we set the maximum and minimum values to 0, so unless the value you are looking for is 0 you would get false returned from the checking of the field in the filter, probably not what you want... If you want to check a range then use addField(String,double,double).
        Parameters:
        field - The field spec.
        value - The value to check against.
        type - The type, see above for valid values.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor. Or if you pass in an invalid type for this method.
      • setFieldValue

        public void setFieldValue​(String field,
                                  double value)
                           throws IllegalArgumentException
        Set new maximum and minimum values for the specified number filter field.
        Parameters:
        field - The field spec.
        value - The new value.
        Throws:
        IllegalArgumentException - If we can't find the specified field.
      • addField

        public void addField​(String field,
                             double max,
                             double min)
        Add a new field for a number range comparison. Even though you should pass in a double ANY number can be checked for, regardless of primitive type. The checking is such that if the value equals one of the values (max or min) then we find a match.
        Parameters:
        field - The field spec.
        max - The maximum value to check against.
        min - The minimum value to check against.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor.
      • setFieldValue

        public void setFieldValue​(String field,
                                  double max,
                                  double min)
                           throws IllegalArgumentException
        Set new maximum and minimum values for the specified number filter field.
        Parameters:
        field - The field spec.
        max - The new maximum to check against.
        min - The new minimum to check against.
        Throws:
        IllegalArgumentException - If we can't find the specified field.
      • addField

        public void addField​(String field,
                             String value,
                             int type)
                      throws IllegalArgumentException
        Add a new field for a String comparison.

        Note: the only supported types for ths method are: GeneralFilter.EQUALS, GeneralFilter.NOT_EQUALS, GeneralFilter.CONTAINS, GeneralFilter.NOT_CONTAINS, GeneralFilter.STARTS_WITH, GeneralFilter.ENDS_WITH.

        Warning: using this method will cause the toString () method to be called on the value we get from the field regardless of type, if you need to compare objects then use the method addField(String,Object,Comparator,int) or addField(String,Object,int).
        Parameters:
        field - The field spec.
        value - The value to compare against.
        type - The type of comparison, see above for valid values.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor. Or if you pass in an invalid type for this method.
      • setFieldValue

        public void setFieldValue​(String field,
                                  String value)
                           throws IllegalArgumentException
        Set the value for the specified String filter field.
        Parameters:
        field - The field spec.
        value - The value to compare against.
        Throws:
        IllegalArgumentException - If we can't find the specified field.
      • addField

        public void addField​(String field,
                             Object object,
                             int type)
                      throws IllegalArgumentException
        Add a new field for an Object comparison. The passed in Object MUST implement the Comparable interface otherwise an exception if thrown. We compare the object gained from the field spec to the object passed in by calling compareTo([Object returned from field spec call]) passing the object returned to the compareTo method of the object passed in here. It is your responsibility to ensure that the object returned from the field spec call will NOT cause a ClassCastException to be thrown in the compareTo method.

        Note: the only supported types for ths method are: GeneralFilter.EQUALS, GeneralFilter.NOT_EQUALS, GeneralFilter.LESS_THAN, GeneralFilter.GREATER_THAN. If you pass in GeneralFilter.NOT_EQUALS then if the compareTo method returns something other than 0 then we accept the object in the filter.
        Parameters:
        field - The field spec.
        value - The value to compare against.
        type - The type of comparison, see above for valid values.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor. Or if you pass in an invalid type for this method, or if the passed in object does not implement the Comparable interface.
      • addField

        public void addField​(String field,
                             Object object,
                             Comparator comp,
                             int type)
                      throws IllegalArgumentException
        Add a new field for an Object comparison. We use the passed in Comparator to compare the objects, in the call to the compare method we pass the object passed into this method as the first argument and the object returned from the field spec call as the second argument.

        It is your responsibility to ensure that the object passed in and returned from the field spec call will NOT cause a ClassCastException to be thrown in the compare method.

        Note: the only supported types for ths method are: GeneralFilter.EQUALS, GeneralFilter.NOT_EQUALS, GeneralFilter.LESS_THAN, GeneralFilter.GREATER_THAN. If you pass in GeneralFilter.NOT_EQUALS then if the compare method returns something other than 0 then we accept the object in the filter.
        Parameters:
        field - The field spec.
        value - The value to compare against.
        type - The type of comparison, see above for valid values.
        Throws:
        IllegalArgumentException - If the field spec is not valid for the class set in the constructor. Or if you pass in an invalid type for this method, or if the passed in object does not implement the Comparable interface.
      • getFilterClass

        public Class getFilterClass()
        Get the class that we are filtering.
        Returns:
        The Class.
      • accept

        public boolean accept​(Object o)
                       throws IllegalAccessException,
                              InvocationTargetException,
                              FilterException
        Cycle over all our fields and check to see if this object matches. We return at the first field that does not match.
        Parameters:
        o - The object to check the fields against.
        Returns:
        true if all our fields match, false otherwise.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public void filter​(Set set,
                           Set newSet)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Iterate over the Set and filter the objects it contains. Any objects that match, via the accept(Object) method will then be added to the newSet parameter. Since we use an Iterator to cycle over the Set the ordering of the values added to the newSet is dependent on the ordering of the newSet Set.

        The Set set is left unchanged.
        Parameters:
        set - The Set to filter.
        newSet - The Set to add successfully filtered objects to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public void filter​(Set set,
                           List newList)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Iterate over the Set and filter the objects it contains. Any objects that match, via the accept(Object) method will then be added to the newList parameter. Since we use an Iterator to cycle over the Set the ordering of the values added to the newList is dependent on the ordering of the set Set.

        The Set set is left unchanged.
        Parameters:
        set - The Set to filter.
        newList - The List to add successfully filtered objects to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public void filter​(List list,
                           Set newSet)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Iterate over the List and filter the objects it contains. Any objects that match, via the accept(Object) method will then be added to the newSet parameter.

        The List list is left unchanged.
        Parameters:
        list - The List to filter.
        newSet - The Set to add successfully filtered objects to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public void filter​(Map map,
                           int type,
                           Map newMap)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Iterate over the Map and filter either the Keys or Values in the Map given our fields. You specify whether you want the Keys or Values to be filtered using the type parameter, pass either GeneralFilter.KEYS or GeneralFilter.VALUES. Any values that match, via the accept(Object) method will then be added to the newMap parameter. Since we use an Iterator to cycle over the Map the ordering of the values added to the newMap is dependent on the ordering of the newMap Map.

        The Map map is left unchanged.

        Note: if the type parm is NOT GeneralFilter.KEYS or GeneralFilter.VALUES then it's assumed you want to filter on the values.
        Parameters:
        map - The Map to filter.
        type - The type to filter on, either keys or values.
        newMap - The map to add successfully filtered keys/values to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public void filter​(Collection collection,
                           Collection newCollection)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Iterate over the Collection and filter given our fields.

        The Collection collection is left unchanged.

        Note: since we use an Iterator to iterate over the Collection it is SLOWER than if you have a List and use the filter(List,List) method since that uses List.size and it has been shown that using the get method can be an order of magnitude faster than using the Iterator. This method is really here to allow filtering of things like Sets. It would be interesting to determine whether performing the following would be more efficient (i.e. faster...) than using the Iterator:
           // Get as an Object array.
           Object[] objs = collection.toArray ();
        
           int size = objs.length;
           for (int i = 0; i < size; i++)
           {
        
               if (this.accept (objs[i]))
               {
        
                  newCollection.add (objs[i]);
        
               }
        
           } 
         

        If you find this to be the case, please contact code-monkey@gentlyweb.com.

        The bottom line is, if you have a List to filter then use the filter(List,List) method rather than this one.

        Parameters:
        collection - The Collection to filter.
        newCollection - The Collection to add successfully filtered objects to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public void filter​(List list,
                           List newList)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Cycle over the List and filter given our fields. The filtered objects are added to the newList in the order they are gained from list.

        The List list is left unchanged.

        This method will be much quicker than using the filter(Collection,Collection) method since it uses the get method of List rather than an Iterator. However if you need to iterate over the List rather than use direct access then cast as a Collection and call filter(Collection,Collection) instead.
        Parameters:
        list - The List to filter.
        newList - The List to add successfully filtered objects to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public Object[] filter​(Object[] objects)
                        throws IllegalAccessException,
                               InvocationTargetException,
                               FilterException
        Filter an array of objects and return a new array of the filtered objects.

        The object array is left unchanged.

        It should be noted that we perform a bit of a cheat here, we use an intermediate ArrayList to add the new objects into and then call toArray to get the objects. This may have efficiency considerations but we're pretty sure that the implementation of ArrayList is gonna be as fast we could write!
        Parameters:
        objects - The objects to filter.
        Returns:
        A new Object array of the filtered objects.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filter

        public Map filter​(Map map,
                          int type)
                   throws IllegalAccessException,
                          InvocationTargetException,
                          FilterException
        Iterate over the Map and filter either the Keys or Values in the Map given our fields. You specify whether you want the Keys or Values to be filtered using the type parameter, pass either GeneralFilter.KEYS or GeneralFilter.VALUES. Any values that match, via the accept(Object) method will then be added to the new Map.

        The Map is left unchanged.

        Note: if the type parm is NOT GeneralFilter.KEYS or GeneralFilter.VALUES then it's assumed you want to filter on the values.

        We try and create a new instance of the same type as the Map passed in. So if the Map passed in is actually a HashMap then we create a new HashMap and then add to that. If the passed in Map actually is a SortedMap then we call filter(SortedMap,int) instead. There is a potential problem here in that we can only call the default no argument constructor for the new Map, if you are using a HashMap and have tuned it with a load factor and capacity then this method will ruin that and we recommend that you use: filter(Map,int,Map) instead.
        Parameters:
        map - The Map to filter.
        type - The type to filter on, either keys or values.
        Returns:
        A new Map to add successfully filtered keys/values to.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date. It is also thrown if we cannot create the new instance of Map it will then contain a nested exception with the "real" reason for the failure.
      • filter

        public SortedMap filter​(SortedMap map,
                                int type)
                         throws IllegalAccessException,
                                InvocationTargetException,
                                FilterException
        Iterate over the SortedMap and filter either the Keys or Values in the SortedMap given our fields. You specify whether you want the Keys or Values to be filtered using the type parameter, pass either GeneralFilter.KEYS or GeneralFilter.VALUES. Any values that match, via the accept(Object) method will then be added to the new SortedMap.

        The Map is left unchanged.

        Note: if the type parm is NOT GeneralFilter.KEYS or GeneralFilter.VALUES then it's assume you want to filter on the values.

        We try and create a new instance of the same type as the SortedMap passed in. And then get the Comparator from the old SortedMap and use it in the constructor of the new SortedMap. If your SortedMap doesn't use a Comparator then it doesn't matter since if your SortedMap follows the general contract for a SortedMap then it should ignore the Comparator value if it is null. If the SortedMap passed in doesn't have a constructor with a single Comparator argument then we try and create a new version via Class.newInstance (), i.e. via a blank constructor, if that isn't present or not accessible then we throw an exception.
        Parameters:
        map - The SortedMap to filter.
        type - The type to filter on, either keys or values.
        Returns:
        A new SortedMap with the successfully filtered keys/values added to it.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date. It is also thrown if we cannot create the new instance of SortedMap it will then contain a nested exception with the "real" reason for the failure.
      • filter

        public Collection filter​(Collection collection)
                          throws IllegalAccessException,
                                 InvocationTargetException,
                                 FilterException
        Iterate over the Collection and filter given our fields, return the filtered objects in a new Collection.

        The Collection passed in is left unchanged.

        Effectively this method is just a wrapper for filter(Collection,Collection).

        The bottom line is, if you have a List to filter then use the filter(List,List) method rather than this one.

        We try and create a new instance of the same type as the Collection passed in. So if the Collection passed in is actually a ArrayList then we create a new ArrayList and then add to that. If the passed in Collection actually is a SortedSet then we call #filter(SortedSet,int) instead, this is to preserve any Comparator that may be used in sorting the Collection.

        Parameters:
        collection - The Collection to filter.
        Returns:
        A new Collection with the successfully filtered objects added.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date. It is also thrown if we cannot create the new instance of Collection it will then contain a nested exception with the "real" reason for the failure.
      • filter

        public Set filter​(Set set)
                   throws IllegalAccessException,
                          InvocationTargetException,
                          FilterException
        Iterate over the Set and filter given our fields, return the filtered objects in a new Set.

        The Set passed in is left unchanged.

        Effectively this method is just a wrapper for filter(Set,Set).

        We try and create a new instance of the same type as the Set passed in. So if the Set passed in is actually a HashSet then we create a new HashSet and then add to that. If the passed in Set actually is a SortedSet then we call #filter(SortedSet,int) instead, this is to preserve any Comparator that may be used in sorting the Set.

        Parameters:
        set - The Set to filter.
        Returns:
        A new Set with the successfully filtered objects added.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date. It is also thrown if we cannot create the new instance of Set it will then contain a nested exception with the "real" reason for the failure.
      • filter

        public SortedSet filter​(SortedSet set)
                         throws IllegalAccessException,
                                InvocationTargetException,
                                FilterException
        Iterate over the SortedSet and filter the objects it contains. Any values that match, via the accept(Object) method will then be added to the new SortedMap.

        The SortedSet is left unchanged.

        We try and create a new instance of the same type as the SortedSet passed in. And then get the Comparator from the old SortedMet and use it in the constructor of the new SortedMet. If your SortedMet doesn't use a Comparator then it doesn't matter since if your SortedMet follows the general contract for a SortedMet then it should ignore the Comparator value if it is null. If the SortedMet passed in doesn't have a constructor with a single Comparator argument then we try and create a new version via Class.newInstance (), i.e. via a blank constructor, if that isn't present or not accessible then we throw an exception.
        Parameters:
        set - The SortedMet to filter.
        Returns:
        A new SortedMet with successfully filtered objects added to it.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date. It is also thrown if we cannot create the new instance of SortedSet it will then contain a nested exception with the "real" reason for the failure.
      • filter

        public List filter​(List list)
                    throws IllegalAccessException,
                           InvocationTargetException,
                           FilterException
        Cycle over the List and filter given our fields. The filtered objects are added to a new List and then returned.

        The List list is left unchanged.

        This method will be much quicker than using the filter(Collection,Collection) method since it uses the get method of List rather than an Iterator. However if you need to iterate over the List rather than use direct access then cast as a Collection and call filter(Collection,Collection) instead and then cast the return as a List.

        We try and create a new instance of the same type as the List passed in. So if the List passed in is actually an ArrayList then we create a new ArrayList and then add to that.

        Parameters:
        list - The List to filter.
        Returns:
        A new List with the successfully filtered objects added to it.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date. It is also thrown if we cannot create the new instance of List it will then contain a nested exception with the "real" reason for the failure.
      • filterAndRemove

        public void filterAndRemove​(List list)
                             throws IllegalAccessException,
                                    InvocationTargetException,
                                    FilterException
        Cycle over the List and filter given our fields directly from the passed in List. The filtered objects are removed from the passed List. This method will probably be slower than doing:
           GeneralFilter gf = new GeneralFilter (MyObjectClass);
        
           // ... configure the filter ...
         
           List myList = gf.filter (myList);
         

        This is because we have to here use an Iterator to strip out the unwanted objects rather than using the get method which is what filter(List) uses.

        Parameters:
        list - The List to filter.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • filterAndRemove

        public void filterAndRemove​(Map map,
                                    int type)
                             throws IllegalAccessException,
                                    InvocationTargetException,
                                    FilterException
        Iterate over the Map and filter given our fields directly from the passed in Map. The filtered objects are removed from the passed Map.

        Note: if the type parm is NOT GeneralFilter.KEYS or GeneralFilter.VALUES then it's assumed you want to filter on the values.
        Parameters:
        set - The Set to filter.
        Throws:
        InvocationTargetException - If we cannot execute the associated Accessor chain and get the value.
        IllegalAccessException - If we cannot execute the associated Accessor chain because of a security violation.
        FilterException - Thrown if the return type is not what is expected from the field type, for example if we are checking a java.utli.Date but the returned type is NOT of type java.util.Date.
      • toString

        public String toString()
        Output the filter fields as a String suitable for debugging.
        Overrides:
        toString in class Object