- Object
-
- TypeFilter
-
- All Implemented Interfaces:
Filter
public abstract class TypeFilter extends Object implements Filter
A base implementation of a class hierarchyFixture
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
-
-
Field Summary
-
Fields inherited from interface Filter
DEFAULT_FILTER
-
-
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 typeTypeFilter
then false is returned.String
toString()
-
-
-
Method Detail
-
isAllowed
public 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.
TypeFilter
then false is returned.If the given filter is null then false is returned.
-
-