From 12f8bc9acc597b590290e4a722d305b53f891888 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 5 Jul 2011 18:10:22 +0200 Subject: [PATCH] remove unused cli pacakge, use args4j instead --- .../src/main/java/sonia/scm/cli/Argument.java | 57 ----- .../main/java/sonia/scm/cli/CliException.java | 82 ------ .../java/sonia/scm/cli/CliHelpBuilder.java | 56 ---- .../main/java/sonia/scm/cli/CliParser.java | 196 -------------- .../sonia/scm/cli/CliRequiredException.java | 53 ---- .../main/java/sonia/scm/cli/ConvertUtil.java | 113 -------- .../sonia/scm/cli/DefaultCliHelpBuilder.java | 241 ------------------ 7 files changed, 798 deletions(-) delete mode 100644 scm-core/src/main/java/sonia/scm/cli/Argument.java delete mode 100644 scm-core/src/main/java/sonia/scm/cli/CliException.java delete mode 100644 scm-core/src/main/java/sonia/scm/cli/CliHelpBuilder.java delete mode 100644 scm-core/src/main/java/sonia/scm/cli/CliParser.java delete mode 100644 scm-core/src/main/java/sonia/scm/cli/CliRequiredException.java delete mode 100644 scm-core/src/main/java/sonia/scm/cli/ConvertUtil.java delete mode 100644 scm-core/src/main/java/sonia/scm/cli/DefaultCliHelpBuilder.java diff --git a/scm-core/src/main/java/sonia/scm/cli/Argument.java b/scm-core/src/main/java/sonia/scm/cli/Argument.java deleted file mode 100644 index 0a94657201..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/Argument.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -//~--- JDK imports ------------------------------------------------------------ - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - * @author Sebastian Sdorra - */ -@Documented -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Argument -{ - String value(); - String longName() default ""; - String description() default ""; - boolean required() default false; -} diff --git a/scm-core/src/main/java/sonia/scm/cli/CliException.java b/scm-core/src/main/java/sonia/scm/cli/CliException.java deleted file mode 100644 index 88ec94e438..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/CliException.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -/** - * - * @author Sebastian Sdorra - */ -public class CliException extends Exception -{ - - /** - * Constructs ... - * - */ - public CliException() {} - - /** - * Constructs ... - * - * - * @param string - */ - public CliException(String string) - { - super(string); - } - - /** - * Constructs ... - * - * - * @param thrwbl - */ - public CliException(Throwable thrwbl) - { - super(thrwbl); - } - - /** - * Constructs ... - * - * - * @param string - * @param thrwbl - */ - public CliException(String string, Throwable thrwbl) - { - super(string, thrwbl); - } -} diff --git a/scm-core/src/main/java/sonia/scm/cli/CliHelpBuilder.java b/scm-core/src/main/java/sonia/scm/cli/CliHelpBuilder.java deleted file mode 100644 index c1f818965f..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/CliHelpBuilder.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.List; - -/** - * - * @author Sebastian Sdorra - */ -public interface CliHelpBuilder -{ - - /** - * Method description - * - * - * @param arguments - * - * @return - */ - public String createHelp(List arguments); -} diff --git a/scm-core/src/main/java/sonia/scm/cli/CliParser.java b/scm-core/src/main/java/sonia/scm/cli/CliParser.java deleted file mode 100644 index cbba7b650d..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/CliParser.java +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -//~--- JDK imports ------------------------------------------------------------ - -import java.lang.reflect.Field; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * @author Sebastian Sdorra - */ -public class CliParser -{ - - /** - * Method description - * - * - * - * @param helpBuilder - * @param clazz - * - * @return - */ - public String createHelp(CliHelpBuilder helpBuilder, Class clazz) - { - Field[] fields = clazz.getDeclaredFields(); - List arguments = new ArrayList(); - - for (Field field : fields) - { - Argument argument = field.getAnnotation(Argument.class); - - if (argument != null) - { - arguments.add(argument); - } - } - - return helpBuilder.createHelp(arguments); - } - - /** - * Method description - * - * - * @param helpBuilder - * @param object - * - * @return - */ - public String createHelp(CliHelpBuilder helpBuilder, Object object) - { - return createHelp(helpBuilder, object.getClass()); - } - - /** - * Method description - * - * - * @param object - * @param arguments - * - * @throws CliException - */ - public void parse(Object object, String[] arguments) throws CliException - { - Field[] fields = object.getClass().getDeclaredFields(); - int length = arguments.length; - - for (Field field : fields) - { - Argument argument = field.getAnnotation(Argument.class); - - if (argument != null) - { - String name = "-" + argument.value(); - String longName = "--" + argument.longName(); - boolean found = false; - - for (int i = 0; i < length; i++) - { - if (arguments[i].equals(name) - || (!longName.equals("--") && arguments[i].startsWith(longName))) - { - found = true; - - if (field.getType().isAssignableFrom(Boolean.class)) - { - setArgument(object, field, Boolean.TRUE); - } - else if (arguments[i].equals(name) && (i + 1 < length)) - { - setArgument(object, field, - ConvertUtil.convertString(field.getType(), - arguments[i + 1])); - } - else if (arguments[i].startsWith(longName + "=")) - { - String value = arguments[i].substring(longName.length() + 1); - - if ((value != null) && (value.length() > 0)) - { - setArgument(object, field, - ConvertUtil.convertString(field.getType(), value)); - } - } - else - { - throw new CliException("missing parameter for " + name); - } - } - } - - if (!found && argument.required()) - { - throw new CliRequiredException(name + " is required"); - } - } - } - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * - * @param object - * @param field - * @param value - * - * @throws CliException - */ - private void setArgument(Object object, Field field, Object value) - throws CliException - { - try - { - boolean modifyAccess = false; - - if (!field.isAccessible()) - { - field.setAccessible(true); - modifyAccess = true; - } - - field.set(object, value); - - if (modifyAccess) - { - field.setAccessible(false); - } - } - catch (Exception ex) - { - throw new CliException(ex); - } - } -} diff --git a/scm-core/src/main/java/sonia/scm/cli/CliRequiredException.java b/scm-core/src/main/java/sonia/scm/cli/CliRequiredException.java deleted file mode 100644 index 92a57f3ecc..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/CliRequiredException.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -/** - * - * @author Sebastian Sdorra - */ -public class CliRequiredException extends CliException -{ - - /** - * Constructs ... - * - * - * @param string - */ - public CliRequiredException(String string) - { - super(string); - } -} diff --git a/scm-core/src/main/java/sonia/scm/cli/ConvertUtil.java b/scm-core/src/main/java/sonia/scm/cli/ConvertUtil.java deleted file mode 100644 index 4563d0649d..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/ConvertUtil.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -//~--- non-JDK imports -------------------------------------------------------- - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -//~--- JDK imports ------------------------------------------------------------ - -import java.math.BigInteger; - -/** - * - * @author Sebastian Sdorra - */ -public class ConvertUtil -{ - - /** Field description */ - private static final Logger logger = - LoggerFactory.getLogger(ConvertUtil.class); - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @param type - * @param value - * - * @return - */ - public static Object convertString(Class type, String value) - { - Object result = null; - - try - { - if (type.isAssignableFrom(String.class)) - { - result = value; - } - else if (type.isAssignableFrom(Short.class)) - { - result = Short.parseShort(value); - } - else if (type.isAssignableFrom(Integer.class)) - { - result = Integer.parseInt(value); - } - else if (type.isAssignableFrom(Long.class)) - { - result = Long.parseLong(value); - } - else if (type.isAssignableFrom(BigInteger.class)) - { - result = new BigInteger(value); - } - else if (type.isAssignableFrom(Float.class)) - { - result = Float.parseFloat(value); - } - else if (type.isAssignableFrom(Double.class)) - { - result = Double.parseDouble(value); - } - else if (type.isAssignableFrom(Boolean.class)) - { - result = Boolean.parseBoolean(value); - } - } - catch (NumberFormatException ex) - { - logger.debug(ex.getMessage(), ex); - } - - return result; - } -} diff --git a/scm-core/src/main/java/sonia/scm/cli/DefaultCliHelpBuilder.java b/scm-core/src/main/java/sonia/scm/cli/DefaultCliHelpBuilder.java deleted file mode 100644 index db4c710022..0000000000 --- a/scm-core/src/main/java/sonia/scm/cli/DefaultCliHelpBuilder.java +++ /dev/null @@ -1,241 +0,0 @@ -/** - * Copyright (c) 2010, Sebastian Sdorra - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * http://bitbucket.org/sdorra/scm-manager - * - */ - - - -package sonia.scm.cli; - -//~--- JDK imports ------------------------------------------------------------ - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * - * @author Sebastian Sdorra - */ -public class DefaultCliHelpBuilder implements CliHelpBuilder -{ - - /** - * Constructs ... - * - */ - public DefaultCliHelpBuilder() {} - - /** - * Constructs ... - * - * - * @param prefix - * @param suffix - */ - public DefaultCliHelpBuilder(String prefix, String suffix) - { - this.prefix = prefix; - this.suffix = suffix; - } - - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @param arguments - * - * @return - */ - @Override - public String createHelp(List arguments) - { - String s = System.getProperty("line.separator"); - int paramLength = 20; - List list = new ArrayList(); - - if (arguments != null) - { - for (Argument argument : arguments) - { - HelpLine line = new HelpLine(); - String name = argument.value(); - String longName = argument.longName(); - String description = argument.description(); - StringBuilder result = new StringBuilder("-"); - - result.append(name); - - if (longName.length() > 0) - { - result.append(",--").append(longName); - } - - line.parameter = result.toString(); - - if (line.parameter.length() > paramLength) - { - paramLength = line.parameter.length(); - } - - if (description.length() > 0) - { - line.description = description; - } - - list.add(line); - } - } - - paramLength += 2; - Collections.sort(list); - - StringBuilder result = new StringBuilder(); - - if ((prefix != null) && (prefix.trim().length() > 0)) - { - result.append(prefix).append(s); - } - - for (HelpLine line : list) - { - int length = line.parameter.length(); - - result.append(line.parameter); - - for (int i = length; i < paramLength; i++) - { - result.append(" "); - } - - result.append(line.description).append(s); - } - - if ((suffix != null) && (suffix.trim().length() > 0)) - { - result.append(suffix).append(s); - } - - return result.toString(); - } - - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public String getPrefix() - { - return prefix; - } - - /** - * Method description - * - * - * @return - */ - public String getSuffix() - { - return suffix; - } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param prefix - */ - public void setPrefix(String prefix) - { - this.prefix = prefix; - } - - /** - * Method description - * - * - * @param suffix - */ - public void setSuffix(String suffix) - { - this.suffix = suffix; - } - - //~--- inner classes -------------------------------------------------------- - - /** - * Class description - * - * - * @version Enter version here..., 10/03/06 - * @author Enter your name here... - */ - private static class HelpLine implements Comparable - { - - /** - * Method description - * - * - * @param o - * - * @return - */ - @Override - public int compareTo(HelpLine o) - { - return parameter.compareTo(o.parameter); - } - - //~--- fields ------------------------------------------------------------- - - /** Field description */ - private String description; - - /** Field description */ - private String parameter; - } - - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private String prefix; - - /** Field description */ - private String suffix; -}