Gridarta Editor
IgnorelistsDefinition.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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.HashMap;
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
34 public class IgnorelistsDefinition {
35 
39  @NotNull
40  private final Map<String, Set<String>> ignoreListTable = new HashMap<>();
41 
47  public boolean containsKey(@NotNull final String name) {
48  return ignoreListTable.containsKey(name);
49  }
50 
57  public void put(@NotNull final String name, @NotNull final String value) {
58  if (name.isEmpty()) {
59  throw new IllegalArgumentException("empty name");
60  }
61 
62  if (value.isEmpty()) {
63  throw new IllegalArgumentException("empty value for name '" + name + "'");
64  }
65 
66  if (!ignoreListTable.computeIfAbsent(name, k -> new HashSet<>()).add(value)) {
67  throw new IllegalArgumentException("duplicate value '" + value + "' for name '" + name + "'");
68  }
69  }
70 
76  @Nullable
77  public Iterable<String> get(@NotNull final String name) {
78  final Set<String> values = ignoreListTable.get(name);
79  return values == null ? null : Collections.unmodifiableCollection(values);
80  }
81 
82 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.archetypetype.IgnorelistsDefinition
The contents of an <ignorelists> element of a types.xml file.
Definition: IgnorelistsDefinition.java:34
net.sf.gridarta.model.archetypetype.IgnorelistsDefinition.ignoreListTable
final Map< String, Set< String > > ignoreListTable
The ignore list entries.
Definition: IgnorelistsDefinition.java:40
net.sf.gridarta.model.archetypetype.IgnorelistsDefinition.containsKey
boolean containsKey(@NotNull final String name)
Returns whether an ignore list name exists.
Definition: IgnorelistsDefinition.java:47
net.sf.gridarta.model.archetypetype.IgnorelistsDefinition.put
void put(@NotNull final String name, @NotNull final String value)
Adds a new entry.
Definition: IgnorelistsDefinition.java:57