20 package net.sf.gridarta.model.validation.checks;
22 import java.util.HashMap;
23 import java.util.IdentityHashMap;
33 import org.jetbrains.annotations.NotNull;
39 public class AttributeRangeChecker<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends
AbstractValidator<G, A, R> implements
GameObjectValidator<G, A, R> {
45 private final Map<Integer, Type<G, A, R>>
types =
new HashMap<>();
51 private final Map<GameObjectMatcher, Type<G, A, R>>
matchers =
new IdentityHashMap<>();
58 super(validatorPreferences);
71 public void add(
final int type, @NotNull
final String name, @NotNull
final String displayName,
final int minValue,
final int maxValue)
throws InvalidCheckException {
72 if (minValue == Integer.MIN_VALUE && maxValue == Integer.MAX_VALUE) {
76 getType(type).add(name, displayName,
new Range(minValue, maxValue));
90 if (minValue == Integer.MIN_VALUE && maxValue == Integer.MAX_VALUE) {
94 getMatcher(matcher).add(name, displayName,
new Range(minValue, maxValue));
105 if (oldType != null) {
110 types.put(type, newType);
122 if (oldType != null) {
127 matchers.put(matcher, newType);
133 if (!gameObject.isHead()) {
138 if (e.getKey().isMatching(gameObject)) {
139 e.getValue().validate(gameObject, errorCollector);
143 final Type<G, A, R> type = types.get(gameObject.getTypeNo());
148 type.
validate(gameObject, errorCollector);
A validator that checks for suspicious attribute values.
This is the base class for validators.
void validateGameObject(@NotNull final G gameObject, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validates a game object.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
Interface for GameObject Validators.
Type< G, A, R > getMatcher(@NotNull final GameObjectMatcher matcher)
Returns the Type instance for a given GameObjectMatcher.
This package contains the framework for validating maps.
final Map< GameObjectMatcher, Type< G, A, R > > matchers
Maps matcher to Type instance.
An Exception indicating that an attribute check is invalid.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Type< G, A, R > getType(final int type)
Returns the Type instance for a given object type.
final Map< Integer, Type< G, A, R > > types
Maps object type to Type instance.
Configuration parameters for Validators.
GameObjects are the objects based on Archetypes found on maps.
void validate(@NotNull final G gameObject, @NotNull final ErrorCollector< G, A, R > errorCollector)
Validate a game object.
Represents a range of attribute values.
Manages all checks for one game object type.
final ValidatorPreferences validatorPreferences
The ValidatorPreferences to use.
An interface for classes that collect errors.
void add(final int type, @NotNull final String name, @NotNull final String displayName, final int minValue, final int maxValue)
Adds an attribute to check.
AttributeRangeChecker(@NotNull final ValidatorPreferences validatorPreferences)
Creates a new instance.
Interface for MapArchObjects.
void add(@NotNull final GameObjectMatcher matcher, @NotNull final String name, @NotNull final String displayName, final int minValue, final int maxValue)
Adds an attribute to check.