Gridarta Editor
AutojoinListsHelper.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.autojoin;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.regex.Pattern;
29 import org.jetbrains.annotations.NotNull;
30 import org.junit.Assert;
31 
36 public class AutojoinListsHelper {
37 
41  @NotNull
42  private static final Pattern ALTERNATIVES_PATTERN = Pattern.compile("\\|");
43 
47  @NotNull
49 
53  @NotNull
55 
60  this(new TestMapModelCreator(false));
61  }
62 
68  this.mapModelCreator = mapModelCreator;
70  }
71 
78  public void newAutojoinLists(@NotNull final String... archetypeNames) throws IllegalAutojoinListException {
79  final List<List<TestArchetype>> archetypes = new ArrayList<>();
80  for (final String archetypeNameList : archetypeNames) {
81  final List<TestArchetype> archetypeList = new ArrayList<>();
82  if (!archetypeNameList.isEmpty()) {
83  for (final String archetypeName : ALTERNATIVES_PATTERN.split(archetypeNameList, -1)) {
84  archetypeList.add(mapModelCreator.getArchetype(archetypeName));
85  }
86  }
87  archetypes.add(archetypeList);
88  }
89  autojoinLists.addAutojoinList(new AutojoinList<>(archetypes));
90  }
91 
97  public void newAutojoinListsFail(@NotNull final String expectedException, @NotNull final String... archetypeNames) {
98  try {
99  newAutojoinLists(archetypeNames);
100  Assert.fail();
101  } catch (final IllegalAutojoinListException ex) {
102  Assert.assertEquals(expectedException, ex.getMessage());
103  }
104  }
105 
106 }
net.sf.gridarta.model.gameobject.TestGameObject
Definition: TestGameObject.java:34
net.sf.gridarta
net.sf.gridarta.model.archetype.TestArchetype
Definition: TestArchetype.java:30
net.sf
net.sf.gridarta.model.autojoin.AutojoinListsHelper.newAutojoinListsFail
void newAutojoinListsFail(@NotNull final String expectedException, @NotNull final String... archetypeNames)
Definition: AutojoinListsHelper.java:97
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.autojoin.AutojoinLists
Definition: AutojoinLists.java:35
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getArchetype
TestArchetype getArchetype(@NotNull final String archetypeName)
Definition: TestMapModelCreator.java:249
net.sf.gridarta.model.autojoin.AutojoinListsHelper.mapModelCreator
final TestMapModelCreator mapModelCreator
Definition: AutojoinListsHelper.java:48
net.sf.gridarta.model.autojoin.AutojoinList
Definition: AutojoinList.java:39
net.sf.gridarta.model.gameobject
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.autojoin.AutojoinListsHelper.ALTERNATIVES_PATTERN
static final Pattern ALTERNATIVES_PATTERN
Definition: AutojoinListsHelper.java:42
net.sf.gridarta.model.mapmodel.TestMapModelCreator
Definition: TestMapModelCreator.java:63
net.sf.gridarta.model.autojoin.IllegalAutojoinListException
Definition: IllegalAutojoinListException.java:28
net.sf.gridarta.model.autojoin.AutojoinListsHelper.AutojoinListsHelper
AutojoinListsHelper(@NotNull final TestMapModelCreator mapModelCreator)
Definition: AutojoinListsHelper.java:67
net.sf.gridarta.model
net.sf.gridarta.model.autojoin.AutojoinListsHelper.AutojoinListsHelper
AutojoinListsHelper()
Definition: AutojoinListsHelper.java:59
net.sf.gridarta.model.autojoin.AutojoinListsHelper.newAutojoinLists
void newAutojoinLists(@NotNull final String... archetypeNames)
Definition: AutojoinListsHelper.java:78
net.sf.gridarta.model.autojoin.AutojoinListsHelper.autojoinLists
final AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > autojoinLists
Definition: AutojoinListsHelper.java:54
net.sf.gridarta.model.maparchobject.TestMapArchObject
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.autojoin.AutojoinListsHelper
Definition: AutojoinListsHelper.java:36
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getAutojoinLists
AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > getAutojoinLists()
Definition: TestMapModelCreator.java:322