Gridarta Editor
GameObjectMatchers.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.match;
21 
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.Map;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
34 
40 public class GameObjectMatchers implements Iterable<NamedGameObjectMatcher>, Serializable {
41 
45  private static final long serialVersionUID = 1L;
46 
51  @NotNull
52  private final Map<String, NamedGameObjectMatcher> gameObjectMatchersByIds = new HashMap<>();
53 
58  @NotNull
59  private final Collection<NamedGameObjectMatcher> gameObjectMatchers = new ArrayList<>();
60 
67  @Nullable
68  public GameObjectMatcher getMatcher(@NotNull final String... ids) {
69  for (final String id : ids) {
70  final GameObjectMatcher matcher = gameObjectMatchersByIds.get(id);
71  if (matcher != null) {
72  return matcher;
73  }
74  }
75  return null;
76  }
77 
84  @Nullable
85  public GameObjectMatcher getMatcherWarn(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final String... ids) {
86  final GameObjectMatcher matcher = getMatcher(ids);
87  if (matcher == null) {
88  errorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID, "GameObjectMatcher '" + ids[0] + "' does not exist");
89  }
90  return matcher;
91  }
92 
97  @NotNull
98  public Collection<NamedGameObjectMatcher> getFilters() {
99  final Collection<NamedGameObjectMatcher> result = new HashSet<>(gameObjectMatchersByIds.size());
100  for (final NamedGameObjectMatcher matcher : gameObjectMatchersByIds.values()) {
101  if (!matcher.isSystemMatcher()) {
102  result.add(matcher);
103  }
104  }
105  return result;
106  }
107 
112  public void addGameObjectMatcher(@NotNull final NamedGameObjectMatcher gameObjectMatcher) {
113  gameObjectMatchers.add(gameObjectMatcher);
114  gameObjectMatchersByIds.put(gameObjectMatcher.getID(), gameObjectMatcher);
115  }
116 
117  @Override
118  public Iterator<NamedGameObjectMatcher> iterator() {
119  return Collections.unmodifiableCollection(gameObjectMatchers).iterator();
120  }
121 
122 }
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.match.GameObjectMatchers.gameObjectMatchersByIds
final Map< String, NamedGameObjectMatcher > gameObjectMatchersByIds
Map with game object object matchers and their IDs.
Definition: GameObjectMatchers.java:52
net.sf.gridarta.model.match.GameObjectMatchers.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: GameObjectMatchers.java:45
net.sf
net.sf.gridarta.model.match.GameObjectMatcher
Interface for classes that match GameObjects.
Definition: GameObjectMatcher.java:30
net.sf.gridarta.model.match.GameObjectMatchers.getMatcher
GameObjectMatcher getMatcher(@NotNull final String... ids)
Returns a matcher by id; returns.
Definition: GameObjectMatchers.java:68
net.sf.gridarta.model.match.GameObjectMatchers.addGameObjectMatcher
void addGameObjectMatcher(@NotNull final NamedGameObjectMatcher gameObjectMatcher)
Adds a new GameObjectMatcher.
Definition: GameObjectMatchers.java:112
net.sf.gridarta.model.match.NamedGameObjectMatcher
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Definition: NamedGameObjectMatcher.java:33
net.sf.gridarta.model.errorview.ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID
GAMEOBJECTMATCHERS_ENTRY_INVALID
Definition: ErrorViewCategory.java:68
net
net.sf.gridarta.model.errorview
Definition: ErrorView.java:20
net.sf.gridarta.model.errorview.ErrorViewCollector
Convenience class for adding messages to a ErrorView instance using a fixed category name.
Definition: ErrorViewCollector.java:31
net.sf.gridarta.model.errorview.ErrorViewCategory
Defines possible error categories for ErrorView instances.
Definition: ErrorViewCategory.java:28
net.sf.gridarta.model.match.GameObjectMatchers
Maintains GameObjectMatcher instances.
Definition: GameObjectMatchers.java:40
net.sf.gridarta.model.match.GameObjectMatchers.getFilters
Collection< NamedGameObjectMatcher > getFilters()
Return all known game object matchers that should be used as filters.
Definition: GameObjectMatchers.java:98
net.sf.gridarta.model.match.GameObjectMatchers.gameObjectMatchers
final Collection< NamedGameObjectMatcher > gameObjectMatchers
List with game object matchers.
Definition: GameObjectMatchers.java:59
net.sf.gridarta.model.match.GameObjectMatchers.getMatcherWarn
GameObjectMatcher getMatcherWarn(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final String... ids)
Returns a matcher by id; prints a warning if the matcher does not exist.
Definition: GameObjectMatchers.java:85
net.sf.gridarta.model
net.sf.gridarta.model.match.GameObjectMatchers.iterator
Iterator< NamedGameObjectMatcher > iterator()
Definition: GameObjectMatchers.java:118