View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.cli2;
18  
19  import java.util.Collections;
20  import java.util.HashSet;
21  import java.util.Set;
22  
23  /**
24   * An enum of possible display settings. These settings are used to control the
25   * presence of various features in the String representations of options,
26   * CommandLines and usage strings.  Usually a Set of DisplaySetting instances
27   * will be passed to a method that will lookup the presence of the values.
28   */
29  public class DisplaySetting {
30  
31      private static final Set all = new HashSet();
32  
33      /**
34       * A Set guaranteed to contain all possible DisplaySetting values
35       */
36      public static final Set ALL = Collections.unmodifiableSet(all);
37  
38      /**
39       * A Set guaranteed to contain no DisplaySetting values
40       */
41      public static final Set NONE = Collections.EMPTY_SET;
42  
43      /**
44       * Indicates that aliases should be included
45       */
46      public static final DisplaySetting DISPLAY_ALIASES =
47          new DisplaySetting("DISPLAY_ALIASES");
48  
49      /**
50       * Indicates that optionality should be included
51       */
52      public static final DisplaySetting DISPLAY_OPTIONAL =
53          new DisplaySetting("DISPLAY_OPTIONAL");
54  
55      /**
56       * Indicates that optional child groups should be displayed in square
57       * brackets.
58       */
59      public static final DisplaySetting DISPLAY_OPTIONAL_CHILD_GROUP =
60          new DisplaySetting("DISPLAY_OPTIONAL_CHILD_GROUP");
61  
62      /**
63       * Indicates that property options should be included
64       */
65      public static final DisplaySetting DISPLAY_PROPERTY_OPTION =
66          new DisplaySetting("DISPLAY_PROPERTY_OPTION");
67  
68      /**
69       * Indicates that switches should be included enabled
70       */
71      public static final DisplaySetting DISPLAY_SWITCH_ENABLED =
72          new DisplaySetting("DISPLAY_SWITCH_ENABLED");
73  
74      /**
75       * Indicates that switches should be included disabled
76       */
77      public static final DisplaySetting DISPLAY_SWITCH_DISABLED =
78          new DisplaySetting("DISPLAY_SWITCH_DISABLED");
79  
80      /**
81       * Indicates that group names should be included
82       */
83      public static final DisplaySetting DISPLAY_GROUP_NAME =
84          new DisplaySetting("DISPLAY_GROUP_NAME");
85  
86      /**
87       * Indicates that groups should be included expanded
88       */
89      public static final DisplaySetting DISPLAY_GROUP_EXPANDED =
90          new DisplaySetting("DISPLAY_GROUP_EXPANDED");
91  
92      /**
93       * Indicates that group arguments should be included
94       */
95      public static final DisplaySetting DISPLAY_GROUP_ARGUMENT =
96          new DisplaySetting("DISPLAY_GROUP_ARGUMENT");
97  
98      /**
99       * Indicates that group outer brackets should be included
100      */
101     public static final DisplaySetting DISPLAY_GROUP_OUTER =
102         new DisplaySetting("DISPLAY_GROUP_OUTER");
103 
104     /**
105      * Indicates that arguments should be included numbered
106      */
107     public static final DisplaySetting DISPLAY_ARGUMENT_NUMBERED =
108         new DisplaySetting("DISPLAY_ARGUMENT_NUMBERED");
109 
110     /**
111      * Indicates that arguments should be included bracketed
112      */
113     public static final DisplaySetting DISPLAY_ARGUMENT_BRACKETED =
114         new DisplaySetting("DISPLAY_ARGUMENT_BRACKETED");
115 
116     /**
117      * Indicates that arguments of Parents should be included
118      */
119     public static final DisplaySetting DISPLAY_PARENT_ARGUMENT =
120         new DisplaySetting("DISPLAY_PARENT_ARGUMENT");
121 
122     /**
123      * Indicates that children of Parents should be included
124      */
125     public static final DisplaySetting DISPLAY_PARENT_CHILDREN =
126         new DisplaySetting("DISPLAY_PARENT_CHILDREN");
127 
128     /**
129      * The name of the setting
130      */
131     private final String name;
132 
133     /**
134      * The hashCode of the setting
135      */
136     private final int hashCode;
137 
138     /**
139      * Creates a new DisplaySetting with the specified name
140      * @param name the name of the setting
141      */
142     private DisplaySetting(final String name) {
143         this.name = name;
144         this.hashCode = name.hashCode();
145         all.add(this);
146     }
147 
148     public int hashCode() {
149         return hashCode;
150     }
151 
152     public boolean equals(final Object that) {
153         if (that instanceof DisplaySetting) {
154             return name.compareTo(that.toString()) == 0;
155         }
156         return false;
157     }
158 
159     public String toString() {
160         return name;
161     }
162 }