20 package net.sf.gridarta.model.validation.checks;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.HashSet;
40 import org.jetbrains.annotations.NotNull;
47 public class ConnectionChecker<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends
AbstractValidator<G, A, R> implements
MapValidator<G, A, R> {
76 super(validatorPreferences);
84 final Map<Integer, Rec> info =
new HashMap<>();
85 for (
final Iterable<G> mapSquare : mapModel) {
86 for (
final G gameObject : mapSquare) {
87 check(gameObject, info);
88 for (
final G invObject : gameObject.recursive()) {
89 check(invObject, info);
94 for (
final Map.Entry<Integer,
Rec> e : info.entrySet()) {
95 e.getValue().addErrors(e.getKey(), mapModel, errorCollector);
104 private void check(@NotNull
final G gameObject, @NotNull
final Map<Integer, Rec> info) {
106 if (values == null) {
110 for (
final int value : values) {
122 private Rec getRec(
final int value, @NotNull
final Map<Integer, Rec> info) {
123 final Rec existingRec = info.get(value);
124 if (existingRec != null) {
128 final Rec rec =
new Rec();
129 info.put(value, rec);
139 return sourceGameObjectMatcher.
isMatching(gameObject);
148 return sinkGameObjectMatcher.
isMatching(gameObject) || sink2GameObjectMatcher.
isMatching(gameObject);
173 private final Collection<G>
unknowns =
new HashSet<>();
179 public void add(@NotNull
final G gameObject) {
180 boolean isUnknown =
true;
182 sourceGameObjects.add(gameObject);
186 sinkGameObjects.add(gameObject);
190 unknowns.add(gameObject);
201 if (!unknowns.isEmpty()) {
202 for (
final G gameObject : unknowns) {
207 if (sourceGameObjects.isEmpty()) {
210 if (sinkGameObjects.isEmpty()) {
void check(@NotNull final G gameObject, @NotNull final Map< Integer, Rec > info)
Processes a game object.
static int [] parseConnections(@NotNull final BaseObject<?, ?, ?, ?> gameObject)
Extract the "connected" value(s) from a given game object.
A MapModel reflects the data of a map.
This is the base class for validators.
boolean isSource(@NotNull final GameObject<?, ?, ?> gameObject)
Returns whether a given game object is a source if connected.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
This package contains the framework for validating maps.
Rec getRec(final int value, @NotNull final Map< Integer, Rec > info)
Returns the record that describes a connection value.
Interface for Map Validators.
final Set< G > sourceGameObjects
The source game objects in this connection set.
Validation error for a set of connected objects for which no sinks exist.
void addErrors(final int connection, @NotNull final MapModel< G, A, R > mapModel, @NotNull final ErrorCollector< G, A, R > errorCollector)
Creates validation errors for this connection set.
Manages information about one connection set.
ConnectionChecker(@NotNull final ValidatorPreferences validatorPreferences, @NotNull final GameObjectMatcher sourceGameObjectMatcher, @NotNull final GameObjectMatcher sinkGameObjectMatcher, @NotNull final GameObjectMatcher sink2GameObjectMatcher)
Create a new instance.
Checks that for each connection value at least one source and at least one sink exists.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
final GameObjectMatcher sinkGameObjectMatcher
The GameObjectMatcher for matching sinks.
final Collection< G > unknowns
The game objects in this connection set which are neither sources nor sinks.
final Set< G > sinkGameObjects
The sink game objects in this connection set.
Configuration parameters for Validators.
GameObjects are the objects based on Archetypes found on maps.
final GameObjectMatcher sink2GameObjectMatcher
The GameObjectMatcher for matching sinks.
Validation error for a set of connected objects for which no sources exist.
Utility class to parse "connected" fields in game objects.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
void validateMap(@NotNull final MapModel< G, A, R > mapModel, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validate a map.
boolean isSink(@NotNull final GameObject< G, A, R > gameObject)
Returns whether a given game object is a sink if connected.
An interface for classes that collect errors.
void add(@NotNull final G gameObject)
Adds a game object to this connection set.
Interface for MapArchObjects.
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches an GameObject.
Validation error for a connected object that is not supposed to be connected.
final GameObjectMatcher sourceGameObjectMatcher
The GameObjectMatcher for matching sources.