20 package net.sf.gridarta.model.filter;
22 import java.util.LinkedHashMap;
27 import org.apache.log4j.Category;
28 import org.apache.log4j.Logger;
29 import org.jetbrains.annotations.NotNull;
64 public NamedFilter(@NotNull
final Iterable<NamedGameObjectMatcher> matchers) {
65 subFilters =
new LinkedHashMap<>();
76 for (
final String name : subFilters.keySet()) {
77 config.setSubFilterEnabled(name,
false);
84 if (LOG.isDebugEnabled()) {
85 LOG.debug(
"match called on " + gameObject.getArchetype().getArchetypeName());
87 for (
final String name : subFilters.keySet()) {
88 if (LOG.isDebugEnabled()) {
89 LOG.debug(
"checking if filter " + name +
" is enabled()");
91 if (config.isSubFilterEnabled(name)) {
92 if (LOG.isDebugEnabled()) {
93 LOG.debug(
"enabled!");
95 if (config.getConfig(name).match(gameObject)) {
96 if (LOG.isDebugEnabled()) {
97 LOG.debug(
"and matched!");
99 return !config.isInverted();
103 if (LOG.isDebugEnabled()) {
104 LOG.debug(
"finished scanning sub filters");
106 return config.isInverted();
107 }
catch (
final Exception e) {
115 boolean didMatch =
false;
116 for (
final String name : subFilters.keySet()) {
118 if (filterConfig.
reset()) {
122 return didMatch ^ config.isInverted();
123 }
catch (
final Exception e) {
137 for (
final Map.Entry<String,
Filter<?, ?>> filterEntry : subFilters.entrySet()) {
150 if (subFilters.containsKey(name)) {
154 subFilters.put(name, filter);
164 if (filter == null) {
179 listener.nameFilterChanged(type, filterName, filter);
188 listenerList.
add(listener);
196 listenerList.
remove(listener);
206 reset(filterOutConfig);
208 match(filterOutConfig, gameObject);
209 return !
reset(filterOutConfig);
212 return !
match(filterOutConfig, gameObject);
Interface for listeners interested in NamedFilter related events.
A Filter that aggregates named filters.
T [] getListeners()
Returns an array of all the listeners.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
boolean reset()
Tells the filter we have finished with current map square and, perhaps, we are jumping on next one...
void removeFilter(@NotNull final String name)
Removes a sub-filter.
A Filter which filters according to a net.sf.gridarta.model.match.NamedGameObjectMatcher.
boolean reset(@NotNull final NamedFilterConfig config)
void fireEvent(@NotNull final NamedFilterChangeType type, @NotNull final String filterName, @NotNull final Filter<?, ?> filter)
Notifies all listeners about a change.
void addFilter(@NotNull final String name, @NotNull final Filter<?, ?> filter)
Adds a sub-Filter.
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Base package of all Gridarta classes.
Reflects a game object (object on a map).
NamedFilter(@NotNull final Iterable< NamedGameObjectMatcher > matchers)
Creates a new instance.
boolean match(@NotNull final NamedFilterConfig config, @NotNull final GameObject<?, ?, ?> gameObject)
void addFilterListener(@NotNull final NamedFilterListener listener)
Adds a NamedFilterListener to be notified about changes.
void remove(@NotNull final T listener)
Removes a listener.
void removeFilterListener(@NotNull final NamedFilterListener listener)
Removes a NamedFilterListener to be notified about changes.
GameObjects are the objects based on Archetypes found on maps.
NamedFilterConfig createConfig()
void add(@NotNull final T listener)
Adds a listener.
boolean hasGlobalMatch(@NotNull final NamedFilterConfig config)
final Map< String, Filter<?, ?> > subFilters
The sub-filters.
Type-safe version of EventListenerList.
static final Category LOG
The Logger for printing log messages.
final EventListenerList2< NamedFilterListener > listenerList
The NamedFilterListeners to notify about changes.
boolean canShow(@NotNull final GameObject<?, ?, ?> gameObject, @NotNull final NamedFilterConfig filterOutConfig)
Returns whether this filter matches a GameObject.
void resetConfig(@NotNull final NamedFilterConfig config)
Disables all sub-filters.
Enumeration of event types of NamedFilterEvent.
A FilterConfig that has a name.