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) {