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-2015 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 }
String getArchetypeName()
Returns the name of this archetype.
Contains a list of (typically wall-)arches which do autojoining.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
GameObjects are the objects based on Archetypes found on maps.
AutojoinList< G, A, R > getAutojoinList(@NotNull final Archetype< G, A, R > archetype)
Returns an AutojoinList for a given archetype.
void addAutojoinList(@NotNull final AutojoinList< G, A, R > autojoinList)
Adds a new autojoin list.
R getArchetype()
Returns the Archetype this GameObject is based on.
static final long serialVersionUID
The serial version UID.
Manages a mapping between archetypes to AutojoinLists.
static final int SIZE
The number of archetypes in an autojoin list.
final Map< Archetype< G, A, R >, AutojoinList< G, A, R > > autojoinLists
Mapping of archetypes to autojoin lists.