From 4a36dbf913e1a1bce6e7e5e53531ef084f59babf Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 2 Jul 2019 17:00:47 -0400 Subject: Update site --- .../bjc.everge/ControlledString.java.html | 294 ++++++++++++++++----- 1 file changed, 231 insertions(+), 63 deletions(-) (limited to 'docs/jacoco-ut/bjc.everge/ControlledString.java.html') diff --git a/docs/jacoco-ut/bjc.everge/ControlledString.java.html b/docs/jacoco-ut/bjc.everge/ControlledString.java.html index 2f928e8..63c0b44 100644 --- a/docs/jacoco-ut/bjc.everge/ControlledString.java.html +++ b/docs/jacoco-ut/bjc.everge/ControlledString.java.html @@ -1,5 +1,7 @@ ControlledString.java

ControlledString.java

package bjc.everge;
 
+import java.util.Arrays;
+
 /**
  * Represents a string with a set of control flags attached to it.
  *
@@ -25,9 +27,9 @@ public class ControlledString {
 		/**
 		 * Create a new blank control.
 		 */
-		public Control() {
+		public Control() {
 
-		}
+		}
 
 		/**
 		 * Create a new argless control.
@@ -35,9 +37,9 @@ public class ControlledString {
 		 * @param nam
 		 * 	The name of the control.
 		 */
-		public Control(String nam) {
-			name = nam;
-		}
+		public Control(String nam) {
+			name = nam;
+		}
 
 		/**
 		 * Create a new control.
@@ -47,12 +49,165 @@ public class ControlledString {
 		 * @param ars
 		 * 	The arguments of the control.
 		 */
-		public Control(String nam, String... ars) {
-			name = nam;
-			args = ars;
-		}
+		public Control(String nam, String... ars) {
+			name = nam;
+			args = ars;
+		}
+
+		/**
+		 * Get the count of arguments this control has.
+		 *
+		 * @return The number of arguments to this control.
+		 */
+		public int count() {
+			return args.length;
+		}
+
+		public String get(int i) {
+			if (i < 0) {
+				String msg = String.format("Control argument index must be greater than 0 (was %d)", i);
+
+				throw new IllegalArgumentException(msg);
+			}
+
+			if (i > args.length) {
+				String msg = String.format("Control argument index must be less than %d (was %d)",
+						args.length, i);
+
+				throw new IllegalArgumentException(msg);
+			}
+
+			return args[i];
+		}
+
+		@Override
+		public String toString() {
+			StringBuilder sb = new StringBuilder();
+			sb.append(name);
+
+			if (args != null && args.length > 0) {
+				sb.append("/");
+
+				for (String arg : args) {
+					sb.append(arg);
+					sb.append(";");
+				}
+			}
+
+			return sb.toString();
+		}
+
+		@Override
+		public int hashCode() {
+			final int prime = 31;
+			int result = 1;
+			result = prime * result + Arrays.hashCode(args);
+			result = prime * result + ((name == null) ? 0 : name.hashCode());
+			return result;
+		}
+
+		@Override
+		public boolean equals(Object obj) {
+			if (this == obj) { return true; }
+			if (obj == null) { return false; }
+			if (getClass() != obj.getClass()) { return false; }
+
+			Control other = (Control) obj;
+
+			if (name == null) {
+				if (other.name != null) { return false; }
+			} else if (!name.equals(other.name)) { return false; }
+
+			boolean isArged  = args != null && args.length > 0;
+			boolean oIsArged = other.args != null && other.args.length > 0;
+
+			if (isArged && !oIsArged) { return false; }
+			if (!isArged && oIsArged) { return false; }
+
+			if (isArged && oIsArged) {
+				return Arrays.equals(args, other.args);
+			}
+
+			return true;
+		}
+
+		/**
+		 * Convenient static constructor for static imports.
+		 *
+		 * @param nam
+		 * 	The name of the control.
+		 * @param ars
+		 * 	The arguments to the control.
+		 * @return A control with the right parameters.
+		 */
+		public static Control C(String nam, String... ars) {
+			return new Control(nam, ars);
+		}
 	}
+	
+	/**
+	 * Parameter class for defining how to parse a ControlledString.
+	 *
+	 * @author Ben Culkin
+	 */
+	public static class ParseStrings {
+		/**
+		 * The indicator for separating controls from the regular string.
+		 */
+		public String contInd;
+
+		/**
+		 * The indicator for separating individual controls.
+		 */
+		public String contSep;
+
+		/**
+		 * The indicator for separating arguments to a control.
+		 */
+		public String contArg;
+
+		/**
+		 * The indicator for escaping any of the indicators (including itself)
+		 */
+		public String contEsc;
 
+		/**
+		 * Create a new set of parse strings.
+		 *
+		 * @param contInd
+		 * 	The control indicator.
+		 * @param contSep
+		 * 	The control separator.
+		 * @param contArg
+		 * 	The argument separator.
+		 * @param contEsc
+		 * 	The control escape.
+		 */
+		public ParseStrings(String contInd, String contSep, String contArg, String contEsc) {
+			this.contInd = contInd;
+			this.contSep = contSep;
+			this.contArg = contArg;
+			this.contEsc = contEsc;
+		}
+
+		/**
+		 * Convenient static constructor.
+		 *
+		 * @param contInd
+		 * 	The control indicator.
+		 * @param contSep
+		 * 	The control separator.
+		 * @param contArg
+		 * 	The argument separator.
+		 * @param contEsc
+		 * 	The control escape.
+		 * @return A new set of control strings.
+		 */
+		public static ParseStrings PS(String contInd, String contSep, String contArg, String contEsc) {
+			return new ParseStrings(contInd, contSep, contArg, contEsc);
+		}
+	}
+	
 	/**
 	 * The string the controls apply to.
 	 */
