From 44a8d9d2d56a311293ec86ea40df7126748300a1 Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Thu, 7 Jun 2018 20:37:51 -0300 Subject: Refactoring The main refactoring here is removing the type field from the various classes, but there are a few other smaller ones. This also contains the grounds for a refactoring on variable use --- src/main/java/bjc/rgens/parser/RuleCase.java | 73 +++------------------------- 1 file changed, 8 insertions(+), 65 deletions(-) (limited to 'src/main/java/bjc/rgens/parser/RuleCase.java') diff --git a/src/main/java/bjc/rgens/parser/RuleCase.java b/src/main/java/bjc/rgens/parser/RuleCase.java index 369c588..33aea0c 100755 --- a/src/main/java/bjc/rgens/parser/RuleCase.java +++ b/src/main/java/bjc/rgens/parser/RuleCase.java @@ -20,91 +20,34 @@ public abstract class RuleCase { private static int nextSerial = 0; - /** - * The possible types of a case. - * - * @author EVE - */ - public static enum CaseType { - /** A normal case, composed from a list of elements. */ - NORMAL, - /** A case that doesn't insert spaces. */ - SPACEFLATTEN, - /** A case that applies a regex after generation. */ - REGEX; - } - - /** The type of this case. */ - public final CaseType type; - public Rule belongsTo; - /** - * The list of element values for this case. - * - *

Used For

- *
- *
NORMAL, SPACEFLATTEN
- *
Used as the list of elementList the rule is composed of.
- *
- */ - protected IList elementList; - - protected RuleCase(CaseType typ) { - serial = nextSerial; - - type = typ; - - nextSerial += 1; - } + public IList elementList; /** * Create a new case of the specified type that takes a element list * parameter. * - * @param typ - * The type of case to create. - * * @param elements * The element list parameter of the case. * - * @throws IllegalArgumentException - * If this type doesn't take a element list parameter. */ - public RuleCase(CaseType typ, IList elements) { - this(typ); - - switch (typ) { - case NORMAL: - case SPACEFLATTEN: - break; - case REGEX: - throw new IllegalArgumentException("This type requires an element list and a pattern"); - default: - throw new IllegalArgumentException("This type doesn't have a element list parameter"); - } - + protected RuleCase(IList elements) { elementList = elements; + + serial = nextSerial; + nextSerial += 1; } public abstract void generate(GenerationState state); - /** - * Get the element list value of this type. - * - * @return - * The element list value of this case, or null if this type - * doesn't have one. - */ - public IList getElements() { - return elementList; - } + public abstract RuleCase withElements(IList elements); public String toString() { if(debugName != null) { - return String.format("Case %d (%s) of %s", serial, debugName, belongsTo); + return String.format("Case %s (#%d) of %s", debugName, serial, belongsTo); } else { - return String.format("Case %d (%s-%d) of %s", serial, belongsTo, serial, belongsTo); + return String.format("Case #%d of %s", serial, belongsTo, serial, belongsTo); } } -- cgit v1.2.3