20 package net.sf.gridarta.model.validation.errors;
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
32 import net.
sf.japi.swing.action.ActionBuilder;
33 import net.
sf.japi.swing.action.ActionBuilderFactory;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
65 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
72 private final String
key;
86 private final List<MapSquare<G, A, R>>
mapSquares =
new ArrayList<>(0);
119 final String name = getClass().getSimpleName();
120 if (!name.endsWith(
"Error")) {
121 throw new IllegalArgumentException(
"Class name must end with \"Error\"");
123 key =
"Validator." + name.substring(0, name.indexOf(
"Error"));
152 return Collections.unmodifiableList(mapSquares);
160 if (!mapSquares.contains(mapSquare)) {
161 if (mapSquare.getMapModel() !=
mapModel) {
162 throw new IllegalArgumentException();
164 mapSquares.add(mapSquare);
173 @SuppressWarnings(
"TypeMayBeWeakened")
175 return Collections.unmodifiableList(gameObjects);
186 if (mapSquare != null) {
216 x = mapSquare != null ? mapSquare.
getMapX() : -1;
217 y = mapSquare != null ? mapSquare.
getMapY() : -1;
224 final StringBuilder sb =
new StringBuilder();
230 return ACTION_BUILDER.format(
key +
".msg", sb.toString(), x, y, archName, parameter0, parameter1, parameter2, parameter3);
239 final StringBuilder sb =
new StringBuilder();
243 return sb.toString();
259 final String title = ACTION_BUILDER.getString(
key +
".title");
284 private <O>
void appendObjects(@NotNull
final StringBuilder sb, @NotNull
final Collection<O> objects, @NotNull
final Formatter<G, A, R, O> formatter, @NotNull
final String prefix, @NotNull
final String postfix,
final int maxObjects) {
285 if (objects.isEmpty()) {
289 final List<O> sortedObjects =
new ArrayList<>(objects);
290 sortedObjects.sort(formatter);
294 for (
final O
object : sortedObjects) {
298 sb.append(formatter.toString(
object));
300 if (count >= maxObjects && sortedObjects.size() > maxObjects + 1) {
int getMapX()
Returns the x coordinate on the map.
abstract String getParameter(int id)
Returns a parameter string to be used in the error message.
String toString()
The String representation of an error is its title.
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
ValidationError(@NotNull final MapModel< G, A, R > mapModel)
Creates a new instance.
final MapModel< G, A, R > mapModel
The MapModel that caused the error.
ValidationError(@NotNull final String key, @NotNull final MapModel< G, A, R > mapModel)
Creates a new instance.
String getMessage()
Returns the error message for this validation error.
void addGameObject(@NotNull final G gameObject)
Adds an erroneous GameObject.
Super class of all errors that could occur during map validation.
MapModel< G, A, R > getMapModel()
Return the map on which the error occurred.
Base package of all Gridarta classes.
Iterable< MapSquare< G, A, R > > getMapSquares()
Returns the MapSquares that caused the error.
Reflects a game object (object on a map).
void appendMapSquares(@NotNull final StringBuilder sb)
Appends the map squares of this error to a StringBuilder.
final Formatter< G, A, R, G > gameObjectFormatter
The MapSquareFormatter for formatting GameObject instances.
void appendTitle(@NotNull final StringBuilder sb)
Appends the title of this error to a StringBuilder.
static final int TITLE_MAP_SQUARES
The maximum number of map squares to show in the title.
static final int TITLE_GAME_OBJECTS
The maximum number of game objects to show in the title.
GameObjects are the objects based on Archetypes found on maps.
final List< MapSquare< G, A, R > > mapSquares
The MapSquares that caused the error.
List< G > getGameObjects()
Returns the GameObjects that caused the error.
void appendGameObjects(@NotNull final StringBuilder sb)
Appends the game objects of this error to a StringBuilder.
final Formatter< G, A, R, MapSquare< G, A, R > > mapSquareFormatter
The MapSquareFormatter for formatting MapSquare instances.
static final long serialVersionUID
The serial version UID.
final List< G > gameObjects
The GameObjects that caused the error.
void addMapSquare(@NotNull final MapSquare< G, A, R > mapSquare)
Adds an erroneous MapSquare.
static final ActionBuilder ACTION_BUILDER
Action Builder.
int getMapY()
Returns the y coordinate on the map.
Interface for MapArchObjects.