@@ -66,9 +221,9 @@ public class ControlledString {
 	/**
 	 * Create a new blank controlled string.
 	 */
-	public ControlledString() {
-		controls = new Control[0];
-	}
+	public ControlledString() {
+		controls = new Control[0];
+	}
 
 	/**
 	 * Create a new controlled string without any controls.
@@ -76,11 +231,11 @@ public class ControlledString {
 	 * @param strung
 	 * 	The string to use.
 	 */
-	public ControlledString(String strung) {
-		strang = strung;
+	public ControlledString(String strung) {
+		strang = strung;
 
-		controls = new Control[0];
-	}
+		controls = new Control[0];
+	}
 
 	/**
 	 * Create a new controlled string.
@@ -90,11 +245,11 @@ public class ControlledString {
 	 * @param controls
 	 * 	The controls that apply to the string.
 	 */
-	public ControlledString(String strung, Control... controls) {
-		strang = strung;
+	public ControlledString(String strung, Control... controls) {
+		strang = strung;
 
-		controls = controls;
-	}
+		this.controls = controls;
+	}
 
 	/**
 	 * Check if the string has controls.
@@ -102,77 +257,90 @@ public class ControlledString {
 	 * @return Whether or not the string has controls.
 	 */
 	public boolean hasControls() {
-		return controls.length > 0;
+		return controls.length > 0;
 	}
 
 	/**
-	 * Parse a controlled string from a regular string.
+	 * Get the count of controls.
 	 *
-	 * The controls must be parsed from the beginning of the string, and are indicated by occurances
-	 * of contInd that bracket them from the string. The individual controls are delimited by
-	 * instances of contSep, with arguments to them being separated by occurances of contArg.
+	 * @return The number of controls for this string.
+	 */
+	public int count() {
+		return controls.length;
+	}
+
+	/**
+	 * Parse a controlled string from a regular string.
 	 *
-	 * Each of those separators (which must be regular strings, not regexes or anything) may be
-	 * escaped by preceeding them with a copy of contEsc.
+	 * The controls must be parsed from the beginning of the string.
 	 *
 	 * @param lne
-	 * 	The string to parse frmo.
-	 * @param contInd
-	 * 	The indicator for whether or not there are controls.
-	 * @param contSep
-	 * 	The separator of individual controls.
-	 * @param contArg
-	 * 	The separator of control arguments.
-	 * @param contEsc
-	 * 	The escape string for each of the separators/indicators.
-	 *
+	 * 	The string to parse from.
+	 * @param parameterObject TODO
 	 * @return A parsed control string.
 	 */
-	public static ControlledString parse(String lne, String contInd, String contSep,
-			String contArg, String contEsc) {
-		if (!lne.startsWith(contInd)) {
-			return new ControlledString(lne);
+	public static ControlledString parse(String lne, ParseStrings parameterObject) 
+	{
+		if (!lne.startsWith(parameterObject.contInd)) {
+			return new ControlledString(lne);
 		}
 
-		String tmp = lne.substring(2);
+		String tmp = lne.substring(2);
 
-		String[] bits = StringUtils.escapeSplit(contEsc, contInd, lne);
+		String[] bits = StringUtils.escapeSplit(parameterObject.contEsc, parameterObject.contInd, lne);
 
-		if (bits.length < 2) {
-			String msg = "Did not find control terminator (%s) where it should be";
-			msg = String.format(msg, contInd);
+		if (bits.length < 2) {
+			String msg = "Did not find control terminator (%s) where it should be";
+			msg = String.format(msg, parameterObject.contInd);
 
-			throw new IllegalArgumentException(msg);
-		}
+			throw new IllegalArgumentException(msg);
+		} 
 
-		ControlledString cs = new ControlledString(bits[0]);
+		ControlledString cs = new ControlledString(bits[0]);
+		if (bits.length > 2) cs.strang = bits[2];
 
-		bits = StringUtils.escapeSplit(contEsc, contSep, bits[1]);
+		bits = StringUtils.escapeSplit(parameterObject.contEsc, parameterObject.contSep, bits[1]);
 
-		cs.controls = new Control[bits.length];
+		cs.controls = new Control[bits.length];
 
-		for (int i = 0; i < bits.length; i++) {
-			String bit = bits[i];
+		for (int i = 0; i < bits.length; i++) {
+			String bit = bits[i];
 
-			String[] bots = StringUtils.escapeSplit(contEsc, contArg, bit);
+			String[] bots = StringUtils.escapeSplit(parameterObject.contEsc, parameterObject.contArg, bit);
 
-			Control cont = new Control(bots[0]);
+			Control cont = new Control(bots[0]);
 
-			if (cont.name.length() > 1) {
-				cont.name = cont.name.toUpperCase();
+			if (cont.name.length() > 1) {
+				cont.name = cont.name.toUpperCase();
 			}
 
-			if (bots.length > 1) {
-				cont.args = new String[bots.length - 1];
-				for (int j = 1; j < bots.length; j++) {
-					cont.args[j - 1] = bots[j];
+			if (bots.length > 1) {
+				cont.args = new String[bots.length - 1];
+				for (int j = 1; j < bots.length; j++) {
+					cont.args[j - 1] = bots[j];
 				}
 			}
 
-			cs.controls[i] = cont;
+			cs.controls[i] = cont;
 		}
 
-		return cs;
+		return cs;
+	}
+
+	@Override
+	public String toString() {
+		StringBuilder sb = new StringBuilder();
+
+		sb.append("//");
+
+		for (Control cont : controls) {
+			sb.append(cont);
+		}
+
+		sb.append("//");
+		sb.append(strang);
+
+		return sb.toString();
 	}
 }
 
\ No newline at end of file -- cgit v1.2.3