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.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.autojoin.AutojoinListsHelper.newAutojoinLists
void newAutojoinLists(@NotNull final String... archetypeNames)
Creates a new AutojoinLists instance.
Definition: AutojoinListsHelper.java:78
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.model.mapmodel.TestMapModelCreator
Helper class for regression tests to create MapModel instances.
Definition: TestMapModelCreator.java:63
net.sf.gridarta.model.autojoin.AutojoinListsHelper
Implements AutojoinList related functions.
Definition: AutojoinListsHelper.java:36
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getAutojoinLists
AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > getAutojoinLists()
Returns the AutojoinLists instance.
Definition: TestMapModelCreator.java:322
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.autojoin.AutojoinListsHelper.newAutojoinListsFail
void newAutojoinListsFail(@NotNull final String expectedException, @NotNull final String... archetypeNames)
Creates a new AutojoinLists instance and expects an error.
Definition: AutojoinListsHelper.java:97
net.sf.gridarta.model.autojoin.AutojoinListsHelper.autojoinLists
final AutojoinLists< TestGameObject, TestMapArchObject, TestArchetype > autojoinLists
The AutojoinLists instance.
Definition: AutojoinListsHelper.java:54
net.sf.gridarta.model.autojoin.AutojoinList
Contains a list of (typically wall-)arches which do autojoining.
Definition: AutojoinList.java:39
net.sf.gridarta.model.autojoin.IllegalAutojoinListException
Exception thrown if an AutojoinList is invalid.
Definition: IllegalAutojoinListException.java:28
net.sf.gridarta.model.autojoin.AutojoinLists
Manages a mapping between archetypes to AutojoinLists.
Definition: AutojoinLists.java:35
net.sf.gridarta.model.mapmodel.TestMapModelCreator.getArchetype
TestArchetype getArchetype(@NotNull final String archetypeName)
Returns an archetype.
Definition: TestMapModelCreator.java:249
net.sf.gridarta.model
net.sf.gridarta.model.autojoin.AutojoinListsHelper.mapModelCreator
final TestMapModelCreator mapModelCreator
The TestMapModelCreator instance.
Definition: AutojoinListsHelper.java:48
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.autojoin.AutojoinListsHelper.AutojoinListsHelper
AutojoinListsHelper()
Creates a new instance.
Definition: AutojoinListsHelper.java:59
net.sf.gridarta.model.autojoin.AutojoinListsHelper.AutojoinListsHelper
AutojoinListsHelper(@NotNull final TestMapModelCreator mapModelCreator)
Creates a new instance.
Definition: AutojoinListsHelper.java:67
net.sf.gridarta.model.autojoin.AutojoinListsHelper.ALTERNATIVES_PATTERN
static final Pattern ALTERNATIVES_PATTERN
A Pattern that matches alternative archetypes.
Definition: AutojoinListsHelper.java:42