Gridarta Editor
ArchetypeTypeList.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.archetypetype;
21 
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.List;
26 import net.sf.gridarta.utils.Pair;
27 import org.jetbrains.annotations.NotNull;
28 
33 public class ArchetypeTypeList implements Iterable<Pair<Integer, String>> {
34 
38  @NotNull
39  private final List<Pair<Integer, String>> list = new ArrayList<>();
40 
41  @NotNull
42  @Override
43  public Iterator<Pair<Integer, String>> iterator() {
44  return Collections.unmodifiableList(list).iterator();
45  }
46 
51  public int size() {
52  return list.size();
53  }
54 
61  public void add(final int value, @NotNull final String name) {
62  if (name.isEmpty()) {
63  throw new IllegalArgumentException("empty name");
64  }
65  for (final Pair<Integer, String> pair : list) {
66  if (pair.getFirst() == value) {
67  throw new IllegalArgumentException("duplicate value '" + value + "' for '" + pair.getSecond() + "' and '" + name + "'");
68  }
69  }
70  list.add(new Pair<>(value, name));
71  }
72 
78  @NotNull
79  public Pair<Integer, String> get(final int index) {
80  return list.get(index);
81  }
82 
83 }
Stores a pair of values.
Definition: Pair.java:26
final List< Pair< Integer, String > > list
The list entries.
Base package of all Gridarta classes.
Iterator< Pair< Integer, String > > iterator()
void add(final int value, @NotNull final String name)
Adds an entry.