Gridarta Editor
Connection.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.gui.panel.connectionview;
21 
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.List;
27 import org.jetbrains.annotations.NotNull;
28 
34 public class Connection<K> implements Iterable<GameObject<?, ?, ?>> {
35 
39  @NotNull
40  private final K key;
41 
48  @NotNull
49  private final List<GameObject<?, ?, ?>> gameObjects = new ArrayList<>(2);
50 
55  public Connection(@NotNull final K key) {
56  this.key = key;
57  }
58 
63  @NotNull
64  @SuppressWarnings("TypeMayBeWeakened")
65  public K getKey() {
66  return key;
67  }
68 
73  public void addGameObject(@NotNull final GameObject<?, ?, ?> gameObject) {
74  if (!gameObjects.contains(gameObject)) {
75  gameObjects.add(gameObject);
76  }
77  }
78 
79  @NotNull
80  @Override
81  public Iterator<GameObject<?, ?, ?>> iterator() {
82  return Collections.unmodifiableList(gameObjects).iterator();
83  }
84 
85 }
Stores GameObjects related to key values.
Definition: Connection.java:34
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.
Connection(@NotNull final K key)
Create a new instance.
Definition: Connection.java:55
Iterator< GameObject<?, ?, ?> > iterator()
Definition: Connection.java:81
final List< GameObject<?, ?, ?> > gameObjects
The game objects for this connection.
Definition: Connection.java:49
void addGameObject(@NotNull final GameObject<?, ?, ?> gameObject)
Add a game object.
Definition: Connection.java:73