Gridarta Editor
AutojoinLists.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.autojoin;
21 
22 import java.io.Serializable;
23 import java.util.IdentityHashMap;
24 import java.util.Map;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public class AutojoinLists<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements Serializable {
36 
40  private static final long serialVersionUID = 1L;
41 
45  private final Map<Archetype<G, A, R>, AutojoinList<G, A, R>> autojoinLists = new IdentityHashMap<>();
46 
53  public void addAutojoinList(@NotNull final AutojoinList<G, A, R> autojoinList) throws IllegalAutojoinListException {
54  for (int i = 0; i < AutojoinList.SIZE; i++) {
55  final Archetype<G, A, R> archetype = autojoinList.getArchetype(i);
56  if (autojoinLists.containsKey(archetype)) {
57  throw new IllegalAutojoinListException("archetype '" + archetype.getArchetypeName() + "' contained in more than one autojoin list");
58  }
59  }
60 
61  for (int i = 0; i < AutojoinList.SIZE; i++) {
62  for (final R archetype : autojoinList.getArchetypes(i)) {
63  autojoinLists.put(archetype, autojoinList);
64  }
65  }
66  }
67 
74  @Nullable
75  public AutojoinList<G, A, R> getAutojoinList(@NotNull final Archetype<G, A, R> archetype) {
76  return autojoinLists.get(archetype);
77  }
78 
79 }
net.sf.gridarta.model.autojoin.AutojoinLists.autojoinLists
final Map< Archetype< G, A, R >, AutojoinList< G, A, R > > autojoinLists
Definition: AutojoinLists.java:45
net.sf.gridarta.model.autojoin.AutojoinLists.getAutojoinList
AutojoinList< G, A, R > getAutojoinList(@NotNull final Archetype< G, A, R > archetype)
Definition: AutojoinLists.java:75
net.sf.gridarta
net.sf.gridarta.model.maparchobject.MapArchObject
Definition: MapArchObject.java:40
net.sf
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.autojoin.AutojoinLists
Definition: AutojoinLists.java:35
net.sf.gridarta.model.gameobject.GameObject
Definition: GameObject.java:36
net.sf.gridarta.model.autojoin.AutojoinList
Definition: AutojoinList.java:39
net.sf.gridarta.model.gameobject
Definition: AbstractGameObject.java:20
net.sf.gridarta.model.autojoin.AutojoinLists.serialVersionUID
static final long serialVersionUID
Definition: AutojoinLists.java:40
net
net.sf.gridarta.model.autojoin.IllegalAutojoinListException
Definition: IllegalAutojoinListException.java:28
net.sf.gridarta.model.autojoin.AutojoinLists.addAutojoinList
void addAutojoinList(@NotNull final AutojoinList< G, A, R > autojoinList)
Definition: AutojoinLists.java:53
net.sf.gridarta.model
net.sf.gridarta.model.autojoin.AutojoinList.SIZE
static final int SIZE
Definition: AutojoinList.java:55
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.baseobject.BaseObject.getArchetype
R getArchetype()
net.sf.gridarta.model.archetype.Archetype.getArchetypeName
String getArchetypeName()
net.sf.gridarta.model.archetype.Archetype
Definition: Archetype.java:41