http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/help/utils/HelpUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/help/utils/HelpUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/help/utils/HelpUtils.java deleted file mode 100644 index 11765c5..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/help/utils/HelpUtils.java +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.help.utils; - -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.internal.cli.help.format.*; -import org.apache.geode.management.internal.cli.modes.CommandModes; -import org.apache.geode.management.internal.cli.modes.CommandModes.CommandMode; -import org.apache.geode.management.internal.cli.parser.Argument; -import org.apache.geode.management.internal.cli.parser.CommandTarget; -import org.apache.geode.management.internal.cli.parser.Option; -import org.apache.geode.management.internal.cli.parser.SyntaxConstants; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @since GemFire 7.0 - */ -public class HelpUtils { - public static final String EXE_PREFIX_FOR_EXTERNAL_HELP = - org.apache.geode.management.internal.cli.shell.Gfsh.GFSH_APP_NAME + " "; - public static final String HELP__COMMAND_AVAILABLE = "Available"; - public static final String HELP__COMMAND_NOTAVAILABLE = "Not Available"; - - private static final String NAME_NAME = "NAME"; - private static final String SYNONYMS_NAME = "SYNONYMS"; - private static final String SYNOPSIS_NAME = "SYNOPSIS"; - private static final String SYNTAX_NAME = "SYNTAX"; - private static final String ARGUMENTS_NAME = "ARGUMENTS"; - private static final String OPTIONS_NAME = "PARAMETERS"; - private static final String IS_AVAILABLE_NAME = "IS AVAILABLE"; - private static final String MODES = "MODES"; - - private static final String REQUIRED_SUB_NAME = "Required: "; - private static final String DEFAULTVALUE_SUB_NAME = "Default value: "; - private static final String SYNONYMS_SUB_NAME = "Synonyms: "; - private static final String SPECIFIEDDEFAULTVALUE_SUB_NAME = - "Default (if the parameter is specified without value): "; - private static final String UNSPECIFIEDDEFAULTVALUE_VALUE_SUB_NAME = - "Default (if the parameter is not specified): "; - - private static final String VALUE_FIELD = "value"; - private static final String TRUE_TOKEN = "true"; - private static final String FALSE_TOKEN = "false"; - - - private static Help help(Block[] blocks) { - return new Help().setBlocks(blocks); - } - - private static Block block(String heading, Row... rows) { - return new Block().setHeading(heading).setRows(rows); - } - - private static Row row(String... info) { - return new Row().setInfo(info); - } - - @Deprecated - public static Help getHelp(CommandTarget commandTarget) { - List<Block> blocks = new ArrayList<Block>(); - // First we will have the block for NAME of the command - blocks.add(block(NAME_NAME, row(commandTarget.getCommandName()))); - // Now add synonyms if any - if (commandTarget.getSynonyms() != null) { - blocks.add(block(SYNONYMS_NAME, row(commandTarget.getSynonyms()))); - } - - - - // Now comes the turn to display synopsis if any - if (commandTarget.getCommandHelp() != null && !commandTarget.getCommandHelp().equals("")) { - blocks.add(block(SYNOPSIS_NAME, row(commandTarget.getCommandHelp()))); - } - // Now display the syntax for the command - StringBuffer buffer = new StringBuffer(); - buffer.append(commandTarget.getCommandName()); - // Create a list which will store optional arguments - List<Argument> optionalArguments = new ArrayList<Argument>(); - for (Argument argument : commandTarget.getOptionParser().getArguments()) { - if (argument.isRequired()) { - buffer.append(" " + argument.getArgumentName()); - } else { - optionalArguments.add(argument); - } - } - for (Argument argument : optionalArguments) { - buffer.append(" " + "[" + argument.getArgumentName() + "]"); - } - // Create a list which will store optional options - List<Option> optionalOptions = new ArrayList<Option>(); - for (Option option : commandTarget.getOptionParser().getOptions()) { - if (option.isRequired()) { - buffer.append(" " + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption()); - // String temp = SyntaxConstants.OPTION_VALUE_SPECIFIER + VALUE_TOKEN + "(" - // + SyntaxConstants.OPTION_VALUE_SEPARATOR + VALUE_TOKEN + ")*"; - String temp = buildOptionHelpText(option); - // - if (option.getSpecifiedDefaultValue() != null - && !option.getSpecifiedDefaultValue().equals("")) { - buffer.append("("); - buffer.append(temp); - buffer.append(")?"); - } else { - buffer.append(temp); - } - } else { - optionalOptions.add(option); - } - } - for (Option option : optionalOptions) { - buffer.append(" " + "[" + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption()); - // String temp = SyntaxConstants.OPTION_VALUE_SPECIFIER + VALUE_TOKEN + "(" - // + SyntaxConstants.OPTION_VALUE_SEPARATOR + VALUE_TOKEN + ")*"; - String temp = buildOptionHelpText(option); - // - if (option.getSpecifiedDefaultValue() != null - && !option.getSpecifiedDefaultValue().equals("")) { - buffer.append("("); - buffer.append(temp); - buffer.append(")?"); - } else { - buffer.append(temp); - } - buffer.append("]"); - } - blocks.add(block(SYNTAX_NAME, row(buffer.toString()))); - // Detailed description of Arguments - if (commandTarget.getOptionParser().getArguments().size() > 0) { - List<Row> rows = new ArrayList<Row>(); - for (Argument argument : commandTarget.getOptionParser().getArguments()) { - rows.add(row(argument.getArgumentName() - + ((argument.getHelp() != null && !argument.getHelp().equals("")) - ? ":" + argument.getHelp() : ""))); - } - Row[] rowsArray = new Row[rows.size()]; - blocks.add(block(ARGUMENTS_NAME, rows.toArray(rowsArray))); - } - - // Detailed description of Options - if (commandTarget.getOptionParser().getOptions().size() > 0) { - List<Row> rows = new ArrayList<Row>(); - for (Option option : commandTarget.getOptionParser().getOptions()) { - rows.add( - row(option.getLongOption() + ((option.getHelp() != null && !option.getHelp().equals("")) - ? ":" + option.getHelp() : ""))); - } - Row[] rowsArray = new Row[rows.size()]; - blocks.add(block(OPTIONS_NAME, rows.toArray(rowsArray))); - } - Block[] blocksArray = new Block[blocks.size()]; - for (int i = 0; i < blocks.size(); i++) { - blocksArray[i] = blocks.get(i); - } - return help(blocksArray); - } - - /** - * Builds help for the specified command. - * - * @param commandTarget command specific target to use to generate help - * @param withinShell if <code>true</code> includes availabilty & doesn't include application name - * @return built NewHelp object for the given command target - */ - public static NewHelp getNewHelp(CommandTarget commandTarget, boolean withinShell) { - DataNode root = new DataNode(null, new ArrayList<DataNode>()); - // First we will have the block for NAME of the command - DataNode name = new DataNode(NAME_NAME, new ArrayList<DataNode>()); - name.addChild(new DataNode(commandTarget.getCommandName(), null)); - root.addChild(name); - if (withinShell) {// include availabilty info - DataNode availability = new DataNode(IS_AVAILABLE_NAME, new ArrayList<DataNode>()); - boolean isAvailable = false; - try { - isAvailable = commandTarget.isAvailable(); - } catch (Exception e) { - isAvailable = false; - } - availability.addChild(new DataNode(String.valueOf(isAvailable), null)); - root.addChild(availability); - } - // Now add synonyms if any - if (commandTarget.getSynonyms() != null) { - DataNode synonyms = new DataNode(SYNONYMS_NAME, new ArrayList<DataNode>()); - for (String string : commandTarget.getSynonyms()) { - synonyms.addChild(new DataNode(string, null)); - } - root.addChild(synonyms); - } - - - // Now comes the turn to display synopsis if any - if (commandTarget.getCommandHelp() != null && !commandTarget.getCommandHelp().equals("")) { - DataNode synopsis = new DataNode(SYNOPSIS_NAME, new ArrayList<DataNode>()); - synopsis.addChild(new DataNode(commandTarget.getCommandHelp(), null)); - root.addChild(synopsis); - } - - - // Now display the syntax for the command - StringBuffer buffer = new StringBuffer(); - if (withinShell) { - buffer.append(commandTarget.getCommandName()); - } else { // add app name in the syntax - buffer.append(EXE_PREFIX_FOR_EXTERNAL_HELP).append(commandTarget.getCommandName()); - } - appendArguments(buffer, commandTarget); - appendOptions(buffer, commandTarget); - DataNode syntax = new DataNode(SYNTAX_NAME, new ArrayList<DataNode>()); - syntax.addChild(new DataNode(buffer.toString(), null)); - root.addChild(syntax); - - - // Detailed description of Arguments - if (commandTarget.getOptionParser().getArguments().size() > 0) { - DataNode arguments = new DataNode(ARGUMENTS_NAME, new ArrayList<DataNode>()); - for (Argument argument : commandTarget.getOptionParser().getArguments()) { - DataNode argumentNode = new DataNode(argument.getArgumentName(), new ArrayList<DataNode>()); - argumentNode - .addChild(new DataNode(((argument.getHelp() != null && !argument.getHelp().equals("")) - ? argument.getHelp() : ""), null)); - argumentNode.addChild(new DataNode( - REQUIRED_SUB_NAME + ((argument.isRequired()) ? TRUE_TOKEN : FALSE_TOKEN), null)); - if (argument.getUnspecifiedDefaultValue() != null) { - argumentNode.addChild( - new DataNode(DEFAULTVALUE_SUB_NAME + argument.getUnspecifiedDefaultValue(), null)); - } - arguments.addChild(argumentNode); - } - root.addChild(arguments); - } - - - try { - CommandModes modes = CommandModes.getInstance(); - Collection<CommandMode> comModes = modes.getCommandModes(commandTarget.getCommandName()); - DataNode modesDN = new DataNode(MODES, new ArrayList<DataNode>()); - if (comModes != null) { - for (CommandMode cmd : comModes) { - StringBuffer sb = new StringBuffer(); - List<Option> optionalOptions = new ArrayList<Option>(); - - sb.append(commandTarget.getCommandName()).append(" "); - if (!cmd.name.equals("default")) - appendRequiredOption(sb, getOption(commandTarget, cmd.leadOption)); - - for (String opt : cmd.options) { - if (!opt.equals(cmd.leadOption)) { - Option option = getOption(commandTarget, opt); - if (option.isRequired()) { - appendRequiredOption(sb, option); - } else - optionalOptions.add(option); - } - } - - for (Option optOpt : optionalOptions) - appendOption(sb, optOpt); - - DataNode modeDN = new DataNode(cmd.text, new ArrayList<DataNode>()); - modeDN.addChild(new DataNode(sb.toString(), null)); - modesDN.addChild(modeDN); - } - root.addChild(modesDN); - } else { - // modesDN.addChild(new DataNode("No command modes found", null)); - // root.addChild(modesDN); - } - - } catch (Exception e) { - } finally { - - } - - // Detailed description of Options - if (commandTarget.getOptionParser().getOptions().size() > 0) { - DataNode options = new DataNode(OPTIONS_NAME, new ArrayList<DataNode>()); - for (Option option : commandTarget.getOptionParser().getOptions()) { - DataNode optionNode = new DataNode(option.getLongOption(), new ArrayList<DataNode>()); - optionNode.addChild(new DataNode( - ((option.getHelp() != null && !option.getHelp().equals("")) ? option.getHelp() : ""), - null)); - if (option.getSynonyms() != null && option.getSynonyms().size() > 0) { - StringBuilder builder = new StringBuilder(); - for (String string : option.getSynonyms()) { - if (builder.length() > 0) { - builder.append(","); - } - builder.append(string); - } - optionNode.addChild(new DataNode(SYNONYMS_SUB_NAME + builder.toString(), null)); - } - optionNode.addChild(new DataNode( - REQUIRED_SUB_NAME + ((option.isRequired()) ? TRUE_TOKEN : FALSE_TOKEN), null)); - if (option.getSpecifiedDefaultValue() != null - && !option.getSpecifiedDefaultValue().equals("")) { - optionNode.addChild(new DataNode( - SPECIFIEDDEFAULTVALUE_SUB_NAME + option.getSpecifiedDefaultValue(), null)); - } - if (option.getUnspecifiedDefaultValue() != null - && !option.getUnspecifiedDefaultValue().equals("")) { - optionNode.addChild(new DataNode( - UNSPECIFIEDDEFAULTVALUE_VALUE_SUB_NAME + option.getUnspecifiedDefaultValue(), null)); - } - options.addChild(optionNode); - } - root.addChild(options); - } - return new NewHelp(root); - } - - private static Option getOption(CommandTarget commandTarget, String opt) { - for (Option option : commandTarget.getOptionParser().getOptions()) { - if (option.getLongOption().equals(opt)) - return option; - } - return null; - } - - private static void appendOptions(StringBuffer buffer, CommandTarget commandTarget) { - List<Option> optionalOptions = new ArrayList<Option>(); - for (Option option : commandTarget.getOptionParser().getOptions()) { - if (option.isRequired()) { - appendRequiredOption(buffer, option); - } else { - optionalOptions.add(option); - } - } - for (Option option : optionalOptions) { - appendOption(buffer, option); - } - } - - private static void appendRequiredOption(StringBuffer buffer, Option option) { - buffer.append(" " + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption()); - String temp = buildOptionHelpText(option); - if (option.getSpecifiedDefaultValue() != null - && !option.getSpecifiedDefaultValue().equals("")) { - buffer.append("(").append(temp).append(")?"); - } else { - buffer.append(temp); - } - } - - private static void appendOption(StringBuffer buffer, Option option) { - buffer.append(" " + "[" + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption()); - String temp = buildOptionHelpText(option); - if (option.getSpecifiedDefaultValue() != null - && !option.getSpecifiedDefaultValue().equals("")) { - buffer.append("(").append(temp).append(")?"); - } else { - buffer.append(temp); - } - buffer.append("]"); - } - - private static void appendArguments(StringBuffer buffer, CommandTarget commandTarget) { - // Create a list which will store optional arguments - List<Argument> optionalArguments = new ArrayList<Argument>(); - for (Argument argument : commandTarget.getOptionParser().getArguments()) { - if (argument.isRequired()) { - buffer.append(" " + argument.getArgumentName()); - } else { - optionalArguments.add(argument); - } - } - for (Argument argument : optionalArguments) { - buffer.append(" " + "[" + argument.getArgumentName() + "]"); - } - } - - public static String buildOptionHelpText(Option option) { - String temp = SyntaxConstants.OPTION_VALUE_SPECIFIER + VALUE_FIELD; - if ((option.getValueSeparator() != null - && !CliMetaData.ANNOTATION_NULL_VALUE.equals(option.getValueSeparator()) - && !option.getValueSeparator().equals("")) - || isCollectionOrArrayType(option.getDataType())) { - temp += "(" + option.getValueSeparator() + VALUE_FIELD + ")*"; - } - return temp; - } - - private static boolean isCollectionOrArrayType(Class<?> typeToCheck) { - return typeToCheck != null - && (typeToCheck.isArray() || Collection.class.isAssignableFrom(typeToCheck)); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Argument.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Argument.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Argument.java deleted file mode 100644 index 9acbc2a..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Argument.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -/** - * Argument of a Command - * - * @since GemFire 7.0 - * - */ -public class Argument extends Parameter { - private String argumentName; - - public String getArgumentName() { - return argumentName; - } - - public void setArgumentName(String argumentName) { - this.argumentName = argumentName; - } - - @Override - public int hashCode() { - final int prime = 13; - int result = 1; - result = prime * result + ((argumentName == null) ? 0 : argumentName.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; - } - Argument argument = (Argument) obj; - if (argumentName == null) { - if (argument.getArgumentName() != null) { - return false; - } - } else if (!argumentName.equals(argument.getArgumentName())) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(Argument.class.getSimpleName()).append("[name=" + argumentName) - .append(",help=" + help).append(",required" + required + "]"); - return builder.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/AvailabilityTarget.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/AvailabilityTarget.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/AvailabilityTarget.java deleted file mode 100644 index eff5fd2..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/AvailabilityTarget.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.lang.reflect.Method; - -import org.apache.geode.management.cli.CliMetaData; -import org.apache.geode.management.cli.CliMetaData.AvailabilityMetadata; -import org.apache.geode.management.internal.cli.i18n.CliStrings; - -/** - * Used for checking availability of a command - * - * @since GemFire 7.0 - */ -public class AvailabilityTarget { - - private final Object target; - private final Method method; - private final String availabilityDescription; - - public AvailabilityTarget(Object target, Method method) { - this.target = target; - this.method = method; - AvailabilityMetadata availabilityMetadata = - this.method.getAnnotation(CliMetaData.AvailabilityMetadata.class); - String specifiedAvailabilityDesc = - CliStrings.AVAILABILITYTARGET_MSG_DEFAULT_UNAVAILABILITY_DESCRIPTION; - if (availabilityMetadata != null) { - specifiedAvailabilityDesc = availabilityMetadata.availabilityDescription(); - } - this.availabilityDescription = specifiedAvailabilityDesc; - } - - public Object getTarget() { - return target; - } - - public Method getMethod() { - return method; - } - - public String getAvailabilityDescription() { - return availabilityDescription; - } - - @Override - public int hashCode() { - final int prime = 17; - int result = 8; - result = prime * result + ((target == null) ? 0 : target.hashCode()); - result = prime * result + ((method == null) ? 0 : method.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; - } - AvailabilityTarget availabilityTarget = (AvailabilityTarget) obj; - if (target == null) { - if (availabilityTarget.getTarget() != null) { - return false; - } - } else if (!target.equals(availabilityTarget.getTarget())) { - return false; - } - if (method == null) { - if (availabilityTarget.getMethod() != null) { - return false; - } - } else if (!method.equals(availabilityTarget.getMethod())) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(AvailabilityTarget.class.getSimpleName()); - builder.append("[" + "target=" + target); - builder.append(",method=" + method); - builder.append("]"); - return builder.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/CommandTarget.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/CommandTarget.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/CommandTarget.java deleted file mode 100644 index 3dfc01a..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/CommandTarget.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.lang.reflect.InvocationTargetException; - -import org.apache.geode.management.internal.cli.GfshParser; - -/** - * Used by {@link GfshParser} to store details of a command - * - * @since GemFire 7.0 - * - */ -public class CommandTarget { - private final String commandName; - private final String[] synonyms; - private final String commandHelp; - private final GfshMethodTarget gfshMethodTarget; - private final GfshOptionParser optionParser; - private AvailabilityTarget availabilityIndicator; - - public CommandTarget(String commandName, String[] synonyms, GfshMethodTarget methodTarget, - GfshOptionParser optionParser, AvailabilityTarget availabilityIndicator, String commandHelp) { - this.commandName = commandName; - this.synonyms = synonyms; - this.gfshMethodTarget = methodTarget; - this.optionParser = optionParser; - this.availabilityIndicator = availabilityIndicator; - this.commandHelp = commandHelp; - } - - public GfshMethodTarget getGfshMethodTarget() { - return gfshMethodTarget; - } - - public GfshOptionParser getOptionParser() { - return optionParser; - } - - public boolean isAvailable() - throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { - if (availabilityIndicator != null) { - return (Boolean) availabilityIndicator.getMethod().invoke(availabilityIndicator.getTarget()); - } else { - return true; - } - } - - public AvailabilityTarget getAvailabilityIndicator() { - return availabilityIndicator; - } - - // TODO Change for concurrent access - public void setAvailabilityIndicator(AvailabilityTarget availabilityIndicator) { - this.availabilityIndicator = availabilityIndicator; - } - - public String getCommandHelp() { - return commandHelp; - } - - public CommandTarget duplicate(String key) { - return duplicate(key, null); - } - - public CommandTarget duplicate(String key, String remainingBuffer) { - return new CommandTarget( - commandName, synonyms, new GfshMethodTarget(gfshMethodTarget.getMethod(), - gfshMethodTarget.getTarget(), remainingBuffer, key), - optionParser, availabilityIndicator, commandHelp); - } - - @Override - public int hashCode() { - final int prime = 47; - int result = 3; - result = prime * result + ((commandName == null) ? 0 : commandName.hashCode()); - result = prime * result + ((commandHelp == null) ? 0 : commandHelp.hashCode()); - result = prime * result + ((gfshMethodTarget == null) ? 0 : gfshMethodTarget.hashCode()); - result = prime * result + ((optionParser == null) ? 0 : optionParser.hashCode()); - result = - prime * result + ((availabilityIndicator == null) ? 0 : availabilityIndicator.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - // If two command targets have the same OptionParser - // then they are equal - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - CommandTarget commandTarget = (CommandTarget) obj; - if (commandName == null) { - if (commandTarget.getCommandName() != null) { - return false; - } - } else if (!commandName.equals(commandTarget.getCommandName())) { - return false; - } - if (commandHelp == null) { - if (commandTarget.getCommandHelp() != null) { - return false; - } - } else if (!commandHelp.equals(commandTarget.getCommandHelp())) { - return false; - } - if (gfshMethodTarget == null) { - if (commandTarget.getGfshMethodTarget() != null) { - return false; - } - } else if (!gfshMethodTarget.equals(commandTarget.getGfshMethodTarget())) { - return false; - } - if (optionParser == null) { - if (commandTarget.getOptionParser() != null) { - return false; - } - } else if (!optionParser.equals(commandTarget.getOptionParser())) { - return false; - } - if (availabilityIndicator == null) { - if (commandTarget.getAvailabilityIndicator() != null) { - return false; - } - } else if (!availabilityIndicator.equals(commandTarget.getAvailabilityIndicator())) { - return false; - } - return true; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(CommandTarget.class.getSimpleName()).append("[" + "commandName=" + commandName) - .append(",commandHelp=" + commandHelp); - builder.append(",synonyms="); - if (synonyms != null) { - for (String string : synonyms) { - builder.append(string + " "); - } - } - builder.append(",gfshMethodTarget=" + gfshMethodTarget); - builder.append(",optionParser=" + optionParser); - builder.append(",availabilityIndicator=" + availabilityIndicator); - builder.append("]"); - return builder.toString(); - } - - public String getCommandName() { - return commandName; - } - - public String[] getSynonyms() { - return synonyms; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshMethodTarget.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshMethodTarget.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshMethodTarget.java deleted file mode 100644 index 6f28830..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshMethodTarget.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.lang.reflect.Method; - -import org.apache.commons.lang.StringUtils; -import org.springframework.util.Assert; -import org.springframework.util.ObjectUtils; - -/** - * A method that can be executed via a shell command. - * - * @since GemFire 7.0 - */ -public class GfshMethodTarget { - - // Fields - private final Method method; - private final Object target; - private final String remainingBuffer; - private final String key; - - /** - * Constructor for a <code>null remainingBuffer</code> and <code>key</code> - * - * @param method the method to invoke (required) - * @param target the object on which the method is to be invoked (required) - */ - public GfshMethodTarget(final Method method, final Object target) { - this(method, target, null, null); - } - - /** - * Constructor that allows all fields to be set - * - * @param method the method to invoke (required) - * @param target the object on which the method is to be invoked (required) - * @param remainingBuffer can be blank - * @param key can be blank - */ - public GfshMethodTarget(final Method method, final Object target, final String remainingBuffer, - final String key) { - Assert.notNull(method, "Method is required"); - Assert.notNull(target, "Target is required"); - this.key = StringUtils.trimToEmpty(key); - this.method = method; - this.remainingBuffer = remainingBuffer; - this.target = target; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (other == null) { - return false; - } - if (getClass() != other.getClass()) { - return false; - } - GfshMethodTarget gfshMethodTarget = (GfshMethodTarget) other; - if (method == null) { - if (gfshMethodTarget.getMethod() != null) { - return false; - } - } else if (!method.equals(gfshMethodTarget.getMethod())) { - return false; - } - if (target == null) { - if (gfshMethodTarget.getTarget() != null) { - return false; - } - } else if (!target.equals(gfshMethodTarget.getTarget())) { - return false; - } - return true; - } - - @Override - public int hashCode() { - return ObjectUtils.nullSafeHashCode(new Object[] {method, target}); - } - - @Override - public final String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(GfshMethodTarget.class.getSimpleName()).append("[key=" + key).append( - ",remainingBuffer=" + remainingBuffer + ",target=" + target + ",method=" + method + "]"); - return builder.toString(); - } - - public String getKey() { - return this.key; - } - - public Method getMethod() { - return this.method; - } - - public String getRemainingBuffer() { - return this.remainingBuffer; - } - - public Object getTarget() { - return this.target; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshOptionParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshOptionParser.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshOptionParser.java deleted file mode 100644 index a64933c..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/GfshOptionParser.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.util.LinkedList; - -import org.apache.geode.management.internal.cli.GfshParser; -import org.apache.geode.management.internal.cli.exceptions.CliException; - -/** - * Delegate used for parsing by {@link GfshParser} - * - * @since GemFire 7.0 - */ -public interface GfshOptionParser { - public void setArguments(LinkedList<Argument> arguments); - - public LinkedList<Argument> getArguments(); - - public void setOptions(LinkedList<Option> options); - - public LinkedList<Option> getOptions(); - - OptionSet parse(String userInput) throws CliException; -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/MethodParameter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/MethodParameter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/MethodParameter.java deleted file mode 100644 index 599fb00..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/MethodParameter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -/** - * Object used for ordering method parameters - * - * @since GemFire 7.0 - * - */ -public class MethodParameter { - private final Object parameter; - private final int parameterNo; - - public MethodParameter(Object parameter, int parameterNo) { - this.parameter = parameter; - this.parameterNo = parameterNo; - } - - public Object getParameter() { - return parameter; - } - - public int getParameterNo() { - return parameterNo; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Option.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Option.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Option.java deleted file mode 100644 index 4eec112..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Option.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.geode.management.internal.cli.parser.preprocessor.PreprocessorUtils; - -/** - * Option of a Command - * - * @since GemFire 7.0 - * - */ -public class Option extends Parameter { - - private static final String NULL = "__NULL__"; - private static final char SHORT_OPTION_DEFAULT = '\u0000'; - // Used for Option Identification - private char shortOption; - private String longOption; - private List<String> synonyms; - private List<String> aggregate; - - // Option Value related - private String specifiedDefaultValue; - - // Constraints on Option - private boolean withRequiredArgs; - private String valueSeparator; - - public Option() { - aggregate = new ArrayList<String>(); - } - - public Option(char shortOption) { - this(shortOption, null, null); - } - - public Option(char shortOption, List<String> synonyms) { - this(shortOption, null, synonyms); - } - - public Option(String longOption) { - this(SHORT_OPTION_DEFAULT, longOption, null); - } - - public Option(String longOption, List<String> synonyms) { - this(SHORT_OPTION_DEFAULT, longOption, synonyms); - } - - public Option(char shortOption, String longOption) { - this(shortOption, longOption, null); - } - - public Option(char shortOption, String longOption, List<String> synonyms) { - aggregate = new ArrayList<String>(); - this.shortOption = shortOption; - this.longOption = longOption; - this.synonyms = synonyms; - if (shortOption != SHORT_OPTION_DEFAULT) { - aggregate.add("" + shortOption); - } - if (longOption != null) { - aggregate.add(longOption); - } - if (synonyms != null) { - aggregate.addAll(synonyms); - } - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append(Option.class.getSimpleName()).append("[longOption=" + longOption) - .append(",help=" + help).append(",required=" + required + "]"); - return builder.toString(); - } - - @Override - public int hashCode() { - final int prime = 41; - int result = 1; - result = prime * result + ((longOption == null) ? 0 : longOption.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; - } - Option option = (Option) obj; - if (longOption == null) { - if (option.getLongOption() != null) { - return false; - } - } else if (!longOption.equals(option.getLongOption())) { - return false; - } - return true; - } - - public List<String> getAggregate() { - return aggregate; - } - - public char getShortOption() { - return shortOption; - } - - public boolean setShortOption(char shortOption) { - if (shortOption != SHORT_OPTION_DEFAULT) { - int index = aggregate.indexOf("" + this.shortOption); - if (index != -1) { - return false; - } else { - this.shortOption = shortOption; - aggregate.add("" + shortOption); - return true; - } - } - return false; - } - - public String getLongOption() { - return longOption; - } - - public boolean setLongOption(String longOption) { - longOption = longOption.trim(); - if (!longOption.equals("")) { - if (this.longOption == null) { - int index = aggregate.indexOf(longOption); - if (index != -1) { - return false; - } else { - this.longOption = longOption; - aggregate.add(longOption); - return true; - } - } - } - return false; - } - - public List<String> getSynonyms() { - return synonyms; - } - - public void setSynonyms(List<String> synonyms) { - this.synonyms = new ArrayList<String>(); - for (String string : synonyms) { - if (!string.equals("")) { - this.synonyms.add(string); - } - } - if (this.synonyms.size() > 0) { - this.aggregate.addAll(this.synonyms); - } - } - - public boolean isWithRequiredArgs() { - return withRequiredArgs; - } - - public void setWithRequiredArgs(boolean withRequiredArgs) { - this.withRequiredArgs = withRequiredArgs; - } - - public String[] getStringArray() { - String[] stringArray = new String[aggregate.size()]; - for (int i = 0; i < stringArray.length; i++) { - stringArray[i] = aggregate.get(i); - } - return stringArray; - } - - public String getSpecifiedDefaultValue() { - if (specifiedDefaultValue.equals(NULL)) { - return null; - } else { - return specifiedDefaultValue; - } - } - - public void setSpecifiedDefaultValue(String specifiedDefaultValue) { - this.specifiedDefaultValue = PreprocessorUtils.trim(specifiedDefaultValue).getString(); - } - - public String getValueSeparator() { - return valueSeparator; - } - - public void setValueSeparator(String valueSeparator) { - this.valueSeparator = valueSeparator; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/OptionSet.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/OptionSet.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/OptionSet.java deleted file mode 100644 index 42270e5..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/OptionSet.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Stores the result after parsing - * - * @since GemFire 7.0 - * - */ -public class OptionSet { - private Map<Option, String> optionsMap; - private Map<Argument, String> argumentsMap; - private int noOfSpacesRemoved; - private List<String> split; - private String userInput; - - public OptionSet() { - optionsMap = new HashMap<Option, String>(); - argumentsMap = new HashMap<Argument, String>(); - } - - public void put(Argument argument, String value) { - argumentsMap.put(argument, value); - } - - public void put(Option option, String value) { - optionsMap.put(option, value); - } - - public boolean hasOption(Option option) { - return optionsMap.containsKey(option); - } - - public boolean hasArgument(Argument argument) { - String string = argumentsMap.get(argument); - if (string != null) { - return true; - } else { - return false; - } - } - - public boolean hasValue(Option option) { - String string = optionsMap.get(option); - if (string != null && !string.equals("__NULL__")) { - return true; - } else { - return false; - } - } - - public String getValue(Argument argument) { - return argumentsMap.get(argument); - } - - public String getValue(Option option) { - return optionsMap.get(option); - } - - public boolean areArgumentsPresent() { - if (!argumentsMap.isEmpty()) { - return true; - } else - return false; - } - - public boolean areOptionsPresent() { - if (!optionsMap.isEmpty()) { - return true; - } else { - return false; - } - } - - public int getNoOfSpacesRemoved() { - return noOfSpacesRemoved; - } - - public void setNoOfSpacesRemoved(int noOfSpacesRemoved) { - this.noOfSpacesRemoved = noOfSpacesRemoved; - } - - /** - * @return the split - */ - public List<String> getSplit() { - return split; - } - - /** - * @param split the split to set - */ - public void setSplit(List<String> split) { - this.split = split; - } - - public String getUserInput() { - return userInput; - } - - public void setUserInput(String userInput) { - this.userInput = userInput; - } - - @Override - public String toString() { - return "OptionSet [optionsMap=" + optionsMap + ", argumentsMap=" + argumentsMap - + ", noOfSpacesRemoved=" + noOfSpacesRemoved + ", split=" + split + ", userInput=" - + userInput + "]"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Parameter.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Parameter.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Parameter.java deleted file mode 100644 index dc371b3..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/Parameter.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import org.springframework.shell.core.Converter; - -import org.apache.geode.management.internal.cli.parser.preprocessor.PreprocessorUtils; - -/** - * Parameter of a Command - * - * @since GemFire 7.0 - */ -public abstract class Parameter { - // help for the Parameter - protected String help; - - // Constraint on the Parameter - protected boolean required; - - // Useful for Value conversion - protected String context; - protected Converter<?> converter; - - // Data type of the option - protected Class<?> dataType; - - // Necessary for preserving order in - // ParseResult object - protected int parameterNo; - - // value related - protected boolean systemProvided; - protected String unspecifiedDefaultValue; - - public String getHelp() { - return help; - } - - public void setHelp(String help) { - this.help = help; - } - - public boolean isRequired() { - return required; - } - - public void setRequired(boolean required) { - this.required = required; - } - - public String getContext() { - return context; - } - - public void setContext(String context) { - this.context = context; - } - - public Converter<?> getConverter() { - return converter; - } - - // TODO Change for concurrent access. - public void setConverter(Converter<?> converter) { - this.converter = converter; - } - - public Class<?> getDataType() { - return dataType; - } - - public void setDataType(Class<?> dataType) { - this.dataType = dataType; - } - - public int getParameterNo() { - return parameterNo; - } - - public void setParameterNo(int parameterNo) { - this.parameterNo = parameterNo; - } - - public boolean isSystemProvided() { - return systemProvided; - } - - public void setSystemProvided(boolean systemProvided) { - this.systemProvided = systemProvided; - } - - public String getUnspecifiedDefaultValue() { - if (unspecifiedDefaultValue.equals("__NULL__")) { - return null; - } else { - return unspecifiedDefaultValue; - } - } - - public void setUnspecifiedDefaultValue(String unspecifiedDefaultValue) { - this.unspecifiedDefaultValue = PreprocessorUtils.trim(unspecifiedDefaultValue).getString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/ParserUtils.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/ParserUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/ParserUtils.java deleted file mode 100644 index 9faccb6..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/ParserUtils.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.geode.management.internal.cli.parser.preprocessor.PreprocessorUtils; - -/** - * - * Utility class for parsing and pre-processing - * - * The methods herein always ensure that the syntax is proper before performing the desired - * operation - * - * @since GemFire 7.0 - */ -public class ParserUtils { - public static String[] split(String input, String splitAround) { - if (input != null && splitAround != null) { - List<String> parts = new ArrayList<String>(); - StringBuffer part = new StringBuffer(); - outer: for (int i = 0; i < input.length(); i++) { - char ch = input.charAt(i); - if (splitAround.startsWith("" + ch)) { - // First check whether syntax is valid - if (PreprocessorUtils.isSyntaxValid(part.toString())) { - // This means that we need to check further whether - // the splitAround is present - StringBuffer temp = new StringBuffer(""); - for (int j = 0; j < splitAround.length() && (i + j) < input.length(); j++) { - temp.append(input.charAt((i + j))); - if (temp.toString().equals(splitAround)) { - parts.add(part.toString().trim()); - part.delete(0, part.length()); - i = i + j + 1; - if (i < input.length()) { - ch = input.charAt(i); - } else { - break outer; - } - break; - } - } - } - } - part.append(ch); - } - // Need to copy the last part in the parts list - if (part.length() > 0) { - if (!PreprocessorUtils.containsOnlyWhiteSpaces(part.toString())) { - if (!part.toString().equals(splitAround)) - parts.add(part.toString().trim()); - } - } - // Convert the list into an array - String[] split = new String[parts.size()]; - for (int i = 0; i < split.length; i++) { - split[i] = parts.get(i); - } - return split; - } else { - return null; - } - } - - public static String[] splitValues(String value, String valueSeparator) { - if (value != null && valueSeparator != null) { - String[] split = split(value, valueSeparator); - if (value.endsWith(valueSeparator) - && PreprocessorUtils.isSyntaxValid(split[split.length - 1])) { - String[] extendedSplit = new String[split.length + 1]; - for (int i = 0; i < split.length; i++) { - extendedSplit[i] = split[i]; - } - extendedSplit[split.length] = ""; - return extendedSplit; - } - - // Remove quotes from the beginning and end of split strings - for (int i = 0; i < split.length; i++) { - if ((split[i].endsWith("\"") && split[i].endsWith("\"")) - || (split[i].startsWith("\'") && split[i].endsWith("\'"))) { - split[i] = split[i].substring(1, split[i].length() - 1); - } - } - - return split; - } else { - return null; - } - } - - public static boolean contains(String value, String subString) { - if (value != null && subString != null) { - // Here we need to keep in mind that once we get the substring, we - // should check whether the syntax remains valid - StringBuffer part = new StringBuffer(); - for (int i = 0; i < value.length(); i++) { - char ch = value.charAt(i); - if (subString.startsWith("" + ch)) { - StringBuffer subPart = new StringBuffer(ch); - if (PreprocessorUtils.isSyntaxValid(part.toString())) { - for (int j = 0; j < subString.length() && (i + j) < value.length(); j++) { - subPart.append("" + value.charAt(i + j)); - if (subPart.toString().equals(subString)) { - // The subString is present - // We can return from here - return true; - } - } - } - } - part.append(ch); - } - } - return false; - } - - public static int lastIndexOf(String value, String subString) { - int index = -1; - if (value != null && subString != null) { - StringBuffer part = new StringBuffer(); - outer: for (int i = 0; i < value.length(); i++) { - char ch = value.charAt(i); - if (subString.startsWith("" + ch)) { - StringBuffer subPart = new StringBuffer(ch); - if (PreprocessorUtils.isSyntaxValid(part.toString())) { - for (int j = 0; j < subString.length() && (i + j) < value.length(); j++) { - subPart.append(value.charAt(i + j)); - if (subPart.toString().equals(subString)) { - // The subString is present - // We can return from here - index = i; - part.delete(0, part.length()); - i += j + 1; - if (i < value.length()) { - ch = value.charAt(i); - } else { - break outer; - } - } - } - } - } - part.append(ch); - } - } - return index; - } - - public static String getPadding(int numOfSpaces) { - char[] arr = new char[numOfSpaces]; - Arrays.fill(arr, ' '); - return new String(arr); - } - - public static String trimBeginning(String stringToTrim) { - if (stringToTrim.startsWith(" ")) { - int i = 0; - for (; i < stringToTrim.length(); i++) { - if (stringToTrim.charAt(i) != ' ') { - break; - } - } - stringToTrim = stringToTrim.substring(i); - } - - return stringToTrim; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/SyntaxConstants.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/SyntaxConstants.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/SyntaxConstants.java deleted file mode 100644 index 52d9212..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/SyntaxConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser; - -/** - * Syntax constants for the parser - * - * @since GemFire 7.0 - * - */ -// TODO merge with CliConstants -public class SyntaxConstants { - public static final String OPTION_VALUE_SPECIFIER = "="; - public static final String VALUE_SEPARATOR = ","; - public static final String ARGUMENT_SEPARATOR = "?"; - public static final String OPTION_SEPARATOR = " "; - public static final String SHORT_OPTION_SPECIFIER = "-"; - public static final String LONG_OPTION_SPECIFIER = "--"; - public static final String COMMAND_DELIMITER = ";"; - public static final String CONTINUATION_CHARACTER = "\\"; -} - http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/jopt/JoptOptionParser.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/jopt/JoptOptionParser.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/jopt/JoptOptionParser.java deleted file mode 100644 index 52224d4..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/jopt/JoptOptionParser.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser.jopt; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import joptsimple.ArgumentAcceptingOptionSpec; -import joptsimple.OptionException; -import joptsimple.OptionParser; -import joptsimple.OptionSpecBuilder; - -import org.apache.commons.lang.StringUtils; - -import org.apache.geode.management.internal.cli.MultipleValueConverter; -import org.apache.geode.management.internal.cli.exceptions.CliCommandOptionException; -import org.apache.geode.management.internal.cli.exceptions.ExceptionGenerator; -import org.apache.geode.management.internal.cli.parser.Argument; -import org.apache.geode.management.internal.cli.parser.GfshOptionParser; -import org.apache.geode.management.internal.cli.parser.Option; -import org.apache.geode.management.internal.cli.parser.OptionSet; -import org.apache.geode.management.internal.cli.parser.SyntaxConstants; -import org.apache.geode.management.internal.cli.parser.preprocessor.Preprocessor; -import org.apache.geode.management.internal.cli.parser.preprocessor.PreprocessorUtils; -import org.apache.geode.management.internal.cli.parser.preprocessor.TrimmedInput; -import org.apache.geode.management.internal.cli.util.HyphenFormatter; - -/** - * Implementation of {@link GfshOptionParser} which internally makes use of - * {@link joptsimple.OptionParser} - * - * Newly constructed JoptOptionParser must be loaded with arguments and options before parsing - * command strings. - * - * @since GemFire 7.0 - */ -public class JoptOptionParser implements GfshOptionParser { - - private OptionParser parser; - private LinkedList<Argument> arguments = new LinkedList<Argument>(); - private LinkedList<Option> options; - - /** - * Constructor - */ - public JoptOptionParser() { - parser = new OptionParser(true); - parser.allowsUnrecognizedOptions(); - } - - public void setArguments(LinkedList<Argument> arguments) { - List<Argument> optional = new LinkedList<Argument>(); - // Let us arrange arguments as mandatory arguments - // followed by optional arguments - for (Argument argument : arguments) { - if (argument.isRequired()) { - this.arguments.add(argument); - } else { - optional.add(argument); - } - } - for (Argument argument : optional) { - this.arguments.add(argument); - } - } - - public void setOptions(LinkedList<Option> options) { - this.options = options; - for (Option option : options) { - addJoptOptionObject(option); - } - } - - private void addJoptOptionObject(Option option) { - OptionSpecBuilder optionBuilder = null; - - optionBuilder = parser.acceptsAll(option.getAggregate(), option.getHelp()); - - /* Now set the the attributes related to the option */ - - ArgumentAcceptingOptionSpec<String> argumentSpecs = null; - - if (option.isWithRequiredArgs()) { - argumentSpecs = optionBuilder.withRequiredArg(); - } else { - argumentSpecs = optionBuilder.withOptionalArg(); - } - - // TODO: temporarily commented out as workaround for GEODE-1598 - // if (option.isRequired()) { - // argumentSpecs.required(); - // } - if (option.getValueSeparator() != null) { - argumentSpecs.withValuesSeparatedBy(option.getValueSeparator()); - } - } - - public OptionSet parse(String userInput) throws CliCommandOptionException { - OptionSet optionSet = new OptionSet(); - optionSet.setUserInput(userInput != null ? userInput.trim() : ""); - if (userInput != null) { - TrimmedInput input = PreprocessorUtils.trim(userInput); - String[] preProcessedInput = - preProcess(new HyphenFormatter().formatCommand(input.getString())); - joptsimple.OptionSet joptOptionSet = null; - CliCommandOptionException ce = null; - // int factor = 0; - try { - joptOptionSet = parser.parse(preProcessedInput); - } catch (OptionException e) { - ce = processException(e); - // TODO: joptOptionSet = e.getDetected(); // removed when geode-joptsimple was removed - } - if (joptOptionSet != null) { - - // Make sure there are no miscellaneous, unknown strings that cannot be identified as - // either options or arguments. - if (joptOptionSet.nonOptionArguments().size() > arguments.size()) { - String unknownString = (String) joptOptionSet.nonOptionArguments().get(arguments.size()); // added - // cast - // when - // geode-joptsimple - // was - // removed - // If the first option is un-parseable then it will be returned as "<option>=<value>" - // since it's - // been interpreted as an argument. However, all subsequent options will be returned as - // "<option>". - // This hack splits off the string before the "=" sign if it's the first case. - if (unknownString.matches("^-*\\w+=.*$")) { - unknownString = unknownString.substring(0, unknownString.indexOf('=')); - } - // TODO: ce = - // processException(OptionException.createUnrecognizedOptionException(unknownString, - // joptOptionSet)); // removed when geode-joptsimple was removed - } - - // First process the arguments - StringBuffer argument = new StringBuffer(); - int j = 0; - for (int i = 0; i < joptOptionSet.nonOptionArguments().size() - && j < arguments.size(); i++) { - argument = argument.append(joptOptionSet.nonOptionArguments().get(i)); - // Check for syntax of arguments before adding them to the - // option set as we want to support quoted arguments and those - // in brackets - if (PreprocessorUtils.isSyntaxValid(argument.toString())) { - optionSet.put(arguments.get(j), argument.toString()); - j++; - argument.delete(0, argument.length()); - } - } - if (argument.length() > 0) { - // Here we do not need to check for the syntax of the argument - // because the argument list is now over and this is the last - // argument which was not added due to improper syntax - optionSet.put(arguments.get(j), argument.toString()); - } - - // Now process the options - for (Option option : options) { - List<String> synonyms = option.getAggregate(); - for (String string : synonyms) { - if (joptOptionSet.has(string)) { - // Check whether the user has actually entered the - // full option or just the start - boolean present = false; - outer: for (String inputSplit : preProcessedInput) { - if (inputSplit.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) { - // Remove option prefix - inputSplit = - StringUtils.removeStart(inputSplit, SyntaxConstants.LONG_OPTION_SPECIFIER); - // Remove value specifier - inputSplit = - StringUtils.removeEnd(inputSplit, SyntaxConstants.OPTION_VALUE_SPECIFIER); - if (!inputSplit.equals("")) { - if (option.getLongOption().equals(inputSplit)) { - present = true; - break outer; - } else { - for (String optionSynonym : option.getSynonyms()) { - if (optionSynonym.equals(inputSplit)) { - present = true; - break outer; - } - } - } - } - } - } - if (present) { - if (joptOptionSet.hasArgument(string)) { - List<?> arguments = joptOptionSet.valuesOf(string); - if (arguments.size() > 1 - && !(option.getConverter() instanceof MultipleValueConverter) - && option.getValueSeparator() == null) { - List<String> optionList = new ArrayList<String>(1); - optionList.add(string); - // TODO: ce = processException(new - // MultipleArgumentsForOptionException(optionList, joptOptionSet)); // removed - // when geode-joptsimple was removed - } else if ((arguments.size() == 1 - && !(option.getConverter() instanceof MultipleValueConverter)) - || option.getValueSeparator() == null) { - optionSet.put(option, arguments.get(0).toString().trim()); - } else { - StringBuffer value = new StringBuffer(); - String valueSeparator = option.getValueSeparator(); - for (Object object : joptOptionSet.valuesOf(string)) { - if (value.length() == 0) { - value.append((String) object); - } else { - if (valueSeparator != null) { - value.append(valueSeparator + ((String) object).trim()); - } else { - value.append(((String) object).trim()); - } - } - } - optionSet.put(option, value.toString()); - } - } else { - optionSet.put(option, option.getSpecifiedDefaultValue()); - } - break; - } - } - } - } - } - - // Convert the preProcessedInput into List<String> - List<String> split = new ArrayList<String>(); - for (int i = 0; i < preProcessedInput.length; i++) { - split.add(preProcessedInput[i]); - } - optionSet.setNoOfSpacesRemoved(input.getNoOfSpacesRemoved() /* + factor */); - optionSet.setSplit(split); - if (ce != null) { - ce.setOptionSet(optionSet); - throw ce; - } - } - return optionSet; - } - - private CliCommandOptionException processException(final OptionException exception) { - return ExceptionGenerator.generate(getOption(exception), exception); - } - - private Option getOption(OptionException oe) { - Option exceptionOption = null; - Iterator<String> iterator = oe.options().iterator(); - outermost: for (Option option : options) { - /* outer: */for (String string : option.getAggregate()) { - /* inner: */while (iterator.hasNext()) { - String joptOption = iterator.next(); - if (string.equals(joptOption)) { - exceptionOption = option; - break outermost; - } - } - } - } - - if (exceptionOption == null) { - if (oe.options() != null) { - if (oe.options().size() > 0) { - exceptionOption = new Option(oe.options().iterator().next()); - } - } - } - return exceptionOption; - } - - private String[] preProcess(String userInput) { - return Preprocessor.split(userInput); - } - - public LinkedList<Argument> getArguments() { - return arguments; - } - - public LinkedList<Option> getOptions() { - return options; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/EnclosingCharacters.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/EnclosingCharacters.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/EnclosingCharacters.java deleted file mode 100644 index a35e626..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/EnclosingCharacters.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser.preprocessor; - -/** - * Used for Supporting enclosed input - * - * @since GemFire 7.0 - * - */ -public final class EnclosingCharacters { - public static final Character DOUBLE_QUOTATION = '\"'; - public static final Character SINGLE_QUOTATION = '\''; - public static final Character OPENING_CURLY_BRACE = '{'; - public static final Character CLOSING_CURLY_BRACE = '}'; - public static final Character OPENING_SQUARE_BRACKET = '['; - public static final Character CLOSING_SQUARE_BRACKET = ']'; - public static final Character OPENING_CIRCULAR_BRACKET = '('; - public static final Character CLOSING_CIRCULAR_BRACKET = ')'; -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/809d64d7/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/Preprocessor.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/Preprocessor.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/Preprocessor.java deleted file mode 100644 index 0dd875a..0000000 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/parser/preprocessor/Preprocessor.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.management.internal.cli.parser.preprocessor; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.geode.management.internal.cli.parser.SyntaxConstants; - -/** - * - * <code><br></code> This Class will serve the same purpose as pre-processors do during compilation - * of a program. - * - * It will act as pre-processor for jopt. - * - * It will split the user input into an array of strings as per the specifications of the command - * for e.g; Different command might require different value separators, different value specifiers - * and many more customizations - * - * @since GemFire 7.0 - * - */ -public class Preprocessor { - private static final String VALUE_SPECIFIER = SyntaxConstants.OPTION_VALUE_SPECIFIER; - private static final String ARGUMENT_SEPARATOR = SyntaxConstants.ARGUMENT_SEPARATOR; - private static final String OPTION_SEPARATOR = SyntaxConstants.OPTION_SEPARATOR; - private static final String LONG_OPTION_SPECIFIER = SyntaxConstants.LONG_OPTION_SPECIFIER; - private static final String OPTION_DELIMITER = OPTION_SEPARATOR + LONG_OPTION_SPECIFIER; - - public static String[] split(final String input) { - if (input == null) { - return null; - } - - final String trimInput = PreprocessorUtils.trim(input).getString(); - final int length = trimInput.length(); - final List<String> returnStrings = new ArrayList<String>(); - - int index = 0; // Current location of the character(s) in the string being examined - int startOfString = 0; // Starting index of the string we're currently parsing and preparing to - // save - - // If this first string doesn't start with the long option specifier, then there are arguments. - // Process the arguments first. - if (!trimInput.regionMatches(index, LONG_OPTION_SPECIFIER, 0, LONG_OPTION_SPECIFIER.length())) { - // Until we find the first occurrence of Option Delimiter (" --") - while (index < length - && !trimInput.regionMatches(index, OPTION_DELIMITER, 0, OPTION_DELIMITER.length())) { - // Anything inside single or double quotes gets ignored - if (trimInput.charAt(index) == '\'' || trimInput.charAt(index) == '\"') { - char charToLookFor = trimInput.charAt(index++); - // Look for the next single or double quote. Those preceded by a '\' character are - // ignored. - while (index < length && (trimInput.charAt(index) != charToLookFor - || trimInput.charAt(index - 1) == '\\')) { - index++; - } - } - - index++; - // 1. There are only arguments & we've reached the end OR - // 2. We are at index where option (" --") has started OR - // 3. One argument has finished & we are now at the next argument - check for Argument - // Separator (" ") - if (index >= length - || trimInput.regionMatches(index, OPTION_DELIMITER, 0, OPTION_DELIMITER.length()) - || trimInput.regionMatches(index, ARGUMENT_SEPARATOR, 0, ARGUMENT_SEPARATOR.length())) { - String stringToAdd = - trimInput.substring(startOfString, (index > length ? length : index)).trim(); - returnStrings.add(stringToAdd); - - if (trimInput.regionMatches(index, ARGUMENT_SEPARATOR, 0, ARGUMENT_SEPARATOR.length())) { - index += ARGUMENT_SEPARATOR.length(); - } - startOfString = index; - } - } - index += OPTION_SEPARATOR.length(); - } - - // Process the options - startOfString = index; - while (index < length) { - // Until we find the first occurrence of Option Separator (" ") or Value Specifier ("=") - while (index < length - && !trimInput.regionMatches(index, OPTION_SEPARATOR, 0, OPTION_SEPARATOR.length()) - && !trimInput.regionMatches(index, VALUE_SPECIFIER, 0, VALUE_SPECIFIER.length())) { - index++; - } - - if (startOfString != index) { - returnStrings.add(trimInput.substring(startOfString, index)); - startOfString = index + 1; - } - - // If value part (starting with "=") has started - if (trimInput.regionMatches(index++, VALUE_SPECIFIER, 0, VALUE_SPECIFIER.length())) { - startOfString = index; - - // Keep going over chars until we find the option separator ("--") - while (index < length - && !trimInput.regionMatches(index, OPTION_SEPARATOR, 0, OPTION_SEPARATOR.length())) { - // Anything inside single or double quotes gets ignored - if (index < length - && (trimInput.charAt(index) == '\'' || trimInput.charAt(index) == '\"')) { - char charToLookFor = trimInput.charAt(index++); - // Look for the next single or double quote. Those preceded by a '\' character are - // ignored. - while (index < length && (trimInput.charAt(index) != charToLookFor - || trimInput.charAt(index - 1) == '\\')) { - index++; - } - } - index++; - } - - // 1. We are done & at the end OR - // 2. There is another word which matches ("--") - if (index >= length - || trimInput.regionMatches(index, OPTION_SEPARATOR, 0, OPTION_SEPARATOR.length())) { - if (startOfString == index) { - // This place-holder value indicates to OptionParser that an option - // was specified without a value. - returnStrings.add("__NULL__"); - } else { - String stringToAdd = - trimInput.substring(startOfString, (index > length ? length : index)); - returnStrings.add(stringToAdd); - } - startOfString = index + 1; - } - index++; - } - } - - return returnStrings.toArray(new String[0]); - } -}
