From 6c607f221091975a0405b772d262a6d3af77f746 Mon Sep 17 00:00:00 2001 From: Pieter12345
These are arguments, then "These
- * are arguments" will be returned. However, assuming -c is registered
- * as a single string type, and the arguments are
- * -c These are arguments, then only "are arguments" is
- * returned. This will return an empty string if no arguments were set.
- *
- * @return
- */
- public String getStringArgument() {
- try {
- Argument a = getArg();
- if (a.arrayVal == null) {
- return "";
- }
- StringBuilder b = new StringBuilder();
- boolean first = true;
- for (String val : a.arrayVal) {
- if (!first) {
- b.append(" ");
- }
- first = false;
- b.append(val);
- }
- return b.toString();
- } catch (ResultUseException e) {
- return "";
- }
- }
-
- /**
- * Returns the string associated with the switch represented by this
- * short code. If the switch wasn't set, null is returned.
- *
- * @param flag
- * @return
- * @throws ArgumentParser.ResultUseException
- */
- public String getStringArgument(Character flag) throws ResultUseException {
- return getStringArgument(getArg(flag));
- }
-
- /**
- * Returns the string associated with the switch represented by this
- * long code. If the switch wasn't set, null is returned.
- *
- * @param flag
- * @return
- * @throws ArgumentParser.ResultUseException
- */
- public String getStringArgument(String flag) throws ResultUseException {
- return getStringArgument(getArg(flag));
- }
-
- private String getStringArgument(Argument arg) {
- if (arg == null) {
- return null;
- }
- if (arg.argType != Type.STRING) {
- throw new ClassCastException("Argument type not set to " + Type.STRING.name() + ". Cannot return a " + "string" + ".");
- }
- return arg.singleVal;
- }
-
- /**
- * Returns the value associated with the switch represented by this
- * short code, pre-parsed as a double. If the switch wasn't set, null is
- * returned.
- *
- * @param flag
- * @return
- * @throws ResultUseException, NumberFormatException
- */
- public Double getNumberArgument(Character flag) throws ResultUseException {
- return getNumberArgument(getArg(flag));
- }
-
- /**
- * Returns the value associated with the switch represented by this long
- * code, pre-parsed as a double. If the switch wasn't set, null is
- * returned.
- *
- * @param flag
- * @return
- * @throws ResultUseException, NumberFormatException
- */
- public Double getNumberArgument(String flag) throws ResultUseException {
- return getNumberArgument(getArg(flag));
- }
-
- private Double getNumberArgument(Argument arg) {
- if (arg == null) {
- return null;
- }
- if (arg.argType != Type.NUMBER) {
- throw new ClassCastException("Argument type not set to " + Type.NUMBER.name() + ". Cannot return a " + "number" + ".");
- }
- return Double.parseDouble(arg.singleVal);
- }
-
- /**
- * Gets the unassociated arguments passed in as a List of Strings. For
- * instance, if the arguments were These are arguments,
- * then ["These", "are", "arguments"] will be returned. However,
- * assuming -c is registered as a single string type, and the arguments
- * are -c These are arguments, then only ["are",
- * "arguments"] is returned. This will return an empty array if no
- * arguments were set.
- *
- * @return
- */
- public Listthese are args would all be loose arguments,
- * because they aren't associated with any explicit switches. Note that
- * there is no Type specified here, that's because the arguments can be
- * grabbed as either an array of strings or a string.
- *
- * @param argType
- * @param defaultVal
- * @param description
- * @return
- */
- public ArgumentParser addArgument(String defaultVal, String description, String usageName, boolean required) {
- return addArgument(null, null, Type.ARRAY_OF_STRINGS, defaultVal, description, usageName, required);
- }
-
- /**
- * Sets the default switch with no default value.
- *
- * @param argType
- * @param description
- * @return
- */
- public ArgumentParser addArgument(String description, String usageName, boolean required) {
- return addArgument(null, null, Type.ARRAY_OF_STRINGS, null, description, usageName, required);
- }
-
- /**
- * Adds a new argument with no default value.
- *
- * @param shortArg
- * @param longArg
- * @param argType
- * @param description
- * @return
- */
- public ArgumentParser addArgument(Character shortArg, String longArg, Type argType, String description, String usageName, boolean required) {
- return addArgument(shortArg, longArg, argType, null, description, usageName, required);
- }
-
- /**
- * Adds a new argument with no long code.
- *
- * @param shortArg
- * @param argType
- * @param defaultVal
- * @param description
- * @return
- */
- public ArgumentParser addArgument(Character shortArg, Type argType, String defaultVal, String description, String usageName, boolean required) {
- return addArgument(shortArg, null, argType, defaultVal, description, usageName, required);
- }
-
- /**
- * Adds a new argument with no short code.
- *
- * @param longArg
- * @param argType
- * @param defaultVal
- * @param description
- * @return
- */
- public ArgumentParser addArgument(String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) {
- return addArgument(null, longArg, argType, defaultVal, description, usageName, required);
- }
-
- /**
- * Adds a new argument with no long code, and no default value.
- *
- * @param shortArg
- * @param argType
- * @param description
- * @return
- */
- public ArgumentParser addArgument(Character shortArg, Type argType, String description, String usageName, boolean required) {
- return addArgument(shortArg, null, argType, null, description, usageName, required);
- }
-
- /**
- * Adds a new argument with no short code, and no default value.
- *
- * @param longArg
- * @param argType
- * @param description
- * @return
- */
- public ArgumentParser addArgument(String longArg, Type argType, String description, String usageName, boolean required) {
- return addArgument(null, longArg, argType, null, description, usageName, required);
- }
-
- /**
- * Adds a new flag.
- *
- * @param shortArg
- * @param longArg
- * @param description
- * @return
- */
- public ArgumentParser addFlag(Character shortArg, String longArg, String description) {
- return addArgument0(shortArg, longArg, Type.BOOLEAN, null, description, null, false);
- }
-
- /**
- * Adds a new flag with no short code.
- *
- * @param longArg
- * @param description
- * @return
- */
- public ArgumentParser addFlag(String longArg, String description) {
- return addArgument0(null, longArg, Type.BOOLEAN, null, description, null, false);
- }
-
- /**
- * Adds a new flag with no long code.
- *
- * @param shortArg
- * @param description
- * @return
- */
- public ArgumentParser addFlag(Character shortArg, String description) {
- return addArgument0(shortArg, null, Type.BOOLEAN, null, description, null, false);
- }
-
- /**
- * Adds a description to the ArgumentParser object, which is used when
- * building the description returned by getBuiltDescription.
- *
- * @param description
- * @return
- */
- public ArgumentParser addDescription(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * Builds a description of this ArgumentParser, which may be useful as
- * "Usage" text to provide to a user if a call to match throws a
- * ValidationException, for instance.
- *
- * @return
- */
- public String getBuiltDescription() {
- StringBuilder b = new StringBuilder();
- //Now, we need to go through and get all the switch names in alphabetical
- //order.
- b.append("\t").append(this.description).append("\n\n");
- Listlike\ this. Within a string, to add a
- * literal backslash in front of an otherwise escapable character, use two
- * backslashes "like this\\"
- *
- * @param args
- * @return
- */
- public ArgumentParserResults match(String args) throws ValidationException {
- return parse(lex(args));
- }
-
- /**
- * Returns a simple List of the arguments, parsed into a proper argument
- * list. This will work essentially identically to how general shell
- * arguments are parsed.
- *
- * @param args
- * @return
- */
- static List"args with spaces" args
- * but through some means or another, you have already parsed the arguments
- * out.
- *
- * @param args
- * @return
- */
- public ArgumentParserResults match(String[] args) throws ValidationException {
- return parse(Arrays.asList(args));
- }
+ /**
+ * A description of the command itself.
+ */
+ String description = "";
+ ListThese are arguments, then "These
+ * are arguments" will be returned. However, assuming -c is registered
+ * as a single string type, and the arguments are
+ * -c These are arguments, then only "are arguments" is
+ * returned. This will return an empty string if no arguments were set.
+ *
+ * @return
+ */
+ public String getStringArgument() {
+ try {
+ Argument a = getArg();
+ if (a.arrayVal == null) {
+ return "";
+ }
+ StringBuilder b = new StringBuilder();
+ boolean first = true;
+ for (String val : a.arrayVal) {
+ if (!first) {
+ b.append(" ");
+ }
+ first = false;
+ b.append(val);
+ }
+ return b.toString();
+ } catch (ResultUseException e) {
+ return "";
+ }
+ }
+
+ /**
+ * Returns the string associated with the switch represented by this
+ * short code. If the switch wasn't set, null is returned.
+ *
+ * @param flag
+ * @return
+ * @throws ArgumentParser.ResultUseException
+ */
+ public String getStringArgument(Character flag) throws ResultUseException {
+ return getStringArgument(getArg(flag));
+ }
+
+ /**
+ * Returns the string associated with the switch represented by this
+ * long code. If the switch wasn't set, null is returned.
+ *
+ * @param flag
+ * @return
+ * @throws ArgumentParser.ResultUseException
+ */
+ public String getStringArgument(String flag) throws ResultUseException {
+ return getStringArgument(getArg(flag));
+ }
+
+ private String getStringArgument(Argument arg) {
+ if (arg == null) {
+ return null;
+ }
+ if (arg.argType != Type.STRING) {
+ throw new ClassCastException("Argument type not set to " + Type.STRING.name() + ". Cannot return a " + "string" + ".");
+ }
+ return arg.singleVal;
+ }
+
+ /**
+ * Returns the value associated with the switch represented by this
+ * short code, pre-parsed as a double. If the switch wasn't set, null is
+ * returned.
+ *
+ * @param flag
+ * @return
+ * @throws ResultUseException, NumberFormatException
+ */
+ public Double getNumberArgument(Character flag) throws ResultUseException {
+ return getNumberArgument(getArg(flag));
+ }
+
+ /**
+ * Returns the value associated with the switch represented by this long
+ * code, pre-parsed as a double. If the switch wasn't set, null is
+ * returned.
+ *
+ * @param flag
+ * @return
+ * @throws ResultUseException, NumberFormatException
+ */
+ public Double getNumberArgument(String flag) throws ResultUseException {
+ return getNumberArgument(getArg(flag));
+ }
+
+ private Double getNumberArgument(Argument arg) {
+ if (arg == null) {
+ return null;
+ }
+ if (arg.argType != Type.NUMBER) {
+ throw new ClassCastException("Argument type not set to " + Type.NUMBER.name() + ". Cannot return a " + "number" + ".");
+ }
+ return Double.parseDouble(arg.singleVal);
+ }
+
+ /**
+ * Gets the unassociated arguments passed in as a List of Strings. For
+ * instance, if the arguments were These are arguments,
+ * then ["These", "are", "arguments"] will be returned. However,
+ * assuming -c is registered as a single string type, and the arguments
+ * are -c These are arguments, then only ["are",
+ * "arguments"] is returned. This will return an empty array if no
+ * arguments were set.
+ *
+ * @return
+ */
+ public Listthese are args would all be loose arguments,
+ * because they aren't associated with any explicit switches. Note that
+ * there is no Type specified here, that's because the arguments can be
+ * grabbed as either an array of strings or a string.
+ *
+ * @param argType
+ * @param defaultVal
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(String defaultVal, String description, String usageName, boolean required) {
+ return addArgument(null, null, Type.ARRAY_OF_STRINGS, defaultVal, description, usageName, required);
+ }
+
+ /**
+ * Sets the default switch with no default value.
+ *
+ * @param argType
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(String description, String usageName, boolean required) {
+ return addArgument(null, null, Type.ARRAY_OF_STRINGS, null, description, usageName, required);
+ }
+
+ /**
+ * Adds a new argument with no default value.
+ *
+ * @param shortArg
+ * @param longArg
+ * @param argType
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(Character shortArg, String longArg, Type argType, String description, String usageName, boolean required) {
+ return addArgument(shortArg, longArg, argType, null, description, usageName, required);
+ }
+
+ /**
+ * Adds a new argument with no long code.
+ *
+ * @param shortArg
+ * @param argType
+ * @param defaultVal
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(Character shortArg, Type argType, String defaultVal, String description, String usageName, boolean required) {
+ return addArgument(shortArg, null, argType, defaultVal, description, usageName, required);
+ }
+
+ /**
+ * Adds a new argument with no short code.
+ *
+ * @param longArg
+ * @param argType
+ * @param defaultVal
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(String longArg, Type argType, String defaultVal, String description, String usageName, boolean required) {
+ return addArgument(null, longArg, argType, defaultVal, description, usageName, required);
+ }
+
+ /**
+ * Adds a new argument with no long code, and no default value.
+ *
+ * @param shortArg
+ * @param argType
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(Character shortArg, Type argType, String description, String usageName, boolean required) {
+ return addArgument(shortArg, null, argType, null, description, usageName, required);
+ }
+
+ /**
+ * Adds a new argument with no short code, and no default value.
+ *
+ * @param longArg
+ * @param argType
+ * @param description
+ * @return
+ */
+ public ArgumentParser addArgument(String longArg, Type argType, String description, String usageName, boolean required) {
+ return addArgument(null, longArg, argType, null, description, usageName, required);
+ }
+
+ /**
+ * Adds a new flag.
+ *
+ * @param shortArg
+ * @param longArg
+ * @param description
+ * @return
+ */
+ public ArgumentParser addFlag(Character shortArg, String longArg, String description) {
+ return addArgument0(shortArg, longArg, Type.BOOLEAN, null, description, null, false);
+ }
+
+ /**
+ * Adds a new flag with no short code.
+ *
+ * @param longArg
+ * @param description
+ * @return
+ */
+ public ArgumentParser addFlag(String longArg, String description) {
+ return addArgument0(null, longArg, Type.BOOLEAN, null, description, null, false);
+ }
+
+ /**
+ * Adds a new flag with no long code.
+ *
+ * @param shortArg
+ * @param description
+ * @return
+ */
+ public ArgumentParser addFlag(Character shortArg, String description) {
+ return addArgument0(shortArg, null, Type.BOOLEAN, null, description, null, false);
+ }
+
+ /**
+ * Adds a description to the ArgumentParser object, which is used when
+ * building the description returned by getBuiltDescription.
+ *
+ * @param description
+ * @return
+ */
+ public ArgumentParser addDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * Builds a description of this ArgumentParser, which may be useful as
+ * "Usage" text to provide to a user if a call to match throws a
+ * ValidationException, for instance.
+ *
+ * @return
+ */
+ public String getBuiltDescription() {
+ StringBuilder b = new StringBuilder();
+ //Now, we need to go through and get all the switch names in alphabetical
+ //order.
+ b.append("\t").append(this.description).append("\n\n");
+ Listlike\ this. Within a string, to add a
+ * literal backslash in front of an otherwise escapable character, use two
+ * backslashes "like this\\"
+ *
+ * @param args
+ * @return
+ */
+ public ArgumentParserResults match(String args) throws ValidationException {
+ return parse(lex(args));
+ }
+
+ /**
+ * Returns a simple List of the arguments, parsed into a proper argument
+ * list. This will work essentially identically to how general shell
+ * arguments are parsed.
+ *
+ * @param args
+ * @return
+ */
+ static List"args with spaces" args
+ * but through some means or another, you have already parsed the arguments
+ * out.
+ *
+ * @param args
+ * @return
+ */
+ public ArgumentParserResults match(String[] args) throws ValidationException {
+ return parse(Arrays.asList(args));
+ }
}
diff --git a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java
index 080cf69a0c..8322472768 100644
--- a/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java
+++ b/src/main/java/com/laytonsmith/PureUtilities/ClassLoading/ClassMirror/ClassMirror.java
@@ -25,606 +25,606 @@
*/
public class ClassMirror
- * volatile Object value = null; // Note the volatility
- * construct() {
- * Object result = value;
- * if(result == null) {
- * synchronized(result) {
- * if(result == null) {
- * result = new Object();
- * value = result;
- * }
- * }
- * }
- * return result;
- * }
- *
- *
- * Note that we are doing the double locking per usual, but the value is volatile. The local result value seems
- * unnecessary at first, but the effect of this is that in cases where value is already initialized
- * (i.e., most of the time), the volatile field is only accessed once (due to "return result;" instead of
- * "return value;"), which can improve the method's overall performance by as much as 25 percent.
- *
- * However, in the case that we have before us, the ConcurrentHashMap handles this for us, by guaranteeing that
- * we never get a value that is partially constructed in the get() method.
- *
- *
+ * You might notice that no fields in this class are volatile. Normally, when you double lock, you must do
+ * something like this to be totally correct:
+ *
+ *
+ * volatile Object value = null; // Note the volatility
+ * construct() {
+ * Object result = value;
+ * if(result == null) {
+ * synchronized(result) {
+ * if(result == null) {
+ * result = new Object();
+ * value = result;
+ * }
+ * }
+ * }
+ * return result;
+ * }
+ *
+ *
+ * Note that we are doing the double locking per usual, but the value is volatile. The local result value seems
+ * unnecessary at first, but the effect of this is that in cases where value is already initialized
+ * (i.e., most of the time), the volatile field is only accessed once (due to "return result;" instead of
+ * "return value;"), which can improve the method's overall performance by as much as 25 percent.
+ *
+ * However, in the case that we have before us, the ConcurrentHashMap handles this for us, by guaranteeing that
+ * we never get a value that is partially constructed in the get() method.
+ *
+ *
*/
private final Map