Module org.dyn4j

Class TypeFilter

  • All Implemented Interfaces:
    Filter

    public abstract class TypeFilter
    extends java.lang.Object
    implements Filter
    A base implementation of a class hierarchy Fixture Filter.

    This class is not used directly but instead extended by marker classes (see example below).

    This filter is designed to allow a hierarchy of categories where each category can collide with it's parents and it's descendants, but not it's siblings.

    For example, imagine we have the following hierarchy of categories:

                 Root Category
                 /           \
            Category1     Category2
            /      \
     Category 3  Category 4
     
    This hierarchy allows the following:
    • A fixture with the Root category can collide with anything.
    • A fixture with the Category1 category can collide with the Category1, Category3, Category4, and Root categories. (i.e. not Category2)
    • A fixture with the Category2 category can collide with the Category2 and Root categories only.
    • A fixture with the Category3 category can collide with the Category3, Category1, and Root categories.
    • A fixture with the Category4 category can collide with the Category4, Category1, and Root categories.

    To implement this you create a class for each category (you could put these in their own class file, its done this way for brevity):

     public final class Categories {
            private static class Root extends TypeFilter {}
            private static class Category1 extends Root {}
            private static class Category2 extends Root {}
            private static class Category3 extends Category1 {}
            private static class Category4 extends Category1 {}
            
            public static final TypeFilter ROOT = new Root();
            public static final TypeFilter CATEGORY1 = new Category1();
            public static final TypeFilter CATEGORY2 = new Category2();
            public static final TypeFilter CATEGORY3 = new Category3();
            public static final TypeFilter CATEGORY4 = new Category4();
     }
     // then set the filter on the fixtures
     fixture.setFilter(Categories.ROOT);
     // or
     fixture.setFilter(Categories.CATEGORY1);
     
    Since:
    3.0.2
    Version:
    3.0.2
    Author:
    William Bittle
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeFilter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isAllowed​(Filter filter)
      Returns true under the following conditions: If this filter is the same type as the given filter. If this filter type is a descendant of the given filter's type. If the given filter's type is a descendant of this filter's type. If the given filter is not of type TypeFilter then false is returned.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TypeFilter

        public TypeFilter()
    • Method Detail

      • isAllowed

        public boolean isAllowed​(Filter filter)
        Returns true under the following conditions:
        1. If this filter is the same type as the given filter.
        2. If this filter type is a descendant of the given filter's type.
        3. If the given filter's type is a descendant of this filter's type.
        If the given filter is not of type TypeFilter then false is returned.

        If the given filter is null then false is returned.

        Specified by:
        isAllowed in interface Filter
        Parameters:
        filter - the other filter
        Returns:
        boolean
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object