-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better way to handle filter references
- Loading branch information
1 parent
0e84ca8
commit c97d1e3
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/in/twizmwaz/cardinal/module/filter/type/FilterReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package in.twizmwaz.cardinal.module.filter.type; | ||
|
||
import in.twizmwaz.cardinal.match.Match; | ||
import in.twizmwaz.cardinal.module.ModuleError; | ||
import in.twizmwaz.cardinal.module.filter.Filter; | ||
import in.twizmwaz.cardinal.module.filter.FilterModule; | ||
import in.twizmwaz.cardinal.module.filter.FilterState; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class FilterReference implements Filter { | ||
|
||
private final String id; | ||
private Filter filter; | ||
|
||
public void load(FilterModule module, Match match) { | ||
filter = module.getFilter(match, id); | ||
if (filter == null) { | ||
module.getErrors().add( | ||
new ModuleError(module, match.getMap(), new String[]{"Could not find filter for id \'" + id + "\'"}, false)); | ||
} | ||
} | ||
|
||
@Override | ||
public FilterState evaluate(Object... objects) { | ||
if (filter != null) { | ||
return filter.evaluate(objects); | ||
} else { | ||
return FilterState.ABSTAIN; | ||
} | ||
} | ||
|
||
} |