View Javadoc

1   /*
2    CommandLineConstants.java
3    Creation date : 24/03/2007
4    Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5   
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    or GNU Lesser General Public License as published by the
9    Free Software Foundation; either version 3 of the License,
10   or (at your option) any later version.
11  
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16  
17   You should have received copies of the GNU General Public License
18   and GNU Lesser General Public License along with this program;
19   if not, write to the Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21   http://www.fsf.org/licensing/licenses/gpl.html
22   http://www.gnu.org/licenses/lgpl.html
23   */
24  
25  package net.sourceforge.plantumldependency.commoncli.constants;
26  
27  import static java.util.Arrays.asList;
28  import static java.util.Collections.unmodifiableSet;
29  
30  import java.util.List;
31  import java.util.Set;
32  import java.util.TreeSet;
33  
34  import net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus;
35  
36  /**
37   * The class which stores all necessary char constants as Strings.
38   *
39   * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
40   * @since 1.3.0
41   * @version 1.3.0
42   */
43  public final class CommandLineConstants {
44  
45      /** The string displayed to show command line examples. */
46      public static final String EXAMPLES_OPTIONS_CMD = "Examples:";
47  
48      /** The {@link Set} containing all important system properties as {@link String}. */
49      public static final Set < String > IMPORTANT_SYSTEM_PROPERTIES = unmodifiableSet(new TreeSet < String >(
50              asList(new String[] {"java.runtime.name", "java.version", "java.vm.name", "os.name", "os.arch",
51                      "os.version"})));
52  
53      /** The string displayed to show java command. */
54      public static final String JAVA_JAR_CMD = "java -jar ";
55  
56      /** The string displayed to show known bugs or limitations. */
57      public static final String KNOWN_BUGS_OR_LIMITATIONS_CMD = "Known bugs or program limitations:";
58  
59      /** The string displayed to show mandatory options. */
60      public static final String MANDATORY_OPTIONS_CMD = "where mandatory options are:";
61  
62      /** Set of all active option status. */
63      public static final Set < OptionStatus > OPTION_STATUS_ACTIVE_SET = createOptionStatusActiveSet(asList(OptionStatus
64              .values()));
65  
66      /** Set of all mandatory option status. */
67      public static final Set < OptionStatus > OPTION_STATUS_MANDATORY_SET = createOptionStatusMandatorySet(asList(OptionStatus
68              .values()));
69  
70      /** Set of all managed option status. */
71      public static final Set < OptionStatus > OPTION_STATUS_SET = unmodifiableSet(new TreeSet < OptionStatus >(
72              asList(OptionStatus.values())));
73  
74      /** The string displayed to show optional options. */
75      public static final String OPTIONAL_OPTIONS_CMD = "where optional options are:";
76  
77      /** The string displayed to show options main usage. */
78      public static final String OPTIONS_CMD = "[OPTIONS]";
79  
80      /** The string representing the protected dot char. */
81      public static final String PROTECTED_DOT_REGEXP = "\\.";
82  
83      /** The string displayed to show command line usage. */
84      public static final String USAGE_CMD = "Usage:";
85  
86      /**
87       * Creates the list of all option status which are considered active, meaning they have to be
88       * taken in the command line when parsing it.
89       *
90       * @param optionStatusList
91       *            the list of all {@link OptionStatus} to look for, mustn't be <code>null</code>.
92       * @return the {@link Set} of all {@link OptionStatus} which are considered active.
93       * @since 1.3.0
94       */
95      private static Set < OptionStatus > createOptionStatusActiveSet(final List < OptionStatus > optionStatusList) {
96          final Set < OptionStatus > optionStatusActiveSet = new TreeSet < OptionStatus >();
97  
98          for (final OptionStatus optionStatus : optionStatusList) {
99              if (optionStatus.isActive()) {
100                 optionStatusActiveSet.add(optionStatus);
101             }
102         }
103 
104         return unmodifiableSet(optionStatusActiveSet);
105     }
106 
107     /**
108      * Creates the list of all option status which are mandatory.
109      *
110      * @param optionStatusList
111      *            the list of all {@link OptionStatus} to look for, mustn't be <code>null</code>.
112      * @return the {@link Set} of all {@link OptionStatus} which are mandatory.
113      * @since 1.3.0
114      */
115     private static Set < OptionStatus > createOptionStatusMandatorySet(final List < OptionStatus > optionStatusList) {
116         final Set < OptionStatus > optionStatuMandatorySet = new TreeSet < OptionStatus >();
117 
118         for (final OptionStatus optionStatus : optionStatusList) {
119             if (optionStatus.isMandatory()) {
120                 optionStatuMandatorySet.add(optionStatus);
121             }
122         }
123 
124         return unmodifiableSet(optionStatuMandatorySet);
125     }
126 
127     /**
128      * Private constructor to prevent from instantiation.
129      *
130      * @since 1.3.0
131      */
132     private CommandLineConstants() {
133         super();
134     }
135 }