Gridarta Editor
Spells.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.spells;
21 
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.Iterator;
26 import java.util.List;
27 import org.jetbrains.annotations.NotNull;
28 
33 public class Spells<S extends Spell> implements Iterable<S> {
34 
38  @NotNull
39  private final List<S> spells = new ArrayList<>();
40 
44  private static final Comparator<Spell> SPELL_COMPARATOR = new Comparator<Spell>() {
45 
46  @Override
47  public int compare(final Spell o1, final Spell o2) {
48  return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
49  }
50 
51  };
52 
56  public void sort() {
58  }
59 
64  public int size() {
65  return spells.size();
66  }
67 
72  @NotNull
73  @Override
74  public Iterator<S> iterator() {
75  return Collections.unmodifiableList(spells).iterator();
76  }
77 
82  public void add(@NotNull final S spell) {
83  spells.add(spell);
84  }
85 
91  public S getSpell(final int index) {
92  try {
93  return spells.get(index);
94  } catch (final IndexOutOfBoundsException ignored) {
95  return spells.get(0);
96  }
97  }
98 
99 }
net.sf.gridarta.model.spells.Spell.getName
String getName()
Definition: Spell.java:49
net.sf.gridarta.model.spells.Spells.SPELL_COMPARATOR
static final Comparator< Spell > SPELL_COMPARATOR
Definition: Spells.java:44
net.sf.gridarta.model.spells.Spells.spells
final List< S > spells
Definition: Spells.java:39
net.sf.gridarta.model.spells.Spell
Definition: Spell.java:28
net.sf.gridarta.model.spells.Spells.add
void add(@NotNull final S spell)
Definition: Spells.java:82
net.sf.gridarta.model.spells.Spells.iterator
Iterator< S > iterator()
Definition: Spells.java:74
net.sf.gridarta.model.spells.Spells.size
int size()
Definition: Spells.java:64
net.sf.gridarta.model.spells.Spells.getSpell
S getSpell(final int index)
Definition: Spells.java:91
net.sf.gridarta.model.spells.Spells.sort
void sort()
Definition: Spells.java:56
net.sf.gridarta.model.spells.Spells
Definition: Spells.java:33