 |
Gridarta Editor
|
Go to the documentation of this file.
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;
33 import net.
sf.japi.swing.action.ActionBuilder;
34 import net.
sf.japi.swing.action.ActionBuilderFactory;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
66 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
73 private final String
key;
87 private final List<MapSquare<G, A, R>>
mapSquares =
new ArrayList<>(0);
120 final String
name = getClass().getSimpleName();
121 if (!
name.endsWith(
"Error")) {
122 throw new IllegalArgumentException(
"Class name must end with \"Error\"");
124 key =
"Validator." +
name.substring(0,
name.indexOf(
"Error"));
153 return Collections.unmodifiableList(
mapSquares);
162 if (mapSquare.getMapModel() !=
mapModel) {
163 throw new IllegalArgumentException(
"map square is not part of this map");
213 x = mapSquare ==
null ? -1 : mapSquare.
getMapX();
214 y = mapSquare ==
null ? -1 : mapSquare.
getMapY();
221 final StringBuilder sb =
new StringBuilder();
236 final StringBuilder sb =
new StringBuilder();
240 return sb.toString();
257 sb.append(title ==
null ?
key : title);
277 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) {
278 if (objects.isEmpty()) {
282 final List<O> sortedObjects =
new ArrayList<>(objects);
283 sortedObjects.sort(formatter);
287 for (
final O
object : sortedObjects) {
291 sb.append(formatter.toString(
object));
293 if (count >= maxObjects && sortedObjects.size() > maxObjects + 1) {
int getMapY()
Returns the y coordinate on the map.
A MapModel reflects the data of a map.
final List< MapSquare< G, A, R > > mapSquares
The MapSquares that caused the error.
final Formatter< G, A, R, G > gameObjectFormatter
The MapSquareFormatter for formatting GameObject instances.
int getMapX()
Returns the x coordinate on the map.
Iterable< MapSquare< G, A, R > > getMapSquares()
Returns the MapSquares that caused the error.
Base package of all Gridarta classes.
Super class of all errors that could occur during map validation.
ValidationError(@NotNull final MapModel< G, A, R > mapModel)
Creates a new instance.
Utility class for HTML related functions.
void appendGameObjects(@NotNull final StringBuilder sb)
Appends the game objects of this error to a StringBuilder.
Reflects a game object (object on a map).
void addGameObject(@NotNull final G gameObject)
Adds an erroneous GameObject.
void appendMapSquares(@NotNull final StringBuilder sb)
Appends the map squares of this error to a StringBuilder.
static String encode(@NotNull final String str)
Encodes a string so that the result can be embedded into HTML.
GameObjects are the objects based on Archetypes found on maps.
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)
Appends the given objects to a StringBuilder.
final List< G > gameObjects
The GameObjects that caused the error.
static final int TITLE_MAP_SQUARES
The maximum number of map squares to show in the title.
Interface for MapArchObjects.
static final ActionBuilder ACTION_BUILDER
Action Builder.
void appendTitle(@NotNull final StringBuilder sb)
Appends the title of this error to a StringBuilder.
final MapModel< G, A, R > mapModel
The MapModel that caused the error.
static String encodeOptional(@Nullable final String str)
Encodes an optional string so that the result can be embedded into HTML.
MapModel< G, A, R > getMapModel()
Return the map on which the error occurred.
List< G > getGameObjects()
Returns the GameObjects that caused the error.
static final int TITLE_GAME_OBJECTS
The maximum number of game objects to show in the title.
void addMapSquare(@NotNull final MapSquare< G, A, R > mapSquare)
Adds an erroneous MapSquare.
abstract String getParameter(int id)
Returns a parameter string to be used in the error message.
static final long serialVersionUID
The serial version UID.
String getMessage()
Returns the error message for this validation error.
String toString()
The String representation of an error is its title.
ValidationError(@NotNull final String key, @NotNull final MapModel< G, A, R > mapModel)
Creates a new instance.
final Formatter< G, A, R, MapSquare< G, A, R > > mapSquareFormatter
The MapSquareFormatter for formatting MapSquare instances.