Gridarta Editor
ReplyValidator.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.var.crossfire.model.validation.checks;
21 
25 import org.apache.log4j.Category;
26 import org.apache.log4j.Logger;
27 import org.jetbrains.annotations.NotNull;
28 
36 @SuppressWarnings("DuplicateBranchesInSwitch")
37 public class ReplyValidator<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
38 
42  @NotNull
43  private static final Category LOG = Logger.getLogger(ReplyValidator.class);
44 
48  @NotNull
49  private State state = State.N;
50 
54  public ReplyValidator() {
55  if (LOG.isDebugEnabled()) {
56  LOG.debug("init: state=" + state);
57  }
58  }
59 
64  public void reset() {
65  state = State.N;
66  if (LOG.isDebugEnabled()) {
67  LOG.debug("reset: state=" + state);
68  }
69  }
70 
75  public void text(@NotNull final ErrorGenerator<G, A, R> generator) {
76  if (LOG.isDebugEnabled()) {
77  LOG.debug("event: text");
78  }
79 
80  switch (state) {
81  case N:
82  return;
83 
84  case M:
85  setState(State.MT);
86  return;
87 
88  case MT:
89  return;
90 
91  case MTR:
92  generator.errorSyntaxError("text after @reply or @question");
93  setState(State.N);
94  return;
95  }
96 
97  throw new AssertionError("state=" + state);
98  }
99 
103  public void match() {
104  if (LOG.isDebugEnabled()) {
105  LOG.debug("event: match");
106  }
107 
108  switch (state) {
109  case N:
110  setState(State.M);
111  return;
112 
113  case M:
114  return;
115 
116  case MT:
117  case MTR:
118  setState(State.N);
119  return;
120  }
121 
122  throw new AssertionError("state=" + state);
123  }
124 
129  public void reply(@NotNull final ErrorGenerator<G, A, R> generator) {
130  if (LOG.isDebugEnabled()) {
131  LOG.debug("event: reply");
132  }
133 
134  switch (state) {
135  case N:
136  return;
137 
138  case M:
139  generator.errorSyntaxError("@reply or @question without preceding text");
140  setState(State.N);
141  return;
142 
143  case MT:
144  setState(State.MTR);
145  return;
146 
147  case MTR:
148  return;
149  }
150 
151  throw new AssertionError("state=" + state);
152  }
153 
158  private void setState(@NotNull final State state) {
159  if (this.state == state) {
160  return;
161  }
162 
163  if (LOG.isDebugEnabled()) {
164  LOG.debug("state=" + state);
165  }
166  this.state = state;
167  }
168 
172  private enum State {
173 
177  N,
178 
182  M,
183 
187  MT,
188 
193  MTR
194 
195  }
196 
197 }
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.reply
void reply(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a qreply or @question line.
Definition: ReplyValidator.java:129
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.text
void text(@NotNull final ErrorGenerator< G, A, R > generator)
Processes a line of text.
Definition: ReplyValidator.java:75
net.sf.gridarta.var.crossfire.model.validation.checks.ErrorGenerator
Generator for SuspiciousMsgChecker related error messages.
Definition: ErrorGenerator.java:38
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.State.MT
MT
A @match line and at least one text line has been processed.
Definition: ReplyValidator.java:187
net.sf
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.State.N
N
Nothing processed yet.
Definition: ReplyValidator.java:177
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.ReplyValidator
ReplyValidator()
Creates a new instance.
Definition: ReplyValidator.java:54
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.setState
void setState(@NotNull final State state)
Updates state and prints a debug message if it changes.
Definition: ReplyValidator.java:158
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.State.M
M
A @match line has been processed.
Definition: ReplyValidator.java:182
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.var.crossfire.model.archetype.Archetype
Implements Crossfire archetypes.
Definition: Archetype.java:30
net.sf.gridarta.var.crossfire.model.maparchobject.MapArchObject
MapArchObject contains the specific meta data about a map that is stored in the map-arch,...
Definition: MapArchObject.java:39
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.match
void match()
Processes a @match line.
Definition: ReplyValidator.java:103
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator
Checks that @match, text, @reply, and @question lines occur in the correct order.
Definition: ReplyValidator.java:37
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.State
The FSM states.
Definition: ReplyValidator.java:172
net.sf.gridarta.var.crossfire.model.gameobject.GameObject
Handles the Crossfire GameObjects.
Definition: GameObject.java:41
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.var.crossfire.model.validation.checks.ReplyValidator.reset
void reset()
Resets the checker state.
Definition: ReplyValidator.java:64