Gridarta Editor
ArchetypeAttributeSections.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.Collections;
23 import java.util.Iterator;
24 import java.util.LinkedHashMap;
25 import java.util.Map;
26 import org.jetbrains.annotations.NotNull;
27 
32 public class ArchetypeAttributeSections implements Iterable<ArchetypeAttributeSection> {
33 
38  @NotNull
39  private final Map<String, ArchetypeAttributeSection> archetypeAttributeSections = new LinkedHashMap<>();
40 
47  }
48 
55  public final void addSection(@NotNull final ArchetypeAttributeSection section) {
56  final String sectionName = section.getSectionName();
57  final ArchetypeAttributeSection existingSection = archetypeAttributeSections.get(sectionName);
58  if (existingSection != null) {
59  existingSection.addAll(section);
60  return;
61  }
62 
63  archetypeAttributeSections.put(sectionName, section);
64  }
65 
71  @NotNull
72  @Override
73  public Iterator<ArchetypeAttributeSection> iterator() {
74  return Collections.unmodifiableMap(archetypeAttributeSections).values().iterator();
75  }
76 
82  public boolean hasAttribute() {
83  for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeAttributeSections.values()) {
84  if (!archetypeAttributeSection.isEmpty()) {
85  return true;
86  }
87  }
88  return false;
89  }
90 
96  public boolean hasAttributeKey(@NotNull final Comparable<String> key) {
97  for (final ArchetypeAttributeSection archetypeAttributeSection : archetypeAttributeSections.values()) {
98  if (archetypeAttributeSection.hasAttributeKey(key)) {
99  return true;
100  }
101  }
102  return false;
103  }
104 
110  public void addArchetypeAttribute(@NotNull final String sectionName, @NotNull final ArchetypeAttribute archetypeAttribute) {
111  getOrCreateSection(sectionName).add(archetypeAttribute);
112  }
113 
120  @NotNull
121  private ArchetypeAttributeSection getOrCreateSection(final String sectionName) {
122  ArchetypeAttributeSection section = archetypeAttributeSections.get(sectionName);
123  if (section == null) {
124  section = new ArchetypeAttributeSection(sectionName);
125  archetypeAttributeSections.put(sectionName, section);
126  }
127  return section;
128  }
129 
130 }
boolean hasAttributeKey(@NotNull final Comparable< String > key)
Returns whether an attribute key is defined.
boolean hasAttribute()
Returns whether this archetype type defines at least one archetype attribute.
static final String GENERAL_SECTION
The name of the "General" section.
This Class contains the data of one archetype attribute.
static final String SPECIAL_SECTION
The name of the "Special" section.
void addArchetypeAttribute(@NotNull final String sectionName, @NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute to this archetype type.
void add(@NotNull final ArchetypeAttribute archetypeAttribute)
Adds an ArchetypeAttribute.
ArchetypeAttributeSection getOrCreateSection(final String sectionName)
Returns an ArchetypeAttributeSection by section name.
Iterator< ArchetypeAttributeSection > iterator()
Returns a read-only Iterator returning all sections in display order.
final void addSection(@NotNull final ArchetypeAttributeSection section)
Adds an ArchetypeAttributeSection.
void addAll(@NotNull final ArchetypeAttributeSection archetypeAttributeSection)
Adds all ArchetypeAttributes of another archetype attributes to this archetype attributes.
final Map< String, ArchetypeAttributeSection > archetypeAttributeSections
All ArchetypeAttributeSections in display order.